1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2015 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"
65 #include "fold-const.h"
66 #include "stringpool.h"
67 #include "stor-layout.h"
75 #include "insn-config.h"
86 #include "dwarf2out.h"
87 #include "dwarf2asm.h"
91 #include "diagnostic.h"
92 #include "tree-pretty-print.h"
95 #include "common/common-target.h"
96 #include "langhooks.h"
100 #include "dumpfile.h"
102 #include "tree-dfa.h"
103 #include "gdb/gdb-index.h"
104 #include "rtl-iter.h"
106 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
107 static rtx_insn *last_var_location_insn;
108 static rtx_insn *cached_next_real_insn;
109 static void dwarf2out_decl (tree);
111 #ifdef VMS_DEBUGGING_INFO
112 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
114 /* Define this macro to be a nonzero value if the directory specifications
115 which are output in the debug info should end with a separator. */
116 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
117 /* Define this macro to evaluate to a nonzero value if GCC should refrain
118 from generating indirect strings in DWARF2 debug information, for instance
119 if your target is stuck with an old version of GDB that is unable to
120 process them properly or uses VMS Debug. */
121 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
123 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
124 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
127 /* ??? Poison these here until it can be done generically. They've been
128 totally replaced in this file; make sure it stays that way. */
129 #undef DWARF2_UNWIND_INFO
130 #undef DWARF2_FRAME_INFO
131 #if (GCC_VERSION >= 3000)
132 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
135 /* The size of the target's pointer type. */
137 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
140 /* Array of RTXes referenced by the debugging information, which therefore
141 must be kept around forever. */
142 static GTY(()) vec<rtx, va_gc> *used_rtx_array;
144 /* A pointer to the base of a list of incomplete types which might be
145 completed at some later time. incomplete_types_list needs to be a
146 vec<tree, va_gc> *because we want to tell the garbage collector about
148 static GTY(()) vec<tree, va_gc> *incomplete_types;
150 /* A pointer to the base of a table of references to declaration
151 scopes. This table is a display which tracks the nesting
152 of declaration scopes at the current scope and containing
153 scopes. This table is used to find the proper place to
154 define type declaration DIE's. */
155 static GTY(()) vec<tree, va_gc> *decl_scope_table;
157 /* Pointers to various DWARF2 sections. */
158 static GTY(()) section *debug_info_section;
159 static GTY(()) section *debug_skeleton_info_section;
160 static GTY(()) section *debug_abbrev_section;
161 static GTY(()) section *debug_skeleton_abbrev_section;
162 static GTY(()) section *debug_aranges_section;
163 static GTY(()) section *debug_addr_section;
164 static GTY(()) section *debug_macinfo_section;
165 static GTY(()) section *debug_line_section;
166 static GTY(()) section *debug_skeleton_line_section;
167 static GTY(()) section *debug_loc_section;
168 static GTY(()) section *debug_pubnames_section;
169 static GTY(()) section *debug_pubtypes_section;
170 static GTY(()) section *debug_str_section;
171 static GTY(()) section *debug_str_dwo_section;
172 static GTY(()) section *debug_str_offsets_section;
173 static GTY(()) section *debug_ranges_section;
174 static GTY(()) section *debug_frame_section;
176 /* Maximum size (in bytes) of an artificially generated label. */
177 #define MAX_ARTIFICIAL_LABEL_BYTES 30
179 /* According to the (draft) DWARF 3 specification, the initial length
180 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
181 bytes are 0xffffffff, followed by the length stored in the next 8
184 However, the SGI/MIPS ABI uses an initial length which is equal to
185 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
187 #ifndef DWARF_INITIAL_LENGTH_SIZE
188 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
191 /* Round SIZE up to the nearest BOUNDARY. */
192 #define DWARF_ROUND(SIZE,BOUNDARY) \
193 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
195 /* CIE identifier. */
196 #if HOST_BITS_PER_WIDE_INT >= 64
197 #define DWARF_CIE_ID \
198 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
200 #define DWARF_CIE_ID DW_CIE_ID
204 /* A vector for a table that contains frame description
205 information for each routine. */
206 #define NOT_INDEXED (-1U)
207 #define NO_INDEX_ASSIGNED (-2U)
209 static GTY(()) vec<dw_fde_ref, va_gc> *fde_vec;
211 struct GTY((for_user)) indirect_string_node {
213 unsigned int refcount;
214 enum dwarf_form form;
219 struct indirect_string_hasher : ggc_ptr_hash<indirect_string_node>
221 typedef const char *compare_type;
223 static hashval_t hash (indirect_string_node *);
224 static bool equal (indirect_string_node *, const char *);
227 static GTY (()) hash_table<indirect_string_hasher> *debug_str_hash;
229 /* With split_debug_info, both the comp_dir and dwo_name go in the
230 main object file, rather than the dwo, similar to the force_direct
231 parameter elsewhere but with additional complications:
233 1) The string is needed in both the main object file and the dwo.
234 That is, the comp_dir and dwo_name will appear in both places.
236 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
237 DW_FORM_GNU_str_index.
239 3) GCC chooses the form to use late, depending on the size and
242 Rather than forcing the all debug string handling functions and
243 callers to deal with these complications, simply use a separate,
244 special-cased string table for any attribute that should go in the
245 main object file. This limits the complexity to just the places
248 static GTY (()) hash_table<indirect_string_hasher> *skeleton_debug_str_hash;
250 static GTY(()) int dw2_string_counter;
252 /* True if the compilation unit places functions in more than one section. */
253 static GTY(()) bool have_multiple_function_sections = false;
255 /* Whether the default text and cold text sections have been used at all. */
257 static GTY(()) bool text_section_used = false;
258 static GTY(()) bool cold_text_section_used = false;
260 /* The default cold text section. */
261 static GTY(()) section *cold_text_section;
263 /* The DIE for C++14 'auto' in a function return type. */
264 static GTY(()) dw_die_ref auto_die;
266 /* The DIE for C++14 'decltype(auto)' in a function return type. */
267 static GTY(()) dw_die_ref decltype_auto_die;
269 /* Forward declarations for functions defined in this file. */
271 static char *stripattributes (const char *);
272 static void output_call_frame_info (int);
273 static void dwarf2out_note_section_used (void);
275 /* Personality decl of current unit. Used only when assembler does not support
277 static GTY(()) rtx current_unit_personality;
279 /* Data and reference forms for relocatable data. */
280 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
281 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
283 #ifndef DEBUG_FRAME_SECTION
284 #define DEBUG_FRAME_SECTION ".debug_frame"
287 #ifndef FUNC_BEGIN_LABEL
288 #define FUNC_BEGIN_LABEL "LFB"
291 #ifndef FUNC_END_LABEL
292 #define FUNC_END_LABEL "LFE"
295 #ifndef PROLOGUE_END_LABEL
296 #define PROLOGUE_END_LABEL "LPE"
299 #ifndef EPILOGUE_BEGIN_LABEL
300 #define EPILOGUE_BEGIN_LABEL "LEB"
303 #ifndef FRAME_BEGIN_LABEL
304 #define FRAME_BEGIN_LABEL "Lframe"
306 #define CIE_AFTER_SIZE_LABEL "LSCIE"
307 #define CIE_END_LABEL "LECIE"
308 #define FDE_LABEL "LSFDE"
309 #define FDE_AFTER_SIZE_LABEL "LASFDE"
310 #define FDE_END_LABEL "LEFDE"
311 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
312 #define LINE_NUMBER_END_LABEL "LELT"
313 #define LN_PROLOG_AS_LABEL "LASLTP"
314 #define LN_PROLOG_END_LABEL "LELTP"
315 #define DIE_LABEL_PREFIX "DW"
317 /* Match the base name of a file to the base name of a compilation unit. */
320 matches_main_base (const char *path)
322 /* Cache the last query. */
323 static const char *last_path = NULL;
324 static int last_match = 0;
325 if (path != last_path)
328 int length = base_of_path (path, &base);
330 last_match = (length == main_input_baselength
331 && memcmp (base, main_input_basename, length) == 0);
336 #ifdef DEBUG_DEBUG_STRUCT
339 dump_struct_debug (tree type, enum debug_info_usage usage,
340 enum debug_struct_file criterion, int generic,
341 int matches, int result)
343 /* Find the type name. */
344 tree type_decl = TYPE_STUB_DECL (type);
346 const char *name = 0;
347 if (TREE_CODE (t) == TYPE_DECL)
350 name = IDENTIFIER_POINTER (t);
352 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
354 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
355 matches ? "bas" : "hdr",
356 generic ? "gen" : "ord",
357 usage == DINFO_USAGE_DFN ? ";" :
358 usage == DINFO_USAGE_DIR_USE ? "." : "*",
360 (void*) type_decl, name);
363 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
364 dump_struct_debug (type, usage, criterion, generic, matches, result)
368 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
373 /* Get the number of HOST_WIDE_INTs needed to represent the precision
377 get_full_len (const wide_int &op)
379 return ((op.get_precision () + HOST_BITS_PER_WIDE_INT - 1)
380 / HOST_BITS_PER_WIDE_INT);
384 should_emit_struct_debug (tree type, enum debug_info_usage usage)
386 enum debug_struct_file criterion;
388 bool generic = lang_hooks.types.generic_p (type);
391 criterion = debug_struct_generic[usage];
393 criterion = debug_struct_ordinary[usage];
395 if (criterion == DINFO_STRUCT_FILE_NONE)
396 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
397 if (criterion == DINFO_STRUCT_FILE_ANY)
398 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
400 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
402 if (type_decl != NULL)
404 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
405 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
407 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
408 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
411 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
414 /* Return a pointer to a copy of the section string name S with all
415 attributes stripped off, and an asterisk prepended (for assemble_name). */
418 stripattributes (const char *s)
420 char *stripped = XNEWVEC (char, strlen (s) + 2);
425 while (*s && *s != ',')
432 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
433 switch to the data section instead, and write out a synthetic start label
434 for collect2 the first time around. */
437 switch_to_eh_frame_section (bool back)
441 #ifdef EH_FRAME_SECTION_NAME
442 if (eh_frame_section == 0)
446 if (EH_TABLES_CAN_BE_READ_ONLY)
452 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
454 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
456 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
459 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
460 && (fde_encoding & 0x70) != DW_EH_PE_aligned
461 && (per_encoding & 0x70) != DW_EH_PE_absptr
462 && (per_encoding & 0x70) != DW_EH_PE_aligned
463 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
464 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
465 ? 0 : SECTION_WRITE);
468 flags = SECTION_WRITE;
469 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
471 #endif /* EH_FRAME_SECTION_NAME */
473 if (eh_frame_section)
474 switch_to_section (eh_frame_section);
477 /* We have no special eh_frame section. Put the information in
478 the data section and emit special labels to guide collect2. */
479 switch_to_section (data_section);
483 label = get_file_function_name ("F");
484 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
485 targetm.asm_out.globalize_label (asm_out_file,
486 IDENTIFIER_POINTER (label));
487 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
492 /* Switch [BACK] to the eh or debug frame table section, depending on
496 switch_to_frame_table_section (int for_eh, bool back)
499 switch_to_eh_frame_section (back);
502 if (!debug_frame_section)
503 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
504 SECTION_DEBUG, NULL);
505 switch_to_section (debug_frame_section);
509 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
511 enum dw_cfi_oprnd_type
512 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
517 case DW_CFA_GNU_window_save:
518 case DW_CFA_remember_state:
519 case DW_CFA_restore_state:
520 return dw_cfi_oprnd_unused;
523 case DW_CFA_advance_loc1:
524 case DW_CFA_advance_loc2:
525 case DW_CFA_advance_loc4:
526 case DW_CFA_MIPS_advance_loc8:
527 return dw_cfi_oprnd_addr;
530 case DW_CFA_offset_extended:
532 case DW_CFA_offset_extended_sf:
533 case DW_CFA_def_cfa_sf:
535 case DW_CFA_restore_extended:
536 case DW_CFA_undefined:
537 case DW_CFA_same_value:
538 case DW_CFA_def_cfa_register:
539 case DW_CFA_register:
540 case DW_CFA_expression:
541 return dw_cfi_oprnd_reg_num;
543 case DW_CFA_def_cfa_offset:
544 case DW_CFA_GNU_args_size:
545 case DW_CFA_def_cfa_offset_sf:
546 return dw_cfi_oprnd_offset;
548 case DW_CFA_def_cfa_expression:
549 return dw_cfi_oprnd_loc;
556 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
558 enum dw_cfi_oprnd_type
559 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
564 case DW_CFA_def_cfa_sf:
566 case DW_CFA_offset_extended_sf:
567 case DW_CFA_offset_extended:
568 return dw_cfi_oprnd_offset;
570 case DW_CFA_register:
571 return dw_cfi_oprnd_reg_num;
573 case DW_CFA_expression:
574 return dw_cfi_oprnd_loc;
577 return dw_cfi_oprnd_unused;
581 /* Output one FDE. */
584 output_fde (dw_fde_ref fde, bool for_eh, bool second,
585 char *section_start_label, int fde_encoding, char *augmentation,
586 bool any_lsda_needed, int lsda_encoding)
588 const char *begin, *end;
589 static unsigned int j;
592 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
594 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
596 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
597 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
598 if (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,
603 ASM_OUTPUT_LABEL (asm_out_file, l1);
606 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
608 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
609 debug_frame_section, "FDE CIE offset");
611 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
612 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
616 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
617 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
618 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
619 "FDE initial location");
620 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
621 end, begin, "FDE address range");
625 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
626 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
633 int size = size_of_encoded_value (lsda_encoding);
635 if (lsda_encoding == DW_EH_PE_aligned)
637 int offset = ( 4 /* Length */
639 + 2 * size_of_encoded_value (fde_encoding)
640 + 1 /* Augmentation size */ );
641 int pad = -offset & (PTR_SIZE - 1);
644 gcc_assert (size_of_uleb128 (size) == 1);
647 dw2_asm_output_data_uleb128 (size, "Augmentation size");
649 if (fde->uses_eh_lsda)
651 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
652 fde->funcdef_number);
653 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
654 gen_rtx_SYMBOL_REF (Pmode, l1),
656 "Language Specific Data Area");
660 if (lsda_encoding == DW_EH_PE_aligned)
661 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
662 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
663 "Language Specific Data Area (none)");
667 dw2_asm_output_data_uleb128 (0, "Augmentation size");
670 /* Loop through the Call Frame Instructions associated with this FDE. */
671 fde->dw_fde_current_label = begin;
673 size_t from, until, i;
676 until = vec_safe_length (fde->dw_fde_cfi);
678 if (fde->dw_fde_second_begin == NULL)
681 until = fde->dw_fde_switch_cfi_index;
683 from = fde->dw_fde_switch_cfi_index;
685 for (i = from; i < until; i++)
686 output_cfi ((*fde->dw_fde_cfi)[i], fde, for_eh);
689 /* If we are to emit a ref/link from function bodies to their frame tables,
690 do it now. This is typically performed to make sure that tables
691 associated with functions are dragged with them and not discarded in
692 garbage collecting links. We need to do this on a per function basis to
693 cope with -ffunction-sections. */
695 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
696 /* Switch to the function section, emit the ref to the tables, and
697 switch *back* into the table section. */
698 switch_to_section (function_section (fde->decl));
699 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
700 switch_to_frame_table_section (for_eh, true);
703 /* Pad the FDE out to an address sized boundary. */
704 ASM_OUTPUT_ALIGN (asm_out_file,
705 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
706 ASM_OUTPUT_LABEL (asm_out_file, l2);
711 /* Return true if frame description entry FDE is needed for EH. */
714 fde_needed_for_eh_p (dw_fde_ref fde)
716 if (flag_asynchronous_unwind_tables)
719 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
722 if (fde->uses_eh_lsda)
725 /* If exceptions are enabled, we have collected nothrow info. */
726 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
732 /* Output the call frame information used to record information
733 that relates to calculating the frame pointer, and records the
734 location of saved registers. */
737 output_call_frame_info (int for_eh)
742 char l1[20], l2[20], section_start_label[20];
743 bool any_lsda_needed = false;
744 char augmentation[6];
745 int augmentation_size;
746 int fde_encoding = DW_EH_PE_absptr;
747 int per_encoding = DW_EH_PE_absptr;
748 int lsda_encoding = DW_EH_PE_absptr;
750 rtx personality = NULL;
753 /* Don't emit a CIE if there won't be any FDEs. */
757 /* Nothing to do if the assembler's doing it all. */
758 if (dwarf2out_do_cfi_asm ())
761 /* If we don't have any functions we'll want to unwind out of, don't emit
762 any EH unwind information. If we make FDEs linkonce, we may have to
763 emit an empty label for an FDE that wouldn't otherwise be emitted. We
764 want to avoid having an FDE kept around when the function it refers to
765 is discarded. Example where this matters: a primary function template
766 in C++ requires EH information, an explicit specialization doesn't. */
769 bool any_eh_needed = false;
771 FOR_EACH_VEC_ELT (*fde_vec, i, fde)
773 if (fde->uses_eh_lsda)
774 any_eh_needed = any_lsda_needed = true;
775 else if (fde_needed_for_eh_p (fde))
776 any_eh_needed = true;
777 else if (TARGET_USES_WEAK_UNWIND_INFO)
778 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, 1, 1);
785 /* We're going to be generating comments, so turn on app. */
789 /* Switch to the proper frame section, first time. */
790 switch_to_frame_table_section (for_eh, false);
792 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
793 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
795 /* Output the CIE. */
796 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
797 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
798 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
799 dw2_asm_output_data (4, 0xffffffff,
800 "Initial length escape value indicating 64-bit DWARF extension");
801 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
802 "Length of Common Information Entry");
803 ASM_OUTPUT_LABEL (asm_out_file, l1);
805 /* Now that the CIE pointer is PC-relative for EH,
806 use 0 to identify the CIE. */
807 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
808 (for_eh ? 0 : DWARF_CIE_ID),
809 "CIE Identifier Tag");
811 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
812 use CIE version 1, unless that would produce incorrect results
813 due to overflowing the return register column. */
814 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
816 if (return_reg >= 256 || dwarf_version > 2)
818 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
821 augmentation_size = 0;
823 personality = current_unit_personality;
829 z Indicates that a uleb128 is present to size the
830 augmentation section.
831 L Indicates the encoding (and thus presence) of
832 an LSDA pointer in the FDE augmentation.
833 R Indicates a non-default pointer encoding for
835 P Indicates the presence of an encoding + language
836 personality routine in the CIE augmentation. */
838 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
839 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
840 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
842 p = augmentation + 1;
846 augmentation_size += 1 + size_of_encoded_value (per_encoding);
847 assemble_external_libcall (personality);
852 augmentation_size += 1;
854 if (fde_encoding != DW_EH_PE_absptr)
857 augmentation_size += 1;
859 if (p > augmentation + 1)
861 augmentation[0] = 'z';
865 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
866 if (personality && per_encoding == DW_EH_PE_aligned)
868 int offset = ( 4 /* Length */
870 + 1 /* CIE version */
871 + strlen (augmentation) + 1 /* Augmentation */
872 + size_of_uleb128 (1) /* Code alignment */
873 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
875 + 1 /* Augmentation size */
876 + 1 /* Personality encoding */ );
877 int pad = -offset & (PTR_SIZE - 1);
879 augmentation_size += pad;
881 /* Augmentations should be small, so there's scarce need to
882 iterate for a solution. Die if we exceed one uleb128 byte. */
883 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
887 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
888 if (dw_cie_version >= 4)
890 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
891 dw2_asm_output_data (1, 0, "CIE Segment Size");
893 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
894 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
895 "CIE Data Alignment Factor");
897 if (dw_cie_version == 1)
898 dw2_asm_output_data (1, return_reg, "CIE RA Column");
900 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
904 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
907 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
908 eh_data_format_name (per_encoding));
909 dw2_asm_output_encoded_addr_rtx (per_encoding,
915 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
916 eh_data_format_name (lsda_encoding));
918 if (fde_encoding != DW_EH_PE_absptr)
919 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
920 eh_data_format_name (fde_encoding));
923 FOR_EACH_VEC_ELT (*cie_cfi_vec, i, cfi)
924 output_cfi (cfi, NULL, for_eh);
926 /* Pad the CIE out to an address sized boundary. */
927 ASM_OUTPUT_ALIGN (asm_out_file,
928 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
929 ASM_OUTPUT_LABEL (asm_out_file, l2);
931 /* Loop through all of the FDE's. */
932 FOR_EACH_VEC_ELT (*fde_vec, i, fde)
936 /* Don't emit EH unwind info for leaf functions that don't need it. */
937 if (for_eh && !fde_needed_for_eh_p (fde))
940 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
941 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
942 augmentation, any_lsda_needed, lsda_encoding);
945 if (for_eh && targetm.terminate_dw2_eh_frame_info)
946 dw2_asm_output_data (4, 0, "End of Table");
948 /* Turn off app to make assembly quicker. */
953 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
956 dwarf2out_do_cfi_startproc (bool second)
960 rtx personality = get_personality_function (current_function_decl);
962 fprintf (asm_out_file, "\t.cfi_startproc\n");
966 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
969 /* ??? The GAS support isn't entirely consistent. We have to
970 handle indirect support ourselves, but PC-relative is done
971 in the assembler. Further, the assembler can't handle any
972 of the weirder relocation types. */
973 if (enc & DW_EH_PE_indirect)
974 ref = dw2_force_const_mem (ref, true);
976 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
977 output_addr_const (asm_out_file, ref);
978 fputc ('\n', asm_out_file);
981 if (crtl->uses_eh_lsda)
985 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
986 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
987 current_function_funcdef_no);
988 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
989 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
991 if (enc & DW_EH_PE_indirect)
992 ref = dw2_force_const_mem (ref, true);
994 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
995 output_addr_const (asm_out_file, ref);
996 fputc ('\n', asm_out_file);
1000 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1001 this allocation may be done before pass_final. */
1004 dwarf2out_alloc_current_fde (void)
1008 fde = ggc_cleared_alloc<dw_fde_node> ();
1009 fde->decl = current_function_decl;
1010 fde->funcdef_number = current_function_funcdef_no;
1011 fde->fde_index = vec_safe_length (fde_vec);
1012 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
1013 fde->uses_eh_lsda = crtl->uses_eh_lsda;
1014 fde->nothrow = crtl->nothrow;
1015 fde->drap_reg = INVALID_REGNUM;
1016 fde->vdrap_reg = INVALID_REGNUM;
1018 /* Record the FDE associated with this function. */
1020 vec_safe_push (fde_vec, fde);
1025 /* Output a marker (i.e. a label) for the beginning of a function, before
1029 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
1030 const char *file ATTRIBUTE_UNUSED)
1032 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1038 current_function_func_begin_label = NULL;
1040 do_frame = dwarf2out_do_frame ();
1042 /* ??? current_function_func_begin_label is also used by except.c for
1043 call-site information. We must emit this label if it might be used. */
1045 && (!flag_exceptions
1046 || targetm_common.except_unwind_info (&global_options) == UI_SJLJ))
1049 fnsec = function_section (current_function_decl);
1050 switch_to_section (fnsec);
1051 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1052 current_function_funcdef_no);
1053 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1054 current_function_funcdef_no);
1055 dup_label = xstrdup (label);
1056 current_function_func_begin_label = dup_label;
1058 /* We can elide the fde allocation if we're not emitting debug info. */
1062 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1063 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1064 would include pass_dwarf2_frame. If we've not created the FDE yet,
1068 fde = dwarf2out_alloc_current_fde ();
1070 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1071 fde->dw_fde_begin = dup_label;
1072 fde->dw_fde_current_label = dup_label;
1073 fde->in_std_section = (fnsec == text_section
1074 || (cold_text_section && fnsec == cold_text_section));
1076 /* We only want to output line number information for the genuine dwarf2
1077 prologue case, not the eh frame case. */
1078 #ifdef DWARF2_DEBUGGING_INFO
1080 dwarf2out_source_line (line, file, 0, true);
1083 if (dwarf2out_do_cfi_asm ())
1084 dwarf2out_do_cfi_startproc (false);
1087 rtx personality = get_personality_function (current_function_decl);
1088 if (!current_unit_personality)
1089 current_unit_personality = personality;
1091 /* We cannot keep a current personality per function as without CFI
1092 asm, at the point where we emit the CFI data, there is no current
1093 function anymore. */
1094 if (personality && current_unit_personality != personality)
1095 sorry ("multiple EH personalities are supported only with assemblers "
1096 "supporting .cfi_personality directive");
1100 /* Output a marker (i.e. a label) for the end of the generated code
1101 for a function prologue. This gets called *after* the prologue code has
1105 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
1106 const char *file ATTRIBUTE_UNUSED)
1108 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1110 /* Output a label to mark the endpoint of the code generated for this
1112 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
1113 current_function_funcdef_no);
1114 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
1115 current_function_funcdef_no);
1116 cfun->fde->dw_fde_vms_end_prologue = xstrdup (label);
1119 /* Output a marker (i.e. a label) for the beginning of the generated code
1120 for a function epilogue. This gets called *before* the prologue code has
1124 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1125 const char *file ATTRIBUTE_UNUSED)
1127 dw_fde_ref fde = cfun->fde;
1128 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1130 if (fde->dw_fde_vms_begin_epilogue)
1133 /* Output a label to mark the endpoint of the code generated for this
1135 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
1136 current_function_funcdef_no);
1137 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
1138 current_function_funcdef_no);
1139 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
1142 /* Output a marker (i.e. a label) for the absolute end of the generated code
1143 for a function definition. This gets called *after* the epilogue code has
1147 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1148 const char *file ATTRIBUTE_UNUSED)
1151 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1153 last_var_location_insn = NULL;
1154 cached_next_real_insn = NULL;
1156 if (dwarf2out_do_cfi_asm ())
1157 fprintf (asm_out_file, "\t.cfi_endproc\n");
1159 /* Output a label to mark the endpoint of the code generated for this
1161 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1162 current_function_funcdef_no);
1163 ASM_OUTPUT_LABEL (asm_out_file, label);
1165 gcc_assert (fde != NULL);
1166 if (fde->dw_fde_second_begin == NULL)
1167 fde->dw_fde_end = xstrdup (label);
1171 dwarf2out_frame_finish (void)
1173 /* Output call frame information. */
1174 if (targetm.debug_unwind_info () == UI_DWARF2)
1175 output_call_frame_info (0);
1177 /* Output another copy for the unwinder. */
1178 if ((flag_unwind_tables || flag_exceptions)
1179 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
1180 output_call_frame_info (1);
1183 /* Note that the current function section is being used for code. */
1186 dwarf2out_note_section_used (void)
1188 section *sec = current_function_section ();
1189 if (sec == text_section)
1190 text_section_used = true;
1191 else if (sec == cold_text_section)
1192 cold_text_section_used = true;
1195 static void var_location_switch_text_section (void);
1196 static void set_cur_line_info_table (section *);
1199 dwarf2out_switch_text_section (void)
1202 dw_fde_ref fde = cfun->fde;
1204 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1206 if (!in_cold_section_p)
1208 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
1209 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
1210 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
1214 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1215 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
1216 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1218 have_multiple_function_sections = true;
1220 /* There is no need to mark used sections when not debugging. */
1221 if (cold_text_section != NULL)
1222 dwarf2out_note_section_used ();
1224 if (dwarf2out_do_cfi_asm ())
1225 fprintf (asm_out_file, "\t.cfi_endproc\n");
1227 /* Now do the real section switch. */
1228 sect = current_function_section ();
1229 switch_to_section (sect);
1231 fde->second_in_std_section
1232 = (sect == text_section
1233 || (cold_text_section && sect == cold_text_section));
1235 if (dwarf2out_do_cfi_asm ())
1236 dwarf2out_do_cfi_startproc (true);
1238 var_location_switch_text_section ();
1240 if (cold_text_section != NULL)
1241 set_cur_line_info_table (sect);
1244 /* And now, the subset of the debugging information support code necessary
1245 for emitting location expressions. */
1247 /* Data about a single source file. */
1248 struct GTY((for_user)) dwarf_file_data {
1249 const char * filename;
1253 /* Describe an entry into the .debug_addr section. */
1257 ate_kind_rtx_dtprel,
1261 struct GTY((for_user)) addr_table_entry {
1263 unsigned int refcount;
1265 union addr_table_entry_struct_union
1267 rtx GTY ((tag ("0"))) rtl;
1268 char * GTY ((tag ("1"))) label;
1270 GTY ((desc ("%1.kind"))) addr;
1273 /* Location lists are ranges + location descriptions for that range,
1274 so you can track variables that are in different places over
1275 their entire life. */
1276 typedef struct GTY(()) dw_loc_list_struct {
1277 dw_loc_list_ref dw_loc_next;
1278 const char *begin; /* Label and addr_entry for start of range */
1279 addr_table_entry *begin_entry;
1280 const char *end; /* Label for end of range */
1281 char *ll_symbol; /* Label for beginning of location list.
1282 Only on head of list */
1283 const char *section; /* Section this loclist is relative to */
1284 dw_loc_descr_ref expr;
1286 /* True if all addresses in this and subsequent lists are known to be
1289 /* True if this list has been replaced by dw_loc_next. */
1292 /* True if the range should be emitted even if begin and end
1297 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
1299 /* Convert a DWARF stack opcode into its string name. */
1302 dwarf_stack_op_name (unsigned int op)
1304 const char *name = get_DW_OP_name (op);
1309 return "OP_<unknown>";
1312 /* Return a pointer to a newly allocated location description. Location
1313 descriptions are simple expression terms that can be strung
1314 together to form more complicated location (address) descriptions. */
1316 static inline dw_loc_descr_ref
1317 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
1318 unsigned HOST_WIDE_INT oprnd2)
1320 dw_loc_descr_ref descr = ggc_cleared_alloc<dw_loc_descr_node> ();
1322 descr->dw_loc_opc = op;
1323 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
1324 descr->dw_loc_oprnd1.val_entry = NULL;
1325 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
1326 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
1327 descr->dw_loc_oprnd2.val_entry = NULL;
1328 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
1333 /* Return a pointer to a newly allocated location description for
1336 static inline dw_loc_descr_ref
1337 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
1340 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
1343 return new_loc_descr (DW_OP_bregx, reg, offset);
1346 /* Add a location description term to a location description expression. */
1349 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
1351 dw_loc_descr_ref *d;
1353 /* Find the end of the chain. */
1354 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
1360 /* Compare two location operands for exact equality. */
1363 dw_val_equal_p (dw_val_node *a, dw_val_node *b)
1365 if (a->val_class != b->val_class)
1367 switch (a->val_class)
1369 case dw_val_class_none:
1371 case dw_val_class_addr:
1372 return rtx_equal_p (a->v.val_addr, b->v.val_addr);
1374 case dw_val_class_offset:
1375 case dw_val_class_unsigned_const:
1376 case dw_val_class_const:
1377 case dw_val_class_range_list:
1378 case dw_val_class_lineptr:
1379 case dw_val_class_macptr:
1380 /* These are all HOST_WIDE_INT, signed or unsigned. */
1381 return a->v.val_unsigned == b->v.val_unsigned;
1383 case dw_val_class_loc:
1384 return a->v.val_loc == b->v.val_loc;
1385 case dw_val_class_loc_list:
1386 return a->v.val_loc_list == b->v.val_loc_list;
1387 case dw_val_class_die_ref:
1388 return a->v.val_die_ref.die == b->v.val_die_ref.die;
1389 case dw_val_class_fde_ref:
1390 return a->v.val_fde_index == b->v.val_fde_index;
1391 case dw_val_class_lbl_id:
1392 case dw_val_class_high_pc:
1393 return strcmp (a->v.val_lbl_id, b->v.val_lbl_id) == 0;
1394 case dw_val_class_str:
1395 return a->v.val_str == b->v.val_str;
1396 case dw_val_class_flag:
1397 return a->v.val_flag == b->v.val_flag;
1398 case dw_val_class_file:
1399 return a->v.val_file == b->v.val_file;
1400 case dw_val_class_decl_ref:
1401 return a->v.val_decl_ref == b->v.val_decl_ref;
1403 case dw_val_class_const_double:
1404 return (a->v.val_double.high == b->v.val_double.high
1405 && a->v.val_double.low == b->v.val_double.low);
1407 case dw_val_class_wide_int:
1408 return *a->v.val_wide == *b->v.val_wide;
1410 case dw_val_class_vec:
1412 size_t a_len = a->v.val_vec.elt_size * a->v.val_vec.length;
1413 size_t b_len = b->v.val_vec.elt_size * b->v.val_vec.length;
1415 return (a_len == b_len
1416 && !memcmp (a->v.val_vec.array, b->v.val_vec.array, a_len));
1419 case dw_val_class_data8:
1420 return memcmp (a->v.val_data8, b->v.val_data8, 8) == 0;
1422 case dw_val_class_vms_delta:
1423 return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)
1424 && !strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1));
1429 /* Compare two location atoms for exact equality. */
1432 loc_descr_equal_p_1 (dw_loc_descr_ref a, dw_loc_descr_ref b)
1434 if (a->dw_loc_opc != b->dw_loc_opc)
1437 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1438 address size, but since we always allocate cleared storage it
1439 should be zero for other types of locations. */
1440 if (a->dtprel != b->dtprel)
1443 return (dw_val_equal_p (&a->dw_loc_oprnd1, &b->dw_loc_oprnd1)
1444 && dw_val_equal_p (&a->dw_loc_oprnd2, &b->dw_loc_oprnd2));
1447 /* Compare two complete location expressions for exact equality. */
1450 loc_descr_equal_p (dw_loc_descr_ref a, dw_loc_descr_ref b)
1456 if (a == NULL || b == NULL)
1458 if (!loc_descr_equal_p_1 (a, b))
1467 /* Add a constant OFFSET to a location expression. */
1470 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
1472 dw_loc_descr_ref loc;
1475 gcc_assert (*list_head != NULL);
1480 /* Find the end of the chain. */
1481 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
1485 if (loc->dw_loc_opc == DW_OP_fbreg
1486 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
1487 p = &loc->dw_loc_oprnd1.v.val_int;
1488 else if (loc->dw_loc_opc == DW_OP_bregx)
1489 p = &loc->dw_loc_oprnd2.v.val_int;
1491 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1492 offset. Don't optimize if an signed integer overflow would happen. */
1494 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
1495 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
1498 else if (offset > 0)
1499 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
1503 loc->dw_loc_next = int_loc_descriptor (-offset);
1504 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
1508 /* Add a constant OFFSET to a location list. */
1511 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
1514 for (d = list_head; d != NULL; d = d->dw_loc_next)
1515 loc_descr_plus_const (&d->expr, offset);
1518 #define DWARF_REF_SIZE \
1519 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1521 static unsigned long int get_base_type_offset (dw_die_ref);
1523 /* Return the size of a location descriptor. */
1525 static unsigned long
1526 size_of_loc_descr (dw_loc_descr_ref loc)
1528 unsigned long size = 1;
1530 switch (loc->dw_loc_opc)
1533 size += DWARF2_ADDR_SIZE;
1535 case DW_OP_GNU_addr_index:
1536 case DW_OP_GNU_const_index:
1537 gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
1538 size += size_of_uleb128 (loc->dw_loc_oprnd1.val_entry->index);
1557 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1560 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1565 case DW_OP_plus_uconst:
1566 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1604 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1607 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1610 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1613 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1614 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1617 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1619 case DW_OP_bit_piece:
1620 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1621 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
1623 case DW_OP_deref_size:
1624 case DW_OP_xderef_size:
1633 case DW_OP_call_ref:
1634 size += DWARF_REF_SIZE;
1636 case DW_OP_implicit_value:
1637 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1638 + loc->dw_loc_oprnd1.v.val_unsigned;
1640 case DW_OP_GNU_implicit_pointer:
1641 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1643 case DW_OP_GNU_entry_value:
1645 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
1646 size += size_of_uleb128 (op_size) + op_size;
1649 case DW_OP_GNU_const_type:
1652 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1653 size += size_of_uleb128 (o) + 1;
1654 switch (loc->dw_loc_oprnd2.val_class)
1656 case dw_val_class_vec:
1657 size += loc->dw_loc_oprnd2.v.val_vec.length
1658 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
1660 case dw_val_class_const:
1661 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1663 case dw_val_class_const_double:
1664 size += HOST_BITS_PER_DOUBLE_INT / BITS_PER_UNIT;
1666 case dw_val_class_wide_int:
1667 size += (get_full_len (*loc->dw_loc_oprnd2.v.val_wide)
1668 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
1675 case DW_OP_GNU_regval_type:
1678 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1679 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1680 + size_of_uleb128 (o);
1683 case DW_OP_GNU_deref_type:
1686 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1687 size += 1 + size_of_uleb128 (o);
1690 case DW_OP_GNU_convert:
1691 case DW_OP_GNU_reinterpret:
1692 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
1693 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1697 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1698 size += size_of_uleb128 (o);
1701 case DW_OP_GNU_parameter_ref:
1711 /* Return the size of a series of location descriptors. */
1714 size_of_locs (dw_loc_descr_ref loc)
1719 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1720 field, to avoid writing to a PCH file. */
1721 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1723 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
1725 size += size_of_loc_descr (l);
1730 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1732 l->dw_loc_addr = size;
1733 size += size_of_loc_descr (l);
1739 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
1740 static void get_ref_die_offset_label (char *, dw_die_ref);
1741 static unsigned long int get_ref_die_offset (dw_die_ref);
1743 /* Output location description stack opcode's operands (if any).
1744 The for_eh_or_skip parameter controls whether register numbers are
1745 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1746 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1747 info). This should be suppressed for the cases that have not been converted
1748 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1751 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
1753 dw_val_ref val1 = &loc->dw_loc_oprnd1;
1754 dw_val_ref val2 = &loc->dw_loc_oprnd2;
1756 switch (loc->dw_loc_opc)
1758 #ifdef DWARF2_DEBUGGING_INFO
1761 dw2_asm_output_data (2, val1->v.val_int, NULL);
1766 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
1767 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
1769 fputc ('\n', asm_out_file);
1774 dw2_asm_output_data (4, val1->v.val_int, NULL);
1779 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
1780 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
1782 fputc ('\n', asm_out_file);
1787 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
1788 dw2_asm_output_data (8, val1->v.val_int, NULL);
1795 gcc_assert (val1->val_class == dw_val_class_loc);
1796 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
1798 dw2_asm_output_data (2, offset, NULL);
1801 case DW_OP_implicit_value:
1802 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1803 switch (val2->val_class)
1805 case dw_val_class_const:
1806 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
1808 case dw_val_class_vec:
1810 unsigned int elt_size = val2->v.val_vec.elt_size;
1811 unsigned int len = val2->v.val_vec.length;
1815 if (elt_size > sizeof (HOST_WIDE_INT))
1820 for (i = 0, p = val2->v.val_vec.array;
1823 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
1824 "fp or vector constant word %u", i);
1827 case dw_val_class_const_double:
1829 unsigned HOST_WIDE_INT first, second;
1831 if (WORDS_BIG_ENDIAN)
1833 first = val2->v.val_double.high;
1834 second = val2->v.val_double.low;
1838 first = val2->v.val_double.low;
1839 second = val2->v.val_double.high;
1841 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1843 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1847 case dw_val_class_wide_int:
1850 int len = get_full_len (*val2->v.val_wide);
1851 if (WORDS_BIG_ENDIAN)
1852 for (i = len - 1; i >= 0; --i)
1853 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1854 val2->v.val_wide->elt (i), NULL);
1856 for (i = 0; i < len; ++i)
1857 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1858 val2->v.val_wide->elt (i), NULL);
1861 case dw_val_class_addr:
1862 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
1863 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
1878 case DW_OP_implicit_value:
1879 /* We currently don't make any attempt to make sure these are
1880 aligned properly like we do for the main unwind info, so
1881 don't support emitting things larger than a byte if we're
1882 only doing unwinding. */
1887 dw2_asm_output_data (1, val1->v.val_int, NULL);
1890 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1893 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
1896 dw2_asm_output_data (1, val1->v.val_int, NULL);
1898 case DW_OP_plus_uconst:
1899 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1933 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
1937 unsigned r = val1->v.val_unsigned;
1938 if (for_eh_or_skip >= 0)
1939 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
1940 gcc_assert (size_of_uleb128 (r)
1941 == size_of_uleb128 (val1->v.val_unsigned));
1942 dw2_asm_output_data_uleb128 (r, NULL);
1946 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
1950 unsigned r = val1->v.val_unsigned;
1951 if (for_eh_or_skip >= 0)
1952 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
1953 gcc_assert (size_of_uleb128 (r)
1954 == size_of_uleb128 (val1->v.val_unsigned));
1955 dw2_asm_output_data_uleb128 (r, NULL);
1956 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
1960 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1962 case DW_OP_bit_piece:
1963 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1964 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
1966 case DW_OP_deref_size:
1967 case DW_OP_xderef_size:
1968 dw2_asm_output_data (1, val1->v.val_int, NULL);
1974 if (targetm.asm_out.output_dwarf_dtprel)
1976 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
1979 fputc ('\n', asm_out_file);
1986 #ifdef DWARF2_DEBUGGING_INFO
1987 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
1994 case DW_OP_GNU_addr_index:
1995 case DW_OP_GNU_const_index:
1996 gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
1997 dw2_asm_output_data_uleb128 (loc->dw_loc_oprnd1.val_entry->index,
1998 "(index into .debug_addr)");
2001 case DW_OP_GNU_implicit_pointer:
2003 char label[MAX_ARTIFICIAL_LABEL_BYTES
2004 + HOST_BITS_PER_WIDE_INT / 2 + 2];
2005 gcc_assert (val1->val_class == dw_val_class_die_ref);
2006 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2007 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2008 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2012 case DW_OP_GNU_entry_value:
2013 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2014 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2017 case DW_OP_GNU_const_type:
2019 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2021 dw2_asm_output_data_uleb128 (o, NULL);
2022 switch (val2->val_class)
2024 case dw_val_class_const:
2025 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2026 dw2_asm_output_data (1, l, NULL);
2027 dw2_asm_output_data (l, val2->v.val_int, NULL);
2029 case dw_val_class_vec:
2031 unsigned int elt_size = val2->v.val_vec.elt_size;
2032 unsigned int len = val2->v.val_vec.length;
2037 dw2_asm_output_data (1, l, NULL);
2038 if (elt_size > sizeof (HOST_WIDE_INT))
2043 for (i = 0, p = val2->v.val_vec.array;
2046 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2047 "fp or vector constant word %u", i);
2050 case dw_val_class_const_double:
2052 unsigned HOST_WIDE_INT first, second;
2053 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2055 dw2_asm_output_data (1, 2 * l, NULL);
2056 if (WORDS_BIG_ENDIAN)
2058 first = val2->v.val_double.high;
2059 second = val2->v.val_double.low;
2063 first = val2->v.val_double.low;
2064 second = val2->v.val_double.high;
2066 dw2_asm_output_data (l, first, NULL);
2067 dw2_asm_output_data (l, second, NULL);
2070 case dw_val_class_wide_int:
2073 int len = get_full_len (*val2->v.val_wide);
2074 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2076 dw2_asm_output_data (1, len * l, NULL);
2077 if (WORDS_BIG_ENDIAN)
2078 for (i = len - 1; i >= 0; --i)
2079 dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
2081 for (i = 0; i < len; ++i)
2082 dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
2090 case DW_OP_GNU_regval_type:
2092 unsigned r = val1->v.val_unsigned;
2093 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2095 if (for_eh_or_skip >= 0)
2097 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2098 gcc_assert (size_of_uleb128 (r)
2099 == size_of_uleb128 (val1->v.val_unsigned));
2101 dw2_asm_output_data_uleb128 (r, NULL);
2102 dw2_asm_output_data_uleb128 (o, NULL);
2105 case DW_OP_GNU_deref_type:
2107 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2109 dw2_asm_output_data (1, val1->v.val_int, NULL);
2110 dw2_asm_output_data_uleb128 (o, NULL);
2113 case DW_OP_GNU_convert:
2114 case DW_OP_GNU_reinterpret:
2115 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2116 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2119 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2121 dw2_asm_output_data_uleb128 (o, NULL);
2125 case DW_OP_GNU_parameter_ref:
2128 gcc_assert (val1->val_class == dw_val_class_die_ref);
2129 o = get_ref_die_offset (val1->v.val_die_ref.die);
2130 dw2_asm_output_data (4, o, NULL);
2135 /* Other codes have no operands. */
2140 /* Output a sequence of location operations.
2141 The for_eh_or_skip parameter controls whether register numbers are
2142 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2143 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2144 info). This should be suppressed for the cases that have not been converted
2145 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2148 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2150 for (; loc != NULL; loc = loc->dw_loc_next)
2152 enum dwarf_location_atom opc = loc->dw_loc_opc;
2153 /* Output the opcode. */
2154 if (for_eh_or_skip >= 0
2155 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2157 unsigned r = (opc - DW_OP_breg0);
2158 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2159 gcc_assert (r <= 31);
2160 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2162 else if (for_eh_or_skip >= 0
2163 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2165 unsigned r = (opc - DW_OP_reg0);
2166 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2167 gcc_assert (r <= 31);
2168 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2171 dw2_asm_output_data (1, opc,
2172 "%s", dwarf_stack_op_name (opc));
2174 /* Output the operand(s) (if any). */
2175 output_loc_operands (loc, for_eh_or_skip);
2179 /* Output location description stack opcode's operands (if any).
2180 The output is single bytes on a line, suitable for .cfi_escape. */
2183 output_loc_operands_raw (dw_loc_descr_ref loc)
2185 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2186 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2188 switch (loc->dw_loc_opc)
2191 case DW_OP_GNU_addr_index:
2192 case DW_OP_GNU_const_index:
2193 case DW_OP_implicit_value:
2194 /* We cannot output addresses in .cfi_escape, only bytes. */
2200 case DW_OP_deref_size:
2201 case DW_OP_xderef_size:
2202 fputc (',', asm_out_file);
2203 dw2_asm_output_data_raw (1, val1->v.val_int);
2208 fputc (',', asm_out_file);
2209 dw2_asm_output_data_raw (2, val1->v.val_int);
2214 fputc (',', asm_out_file);
2215 dw2_asm_output_data_raw (4, val1->v.val_int);
2220 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2221 fputc (',', asm_out_file);
2222 dw2_asm_output_data_raw (8, val1->v.val_int);
2230 gcc_assert (val1->val_class == dw_val_class_loc);
2231 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2233 fputc (',', asm_out_file);
2234 dw2_asm_output_data_raw (2, offset);
2240 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2241 gcc_assert (size_of_uleb128 (r)
2242 == size_of_uleb128 (val1->v.val_unsigned));
2243 fputc (',', asm_out_file);
2244 dw2_asm_output_data_uleb128_raw (r);
2249 case DW_OP_plus_uconst:
2251 fputc (',', asm_out_file);
2252 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2255 case DW_OP_bit_piece:
2256 fputc (',', asm_out_file);
2257 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2258 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
2295 fputc (',', asm_out_file);
2296 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
2301 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2302 gcc_assert (size_of_uleb128 (r)
2303 == size_of_uleb128 (val1->v.val_unsigned));
2304 fputc (',', asm_out_file);
2305 dw2_asm_output_data_uleb128_raw (r);
2306 fputc (',', asm_out_file);
2307 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
2311 case DW_OP_GNU_implicit_pointer:
2312 case DW_OP_GNU_entry_value:
2313 case DW_OP_GNU_const_type:
2314 case DW_OP_GNU_regval_type:
2315 case DW_OP_GNU_deref_type:
2316 case DW_OP_GNU_convert:
2317 case DW_OP_GNU_reinterpret:
2318 case DW_OP_GNU_parameter_ref:
2323 /* Other codes have no operands. */
2329 output_loc_sequence_raw (dw_loc_descr_ref loc)
2333 enum dwarf_location_atom opc = loc->dw_loc_opc;
2334 /* Output the opcode. */
2335 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2337 unsigned r = (opc - DW_OP_breg0);
2338 r = DWARF2_FRAME_REG_OUT (r, 1);
2339 gcc_assert (r <= 31);
2340 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2342 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2344 unsigned r = (opc - DW_OP_reg0);
2345 r = DWARF2_FRAME_REG_OUT (r, 1);
2346 gcc_assert (r <= 31);
2347 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2349 /* Output the opcode. */
2350 fprintf (asm_out_file, "%#x", opc);
2351 output_loc_operands_raw (loc);
2353 if (!loc->dw_loc_next)
2355 loc = loc->dw_loc_next;
2357 fputc (',', asm_out_file);
2361 /* This function builds a dwarf location descriptor sequence from a
2362 dw_cfa_location, adding the given OFFSET to the result of the
2365 struct dw_loc_descr_node *
2366 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
2368 struct dw_loc_descr_node *head, *tmp;
2370 offset += cfa->offset;
2374 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
2375 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2376 head->dw_loc_oprnd1.val_entry = NULL;
2377 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2378 add_loc_descr (&head, tmp);
2381 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
2382 add_loc_descr (&head, tmp);
2386 head = new_reg_loc_descr (cfa->reg, offset);
2391 /* This function builds a dwarf location descriptor sequence for
2392 the address at OFFSET from the CFA when stack is aligned to
2395 struct dw_loc_descr_node *
2396 build_cfa_aligned_loc (dw_cfa_location *cfa,
2397 HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
2399 struct dw_loc_descr_node *head;
2400 unsigned int dwarf_fp
2401 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
2403 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2404 if (cfa->reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
2406 head = new_reg_loc_descr (dwarf_fp, 0);
2407 add_loc_descr (&head, int_loc_descriptor (alignment));
2408 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
2409 loc_descr_plus_const (&head, offset);
2412 head = new_reg_loc_descr (dwarf_fp, offset);
2416 /* And now, the support for symbolic debugging information. */
2418 /* .debug_str support. */
2420 static void dwarf2out_init (const char *);
2421 static void dwarf2out_finish (const char *);
2422 static void dwarf2out_early_finish (void);
2423 static void dwarf2out_assembly_start (void);
2424 static void dwarf2out_define (unsigned int, const char *);
2425 static void dwarf2out_undef (unsigned int, const char *);
2426 static void dwarf2out_start_source_file (unsigned, const char *);
2427 static void dwarf2out_end_source_file (unsigned);
2428 static void dwarf2out_function_decl (tree);
2429 static void dwarf2out_begin_block (unsigned, unsigned);
2430 static void dwarf2out_end_block (unsigned, unsigned);
2431 static bool dwarf2out_ignore_block (const_tree);
2432 static void dwarf2out_early_global_decl (tree);
2433 static void dwarf2out_late_global_decl (tree);
2434 static void dwarf2out_type_decl (tree, int);
2435 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
2436 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
2438 static void dwarf2out_abstract_function (tree);
2439 static void dwarf2out_var_location (rtx_insn *);
2440 static void dwarf2out_begin_function (tree);
2441 static void dwarf2out_end_function (unsigned int);
2442 static void dwarf2out_register_main_translation_unit (tree unit);
2443 static void dwarf2out_set_name (tree, tree);
2445 /* The debug hooks structure. */
2447 const struct gcc_debug_hooks dwarf2_debug_hooks =
2451 dwarf2out_early_finish,
2452 dwarf2out_assembly_start,
2455 dwarf2out_start_source_file,
2456 dwarf2out_end_source_file,
2457 dwarf2out_begin_block,
2458 dwarf2out_end_block,
2459 dwarf2out_ignore_block,
2460 dwarf2out_source_line,
2461 dwarf2out_begin_prologue,
2462 #if VMS_DEBUGGING_INFO
2463 dwarf2out_vms_end_prologue,
2464 dwarf2out_vms_begin_epilogue,
2466 debug_nothing_int_charstar,
2467 debug_nothing_int_charstar,
2469 dwarf2out_end_epilogue,
2470 dwarf2out_begin_function,
2471 dwarf2out_end_function, /* end_function */
2472 dwarf2out_register_main_translation_unit,
2473 dwarf2out_function_decl, /* function_decl */
2474 dwarf2out_early_global_decl,
2475 dwarf2out_late_global_decl,
2476 dwarf2out_type_decl, /* type_decl */
2477 dwarf2out_imported_module_or_decl,
2478 debug_nothing_tree, /* deferred_inline_function */
2479 /* The DWARF 2 backend tries to reduce debugging bloat by not
2480 emitting the abstract description of inline functions until
2481 something tries to reference them. */
2482 dwarf2out_abstract_function, /* outlining_inline_function */
2483 debug_nothing_rtx_code_label, /* label */
2484 debug_nothing_int, /* handle_pch */
2485 dwarf2out_var_location,
2486 dwarf2out_switch_text_section,
2488 1, /* start_end_main_source_file */
2489 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
2492 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks =
2495 debug_nothing_charstar,
2498 debug_nothing_int_charstar,
2499 debug_nothing_int_charstar,
2500 debug_nothing_int_charstar,
2502 debug_nothing_int_int, /* begin_block */
2503 debug_nothing_int_int, /* end_block */
2504 debug_true_const_tree, /* ignore_block */
2505 dwarf2out_source_line, /* source_line */
2506 debug_nothing_int_charstar, /* begin_prologue */
2507 debug_nothing_int_charstar, /* end_prologue */
2508 debug_nothing_int_charstar, /* begin_epilogue */
2509 debug_nothing_int_charstar, /* end_epilogue */
2510 debug_nothing_tree, /* begin_function */
2511 debug_nothing_int, /* end_function */
2512 debug_nothing_tree, /* register_main_translation_unit */
2513 debug_nothing_tree, /* function_decl */
2514 debug_nothing_tree, /* early_global_decl */
2515 debug_nothing_tree, /* late_global_decl */
2516 debug_nothing_tree_int, /* type_decl */
2517 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
2518 debug_nothing_tree, /* deferred_inline_function */
2519 debug_nothing_tree, /* outlining_inline_function */
2520 debug_nothing_rtx_code_label, /* label */
2521 debug_nothing_int, /* handle_pch */
2522 debug_nothing_rtx_insn, /* var_location */
2523 debug_nothing_void, /* switch_text_section */
2524 debug_nothing_tree_tree, /* set_name */
2525 0, /* start_end_main_source_file */
2526 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
2529 /* NOTE: In the comments in this file, many references are made to
2530 "Debugging Information Entries". This term is abbreviated as `DIE'
2531 throughout the remainder of this file. */
2533 /* An internal representation of the DWARF output is built, and then
2534 walked to generate the DWARF debugging info. The walk of the internal
2535 representation is done after the entire program has been compiled.
2536 The types below are used to describe the internal representation. */
2538 /* Whether to put type DIEs into their own section .debug_types instead
2539 of making them part of the .debug_info section. Only supported for
2540 Dwarf V4 or higher and the user didn't disable them through
2541 -fno-debug-types-section. It is more efficient to put them in a
2542 separate comdat sections since the linker will then be able to
2543 remove duplicates. But not all tools support .debug_types sections
2546 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2548 /* Various DIE's use offsets relative to the beginning of the
2549 .debug_info section to refer to each other. */
2551 typedef long int dw_offset;
2553 struct comdat_type_node;
2555 /* The entries in the line_info table more-or-less mirror the opcodes
2556 that are used in the real dwarf line table. Arrays of these entries
2557 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2560 enum dw_line_info_opcode {
2561 /* Emit DW_LNE_set_address; the operand is the label index. */
2564 /* Emit a row to the matrix with the given line. This may be done
2565 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2569 /* Emit a DW_LNS_set_file. */
2572 /* Emit a DW_LNS_set_column. */
2575 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2578 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2579 LI_set_prologue_end,
2580 LI_set_epilogue_begin,
2582 /* Emit a DW_LNE_set_discriminator. */
2583 LI_set_discriminator
2586 typedef struct GTY(()) dw_line_info_struct {
2587 enum dw_line_info_opcode opcode;
2589 } dw_line_info_entry;
2592 struct GTY(()) dw_line_info_table {
2593 /* The label that marks the end of this section. */
2594 const char *end_label;
2596 /* The values for the last row of the matrix, as collected in the table.
2597 These are used to minimize the changes to the next row. */
2598 unsigned int file_num;
2599 unsigned int line_num;
2600 unsigned int column_num;
2605 vec<dw_line_info_entry, va_gc> *entries;
2609 /* Each DIE attribute has a field specifying the attribute kind,
2610 a link to the next attribute in the chain, and an attribute value.
2611 Attributes are typically linked below the DIE they modify. */
2613 typedef struct GTY(()) dw_attr_struct {
2614 enum dwarf_attribute dw_attr;
2615 dw_val_node dw_attr_val;
2620 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2621 The children of each node form a circular list linked by
2622 die_sib. die_child points to the node *before* the "first" child node. */
2624 typedef struct GTY((chain_circular ("%h.die_sib"), for_user)) die_struct {
2625 union die_symbol_or_type_node
2627 const char * GTY ((tag ("0"))) die_symbol;
2628 comdat_type_node *GTY ((tag ("1"))) die_type_node;
2630 GTY ((desc ("%0.comdat_type_p"))) die_id;
2631 vec<dw_attr_node, va_gc> *die_attr;
2632 dw_die_ref die_parent;
2633 dw_die_ref die_child;
2635 dw_die_ref die_definition; /* ref from a specification to its definition */
2636 dw_offset die_offset;
2637 unsigned long die_abbrev;
2639 unsigned int decl_id;
2640 enum dwarf_tag die_tag;
2641 /* Die is used and must not be pruned as unused. */
2642 BOOL_BITFIELD die_perennial_p : 1;
2643 BOOL_BITFIELD comdat_type_p : 1; /* DIE has a type signature */
2644 /* Lots of spare bits. */
2648 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2649 static bool early_dwarf;
2650 struct set_early_dwarf {
2652 set_early_dwarf () : saved(early_dwarf) { early_dwarf = true; }
2653 ~set_early_dwarf () { early_dwarf = saved; }
2656 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2657 #define FOR_EACH_CHILD(die, c, expr) do { \
2658 c = die->die_child; \
2662 } while (c != die->die_child); \
2665 /* The pubname structure */
2667 typedef struct GTY(()) pubname_struct {
2674 struct GTY(()) dw_ranges {
2675 /* If this is positive, it's a block number, otherwise it's a
2676 bitwise-negated index into dw_ranges_by_label. */
2680 /* A structure to hold a macinfo entry. */
2682 typedef struct GTY(()) macinfo_struct {
2684 unsigned HOST_WIDE_INT lineno;
2690 struct GTY(()) dw_ranges_by_label {
2695 /* The comdat type node structure. */
2696 struct GTY(()) comdat_type_node
2698 dw_die_ref root_die;
2699 dw_die_ref type_die;
2700 dw_die_ref skeleton_die;
2701 char signature[DWARF_TYPE_SIGNATURE_SIZE];
2702 comdat_type_node *next;
2705 /* A list of DIEs for which we can't determine ancestry (parent_die
2706 field) just yet. Later in dwarf2out_finish we will fill in the
2708 typedef struct GTY(()) limbo_die_struct {
2710 /* The tree for which this DIE was created. We use this to
2711 determine ancestry later. */
2713 struct limbo_die_struct *next;
2717 typedef struct skeleton_chain_struct
2721 struct skeleton_chain_struct *parent;
2723 skeleton_chain_node;
2725 /* Define a macro which returns nonzero for a TYPE_DECL which was
2726 implicitly generated for a type.
2728 Note that, unlike the C front-end (which generates a NULL named
2729 TYPE_DECL node for each complete tagged type, each array type,
2730 and each function type node created) the C++ front-end generates
2731 a _named_ TYPE_DECL node for each tagged type node created.
2732 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2733 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2734 front-end, but for each type, tagged or not. */
2736 #define TYPE_DECL_IS_STUB(decl) \
2737 (DECL_NAME (decl) == NULL_TREE \
2738 || (DECL_ARTIFICIAL (decl) \
2739 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2740 /* This is necessary for stub decls that \
2741 appear in nested inline functions. */ \
2742 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2743 && (decl_ultimate_origin (decl) \
2744 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2746 /* Information concerning the compilation unit's programming
2747 language, and compiler version. */
2749 /* Fixed size portion of the DWARF compilation unit header. */
2750 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2751 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2753 /* Fixed size portion of the DWARF comdat type unit header. */
2754 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2755 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2756 + DWARF_OFFSET_SIZE)
2758 /* Fixed size portion of public names info. */
2759 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2761 /* Fixed size portion of the address range info. */
2762 #define DWARF_ARANGES_HEADER_SIZE \
2763 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2764 DWARF2_ADDR_SIZE * 2) \
2765 - DWARF_INITIAL_LENGTH_SIZE)
2767 /* Size of padding portion in the address range info. It must be
2768 aligned to twice the pointer size. */
2769 #define DWARF_ARANGES_PAD_SIZE \
2770 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2771 DWARF2_ADDR_SIZE * 2) \
2772 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2774 /* Use assembler line directives if available. */
2775 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2776 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2777 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2779 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2783 /* Minimum line offset in a special line info. opcode.
2784 This value was chosen to give a reasonable range of values. */
2785 #define DWARF_LINE_BASE -10
2787 /* First special line opcode - leave room for the standard opcodes. */
2788 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2790 /* Range of line offsets in a special line info. opcode. */
2791 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2793 /* Flag that indicates the initial value of the is_stmt_start flag.
2794 In the present implementation, we do not mark any lines as
2795 the beginning of a source statement, because that information
2796 is not made available by the GCC front-end. */
2797 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2799 /* Maximum number of operations per instruction bundle. */
2800 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2801 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2804 /* This location is used by calc_die_sizes() to keep track
2805 the offset of each DIE within the .debug_info section. */
2806 static unsigned long next_die_offset;
2808 /* Record the root of the DIE's built for the current compilation unit. */
2809 static GTY(()) dw_die_ref single_comp_unit_die;
2811 /* A list of type DIEs that have been separated into comdat sections. */
2812 static GTY(()) comdat_type_node *comdat_type_list;
2814 /* A list of DIEs with a NULL parent waiting to be relocated. */
2815 static GTY(()) limbo_die_node *limbo_die_list;
2817 /* A list of DIEs for which we may have to generate
2818 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2819 static GTY(()) limbo_die_node *deferred_asm_name;
2821 struct dwarf_file_hasher : ggc_ptr_hash<dwarf_file_data>
2823 typedef const char *compare_type;
2825 static hashval_t hash (dwarf_file_data *);
2826 static bool equal (dwarf_file_data *, const char *);
2829 /* Filenames referenced by this compilation unit. */
2830 static GTY(()) hash_table<dwarf_file_hasher> *file_table;
2832 struct decl_die_hasher : ggc_ptr_hash<die_node>
2834 typedef tree compare_type;
2836 static hashval_t hash (die_node *);
2837 static bool equal (die_node *, tree);
2839 /* A hash table of references to DIE's that describe declarations.
2840 The key is a DECL_UID() which is a unique number identifying each decl. */
2841 static GTY (()) hash_table<decl_die_hasher> *decl_die_table;
2843 struct block_die_hasher : ggc_ptr_hash<die_struct>
2845 static hashval_t hash (die_struct *);
2846 static bool equal (die_struct *, die_struct *);
2849 /* A hash table of references to DIE's that describe COMMON blocks.
2850 The key is DECL_UID() ^ die_parent. */
2851 static GTY (()) hash_table<block_die_hasher> *common_block_die_table;
2853 typedef struct GTY(()) die_arg_entry_struct {
2859 /* Node of the variable location list. */
2860 struct GTY ((chain_next ("%h.next"))) var_loc_node {
2861 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2862 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2863 in mode of the EXPR_LIST node and first EXPR_LIST operand
2864 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2865 location or NULL for padding. For larger bitsizes,
2866 mode is 0 and first operand is a CONCAT with bitsize
2867 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2868 NULL as second operand. */
2870 const char * GTY (()) label;
2871 struct var_loc_node * GTY (()) next;
2874 /* Variable location list. */
2875 struct GTY ((for_user)) var_loc_list_def {
2876 struct var_loc_node * GTY (()) first;
2878 /* Pointer to the last but one or last element of the
2879 chained list. If the list is empty, both first and
2880 last are NULL, if the list contains just one node
2881 or the last node certainly is not redundant, it points
2882 to the last node, otherwise points to the last but one.
2883 Do not mark it for GC because it is marked through the chain. */
2884 struct var_loc_node * GTY ((skip ("%h"))) last;
2886 /* Pointer to the last element before section switch,
2887 if NULL, either sections weren't switched or first
2888 is after section switch. */
2889 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
2891 /* DECL_UID of the variable decl. */
2892 unsigned int decl_id;
2894 typedef struct var_loc_list_def var_loc_list;
2896 /* Call argument location list. */
2897 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
2898 rtx GTY (()) call_arg_loc_note;
2899 const char * GTY (()) label;
2900 tree GTY (()) block;
2902 rtx GTY (()) symbol_ref;
2903 struct call_arg_loc_node * GTY (()) next;
2907 struct decl_loc_hasher : ggc_ptr_hash<var_loc_list>
2909 typedef const_tree compare_type;
2911 static hashval_t hash (var_loc_list *);
2912 static bool equal (var_loc_list *, const_tree);
2915 /* Table of decl location linked lists. */
2916 static GTY (()) hash_table<decl_loc_hasher> *decl_loc_table;
2918 /* Head and tail of call_arg_loc chain. */
2919 static GTY (()) struct call_arg_loc_node *call_arg_locations;
2920 static struct call_arg_loc_node *call_arg_loc_last;
2922 /* Number of call sites in the current function. */
2923 static int call_site_count = -1;
2924 /* Number of tail call sites in the current function. */
2925 static int tail_call_site_count = -1;
2927 /* A cached location list. */
2928 struct GTY ((for_user)) cached_dw_loc_list_def {
2929 /* The DECL_UID of the decl that this entry describes. */
2930 unsigned int decl_id;
2932 /* The cached location list. */
2933 dw_loc_list_ref loc_list;
2935 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
2937 struct dw_loc_list_hasher : ggc_ptr_hash<cached_dw_loc_list>
2940 typedef const_tree compare_type;
2942 static hashval_t hash (cached_dw_loc_list *);
2943 static bool equal (cached_dw_loc_list *, const_tree);
2946 /* Table of cached location lists. */
2947 static GTY (()) hash_table<dw_loc_list_hasher> *cached_dw_loc_list_table;
2949 /* A pointer to the base of a list of references to DIE's that
2950 are uniquely identified by their tag, presence/absence of
2951 children DIE's, and list of attribute/value pairs. */
2952 static GTY((length ("abbrev_die_table_allocated")))
2953 dw_die_ref *abbrev_die_table;
2955 /* Number of elements currently allocated for abbrev_die_table. */
2956 static GTY(()) unsigned abbrev_die_table_allocated;
2958 /* Number of elements in abbrev_die_table currently in use. */
2959 static GTY(()) unsigned abbrev_die_table_in_use;
2961 /* Size (in elements) of increments by which we may expand the
2962 abbrev_die_table. */
2963 #define ABBREV_DIE_TABLE_INCREMENT 256
2965 /* A global counter for generating labels for line number data. */
2966 static unsigned int line_info_label_num;
2968 /* The current table to which we should emit line number information
2969 for the current function. This will be set up at the beginning of
2970 assembly for the function. */
2971 static dw_line_info_table *cur_line_info_table;
2973 /* The two default tables of line number info. */
2974 static GTY(()) dw_line_info_table *text_section_line_info;
2975 static GTY(()) dw_line_info_table *cold_text_section_line_info;
2977 /* The set of all non-default tables of line number info. */
2978 static GTY(()) vec<dw_line_info_table *, va_gc> *separate_line_info;
2980 /* A flag to tell pubnames/types export if there is an info section to
2982 static bool info_section_emitted;
2984 /* A pointer to the base of a table that contains a list of publicly
2985 accessible names. */
2986 static GTY (()) vec<pubname_entry, va_gc> *pubname_table;
2988 /* A pointer to the base of a table that contains a list of publicly
2989 accessible types. */
2990 static GTY (()) vec<pubname_entry, va_gc> *pubtype_table;
2992 /* A pointer to the base of a table that contains a list of macro
2993 defines/undefines (and file start/end markers). */
2994 static GTY (()) vec<macinfo_entry, va_gc> *macinfo_table;
2996 /* True if .debug_macinfo or .debug_macros section is going to be
2998 #define have_macinfo \
2999 (debug_info_level >= DINFO_LEVEL_VERBOSE \
3000 && !macinfo_table->is_empty ())
3002 /* Array of dies for which we should generate .debug_ranges info. */
3003 static GTY ((length ("ranges_table_allocated"))) dw_ranges *ranges_table;
3005 /* Number of elements currently allocated for ranges_table. */
3006 static GTY(()) unsigned ranges_table_allocated;
3008 /* Number of elements in ranges_table currently in use. */
3009 static GTY(()) unsigned ranges_table_in_use;
3011 /* Array of pairs of labels referenced in ranges_table. */
3012 static GTY ((length ("ranges_by_label_allocated")))
3013 dw_ranges_by_label *ranges_by_label;
3015 /* Number of elements currently allocated for ranges_by_label. */
3016 static GTY(()) unsigned ranges_by_label_allocated;
3018 /* Number of elements in ranges_by_label currently in use. */
3019 static GTY(()) unsigned ranges_by_label_in_use;
3021 /* Size (in elements) of increments by which we may expand the
3023 #define RANGES_TABLE_INCREMENT 64
3025 /* Whether we have location lists that need outputting */
3026 static GTY(()) bool have_location_lists;
3028 /* Unique label counter. */
3029 static GTY(()) unsigned int loclabel_num;
3031 /* Unique label counter for point-of-call tables. */
3032 static GTY(()) unsigned int poc_label_num;
3034 /* The last file entry emitted by maybe_emit_file(). */
3035 static GTY(()) struct dwarf_file_data * last_emitted_file;
3037 /* Number of internal labels generated by gen_internal_sym(). */
3038 static GTY(()) int label_num;
3040 static GTY(()) vec<die_arg_entry, va_gc> *tmpl_value_parm_die_table;
3042 /* Instances of generic types for which we need to generate debug
3043 info that describe their generic parameters and arguments. That
3044 generation needs to happen once all types are properly laid out so
3045 we do it at the end of compilation. */
3046 static GTY(()) vec<tree, va_gc> *generic_type_instances;
3048 /* Offset from the "steady-state frame pointer" to the frame base,
3049 within the current function. */
3050 static HOST_WIDE_INT frame_pointer_fb_offset;
3051 static bool frame_pointer_fb_offset_valid;
3053 static vec<dw_die_ref> base_types;
3055 /* Flags to represent a set of attribute classes for attributes that represent
3056 a scalar value (bounds, pointers, ...). */
3059 dw_scalar_form_constant = 0x01,
3060 dw_scalar_form_exprloc = 0x02,
3061 dw_scalar_form_reference = 0x04
3064 /* Forward declarations for functions defined in this file. */
3066 static int is_pseudo_reg (const_rtx);
3067 static tree type_main_variant (tree);
3068 static int is_tagged_type (const_tree);
3069 static const char *dwarf_tag_name (unsigned);
3070 static const char *dwarf_attr_name (unsigned);
3071 static const char *dwarf_form_name (unsigned);
3072 static tree decl_ultimate_origin (const_tree);
3073 static tree decl_class_context (tree);
3074 static void add_dwarf_attr (dw_die_ref, dw_attr_node *);
3075 static inline enum dw_val_class AT_class (dw_attr_node *);
3076 static inline unsigned int AT_index (dw_attr_node *);
3077 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3078 static inline unsigned AT_flag (dw_attr_node *);
3079 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3080 static inline HOST_WIDE_INT AT_int (dw_attr_node *);
3081 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3082 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_node *);
3083 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3084 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3085 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3086 unsigned int, unsigned char *);
3087 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3088 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3089 static inline const char *AT_string (dw_attr_node *);
3090 static enum dwarf_form AT_string_form (dw_attr_node *);
3091 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3092 static void add_AT_specification (dw_die_ref, dw_die_ref);
3093 static inline dw_die_ref AT_ref (dw_attr_node *);
3094 static inline int AT_ref_external (dw_attr_node *);
3095 static inline void set_AT_ref_external (dw_attr_node *, int);
3096 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3097 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3098 static inline dw_loc_descr_ref AT_loc (dw_attr_node *);
3099 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3101 static inline dw_loc_list_ref AT_loc_list (dw_attr_node *);
3102 static addr_table_entry *add_addr_table_entry (void *, enum ate_kind);
3103 static void remove_addr_table_entry (addr_table_entry *);
3104 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx, bool);
3105 static inline rtx AT_addr (dw_attr_node *);
3106 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3107 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3108 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3109 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3110 unsigned HOST_WIDE_INT);
3111 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3112 unsigned long, bool);
3113 static inline const char *AT_lbl (dw_attr_node *);
3114 static dw_attr_node *get_AT (dw_die_ref, enum dwarf_attribute);
3115 static const char *get_AT_low_pc (dw_die_ref);
3116 static const char *get_AT_hi_pc (dw_die_ref);
3117 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3118 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3119 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3120 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3121 static bool is_cxx (void);
3122 static bool is_fortran (void);
3123 static bool is_ada (void);
3124 static bool remove_AT (dw_die_ref, enum dwarf_attribute);
3125 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3126 static void add_child_die (dw_die_ref, dw_die_ref);
3127 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3128 static dw_die_ref lookup_type_die (tree);
3129 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3130 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3131 static void equate_type_number_to_die (tree, dw_die_ref);
3132 static dw_die_ref lookup_decl_die (tree);
3133 static var_loc_list *lookup_decl_loc (const_tree);
3134 static void equate_decl_number_to_die (tree, dw_die_ref);
3135 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
3136 static void print_spaces (FILE *);
3137 static void print_die (dw_die_ref, FILE *);
3138 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3139 static dw_die_ref pop_compile_unit (dw_die_ref);
3140 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3141 static void attr_checksum (dw_attr_node *, struct md5_ctx *, int *);
3142 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3143 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3144 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3145 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3146 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_node *,
3147 struct md5_ctx *, int *);
3148 struct checksum_attributes;
3149 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3150 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3151 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3152 static void generate_type_signature (dw_die_ref, comdat_type_node *);
3153 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3154 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3155 static int same_attr_p (dw_attr_node *, dw_attr_node *, int *);
3156 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3157 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3158 static void compute_section_prefix (dw_die_ref);
3159 static int is_type_die (dw_die_ref);
3160 static int is_comdat_die (dw_die_ref);
3161 static int is_symbol_die (dw_die_ref);
3162 static inline bool is_template_instantiation (dw_die_ref);
3163 static void assign_symbol_names (dw_die_ref);
3164 static void break_out_includes (dw_die_ref);
3165 static int is_declaration_die (dw_die_ref);
3166 static int should_move_die_to_comdat (dw_die_ref);
3167 static dw_die_ref clone_as_declaration (dw_die_ref);
3168 static dw_die_ref clone_die (dw_die_ref);
3169 static dw_die_ref clone_tree (dw_die_ref);
3170 static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref);
3171 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3172 static void generate_skeleton_bottom_up (skeleton_chain_node *);
3173 static dw_die_ref generate_skeleton (dw_die_ref);
3174 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3177 static void break_out_comdat_types (dw_die_ref);
3178 static void copy_decls_for_unworthy_types (dw_die_ref);
3180 static void add_sibling_attributes (dw_die_ref);
3181 static void output_location_lists (dw_die_ref);
3182 static int constant_size (unsigned HOST_WIDE_INT);
3183 static unsigned long size_of_die (dw_die_ref);
3184 static void calc_die_sizes (dw_die_ref);
3185 static void calc_base_type_die_sizes (void);
3186 static void mark_dies (dw_die_ref);
3187 static void unmark_dies (dw_die_ref);
3188 static void unmark_all_dies (dw_die_ref);
3189 static unsigned long size_of_pubnames (vec<pubname_entry, va_gc> *);
3190 static unsigned long size_of_aranges (void);
3191 static enum dwarf_form value_format (dw_attr_node *);
3192 static void output_value_format (dw_attr_node *);
3193 static void output_abbrev_section (void);
3194 static void output_die_abbrevs (unsigned long, dw_die_ref);
3195 static void output_die_symbol (dw_die_ref);
3196 static void output_die (dw_die_ref);
3197 static void output_compilation_unit_header (void);
3198 static void output_comp_unit (dw_die_ref, int);
3199 static void output_comdat_type_unit (comdat_type_node *);
3200 static const char *dwarf2_name (tree, int);
3201 static void add_pubname (tree, dw_die_ref);
3202 static void add_enumerator_pubname (const char *, dw_die_ref);
3203 static void add_pubname_string (const char *, dw_die_ref);
3204 static void add_pubtype (tree, dw_die_ref);
3205 static void output_pubnames (vec<pubname_entry, va_gc> *);
3206 static void output_aranges (unsigned long);
3207 static unsigned int add_ranges_num (int);
3208 static unsigned int add_ranges (const_tree);
3209 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3211 static void output_ranges (void);
3212 static dw_line_info_table *new_line_info_table (void);
3213 static void output_line_info (bool);
3214 static void output_file_names (void);
3215 static dw_die_ref base_type_die (tree);
3216 static int is_base_type (tree);
3217 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
3218 static int decl_quals (const_tree);
3219 static dw_die_ref modified_type_die (tree, int, dw_die_ref);
3220 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3221 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3222 static int type_is_enum (const_tree);
3223 static unsigned int dbx_reg_number (const_rtx);
3224 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3225 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3226 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3227 enum var_init_status);
3228 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3229 enum var_init_status);
3230 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
3231 enum var_init_status);
3232 static int is_based_loc (const_rtx);
3233 static bool resolve_one_addr (rtx *);
3234 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3235 enum var_init_status);
3236 static dw_loc_descr_ref loc_descriptor (rtx, machine_mode mode,
3237 enum var_init_status);
3238 struct loc_descr_context;
3239 static dw_loc_list_ref loc_list_from_tree (tree, int,
3240 const struct loc_descr_context *);
3241 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int,
3242 const struct loc_descr_context *);
3243 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3244 static tree field_type (const_tree);
3245 static unsigned int simple_type_align_in_bits (const_tree);
3246 static unsigned int simple_decl_align_in_bits (const_tree);
3247 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3248 static HOST_WIDE_INT field_byte_offset (const_tree);
3249 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3251 static void add_data_member_location_attribute (dw_die_ref, tree);
3252 static bool add_const_value_attribute (dw_die_ref, rtx);
3253 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3254 static void insert_wide_int (const wide_int &, unsigned char *, int);
3255 static void insert_float (const_rtx, unsigned char *);
3256 static rtx rtl_for_decl_location (tree);
3257 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
3258 enum dwarf_attribute);
3259 static bool tree_add_const_value_attribute (dw_die_ref, tree);
3260 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3261 static void add_name_attribute (dw_die_ref, const char *);
3262 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3263 static void add_comp_dir_attribute (dw_die_ref);
3264 static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
3265 const struct loc_descr_context *);
3266 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree,
3267 const struct loc_descr_context *);
3268 static void add_subscript_info (dw_die_ref, tree, bool);
3269 static void add_byte_size_attribute (dw_die_ref, tree);
3270 static void add_bit_offset_attribute (dw_die_ref, tree);
3271 static void add_bit_size_attribute (dw_die_ref, tree);
3272 static void add_prototyped_attribute (dw_die_ref, tree);
3273 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
3274 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3275 static void add_src_coords_attributes (dw_die_ref, tree);
3276 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3277 static void push_decl_scope (tree);
3278 static void pop_decl_scope (void);
3279 static dw_die_ref scope_die_for (tree, dw_die_ref);
3280 static inline int local_scope_p (dw_die_ref);
3281 static inline int class_scope_p (dw_die_ref);
3282 static inline int class_or_namespace_scope_p (dw_die_ref);
3283 static void add_type_attribute (dw_die_ref, tree, int, dw_die_ref);
3284 static void add_calling_convention_attribute (dw_die_ref, tree);
3285 static const char *type_tag (const_tree);
3286 static tree member_declared_type (const_tree);
3288 static const char *decl_start_label (tree);
3290 static void gen_array_type_die (tree, dw_die_ref);
3291 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
3293 static void gen_entry_point_die (tree, dw_die_ref);
3295 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3296 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
3297 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
3298 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3299 static void gen_formal_types_die (tree, dw_die_ref);
3300 static void gen_subprogram_die (tree, dw_die_ref);
3301 static void gen_variable_die (tree, tree, dw_die_ref);
3302 static void gen_const_die (tree, dw_die_ref);
3303 static void gen_label_die (tree, dw_die_ref);
3304 static void gen_lexical_block_die (tree, dw_die_ref);
3305 static void gen_inlined_subroutine_die (tree, dw_die_ref);
3306 static void gen_field_die (tree, dw_die_ref);
3307 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3308 static dw_die_ref gen_compile_unit_die (const char *);
3309 static void gen_inheritance_die (tree, tree, dw_die_ref);
3310 static void gen_member_die (tree, dw_die_ref);
3311 static void gen_struct_or_union_type_die (tree, dw_die_ref,
3312 enum debug_info_usage);
3313 static void gen_subroutine_type_die (tree, dw_die_ref);
3314 static void gen_typedef_die (tree, dw_die_ref);
3315 static void gen_type_die (tree, dw_die_ref);
3316 static void gen_block_die (tree, dw_die_ref);
3317 static void decls_for_scope (tree, dw_die_ref);
3318 static inline int is_redundant_typedef (const_tree);
3319 static bool is_naming_typedef_decl (const_tree);
3320 static inline dw_die_ref get_context_die (tree);
3321 static void gen_namespace_die (tree, dw_die_ref);
3322 static dw_die_ref gen_namelist_decl (tree, dw_die_ref, tree);
3323 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
3324 static dw_die_ref force_decl_die (tree);
3325 static dw_die_ref force_type_die (tree);
3326 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3327 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
3328 static struct dwarf_file_data * lookup_filename (const char *);
3329 static void retry_incomplete_types (void);
3330 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3331 static void gen_generic_params_dies (tree);
3332 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
3333 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
3334 static void splice_child_die (dw_die_ref, dw_die_ref);
3335 static int file_info_cmp (const void *, const void *);
3336 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3337 const char *, const char *);
3338 static void output_loc_list (dw_loc_list_ref);
3339 static char *gen_internal_sym (const char *);
3340 static bool want_pubnames (void);
3342 static void prune_unmark_dies (dw_die_ref);
3343 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
3344 static void prune_unused_types_mark (dw_die_ref, int);
3345 static void prune_unused_types_walk (dw_die_ref);
3346 static void prune_unused_types_walk_attribs (dw_die_ref);
3347 static void prune_unused_types_prune (dw_die_ref);
3348 static void prune_unused_types (void);
3349 static int maybe_emit_file (struct dwarf_file_data *fd);
3350 static inline const char *AT_vms_delta1 (dw_attr_node *);
3351 static inline const char *AT_vms_delta2 (dw_attr_node *);
3352 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
3353 const char *, const char *);
3354 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
3355 static void gen_remaining_tmpl_value_param_die_attribute (void);
3356 static bool generic_type_p (tree);
3357 static void schedule_generic_params_dies_gen (tree t);
3358 static void gen_scheduled_generic_parms_dies (void);
3360 static const char *comp_dir_string (void);
3362 static void hash_loc_operands (dw_loc_descr_ref, inchash::hash &);
3364 /* enum for tracking thread-local variables whose address is really an offset
3365 relative to the TLS pointer, which will need link-time relocation, but will
3366 not need relocation by the DWARF consumer. */
3374 /* Return the operator to use for an address of a variable. For dtprel_true, we
3375 use DW_OP_const*. For regular variables, which need both link-time
3376 relocation and consumer-level relocation (e.g., to account for shared objects
3377 loaded at a random address), we use DW_OP_addr*. */
3379 static inline enum dwarf_location_atom
3380 dw_addr_op (enum dtprel_bool dtprel)
3382 if (dtprel == dtprel_true)
3383 return (dwarf_split_debug_info ? DW_OP_GNU_const_index
3384 : (DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u));
3386 return dwarf_split_debug_info ? DW_OP_GNU_addr_index : DW_OP_addr;
3389 /* Return a pointer to a newly allocated address location description. If
3390 dwarf_split_debug_info is true, then record the address with the appropriate
3392 static inline dw_loc_descr_ref
3393 new_addr_loc_descr (rtx addr, enum dtprel_bool dtprel)
3395 dw_loc_descr_ref ref = new_loc_descr (dw_addr_op (dtprel), 0, 0);
3397 ref->dw_loc_oprnd1.val_class = dw_val_class_addr;
3398 ref->dw_loc_oprnd1.v.val_addr = addr;
3399 ref->dtprel = dtprel;
3400 if (dwarf_split_debug_info)
3401 ref->dw_loc_oprnd1.val_entry
3402 = add_addr_table_entry (addr,
3403 dtprel ? ate_kind_rtx_dtprel : ate_kind_rtx);
3405 ref->dw_loc_oprnd1.val_entry = NULL;
3410 /* Section names used to hold DWARF debugging information. */
3412 #ifndef DEBUG_INFO_SECTION
3413 #define DEBUG_INFO_SECTION ".debug_info"
3415 #ifndef DEBUG_DWO_INFO_SECTION
3416 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3418 #ifndef DEBUG_ABBREV_SECTION
3419 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3421 #ifndef DEBUG_DWO_ABBREV_SECTION
3422 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3424 #ifndef DEBUG_ARANGES_SECTION
3425 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3427 #ifndef DEBUG_ADDR_SECTION
3428 #define DEBUG_ADDR_SECTION ".debug_addr"
3430 #ifndef DEBUG_NORM_MACINFO_SECTION
3431 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3433 #ifndef DEBUG_DWO_MACINFO_SECTION
3434 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3436 #ifndef DEBUG_MACINFO_SECTION
3437 #define DEBUG_MACINFO_SECTION \
3438 (!dwarf_split_debug_info \
3439 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3441 #ifndef DEBUG_NORM_MACRO_SECTION
3442 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3444 #ifndef DEBUG_DWO_MACRO_SECTION
3445 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3447 #ifndef DEBUG_MACRO_SECTION
3448 #define DEBUG_MACRO_SECTION \
3449 (!dwarf_split_debug_info \
3450 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3452 #ifndef DEBUG_LINE_SECTION
3453 #define DEBUG_LINE_SECTION ".debug_line"
3455 #ifndef DEBUG_DWO_LINE_SECTION
3456 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3458 #ifndef DEBUG_LOC_SECTION
3459 #define DEBUG_LOC_SECTION ".debug_loc"
3461 #ifndef DEBUG_DWO_LOC_SECTION
3462 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3464 #ifndef DEBUG_PUBNAMES_SECTION
3465 #define DEBUG_PUBNAMES_SECTION \
3466 ((debug_generate_pub_sections == 2) \
3467 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3469 #ifndef DEBUG_PUBTYPES_SECTION
3470 #define DEBUG_PUBTYPES_SECTION \
3471 ((debug_generate_pub_sections == 2) \
3472 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3474 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3475 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3476 #ifndef DEBUG_STR_OFFSETS_SECTION
3477 #define DEBUG_STR_OFFSETS_SECTION \
3478 (!dwarf_split_debug_info \
3479 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3481 #ifndef DEBUG_STR_DWO_SECTION
3482 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3484 #ifndef DEBUG_STR_SECTION
3485 #define DEBUG_STR_SECTION ".debug_str"
3487 #ifndef DEBUG_RANGES_SECTION
3488 #define DEBUG_RANGES_SECTION ".debug_ranges"
3491 /* Standard ELF section names for compiled code and data. */
3492 #ifndef TEXT_SECTION_NAME
3493 #define TEXT_SECTION_NAME ".text"
3496 /* Section flags for .debug_macinfo/.debug_macro section. */
3497 #define DEBUG_MACRO_SECTION_FLAGS \
3498 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3500 /* Section flags for .debug_str section. */
3501 #define DEBUG_STR_SECTION_FLAGS \
3502 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3503 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3506 /* Section flags for .debug_str.dwo section. */
3507 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3509 /* Labels we insert at beginning sections we can reference instead of
3510 the section names themselves. */
3512 #ifndef TEXT_SECTION_LABEL
3513 #define TEXT_SECTION_LABEL "Ltext"
3515 #ifndef COLD_TEXT_SECTION_LABEL
3516 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3518 #ifndef DEBUG_LINE_SECTION_LABEL
3519 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3521 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3522 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3524 #ifndef DEBUG_INFO_SECTION_LABEL
3525 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3527 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3528 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3530 #ifndef DEBUG_ABBREV_SECTION_LABEL
3531 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3533 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3534 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3536 #ifndef DEBUG_ADDR_SECTION_LABEL
3537 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3539 #ifndef DEBUG_LOC_SECTION_LABEL
3540 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3542 #ifndef DEBUG_RANGES_SECTION_LABEL
3543 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3545 #ifndef DEBUG_MACINFO_SECTION_LABEL
3546 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3548 #ifndef DEBUG_MACRO_SECTION_LABEL
3549 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3551 #define SKELETON_COMP_DIE_ABBREV 1
3552 #define SKELETON_TYPE_DIE_ABBREV 2
3554 /* Definitions of defaults for formats and names of various special
3555 (artificial) labels which may be generated within this file (when the -g
3556 options is used and DWARF2_DEBUGGING_INFO is in effect.
3557 If necessary, these may be overridden from within the tm.h file, but
3558 typically, overriding these defaults is unnecessary. */
3560 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3561 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3562 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3563 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3564 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3565 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3566 static char debug_skeleton_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3567 static char debug_skeleton_abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3568 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3569 static char debug_addr_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3570 static char debug_skeleton_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3571 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3572 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3573 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3575 #ifndef TEXT_END_LABEL
3576 #define TEXT_END_LABEL "Letext"
3578 #ifndef COLD_END_LABEL
3579 #define COLD_END_LABEL "Letext_cold"
3581 #ifndef BLOCK_BEGIN_LABEL
3582 #define BLOCK_BEGIN_LABEL "LBB"
3584 #ifndef BLOCK_END_LABEL
3585 #define BLOCK_END_LABEL "LBE"
3587 #ifndef LINE_CODE_LABEL
3588 #define LINE_CODE_LABEL "LM"
3592 /* Return the root of the DIE's built for the current compilation unit. */
3594 comp_unit_die (void)
3596 if (!single_comp_unit_die)
3597 single_comp_unit_die = gen_compile_unit_die (NULL);
3598 return single_comp_unit_die;
3601 /* We allow a language front-end to designate a function that is to be
3602 called to "demangle" any name before it is put into a DIE. */
3604 static const char *(*demangle_name_func) (const char *);
3607 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3609 demangle_name_func = func;
3612 /* Test if rtl node points to a pseudo register. */
3615 is_pseudo_reg (const_rtx rtl)
3617 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3618 || (GET_CODE (rtl) == SUBREG
3619 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3622 /* Return a reference to a type, with its const and volatile qualifiers
3626 type_main_variant (tree type)
3628 type = TYPE_MAIN_VARIANT (type);
3630 /* ??? There really should be only one main variant among any group of
3631 variants of a given type (and all of the MAIN_VARIANT values for all
3632 members of the group should point to that one type) but sometimes the C
3633 front-end messes this up for array types, so we work around that bug
3635 if (TREE_CODE (type) == ARRAY_TYPE)
3636 while (type != TYPE_MAIN_VARIANT (type))
3637 type = TYPE_MAIN_VARIANT (type);
3642 /* Return nonzero if the given type node represents a tagged type. */
3645 is_tagged_type (const_tree type)
3647 enum tree_code code = TREE_CODE (type);
3649 return (code == RECORD_TYPE || code == UNION_TYPE
3650 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3653 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3656 get_ref_die_offset_label (char *label, dw_die_ref ref)
3658 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
3661 /* Return die_offset of a DIE reference to a base type. */
3663 static unsigned long int
3664 get_base_type_offset (dw_die_ref ref)
3666 if (ref->die_offset)
3667 return ref->die_offset;
3668 if (comp_unit_die ()->die_abbrev)
3670 calc_base_type_die_sizes ();
3671 gcc_assert (ref->die_offset);
3673 return ref->die_offset;
3676 /* Return die_offset of a DIE reference other than base type. */
3678 static unsigned long int
3679 get_ref_die_offset (dw_die_ref ref)
3681 gcc_assert (ref->die_offset);
3682 return ref->die_offset;
3685 /* Convert a DIE tag into its string name. */
3688 dwarf_tag_name (unsigned int tag)
3690 const char *name = get_DW_TAG_name (tag);
3695 return "DW_TAG_<unknown>";
3698 /* Convert a DWARF attribute code into its string name. */
3701 dwarf_attr_name (unsigned int attr)
3707 #if VMS_DEBUGGING_INFO
3708 case DW_AT_HP_prologue:
3709 return "DW_AT_HP_prologue";
3711 case DW_AT_MIPS_loop_unroll_factor:
3712 return "DW_AT_MIPS_loop_unroll_factor";
3715 #if VMS_DEBUGGING_INFO
3716 case DW_AT_HP_epilogue:
3717 return "DW_AT_HP_epilogue";
3719 case DW_AT_MIPS_stride:
3720 return "DW_AT_MIPS_stride";
3724 name = get_DW_AT_name (attr);
3729 return "DW_AT_<unknown>";
3732 /* Convert a DWARF value form code into its string name. */
3735 dwarf_form_name (unsigned int form)
3737 const char *name = get_DW_FORM_name (form);
3742 return "DW_FORM_<unknown>";
3745 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3746 instance of an inlined instance of a decl which is local to an inline
3747 function, so we have to trace all of the way back through the origin chain
3748 to find out what sort of node actually served as the original seed for the
3752 decl_ultimate_origin (const_tree decl)
3754 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
3757 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3758 we're trying to output the abstract instance of this function. */
3759 if (DECL_ABSTRACT_P (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3762 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3763 most distant ancestor, this should never happen. */
3764 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
3766 return DECL_ABSTRACT_ORIGIN (decl);
3769 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3770 of a virtual function may refer to a base class, so we check the 'this'
3774 decl_class_context (tree decl)
3776 tree context = NULL_TREE;
3778 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3779 context = DECL_CONTEXT (decl);
3781 context = TYPE_MAIN_VARIANT
3782 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3784 if (context && !TYPE_P (context))
3785 context = NULL_TREE;
3790 /* Add an attribute/value pair to a DIE. */
3793 add_dwarf_attr (dw_die_ref die, dw_attr_node *attr)
3795 /* Maybe this should be an assert? */
3799 vec_safe_reserve (die->die_attr, 1);
3800 vec_safe_push (die->die_attr, *attr);
3803 static inline enum dw_val_class
3804 AT_class (dw_attr_node *a)
3806 return a->dw_attr_val.val_class;
3809 /* Return the index for any attribute that will be referenced with a
3810 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3811 are stored in dw_attr_val.v.val_str for reference counting
3814 static inline unsigned int
3815 AT_index (dw_attr_node *a)
3817 if (AT_class (a) == dw_val_class_str)
3818 return a->dw_attr_val.v.val_str->index;
3819 else if (a->dw_attr_val.val_entry != NULL)
3820 return a->dw_attr_val.val_entry->index;
3824 /* Add a flag value attribute to a DIE. */
3827 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
3831 attr.dw_attr = attr_kind;
3832 attr.dw_attr_val.val_class = dw_val_class_flag;
3833 attr.dw_attr_val.val_entry = NULL;
3834 attr.dw_attr_val.v.val_flag = flag;
3835 add_dwarf_attr (die, &attr);
3838 static inline unsigned
3839 AT_flag (dw_attr_node *a)
3841 gcc_assert (a && AT_class (a) == dw_val_class_flag);
3842 return a->dw_attr_val.v.val_flag;
3845 /* Add a signed integer attribute value to a DIE. */
3848 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
3852 attr.dw_attr = attr_kind;
3853 attr.dw_attr_val.val_class = dw_val_class_const;
3854 attr.dw_attr_val.val_entry = NULL;
3855 attr.dw_attr_val.v.val_int = int_val;
3856 add_dwarf_attr (die, &attr);
3859 static inline HOST_WIDE_INT
3860 AT_int (dw_attr_node *a)
3862 gcc_assert (a && AT_class (a) == dw_val_class_const);
3863 return a->dw_attr_val.v.val_int;
3866 /* Add an unsigned integer attribute value to a DIE. */
3869 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
3870 unsigned HOST_WIDE_INT unsigned_val)
3874 attr.dw_attr = attr_kind;
3875 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
3876 attr.dw_attr_val.val_entry = NULL;
3877 attr.dw_attr_val.v.val_unsigned = unsigned_val;
3878 add_dwarf_attr (die, &attr);
3881 static inline unsigned HOST_WIDE_INT
3882 AT_unsigned (dw_attr_node *a)
3884 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
3885 return a->dw_attr_val.v.val_unsigned;
3888 /* Add an unsigned wide integer attribute value to a DIE. */
3891 add_AT_wide (dw_die_ref die, enum dwarf_attribute attr_kind,
3896 attr.dw_attr = attr_kind;
3897 attr.dw_attr_val.val_class = dw_val_class_wide_int;
3898 attr.dw_attr_val.val_entry = NULL;
3899 attr.dw_attr_val.v.val_wide = ggc_alloc<wide_int> ();
3900 *attr.dw_attr_val.v.val_wide = w;
3901 add_dwarf_attr (die, &attr);
3904 /* Add an unsigned double integer attribute value to a DIE. */
3907 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
3908 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
3912 attr.dw_attr = attr_kind;
3913 attr.dw_attr_val.val_class = dw_val_class_const_double;
3914 attr.dw_attr_val.val_entry = NULL;
3915 attr.dw_attr_val.v.val_double.high = high;
3916 attr.dw_attr_val.v.val_double.low = low;
3917 add_dwarf_attr (die, &attr);
3920 /* Add a floating point attribute value to a DIE and return it. */
3923 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
3924 unsigned int length, unsigned int elt_size, unsigned char *array)
3928 attr.dw_attr = attr_kind;
3929 attr.dw_attr_val.val_class = dw_val_class_vec;
3930 attr.dw_attr_val.val_entry = NULL;
3931 attr.dw_attr_val.v.val_vec.length = length;
3932 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
3933 attr.dw_attr_val.v.val_vec.array = array;
3934 add_dwarf_attr (die, &attr);
3937 /* Add an 8-byte data attribute value to a DIE. */
3940 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
3941 unsigned char data8[8])
3945 attr.dw_attr = attr_kind;
3946 attr.dw_attr_val.val_class = dw_val_class_data8;
3947 attr.dw_attr_val.val_entry = NULL;
3948 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
3949 add_dwarf_attr (die, &attr);
3952 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3953 dwarf_split_debug_info, address attributes in dies destined for the
3954 final executable have force_direct set to avoid using indexed
3958 add_AT_low_high_pc (dw_die_ref die, const char *lbl_low, const char *lbl_high,
3964 lbl_id = xstrdup (lbl_low);
3965 attr.dw_attr = DW_AT_low_pc;
3966 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
3967 attr.dw_attr_val.v.val_lbl_id = lbl_id;
3968 if (dwarf_split_debug_info && !force_direct)
3969 attr.dw_attr_val.val_entry
3970 = add_addr_table_entry (lbl_id, ate_kind_label);
3972 attr.dw_attr_val.val_entry = NULL;
3973 add_dwarf_attr (die, &attr);
3975 attr.dw_attr = DW_AT_high_pc;
3976 if (dwarf_version < 4)
3977 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
3979 attr.dw_attr_val.val_class = dw_val_class_high_pc;
3980 lbl_id = xstrdup (lbl_high);
3981 attr.dw_attr_val.v.val_lbl_id = lbl_id;
3982 if (attr.dw_attr_val.val_class == dw_val_class_lbl_id
3983 && dwarf_split_debug_info && !force_direct)
3984 attr.dw_attr_val.val_entry
3985 = add_addr_table_entry (lbl_id, ate_kind_label);
3987 attr.dw_attr_val.val_entry = NULL;
3988 add_dwarf_attr (die, &attr);
3991 /* Hash and equality functions for debug_str_hash. */
3994 indirect_string_hasher::hash (indirect_string_node *x)
3996 return htab_hash_string (x->str);
4000 indirect_string_hasher::equal (indirect_string_node *x1, const char *x2)
4002 return strcmp (x1->str, x2) == 0;
4005 /* Add STR to the given string hash table. */
4007 static struct indirect_string_node *
4008 find_AT_string_in_table (const char *str,
4009 hash_table<indirect_string_hasher> *table)
4011 struct indirect_string_node *node;
4013 indirect_string_node **slot
4014 = table->find_slot_with_hash (str, htab_hash_string (str), INSERT);
4017 node = ggc_cleared_alloc<indirect_string_node> ();
4018 node->str = ggc_strdup (str);
4028 /* Add STR to the indirect string hash table. */
4030 static struct indirect_string_node *
4031 find_AT_string (const char *str)
4033 if (! debug_str_hash)
4034 debug_str_hash = hash_table<indirect_string_hasher>::create_ggc (10);
4036 return find_AT_string_in_table (str, debug_str_hash);
4039 /* Add a string attribute value to a DIE. */
4042 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4045 struct indirect_string_node *node;
4047 node = find_AT_string (str);
4049 attr.dw_attr = attr_kind;
4050 attr.dw_attr_val.val_class = dw_val_class_str;
4051 attr.dw_attr_val.val_entry = NULL;
4052 attr.dw_attr_val.v.val_str = node;
4053 add_dwarf_attr (die, &attr);
4056 static inline const char *
4057 AT_string (dw_attr_node *a)
4059 gcc_assert (a && AT_class (a) == dw_val_class_str);
4060 return a->dw_attr_val.v.val_str->str;
4063 /* Call this function directly to bypass AT_string_form's logic to put
4064 the string inline in the die. */
4067 set_indirect_string (struct indirect_string_node *node)
4070 /* Already indirect is a no op. */
4071 if (node->form == DW_FORM_strp || node->form == DW_FORM_GNU_str_index)
4073 gcc_assert (node->label);
4076 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4077 ++dw2_string_counter;
4078 node->label = xstrdup (label);
4080 if (!dwarf_split_debug_info)
4082 node->form = DW_FORM_strp;
4083 node->index = NOT_INDEXED;
4087 node->form = DW_FORM_GNU_str_index;
4088 node->index = NO_INDEX_ASSIGNED;
4092 /* Find out whether a string should be output inline in DIE
4093 or out-of-line in .debug_str section. */
4095 static enum dwarf_form
4096 find_string_form (struct indirect_string_node *node)
4103 len = strlen (node->str) + 1;
4105 /* If the string is shorter or equal to the size of the reference, it is
4106 always better to put it inline. */
4107 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4108 return node->form = DW_FORM_string;
4110 /* If we cannot expect the linker to merge strings in .debug_str
4111 section, only put it into .debug_str if it is worth even in this
4113 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4114 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
4115 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
4116 return node->form = DW_FORM_string;
4118 set_indirect_string (node);
4123 /* Find out whether the string referenced from the attribute should be
4124 output inline in DIE or out-of-line in .debug_str section. */
4126 static enum dwarf_form
4127 AT_string_form (dw_attr_node *a)
4129 gcc_assert (a && AT_class (a) == dw_val_class_str);
4130 return find_string_form (a->dw_attr_val.v.val_str);
4133 /* Add a DIE reference attribute value to a DIE. */
4136 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4140 #ifdef ENABLE_CHECKING
4141 gcc_assert (targ_die != NULL);
4143 /* With LTO we can end up trying to reference something we didn't create
4144 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4145 if (targ_die == NULL)
4149 attr.dw_attr = attr_kind;
4150 attr.dw_attr_val.val_class = dw_val_class_die_ref;
4151 attr.dw_attr_val.val_entry = NULL;
4152 attr.dw_attr_val.v.val_die_ref.die = targ_die;
4153 attr.dw_attr_val.v.val_die_ref.external = 0;
4154 add_dwarf_attr (die, &attr);
4157 /* Change DIE reference REF to point to NEW_DIE instead. */
4160 change_AT_die_ref (dw_attr_node *ref, dw_die_ref new_die)
4162 gcc_assert (ref->dw_attr_val.val_class == dw_val_class_die_ref);
4163 ref->dw_attr_val.v.val_die_ref.die = new_die;
4164 ref->dw_attr_val.v.val_die_ref.external = 0;
4167 /* Add an AT_specification attribute to a DIE, and also make the back
4168 pointer from the specification to the definition. */
4171 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4173 add_AT_die_ref (die, DW_AT_specification, targ_die);
4174 gcc_assert (!targ_die->die_definition);
4175 targ_die->die_definition = die;
4178 static inline dw_die_ref
4179 AT_ref (dw_attr_node *a)
4181 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4182 return a->dw_attr_val.v.val_die_ref.die;
4186 AT_ref_external (dw_attr_node *a)
4188 if (a && AT_class (a) == dw_val_class_die_ref)
4189 return a->dw_attr_val.v.val_die_ref.external;
4195 set_AT_ref_external (dw_attr_node *a, int i)
4197 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4198 a->dw_attr_val.v.val_die_ref.external = i;
4201 /* Add an FDE reference attribute value to a DIE. */
4204 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4208 attr.dw_attr = attr_kind;
4209 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
4210 attr.dw_attr_val.val_entry = NULL;
4211 attr.dw_attr_val.v.val_fde_index = targ_fde;
4212 add_dwarf_attr (die, &attr);
4215 /* Add a location description attribute value to a DIE. */
4218 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4222 attr.dw_attr = attr_kind;
4223 attr.dw_attr_val.val_class = dw_val_class_loc;
4224 attr.dw_attr_val.val_entry = NULL;
4225 attr.dw_attr_val.v.val_loc = loc;
4226 add_dwarf_attr (die, &attr);
4229 static inline dw_loc_descr_ref
4230 AT_loc (dw_attr_node *a)
4232 gcc_assert (a && AT_class (a) == dw_val_class_loc);
4233 return a->dw_attr_val.v.val_loc;
4237 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4241 attr.dw_attr = attr_kind;
4242 attr.dw_attr_val.val_class = dw_val_class_loc_list;
4243 attr.dw_attr_val.val_entry = NULL;
4244 attr.dw_attr_val.v.val_loc_list = loc_list;
4245 add_dwarf_attr (die, &attr);
4246 have_location_lists = true;
4249 static inline dw_loc_list_ref
4250 AT_loc_list (dw_attr_node *a)
4252 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4253 return a->dw_attr_val.v.val_loc_list;
4256 static inline dw_loc_list_ref *
4257 AT_loc_list_ptr (dw_attr_node *a)
4259 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4260 return &a->dw_attr_val.v.val_loc_list;
4263 struct addr_hasher : ggc_ptr_hash<addr_table_entry>
4265 static hashval_t hash (addr_table_entry *);
4266 static bool equal (addr_table_entry *, addr_table_entry *);
4269 /* Table of entries into the .debug_addr section. */
4271 static GTY (()) hash_table<addr_hasher> *addr_index_table;
4273 /* Hash an address_table_entry. */
4276 addr_hasher::hash (addr_table_entry *a)
4278 inchash::hash hstate;
4284 case ate_kind_rtx_dtprel:
4287 case ate_kind_label:
4288 return htab_hash_string (a->addr.label);
4292 inchash::add_rtx (a->addr.rtl, hstate);
4293 return hstate.end ();
4296 /* Determine equality for two address_table_entries. */
4299 addr_hasher::equal (addr_table_entry *a1, addr_table_entry *a2)
4301 if (a1->kind != a2->kind)
4306 case ate_kind_rtx_dtprel:
4307 return rtx_equal_p (a1->addr.rtl, a2->addr.rtl);
4308 case ate_kind_label:
4309 return strcmp (a1->addr.label, a2->addr.label) == 0;
4315 /* Initialize an addr_table_entry. */
4318 init_addr_table_entry (addr_table_entry *e, enum ate_kind kind, void *addr)
4324 case ate_kind_rtx_dtprel:
4325 e->addr.rtl = (rtx) addr;
4327 case ate_kind_label:
4328 e->addr.label = (char *) addr;
4332 e->index = NO_INDEX_ASSIGNED;
4335 /* Add attr to the address table entry to the table. Defer setting an
4336 index until output time. */
4338 static addr_table_entry *
4339 add_addr_table_entry (void *addr, enum ate_kind kind)
4341 addr_table_entry *node;
4342 addr_table_entry finder;
4344 gcc_assert (dwarf_split_debug_info);
4345 if (! addr_index_table)
4346 addr_index_table = hash_table<addr_hasher>::create_ggc (10);
4347 init_addr_table_entry (&finder, kind, addr);
4348 addr_table_entry **slot = addr_index_table->find_slot (&finder, INSERT);
4350 if (*slot == HTAB_EMPTY_ENTRY)
4352 node = ggc_cleared_alloc<addr_table_entry> ();
4353 init_addr_table_entry (node, kind, addr);
4363 /* Remove an entry from the addr table by decrementing its refcount.
4364 Strictly, decrementing the refcount would be enough, but the
4365 assertion that the entry is actually in the table has found
4369 remove_addr_table_entry (addr_table_entry *entry)
4371 gcc_assert (dwarf_split_debug_info && addr_index_table);
4372 /* After an index is assigned, the table is frozen. */
4373 gcc_assert (entry->refcount > 0 && entry->index == NO_INDEX_ASSIGNED);
4377 /* Given a location list, remove all addresses it refers to from the
4381 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr)
4383 for (; descr; descr = descr->dw_loc_next)
4384 if (descr->dw_loc_oprnd1.val_entry != NULL)
4386 gcc_assert (descr->dw_loc_oprnd1.val_entry->index == NO_INDEX_ASSIGNED);
4387 remove_addr_table_entry (descr->dw_loc_oprnd1.val_entry);
4391 /* A helper function for dwarf2out_finish called through
4392 htab_traverse. Assign an addr_table_entry its index. All entries
4393 must be collected into the table when this function is called,
4394 because the indexing code relies on htab_traverse to traverse nodes
4395 in the same order for each run. */
4398 index_addr_table_entry (addr_table_entry **h, unsigned int *index)
4400 addr_table_entry *node = *h;
4402 /* Don't index unreferenced nodes. */
4403 if (node->refcount == 0)
4406 gcc_assert (node->index == NO_INDEX_ASSIGNED);
4407 node->index = *index;
4413 /* Add an address constant attribute value to a DIE. When using
4414 dwarf_split_debug_info, address attributes in dies destined for the
4415 final executable should be direct references--setting the parameter
4416 force_direct ensures this behavior. */
4419 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr,
4424 attr.dw_attr = attr_kind;
4425 attr.dw_attr_val.val_class = dw_val_class_addr;
4426 attr.dw_attr_val.v.val_addr = addr;
4427 if (dwarf_split_debug_info && !force_direct)
4428 attr.dw_attr_val.val_entry = add_addr_table_entry (addr, ate_kind_rtx);
4430 attr.dw_attr_val.val_entry = NULL;
4431 add_dwarf_attr (die, &attr);
4434 /* Get the RTX from to an address DIE attribute. */
4437 AT_addr (dw_attr_node *a)
4439 gcc_assert (a && AT_class (a) == dw_val_class_addr);
4440 return a->dw_attr_val.v.val_addr;
4443 /* Add a file attribute value to a DIE. */
4446 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
4447 struct dwarf_file_data *fd)
4451 attr.dw_attr = attr_kind;
4452 attr.dw_attr_val.val_class = dw_val_class_file;
4453 attr.dw_attr_val.val_entry = NULL;
4454 attr.dw_attr_val.v.val_file = fd;
4455 add_dwarf_attr (die, &attr);
4458 /* Get the dwarf_file_data from a file DIE attribute. */
4460 static inline struct dwarf_file_data *
4461 AT_file (dw_attr_node *a)
4463 gcc_assert (a && AT_class (a) == dw_val_class_file);
4464 return a->dw_attr_val.v.val_file;
4467 /* Add a vms delta attribute value to a DIE. */
4470 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
4471 const char *lbl1, const char *lbl2)
4475 attr.dw_attr = attr_kind;
4476 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
4477 attr.dw_attr_val.val_entry = NULL;
4478 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
4479 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
4480 add_dwarf_attr (die, &attr);
4483 /* Add a label identifier attribute value to a DIE. */
4486 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind,
4491 attr.dw_attr = attr_kind;
4492 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4493 attr.dw_attr_val.val_entry = NULL;
4494 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4495 if (dwarf_split_debug_info)
4496 attr.dw_attr_val.val_entry
4497 = add_addr_table_entry (attr.dw_attr_val.v.val_lbl_id,
4499 add_dwarf_attr (die, &attr);
4502 /* Add a section offset attribute value to a DIE, an offset into the
4503 debug_line section. */
4506 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4511 attr.dw_attr = attr_kind;
4512 attr.dw_attr_val.val_class = dw_val_class_lineptr;
4513 attr.dw_attr_val.val_entry = NULL;
4514 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4515 add_dwarf_attr (die, &attr);
4518 /* Add a section offset attribute value to a DIE, an offset into the
4519 debug_macinfo section. */
4522 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4527 attr.dw_attr = attr_kind;
4528 attr.dw_attr_val.val_class = dw_val_class_macptr;
4529 attr.dw_attr_val.val_entry = NULL;
4530 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4531 add_dwarf_attr (die, &attr);
4534 /* Add an offset attribute value to a DIE. */
4537 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
4538 unsigned HOST_WIDE_INT offset)
4542 attr.dw_attr = attr_kind;
4543 attr.dw_attr_val.val_class = dw_val_class_offset;
4544 attr.dw_attr_val.val_entry = NULL;
4545 attr.dw_attr_val.v.val_offset = offset;
4546 add_dwarf_attr (die, &attr);
4549 /* Add a range_list attribute value to a DIE. When using
4550 dwarf_split_debug_info, address attributes in dies destined for the
4551 final executable should be direct references--setting the parameter
4552 force_direct ensures this behavior. */
4554 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4555 #define RELOCATED_OFFSET (NULL)
4558 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4559 long unsigned int offset, bool force_direct)
4563 attr.dw_attr = attr_kind;
4564 attr.dw_attr_val.val_class = dw_val_class_range_list;
4565 /* For the range_list attribute, use val_entry to store whether the
4566 offset should follow split-debug-info or normal semantics. This
4567 value is read in output_range_list_offset. */
4568 if (dwarf_split_debug_info && !force_direct)
4569 attr.dw_attr_val.val_entry = UNRELOCATED_OFFSET;
4571 attr.dw_attr_val.val_entry = RELOCATED_OFFSET;
4572 attr.dw_attr_val.v.val_offset = offset;
4573 add_dwarf_attr (die, &attr);
4576 /* Return the start label of a delta attribute. */
4578 static inline const char *
4579 AT_vms_delta1 (dw_attr_node *a)
4581 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4582 return a->dw_attr_val.v.val_vms_delta.lbl1;
4585 /* Return the end label of a delta attribute. */
4587 static inline const char *
4588 AT_vms_delta2 (dw_attr_node *a)
4590 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4591 return a->dw_attr_val.v.val_vms_delta.lbl2;
4594 static inline const char *
4595 AT_lbl (dw_attr_node *a)
4597 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
4598 || AT_class (a) == dw_val_class_lineptr
4599 || AT_class (a) == dw_val_class_macptr
4600 || AT_class (a) == dw_val_class_high_pc));
4601 return a->dw_attr_val.v.val_lbl_id;
4604 /* Get the attribute of type attr_kind. */
4606 static dw_attr_node *
4607 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4611 dw_die_ref spec = NULL;
4616 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
4617 if (a->dw_attr == attr_kind)
4619 else if (a->dw_attr == DW_AT_specification
4620 || a->dw_attr == DW_AT_abstract_origin)
4624 return get_AT (spec, attr_kind);
4629 /* Returns the parent of the declaration of DIE. */
4632 get_die_parent (dw_die_ref die)
4639 if ((t = get_AT_ref (die, DW_AT_abstract_origin))
4640 || (t = get_AT_ref (die, DW_AT_specification)))
4643 return die->die_parent;
4646 /* Return the "low pc" attribute value, typically associated with a subprogram
4647 DIE. Return null if the "low pc" attribute is either not present, or if it
4648 cannot be represented as an assembler label identifier. */
4650 static inline const char *
4651 get_AT_low_pc (dw_die_ref die)
4653 dw_attr_node *a = get_AT (die, DW_AT_low_pc);
4655 return a ? AT_lbl (a) : NULL;
4658 /* Return the "high pc" attribute value, typically associated with a subprogram
4659 DIE. Return null if the "high pc" attribute is either not present, or if it
4660 cannot be represented as an assembler label identifier. */
4662 static inline const char *
4663 get_AT_hi_pc (dw_die_ref die)
4665 dw_attr_node *a = get_AT (die, DW_AT_high_pc);
4667 return a ? AT_lbl (a) : NULL;
4670 /* Return the value of the string attribute designated by ATTR_KIND, or
4671 NULL if it is not present. */
4673 static inline const char *
4674 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4676 dw_attr_node *a = get_AT (die, attr_kind);
4678 return a ? AT_string (a) : NULL;
4681 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4682 if it is not present. */
4685 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4687 dw_attr_node *a = get_AT (die, attr_kind);
4689 return a ? AT_flag (a) : 0;
4692 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4693 if it is not present. */
4695 static inline unsigned
4696 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4698 dw_attr_node *a = get_AT (die, attr_kind);
4700 return a ? AT_unsigned (a) : 0;
4703 static inline dw_die_ref
4704 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4706 dw_attr_node *a = get_AT (die, attr_kind);
4708 return a ? AT_ref (a) : NULL;
4711 static inline struct dwarf_file_data *
4712 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
4714 dw_attr_node *a = get_AT (die, attr_kind);
4716 return a ? AT_file (a) : NULL;
4719 /* Return TRUE if the language is C++. */
4724 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4726 return (lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus
4727 || lang == DW_LANG_C_plus_plus_11 || lang == DW_LANG_C_plus_plus_14);
4730 /* Return TRUE if the language is Java. */
4735 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4737 return lang == DW_LANG_Java;
4740 /* Return TRUE if the language is Fortran. */
4745 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4747 return (lang == DW_LANG_Fortran77
4748 || lang == DW_LANG_Fortran90
4749 || lang == DW_LANG_Fortran95
4750 || lang == DW_LANG_Fortran03
4751 || lang == DW_LANG_Fortran08);
4754 /* Return TRUE if the language is Ada. */
4759 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4761 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4764 /* Remove the specified attribute if present. Return TRUE if removal
4768 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4776 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
4777 if (a->dw_attr == attr_kind)
4779 if (AT_class (a) == dw_val_class_str)
4780 if (a->dw_attr_val.v.val_str->refcount)
4781 a->dw_attr_val.v.val_str->refcount--;
4783 /* vec::ordered_remove should help reduce the number of abbrevs
4785 die->die_attr->ordered_remove (ix);
4791 /* Remove CHILD from its parent. PREV must have the property that
4792 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4795 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
4797 gcc_assert (child->die_parent == prev->die_parent);
4798 gcc_assert (prev->die_sib == child);
4801 gcc_assert (child->die_parent->die_child == child);
4805 prev->die_sib = child->die_sib;
4806 if (child->die_parent->die_child == child)
4807 child->die_parent->die_child = prev;
4810 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4811 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4814 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
4816 dw_die_ref parent = old_child->die_parent;
4818 gcc_assert (parent == prev->die_parent);
4819 gcc_assert (prev->die_sib == old_child);
4821 new_child->die_parent = parent;
4822 if (prev == old_child)
4824 gcc_assert (parent->die_child == old_child);
4825 new_child->die_sib = new_child;
4829 prev->die_sib = new_child;
4830 new_child->die_sib = old_child->die_sib;
4832 if (old_child->die_parent->die_child == old_child)
4833 old_child->die_parent->die_child = new_child;
4836 /* Move all children from OLD_PARENT to NEW_PARENT. */
4839 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
4842 new_parent->die_child = old_parent->die_child;
4843 old_parent->die_child = NULL;
4844 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
4847 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4851 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
4857 dw_die_ref prev = c;
4859 while (c->die_tag == tag)
4861 remove_child_with_prev (c, prev);
4862 c->die_parent = NULL;
4863 /* Might have removed every child. */
4864 if (c == c->die_sib)
4868 } while (c != die->die_child);
4871 /* Add a CHILD_DIE as the last child of DIE. */
4874 add_child_die (dw_die_ref die, dw_die_ref child_die)
4876 /* FIXME this should probably be an assert. */
4877 if (! die || ! child_die)
4879 gcc_assert (die != child_die);
4881 child_die->die_parent = die;
4884 child_die->die_sib = die->die_child->die_sib;
4885 die->die_child->die_sib = child_die;
4888 child_die->die_sib = child_die;
4889 die->die_child = child_die;
4892 /* Unassociate CHILD from its parent, and make its parent be
4896 reparent_child (dw_die_ref child, dw_die_ref new_parent)
4898 for (dw_die_ref p = child->die_parent->die_child; ; p = p->die_sib)
4899 if (p->die_sib == child)
4901 remove_child_with_prev (child, p);
4904 add_child_die (new_parent, child);
4907 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4908 is the specification, to the end of PARENT's list of children.
4909 This is done by removing and re-adding it. */
4912 splice_child_die (dw_die_ref parent, dw_die_ref child)
4914 /* We want the declaration DIE from inside the class, not the
4915 specification DIE at toplevel. */
4916 if (child->die_parent != parent)
4918 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4924 gcc_assert (child->die_parent == parent
4925 || (child->die_parent
4926 == get_AT_ref (parent, DW_AT_specification)));
4928 reparent_child (child, parent);
4931 /* Create and return a new die with a parent of PARENT_DIE. If
4932 PARENT_DIE is NULL, the new DIE is placed in limbo and an
4933 associated tree T must be supplied to determine parenthood
4936 static inline dw_die_ref
4937 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
4939 dw_die_ref die = ggc_cleared_alloc<die_node> ();
4941 die->die_tag = tag_value;
4943 if (parent_die != NULL)
4944 add_child_die (parent_die, die);
4947 limbo_die_node *limbo_node;
4949 /* No DIEs created after early dwarf should end up in limbo,
4950 because the limbo list should not persist past LTO
4952 if (tag_value != DW_TAG_compile_unit
4953 /* These are allowed because they're generated while
4954 breaking out COMDAT units late. */
4955 && tag_value != DW_TAG_type_unit
4957 /* Allow nested functions to live in limbo because they will
4958 only temporarily live there, as decls_for_scope will fix
4960 && (TREE_CODE (t) != FUNCTION_DECL
4961 || !decl_function_context (t))
4962 /* Same as nested functions above but for types. Types that
4963 are local to a function will be fixed in
4965 && (!RECORD_OR_UNION_TYPE_P (t)
4966 || !TYPE_CONTEXT (t)
4967 || TREE_CODE (TYPE_CONTEXT (t)) != FUNCTION_DECL)
4968 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
4969 especially in the ltrans stage, but once we implement LTO
4970 dwarf streaming, we should remove this exception. */
4973 fprintf (stderr, "symbol ended up in limbo too late:");
4974 debug_generic_stmt (t);
4978 limbo_node = ggc_cleared_alloc<limbo_die_node> ();
4979 limbo_node->die = die;
4980 limbo_node->created_for = t;
4981 limbo_node->next = limbo_die_list;
4982 limbo_die_list = limbo_node;
4988 /* Return the DIE associated with the given type specifier. */
4990 static inline dw_die_ref
4991 lookup_type_die (tree type)
4993 return TYPE_SYMTAB_DIE (type);
4996 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4997 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4998 anonymous type instead the one of the naming typedef. */
5000 static inline dw_die_ref
5001 strip_naming_typedef (tree type, dw_die_ref type_die)
5004 && TREE_CODE (type) == RECORD_TYPE
5006 && type_die->die_tag == DW_TAG_typedef
5007 && is_naming_typedef_decl (TYPE_NAME (type)))
5008 type_die = get_AT_ref (type_die, DW_AT_type);
5012 /* Like lookup_type_die, but if type is an anonymous type named by a
5013 typedef[1], return the DIE of the anonymous type instead the one of
5014 the naming typedef. This is because in gen_typedef_die, we did
5015 equate the anonymous struct named by the typedef with the DIE of
5016 the naming typedef. So by default, lookup_type_die on an anonymous
5017 struct yields the DIE of the naming typedef.
5019 [1]: Read the comment of is_naming_typedef_decl to learn about what
5020 a naming typedef is. */
5022 static inline dw_die_ref
5023 lookup_type_die_strip_naming_typedef (tree type)
5025 dw_die_ref die = lookup_type_die (type);
5026 return strip_naming_typedef (type, die);
5029 /* Equate a DIE to a given type specifier. */
5032 equate_type_number_to_die (tree type, dw_die_ref type_die)
5034 TYPE_SYMTAB_DIE (type) = type_die;
5037 /* Returns a hash value for X (which really is a die_struct). */
5040 decl_die_hasher::hash (die_node *x)
5042 return (hashval_t) x->decl_id;
5045 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5048 decl_die_hasher::equal (die_node *x, tree y)
5050 return (x->decl_id == DECL_UID (y));
5053 /* Return the DIE associated with a given declaration. */
5055 static inline dw_die_ref
5056 lookup_decl_die (tree decl)
5058 return decl_die_table->find_with_hash (decl, DECL_UID (decl));
5061 /* Returns a hash value for X (which really is a var_loc_list). */
5064 decl_loc_hasher::hash (var_loc_list *x)
5066 return (hashval_t) x->decl_id;
5069 /* Return nonzero if decl_id of var_loc_list X is the same as
5073 decl_loc_hasher::equal (var_loc_list *x, const_tree y)
5075 return (x->decl_id == DECL_UID (y));
5078 /* Return the var_loc list associated with a given declaration. */
5080 static inline var_loc_list *
5081 lookup_decl_loc (const_tree decl)
5083 if (!decl_loc_table)
5085 return decl_loc_table->find_with_hash (decl, DECL_UID (decl));
5088 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5091 dw_loc_list_hasher::hash (cached_dw_loc_list *x)
5093 return (hashval_t) x->decl_id;
5096 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5100 dw_loc_list_hasher::equal (cached_dw_loc_list *x, const_tree y)
5102 return (x->decl_id == DECL_UID (y));
5105 /* Equate a DIE to a particular declaration. */
5108 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5110 unsigned int decl_id = DECL_UID (decl);
5112 *decl_die_table->find_slot_with_hash (decl, decl_id, INSERT) = decl_die;
5113 decl_die->decl_id = decl_id;
5116 /* Return how many bits covers PIECE EXPR_LIST. */
5118 static HOST_WIDE_INT
5119 decl_piece_bitsize (rtx piece)
5121 int ret = (int) GET_MODE (piece);
5124 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
5125 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
5126 return INTVAL (XEXP (XEXP (piece, 0), 0));
5129 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5132 decl_piece_varloc_ptr (rtx piece)
5134 if ((int) GET_MODE (piece))
5135 return &XEXP (piece, 0);
5137 return &XEXP (XEXP (piece, 0), 1);
5140 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5141 Next is the chain of following piece nodes. */
5143 static rtx_expr_list *
5144 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
5146 if (bitsize > 0 && bitsize <= (int) MAX_MACHINE_MODE)
5147 return alloc_EXPR_LIST (bitsize, loc_note, next);
5149 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
5154 /* Return rtx that should be stored into loc field for
5155 LOC_NOTE and BITPOS/BITSIZE. */
5158 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
5159 HOST_WIDE_INT bitsize)
5163 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
5165 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
5170 /* This function either modifies location piece list *DEST in
5171 place (if SRC and INNER is NULL), or copies location piece list
5172 *SRC to *DEST while modifying it. Location BITPOS is modified
5173 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5174 not copied and if needed some padding around it is added.
5175 When modifying in place, DEST should point to EXPR_LIST where
5176 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5177 to the start of the whole list and INNER points to the EXPR_LIST
5178 where earlier pieces cover PIECE_BITPOS bits. */
5181 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
5182 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
5183 HOST_WIDE_INT bitsize, rtx loc_note)
5186 bool copy = inner != NULL;
5190 /* First copy all nodes preceding the current bitpos. */
5191 while (src != inner)
5193 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5194 decl_piece_bitsize (*src), NULL_RTX);
5195 dest = &XEXP (*dest, 1);
5196 src = &XEXP (*src, 1);
5199 /* Add padding if needed. */
5200 if (bitpos != piece_bitpos)
5202 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
5203 copy ? NULL_RTX : *dest);
5204 dest = &XEXP (*dest, 1);
5206 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
5209 /* A piece with correct bitpos and bitsize already exist,
5210 just update the location for it and return. */
5211 *decl_piece_varloc_ptr (*dest) = loc_note;
5214 /* Add the piece that changed. */
5215 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
5216 dest = &XEXP (*dest, 1);
5217 /* Skip over pieces that overlap it. */
5218 diff = bitpos - piece_bitpos + bitsize;
5221 while (diff > 0 && *src)
5224 diff -= decl_piece_bitsize (piece);
5226 src = &XEXP (piece, 1);
5229 *src = XEXP (piece, 1);
5230 free_EXPR_LIST_node (piece);
5233 /* Add padding if needed. */
5234 if (diff < 0 && *src)
5238 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
5239 dest = &XEXP (*dest, 1);
5243 /* Finally copy all nodes following it. */
5246 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5247 decl_piece_bitsize (*src), NULL_RTX);
5248 dest = &XEXP (*dest, 1);
5249 src = &XEXP (*src, 1);
5253 /* Add a variable location node to the linked list for DECL. */
5255 static struct var_loc_node *
5256 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
5258 unsigned int decl_id;
5260 struct var_loc_node *loc = NULL;
5261 HOST_WIDE_INT bitsize = -1, bitpos = -1;
5263 if (TREE_CODE (decl) == VAR_DECL
5264 && DECL_HAS_DEBUG_EXPR_P (decl))
5266 tree realdecl = DECL_DEBUG_EXPR (decl);
5267 if (handled_component_p (realdecl)
5268 || (TREE_CODE (realdecl) == MEM_REF
5269 && TREE_CODE (TREE_OPERAND (realdecl, 0)) == ADDR_EXPR))
5271 HOST_WIDE_INT maxsize;
5274 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
5275 if (!DECL_P (innerdecl)
5276 || DECL_IGNORED_P (innerdecl)
5277 || TREE_STATIC (innerdecl)
5279 || bitpos + bitsize > 256
5280 || bitsize != maxsize)
5286 decl_id = DECL_UID (decl);
5288 = decl_loc_table->find_slot_with_hash (decl, decl_id, INSERT);
5291 temp = ggc_cleared_alloc<var_loc_list> ();
5292 temp->decl_id = decl_id;
5298 /* For PARM_DECLs try to keep around the original incoming value,
5299 even if that means we'll emit a zero-range .debug_loc entry. */
5301 && temp->first == temp->last
5302 && TREE_CODE (decl) == PARM_DECL
5303 && NOTE_P (temp->first->loc)
5304 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
5305 && DECL_INCOMING_RTL (decl)
5306 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
5307 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
5308 == GET_CODE (DECL_INCOMING_RTL (decl))
5309 && prev_real_insn (temp->first->loc) == NULL_RTX
5311 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
5312 NOTE_VAR_LOCATION_LOC (loc_note))
5313 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
5314 != NOTE_VAR_LOCATION_STATUS (loc_note))))
5316 loc = ggc_cleared_alloc<var_loc_node> ();
5317 temp->first->next = loc;
5319 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5321 else if (temp->last)
5323 struct var_loc_node *last = temp->last, *unused = NULL;
5324 rtx *piece_loc = NULL, last_loc_note;
5325 HOST_WIDE_INT piece_bitpos = 0;
5329 gcc_assert (last->next == NULL);
5331 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
5333 piece_loc = &last->loc;
5336 HOST_WIDE_INT cur_bitsize = decl_piece_bitsize (*piece_loc);
5337 if (piece_bitpos + cur_bitsize > bitpos)
5339 piece_bitpos += cur_bitsize;
5340 piece_loc = &XEXP (*piece_loc, 1);
5344 /* TEMP->LAST here is either pointer to the last but one or
5345 last element in the chained list, LAST is pointer to the
5347 if (label && strcmp (last->label, label) == 0)
5349 /* For SRA optimized variables if there weren't any real
5350 insns since last note, just modify the last node. */
5351 if (piece_loc != NULL)
5353 adjust_piece_list (piece_loc, NULL, NULL,
5354 bitpos, piece_bitpos, bitsize, loc_note);
5357 /* If the last note doesn't cover any instructions, remove it. */
5358 if (temp->last != last)
5360 temp->last->next = NULL;
5363 gcc_assert (strcmp (last->label, label) != 0);
5367 gcc_assert (temp->first == temp->last
5368 || (temp->first->next == temp->last
5369 && TREE_CODE (decl) == PARM_DECL));
5370 memset (temp->last, '\0', sizeof (*temp->last));
5371 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
5375 if (bitsize == -1 && NOTE_P (last->loc))
5376 last_loc_note = last->loc;
5377 else if (piece_loc != NULL
5378 && *piece_loc != NULL_RTX
5379 && piece_bitpos == bitpos
5380 && decl_piece_bitsize (*piece_loc) == bitsize)
5381 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
5383 last_loc_note = NULL_RTX;
5384 /* If the current location is the same as the end of the list,
5385 and either both or neither of the locations is uninitialized,
5386 we have nothing to do. */
5387 if (last_loc_note == NULL_RTX
5388 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
5389 NOTE_VAR_LOCATION_LOC (loc_note)))
5390 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5391 != NOTE_VAR_LOCATION_STATUS (loc_note))
5392 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5393 == VAR_INIT_STATUS_UNINITIALIZED)
5394 || (NOTE_VAR_LOCATION_STATUS (loc_note)
5395 == VAR_INIT_STATUS_UNINITIALIZED))))
5397 /* Add LOC to the end of list and update LAST. If the last
5398 element of the list has been removed above, reuse its
5399 memory for the new node, otherwise allocate a new one. */
5403 memset (loc, '\0', sizeof (*loc));
5406 loc = ggc_cleared_alloc<var_loc_node> ();
5407 if (bitsize == -1 || piece_loc == NULL)
5408 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5410 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
5411 bitpos, piece_bitpos, bitsize, loc_note);
5413 /* Ensure TEMP->LAST will point either to the new last but one
5414 element of the chain, or to the last element in it. */
5415 if (last != temp->last)
5423 loc = ggc_cleared_alloc<var_loc_node> ();
5426 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5431 /* Keep track of the number of spaces used to indent the
5432 output of the debugging routines that print the structure of
5433 the DIE internal representation. */
5434 static int print_indent;
5436 /* Indent the line the number of spaces given by print_indent. */
5439 print_spaces (FILE *outfile)
5441 fprintf (outfile, "%*s", print_indent, "");
5444 /* Print a type signature in hex. */
5447 print_signature (FILE *outfile, char *sig)
5451 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
5452 fprintf (outfile, "%02x", sig[i] & 0xff);
5455 static void print_loc_descr (dw_loc_descr_ref, FILE *);
5457 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5458 RECURSE, output location descriptor operations. */
5461 print_dw_val (dw_val_node *val, bool recurse, FILE *outfile)
5463 switch (val->val_class)
5465 case dw_val_class_addr:
5466 fprintf (outfile, "address");
5468 case dw_val_class_offset:
5469 fprintf (outfile, "offset");
5471 case dw_val_class_loc:
5472 fprintf (outfile, "location descriptor");
5473 if (val->v.val_loc == NULL)
5474 fprintf (outfile, " -> <null>\n");
5477 fprintf (outfile, ":\n");
5479 print_loc_descr (val->v.val_loc, outfile);
5483 fprintf (outfile, " (%p)\n", (void *) val->v.val_loc);
5485 case dw_val_class_loc_list:
5486 fprintf (outfile, "location list -> label:%s",
5487 val->v.val_loc_list->ll_symbol);
5489 case dw_val_class_range_list:
5490 fprintf (outfile, "range list");
5492 case dw_val_class_const:
5493 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, val->v.val_int);
5495 case dw_val_class_unsigned_const:
5496 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, val->v.val_unsigned);
5498 case dw_val_class_const_double:
5499 fprintf (outfile, "constant (" HOST_WIDE_INT_PRINT_DEC","\
5500 HOST_WIDE_INT_PRINT_UNSIGNED")",
5501 val->v.val_double.high,
5502 val->v.val_double.low);
5504 case dw_val_class_wide_int:
5506 int i = val->v.val_wide->get_len ();
5507 fprintf (outfile, "constant (");
5509 if (val->v.val_wide->elt (i - 1) == 0)
5510 fprintf (outfile, "0x");
5511 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX,
5512 val->v.val_wide->elt (--i));
5514 fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX,
5515 val->v.val_wide->elt (i));
5516 fprintf (outfile, ")");
5519 case dw_val_class_vec:
5520 fprintf (outfile, "floating-point or vector constant");
5522 case dw_val_class_flag:
5523 fprintf (outfile, "%u", val->v.val_flag);
5525 case dw_val_class_die_ref:
5526 if (val->v.val_die_ref.die != NULL)
5528 dw_die_ref die = val->v.val_die_ref.die;
5530 if (die->comdat_type_p)
5532 fprintf (outfile, "die -> signature: ");
5533 print_signature (outfile,
5534 die->die_id.die_type_node->signature);
5536 else if (die->die_id.die_symbol)
5537 fprintf (outfile, "die -> label: %s", die->die_id.die_symbol);
5539 fprintf (outfile, "die -> %ld", die->die_offset);
5540 fprintf (outfile, " (%p)", (void *) die);
5543 fprintf (outfile, "die -> <null>");
5545 case dw_val_class_vms_delta:
5546 fprintf (outfile, "delta: @slotcount(%s-%s)",
5547 val->v.val_vms_delta.lbl2, val->v.val_vms_delta.lbl1);
5549 case dw_val_class_lbl_id:
5550 case dw_val_class_lineptr:
5551 case dw_val_class_macptr:
5552 case dw_val_class_high_pc:
5553 fprintf (outfile, "label: %s", val->v.val_lbl_id);
5555 case dw_val_class_str:
5556 if (val->v.val_str->str != NULL)
5557 fprintf (outfile, "\"%s\"", val->v.val_str->str);
5559 fprintf (outfile, "<null>");
5561 case dw_val_class_file:
5562 fprintf (outfile, "\"%s\" (%d)", val->v.val_file->filename,
5563 val->v.val_file->emitted_number);
5565 case dw_val_class_data8:
5569 for (i = 0; i < 8; i++)
5570 fprintf (outfile, "%02x", val->v.val_data8[i]);
5578 /* Likewise, for a DIE attribute. */
5581 print_attribute (dw_attr_node *a, bool recurse, FILE *outfile)
5583 print_dw_val (&a->dw_attr_val, recurse, outfile);
5587 /* Print the list of operands in the LOC location description to OUTFILE. This
5588 routine is a debugging aid only. */
5591 print_loc_descr (dw_loc_descr_ref loc, FILE *outfile)
5593 dw_loc_descr_ref l = loc;
5597 print_spaces (outfile);
5598 fprintf (outfile, "<null>\n");
5602 for (l = loc; l != NULL; l = l->dw_loc_next)
5604 print_spaces (outfile);
5605 fprintf (outfile, "(%p) %s",
5607 dwarf_stack_op_name (l->dw_loc_opc));
5608 if (l->dw_loc_oprnd1.val_class != dw_val_class_none)
5610 fprintf (outfile, " ");
5611 print_dw_val (&l->dw_loc_oprnd1, false, outfile);
5613 if (l->dw_loc_oprnd2.val_class != dw_val_class_none)
5615 fprintf (outfile, ", ");
5616 print_dw_val (&l->dw_loc_oprnd2, false, outfile);
5618 fprintf (outfile, "\n");
5622 /* Print the information associated with a given DIE, and its children.
5623 This routine is a debugging aid only. */
5626 print_die (dw_die_ref die, FILE *outfile)
5632 print_spaces (outfile);
5633 fprintf (outfile, "DIE %4ld: %s (%p)\n",
5634 die->die_offset, dwarf_tag_name (die->die_tag),
5636 print_spaces (outfile);
5637 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5638 fprintf (outfile, " offset: %ld", die->die_offset);
5639 fprintf (outfile, " mark: %d\n", die->die_mark);
5641 if (die->comdat_type_p)
5643 print_spaces (outfile);
5644 fprintf (outfile, " signature: ");
5645 print_signature (outfile, die->die_id.die_type_node->signature);
5646 fprintf (outfile, "\n");
5649 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5651 print_spaces (outfile);
5652 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5654 print_attribute (a, true, outfile);
5655 fprintf (outfile, "\n");
5658 if (die->die_child != NULL)
5661 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5664 if (print_indent == 0)
5665 fprintf (outfile, "\n");
5668 /* Print the list of operations in the LOC location description. */
5671 debug_dwarf_loc_descr (dw_loc_descr_ref loc)
5673 print_loc_descr (loc, stderr);
5676 /* Print the information collected for a given DIE. */
5679 debug_dwarf_die (dw_die_ref die)
5681 print_die (die, stderr);
5685 debug (die_struct &ref)
5687 print_die (&ref, stderr);
5691 debug (die_struct *ptr)
5696 fprintf (stderr, "<nil>\n");
5700 /* Print all DWARF information collected for the compilation unit.
5701 This routine is a debugging aid only. */
5707 print_die (comp_unit_die (), stderr);
5710 #ifdef ENABLE_CHECKING
5711 /* Sanity checks on DIEs. */
5714 check_die (dw_die_ref die)
5718 bool inline_found = false;
5719 int n_location = 0, n_low_pc = 0, n_high_pc = 0, n_artificial = 0;
5720 int n_decl_line = 0, n_decl_file = 0;
5721 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5726 if (a->dw_attr_val.v.val_unsigned)
5727 inline_found = true;
5729 case DW_AT_location:
5738 case DW_AT_artificial:
5741 case DW_AT_decl_line:
5744 case DW_AT_decl_file:
5751 if (n_location > 1 || n_low_pc > 1 || n_high_pc > 1 || n_artificial > 1
5752 || n_decl_line > 1 || n_decl_file > 1)
5754 fprintf (stderr, "Duplicate attributes in DIE:\n");
5755 debug_dwarf_die (die);
5760 /* A debugging information entry that is a member of an abstract
5761 instance tree [that has DW_AT_inline] should not contain any
5762 attributes which describe aspects of the subroutine which vary
5763 between distinct inlined expansions or distinct out-of-line
5765 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5766 gcc_assert (a->dw_attr != DW_AT_low_pc
5767 && a->dw_attr != DW_AT_high_pc
5768 && a->dw_attr != DW_AT_location
5769 && a->dw_attr != DW_AT_frame_base
5770 && a->dw_attr != DW_AT_GNU_all_call_sites);
5775 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5776 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5777 DIE that marks the start of the DIEs for this include file. */
5780 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5782 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5783 dw_die_ref new_unit = gen_compile_unit_die (filename);
5785 new_unit->die_sib = old_unit;
5789 /* Close an include-file CU and reopen the enclosing one. */
5792 pop_compile_unit (dw_die_ref old_unit)
5794 dw_die_ref new_unit = old_unit->die_sib;
5796 old_unit->die_sib = NULL;
5800 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5801 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5802 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5804 /* Calculate the checksum of a location expression. */
5807 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5810 inchash::hash hstate;
5813 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
5815 hash_loc_operands (loc, hstate);
5816 hash = hstate.end();
5820 /* Calculate the checksum of an attribute. */
5823 attr_checksum (dw_attr_node *at, struct md5_ctx *ctx, int *mark)
5825 dw_loc_descr_ref loc;
5828 CHECKSUM (at->dw_attr);
5830 /* We don't care that this was compiled with a different compiler
5831 snapshot; if the output is the same, that's what matters. */
5832 if (at->dw_attr == DW_AT_producer)
5835 switch (AT_class (at))
5837 case dw_val_class_const:
5838 CHECKSUM (at->dw_attr_val.v.val_int);
5840 case dw_val_class_unsigned_const:
5841 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5843 case dw_val_class_const_double:
5844 CHECKSUM (at->dw_attr_val.v.val_double);
5846 case dw_val_class_wide_int:
5847 CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
5848 get_full_len (*at->dw_attr_val.v.val_wide)
5849 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
5851 case dw_val_class_vec:
5852 CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
5853 (at->dw_attr_val.v.val_vec.length
5854 * at->dw_attr_val.v.val_vec.elt_size));
5856 case dw_val_class_flag:
5857 CHECKSUM (at->dw_attr_val.v.val_flag);
5859 case dw_val_class_str:
5860 CHECKSUM_STRING (AT_string (at));
5863 case dw_val_class_addr:
5865 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5866 CHECKSUM_STRING (XSTR (r, 0));
5869 case dw_val_class_offset:
5870 CHECKSUM (at->dw_attr_val.v.val_offset);
5873 case dw_val_class_loc:
5874 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5875 loc_checksum (loc, ctx);
5878 case dw_val_class_die_ref:
5879 die_checksum (AT_ref (at), ctx, mark);
5882 case dw_val_class_fde_ref:
5883 case dw_val_class_vms_delta:
5884 case dw_val_class_lbl_id:
5885 case dw_val_class_lineptr:
5886 case dw_val_class_macptr:
5887 case dw_val_class_high_pc:
5890 case dw_val_class_file:
5891 CHECKSUM_STRING (AT_file (at)->filename);
5894 case dw_val_class_data8:
5895 CHECKSUM (at->dw_attr_val.v.val_data8);
5903 /* Calculate the checksum of a DIE. */
5906 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5912 /* To avoid infinite recursion. */
5915 CHECKSUM (die->die_mark);
5918 die->die_mark = ++(*mark);
5920 CHECKSUM (die->die_tag);
5922 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5923 attr_checksum (a, ctx, mark);
5925 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
5929 #undef CHECKSUM_BLOCK
5930 #undef CHECKSUM_STRING
5932 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5933 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5934 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5935 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5936 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5937 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5938 #define CHECKSUM_ATTR(FOO) \
5939 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5941 /* Calculate the checksum of a number in signed LEB128 format. */
5944 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
5951 byte = (value & 0x7f);
5953 more = !((value == 0 && (byte & 0x40) == 0)
5954 || (value == -1 && (byte & 0x40) != 0));
5963 /* Calculate the checksum of a number in unsigned LEB128 format. */
5966 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
5970 unsigned char byte = (value & 0x7f);
5973 /* More bytes to follow. */
5981 /* Checksum the context of the DIE. This adds the names of any
5982 surrounding namespaces or structures to the checksum. */
5985 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
5989 int tag = die->die_tag;
5991 if (tag != DW_TAG_namespace
5992 && tag != DW_TAG_structure_type
5993 && tag != DW_TAG_class_type)
5996 name = get_AT_string (die, DW_AT_name);
5998 spec = get_AT_ref (die, DW_AT_specification);
6002 if (die->die_parent != NULL)
6003 checksum_die_context (die->die_parent, ctx);
6005 CHECKSUM_ULEB128 ('C');
6006 CHECKSUM_ULEB128 (tag);
6008 CHECKSUM_STRING (name);
6011 /* Calculate the checksum of a location expression. */
6014 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6016 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6017 were emitted as a DW_FORM_sdata instead of a location expression. */
6018 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
6020 CHECKSUM_ULEB128 (DW_FORM_sdata);
6021 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
6025 /* Otherwise, just checksum the raw location expression. */
6028 inchash::hash hstate;
6031 CHECKSUM_ULEB128 (loc->dtprel);
6032 CHECKSUM_ULEB128 (loc->dw_loc_opc);
6033 hash_loc_operands (loc, hstate);
6034 hash = hstate.end ();
6036 loc = loc->dw_loc_next;
6040 /* Calculate the checksum of an attribute. */
6043 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_node *at,
6044 struct md5_ctx *ctx, int *mark)
6046 dw_loc_descr_ref loc;
6049 if (AT_class (at) == dw_val_class_die_ref)
6051 dw_die_ref target_die = AT_ref (at);
6053 /* For pointer and reference types, we checksum only the (qualified)
6054 name of the target type (if there is a name). For friend entries,
6055 we checksum only the (qualified) name of the target type or function.
6056 This allows the checksum to remain the same whether the target type
6057 is complete or not. */
6058 if ((at->dw_attr == DW_AT_type
6059 && (tag == DW_TAG_pointer_type
6060 || tag == DW_TAG_reference_type
6061 || tag == DW_TAG_rvalue_reference_type
6062 || tag == DW_TAG_ptr_to_member_type))
6063 || (at->dw_attr == DW_AT_friend
6064 && tag == DW_TAG_friend))
6066 dw_attr_node *name_attr = get_AT (target_die, DW_AT_name);
6068 if (name_attr != NULL)
6070 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
6074 CHECKSUM_ULEB128 ('N');
6075 CHECKSUM_ULEB128 (at->dw_attr);
6076 if (decl->die_parent != NULL)
6077 checksum_die_context (decl->die_parent, ctx);
6078 CHECKSUM_ULEB128 ('E');
6079 CHECKSUM_STRING (AT_string (name_attr));
6084 /* For all other references to another DIE, we check to see if the
6085 target DIE has already been visited. If it has, we emit a
6086 backward reference; if not, we descend recursively. */
6087 if (target_die->die_mark > 0)
6089 CHECKSUM_ULEB128 ('R');
6090 CHECKSUM_ULEB128 (at->dw_attr);
6091 CHECKSUM_ULEB128 (target_die->die_mark);
6095 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
6099 target_die->die_mark = ++(*mark);
6100 CHECKSUM_ULEB128 ('T');
6101 CHECKSUM_ULEB128 (at->dw_attr);
6102 if (decl->die_parent != NULL)
6103 checksum_die_context (decl->die_parent, ctx);
6104 die_checksum_ordered (target_die, ctx, mark);
6109 CHECKSUM_ULEB128 ('A');
6110 CHECKSUM_ULEB128 (at->dw_attr);
6112 switch (AT_class (at))
6114 case dw_val_class_const:
6115 CHECKSUM_ULEB128 (DW_FORM_sdata);
6116 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
6119 case dw_val_class_unsigned_const:
6120 CHECKSUM_ULEB128 (DW_FORM_sdata);
6121 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
6124 case dw_val_class_const_double:
6125 CHECKSUM_ULEB128 (DW_FORM_block);
6126 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
6127 CHECKSUM (at->dw_attr_val.v.val_double);
6130 case dw_val_class_wide_int:
6131 CHECKSUM_ULEB128 (DW_FORM_block);
6132 CHECKSUM_ULEB128 (get_full_len (*at->dw_attr_val.v.val_wide)
6133 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
6134 CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
6135 get_full_len (*at->dw_attr_val.v.val_wide)
6136 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
6139 case dw_val_class_vec:
6140 CHECKSUM_ULEB128 (DW_FORM_block);
6141 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_vec.length
6142 * at->dw_attr_val.v.val_vec.elt_size);
6143 CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
6144 (at->dw_attr_val.v.val_vec.length
6145 * at->dw_attr_val.v.val_vec.elt_size));
6148 case dw_val_class_flag:
6149 CHECKSUM_ULEB128 (DW_FORM_flag);
6150 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
6153 case dw_val_class_str:
6154 CHECKSUM_ULEB128 (DW_FORM_string);
6155 CHECKSUM_STRING (AT_string (at));
6158 case dw_val_class_addr:
6160 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6161 CHECKSUM_ULEB128 (DW_FORM_string);
6162 CHECKSUM_STRING (XSTR (r, 0));
6165 case dw_val_class_offset:
6166 CHECKSUM_ULEB128 (DW_FORM_sdata);
6167 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
6170 case dw_val_class_loc:
6171 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6172 loc_checksum_ordered (loc, ctx);
6175 case dw_val_class_fde_ref:
6176 case dw_val_class_lbl_id:
6177 case dw_val_class_lineptr:
6178 case dw_val_class_macptr:
6179 case dw_val_class_high_pc:
6182 case dw_val_class_file:
6183 CHECKSUM_ULEB128 (DW_FORM_string);
6184 CHECKSUM_STRING (AT_file (at)->filename);
6187 case dw_val_class_data8:
6188 CHECKSUM (at->dw_attr_val.v.val_data8);
6196 struct checksum_attributes
6198 dw_attr_node *at_name;
6199 dw_attr_node *at_type;
6200 dw_attr_node *at_friend;
6201 dw_attr_node *at_accessibility;
6202 dw_attr_node *at_address_class;
6203 dw_attr_node *at_allocated;
6204 dw_attr_node *at_artificial;
6205 dw_attr_node *at_associated;
6206 dw_attr_node *at_binary_scale;
6207 dw_attr_node *at_bit_offset;
6208 dw_attr_node *at_bit_size;
6209 dw_attr_node *at_bit_stride;
6210 dw_attr_node *at_byte_size;
6211 dw_attr_node *at_byte_stride;
6212 dw_attr_node *at_const_value;
6213 dw_attr_node *at_containing_type;
6214 dw_attr_node *at_count;
6215 dw_attr_node *at_data_location;
6216 dw_attr_node *at_data_member_location;
6217 dw_attr_node *at_decimal_scale;
6218 dw_attr_node *at_decimal_sign;
6219 dw_attr_node *at_default_value;
6220 dw_attr_node *at_digit_count;
6221 dw_attr_node *at_discr;
6222 dw_attr_node *at_discr_list;
6223 dw_attr_node *at_discr_value;
6224 dw_attr_node *at_encoding;
6225 dw_attr_node *at_endianity;
6226 dw_attr_node *at_explicit;
6227 dw_attr_node *at_is_optional;
6228 dw_attr_node *at_location;
6229 dw_attr_node *at_lower_bound;
6230 dw_attr_node *at_mutable;
6231 dw_attr_node *at_ordering;
6232 dw_attr_node *at_picture_string;
6233 dw_attr_node *at_prototyped;
6234 dw_attr_node *at_small;
6235 dw_attr_node *at_segment;
6236 dw_attr_node *at_string_length;
6237 dw_attr_node *at_threads_scaled;
6238 dw_attr_node *at_upper_bound;
6239 dw_attr_node *at_use_location;
6240 dw_attr_node *at_use_UTF8;
6241 dw_attr_node *at_variable_parameter;
6242 dw_attr_node *at_virtuality;
6243 dw_attr_node *at_visibility;
6244 dw_attr_node *at_vtable_elem_location;
6247 /* Collect the attributes that we will want to use for the checksum. */
6250 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
6255 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
6266 attrs->at_friend = a;
6268 case DW_AT_accessibility:
6269 attrs->at_accessibility = a;
6271 case DW_AT_address_class:
6272 attrs->at_address_class = a;
6274 case DW_AT_allocated:
6275 attrs->at_allocated = a;
6277 case DW_AT_artificial:
6278 attrs->at_artificial = a;
6280 case DW_AT_associated:
6281 attrs->at_associated = a;
6283 case DW_AT_binary_scale:
6284 attrs->at_binary_scale = a;
6286 case DW_AT_bit_offset:
6287 attrs->at_bit_offset = a;
6289 case DW_AT_bit_size:
6290 attrs->at_bit_size = a;
6292 case DW_AT_bit_stride:
6293 attrs->at_bit_stride = a;
6295 case DW_AT_byte_size:
6296 attrs->at_byte_size = a;
6298 case DW_AT_byte_stride:
6299 attrs->at_byte_stride = a;
6301 case DW_AT_const_value:
6302 attrs->at_const_value = a;
6304 case DW_AT_containing_type:
6305 attrs->at_containing_type = a;
6308 attrs->at_count = a;
6310 case DW_AT_data_location:
6311 attrs->at_data_location = a;
6313 case DW_AT_data_member_location:
6314 attrs->at_data_member_location = a;
6316 case DW_AT_decimal_scale:
6317 attrs->at_decimal_scale = a;
6319 case DW_AT_decimal_sign:
6320 attrs->at_decimal_sign = a;
6322 case DW_AT_default_value:
6323 attrs->at_default_value = a;
6325 case DW_AT_digit_count:
6326 attrs->at_digit_count = a;
6329 attrs->at_discr = a;
6331 case DW_AT_discr_list:
6332 attrs->at_discr_list = a;
6334 case DW_AT_discr_value:
6335 attrs->at_discr_value = a;
6337 case DW_AT_encoding:
6338 attrs->at_encoding = a;
6340 case DW_AT_endianity:
6341 attrs->at_endianity = a;
6343 case DW_AT_explicit:
6344 attrs->at_explicit = a;
6346 case DW_AT_is_optional:
6347 attrs->at_is_optional = a;
6349 case DW_AT_location:
6350 attrs->at_location = a;
6352 case DW_AT_lower_bound:
6353 attrs->at_lower_bound = a;
6356 attrs->at_mutable = a;
6358 case DW_AT_ordering:
6359 attrs->at_ordering = a;
6361 case DW_AT_picture_string:
6362 attrs->at_picture_string = a;
6364 case DW_AT_prototyped:
6365 attrs->at_prototyped = a;
6368 attrs->at_small = a;
6371 attrs->at_segment = a;
6373 case DW_AT_string_length:
6374 attrs->at_string_length = a;
6376 case DW_AT_threads_scaled:
6377 attrs->at_threads_scaled = a;
6379 case DW_AT_upper_bound:
6380 attrs->at_upper_bound = a;
6382 case DW_AT_use_location:
6383 attrs->at_use_location = a;
6385 case DW_AT_use_UTF8:
6386 attrs->at_use_UTF8 = a;
6388 case DW_AT_variable_parameter:
6389 attrs->at_variable_parameter = a;
6391 case DW_AT_virtuality:
6392 attrs->at_virtuality = a;
6394 case DW_AT_visibility:
6395 attrs->at_visibility = a;
6397 case DW_AT_vtable_elem_location:
6398 attrs->at_vtable_elem_location = a;
6406 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6409 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6413 struct checksum_attributes attrs;
6415 CHECKSUM_ULEB128 ('D');
6416 CHECKSUM_ULEB128 (die->die_tag);
6418 memset (&attrs, 0, sizeof (attrs));
6420 decl = get_AT_ref (die, DW_AT_specification);
6422 collect_checksum_attributes (&attrs, decl);
6423 collect_checksum_attributes (&attrs, die);
6425 CHECKSUM_ATTR (attrs.at_name);
6426 CHECKSUM_ATTR (attrs.at_accessibility);
6427 CHECKSUM_ATTR (attrs.at_address_class);
6428 CHECKSUM_ATTR (attrs.at_allocated);
6429 CHECKSUM_ATTR (attrs.at_artificial);
6430 CHECKSUM_ATTR (attrs.at_associated);
6431 CHECKSUM_ATTR (attrs.at_binary_scale);
6432 CHECKSUM_ATTR (attrs.at_bit_offset);
6433 CHECKSUM_ATTR (attrs.at_bit_size);
6434 CHECKSUM_ATTR (attrs.at_bit_stride);
6435 CHECKSUM_ATTR (attrs.at_byte_size);
6436 CHECKSUM_ATTR (attrs.at_byte_stride);
6437 CHECKSUM_ATTR (attrs.at_const_value);
6438 CHECKSUM_ATTR (attrs.at_containing_type);
6439 CHECKSUM_ATTR (attrs.at_count);
6440 CHECKSUM_ATTR (attrs.at_data_location);
6441 CHECKSUM_ATTR (attrs.at_data_member_location);
6442 CHECKSUM_ATTR (attrs.at_decimal_scale);
6443 CHECKSUM_ATTR (attrs.at_decimal_sign);
6444 CHECKSUM_ATTR (attrs.at_default_value);
6445 CHECKSUM_ATTR (attrs.at_digit_count);
6446 CHECKSUM_ATTR (attrs.at_discr);
6447 CHECKSUM_ATTR (attrs.at_discr_list);
6448 CHECKSUM_ATTR (attrs.at_discr_value);
6449 CHECKSUM_ATTR (attrs.at_encoding);
6450 CHECKSUM_ATTR (attrs.at_endianity);
6451 CHECKSUM_ATTR (attrs.at_explicit);
6452 CHECKSUM_ATTR (attrs.at_is_optional);
6453 CHECKSUM_ATTR (attrs.at_location);
6454 CHECKSUM_ATTR (attrs.at_lower_bound);
6455 CHECKSUM_ATTR (attrs.at_mutable);
6456 CHECKSUM_ATTR (attrs.at_ordering);
6457 CHECKSUM_ATTR (attrs.at_picture_string);
6458 CHECKSUM_ATTR (attrs.at_prototyped);
6459 CHECKSUM_ATTR (attrs.at_small);
6460 CHECKSUM_ATTR (attrs.at_segment);
6461 CHECKSUM_ATTR (attrs.at_string_length);
6462 CHECKSUM_ATTR (attrs.at_threads_scaled);
6463 CHECKSUM_ATTR (attrs.at_upper_bound);
6464 CHECKSUM_ATTR (attrs.at_use_location);
6465 CHECKSUM_ATTR (attrs.at_use_UTF8);
6466 CHECKSUM_ATTR (attrs.at_variable_parameter);
6467 CHECKSUM_ATTR (attrs.at_virtuality);
6468 CHECKSUM_ATTR (attrs.at_visibility);
6469 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
6470 CHECKSUM_ATTR (attrs.at_type);
6471 CHECKSUM_ATTR (attrs.at_friend);
6473 /* Checksum the child DIEs. */
6476 dw_attr_node *name_attr;
6479 name_attr = get_AT (c, DW_AT_name);
6480 if (is_template_instantiation (c))
6482 /* Ignore instantiations of member type and function templates. */
6484 else if (name_attr != NULL
6485 && (is_type_die (c) || c->die_tag == DW_TAG_subprogram))
6487 /* Use a shallow checksum for named nested types and member
6489 CHECKSUM_ULEB128 ('S');
6490 CHECKSUM_ULEB128 (c->die_tag);
6491 CHECKSUM_STRING (AT_string (name_attr));
6495 /* Use a deep checksum for other children. */
6496 /* Mark this DIE so it gets processed when unmarking. */
6497 if (c->die_mark == 0)
6499 die_checksum_ordered (c, ctx, mark);
6501 } while (c != die->die_child);
6503 CHECKSUM_ULEB128 (0);
6506 /* Add a type name and tag to a hash. */
6508 die_odr_checksum (int tag, const char *name, md5_ctx *ctx)
6510 CHECKSUM_ULEB128 (tag);
6511 CHECKSUM_STRING (name);
6515 #undef CHECKSUM_STRING
6516 #undef CHECKSUM_ATTR
6517 #undef CHECKSUM_LEB128
6518 #undef CHECKSUM_ULEB128
6520 /* Generate the type signature for DIE. This is computed by generating an
6521 MD5 checksum over the DIE's tag, its relevant attributes, and its
6522 children. Attributes that are references to other DIEs are processed
6523 by recursion, using the MARK field to prevent infinite recursion.
6524 If the DIE is nested inside a namespace or another type, we also
6525 need to include that context in the signature. The lower 64 bits
6526 of the resulting MD5 checksum comprise the signature. */
6529 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
6533 unsigned char checksum[16];
6538 name = get_AT_string (die, DW_AT_name);
6539 decl = get_AT_ref (die, DW_AT_specification);
6540 parent = get_die_parent (die);
6542 /* First, compute a signature for just the type name (and its surrounding
6543 context, if any. This is stored in the type unit DIE for link-time
6544 ODR (one-definition rule) checking. */
6546 if (is_cxx () && name != NULL)
6548 md5_init_ctx (&ctx);
6550 /* Checksum the names of surrounding namespaces and structures. */
6552 checksum_die_context (parent, &ctx);
6554 /* Checksum the current DIE. */
6555 die_odr_checksum (die->die_tag, name, &ctx);
6556 md5_finish_ctx (&ctx, checksum);
6558 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
6561 /* Next, compute the complete type signature. */
6563 md5_init_ctx (&ctx);
6565 die->die_mark = mark;
6567 /* Checksum the names of surrounding namespaces and structures. */
6569 checksum_die_context (parent, &ctx);
6571 /* Checksum the DIE and its children. */
6572 die_checksum_ordered (die, &ctx, &mark);
6573 unmark_all_dies (die);
6574 md5_finish_ctx (&ctx, checksum);
6576 /* Store the signature in the type node and link the type DIE and the
6577 type node together. */
6578 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
6579 DWARF_TYPE_SIGNATURE_SIZE);
6580 die->comdat_type_p = true;
6581 die->die_id.die_type_node = type_node;
6582 type_node->type_die = die;
6584 /* If the DIE is a specification, link its declaration to the type node
6588 decl->comdat_type_p = true;
6589 decl->die_id.die_type_node = type_node;
6593 /* Do the location expressions look same? */
6595 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6597 return loc1->dw_loc_opc == loc2->dw_loc_opc
6598 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6599 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6602 /* Do the values look the same? */
6604 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6606 dw_loc_descr_ref loc1, loc2;
6609 if (v1->val_class != v2->val_class)
6612 switch (v1->val_class)
6614 case dw_val_class_const:
6615 return v1->v.val_int == v2->v.val_int;
6616 case dw_val_class_unsigned_const:
6617 return v1->v.val_unsigned == v2->v.val_unsigned;
6618 case dw_val_class_const_double:
6619 return v1->v.val_double.high == v2->v.val_double.high
6620 && v1->v.val_double.low == v2->v.val_double.low;
6621 case dw_val_class_wide_int:
6622 return *v1->v.val_wide == *v2->v.val_wide;
6623 case dw_val_class_vec:
6624 if (v1->v.val_vec.length != v2->v.val_vec.length
6625 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6627 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6628 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6631 case dw_val_class_flag:
6632 return v1->v.val_flag == v2->v.val_flag;
6633 case dw_val_class_str:
6634 return !strcmp (v1->v.val_str->str, v2->v.val_str->str);
6636 case dw_val_class_addr:
6637 r1 = v1->v.val_addr;
6638 r2 = v2->v.val_addr;
6639 if (GET_CODE (r1) != GET_CODE (r2))
6641 return !rtx_equal_p (r1, r2);
6643 case dw_val_class_offset:
6644 return v1->v.val_offset == v2->v.val_offset;
6646 case dw_val_class_loc:
6647 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6649 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6650 if (!same_loc_p (loc1, loc2, mark))
6652 return !loc1 && !loc2;
6654 case dw_val_class_die_ref:
6655 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6657 case dw_val_class_fde_ref:
6658 case dw_val_class_vms_delta:
6659 case dw_val_class_lbl_id:
6660 case dw_val_class_lineptr:
6661 case dw_val_class_macptr:
6662 case dw_val_class_high_pc:
6665 case dw_val_class_file:
6666 return v1->v.val_file == v2->v.val_file;
6668 case dw_val_class_data8:
6669 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
6676 /* Do the attributes look the same? */
6679 same_attr_p (dw_attr_node *at1, dw_attr_node *at2, int *mark)
6681 if (at1->dw_attr != at2->dw_attr)
6684 /* We don't care that this was compiled with a different compiler
6685 snapshot; if the output is the same, that's what matters. */
6686 if (at1->dw_attr == DW_AT_producer)
6689 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6692 /* Do the dies look the same? */
6695 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6701 /* To avoid infinite recursion. */
6703 return die1->die_mark == die2->die_mark;
6704 die1->die_mark = die2->die_mark = ++(*mark);
6706 if (die1->die_tag != die2->die_tag)
6709 if (vec_safe_length (die1->die_attr) != vec_safe_length (die2->die_attr))
6712 FOR_EACH_VEC_SAFE_ELT (die1->die_attr, ix, a1)
6713 if (!same_attr_p (a1, &(*die2->die_attr)[ix], mark))
6716 c1 = die1->die_child;
6717 c2 = die2->die_child;
6726 if (!same_die_p (c1, c2, mark))
6730 if (c1 == die1->die_child)
6732 if (c2 == die2->die_child)
6742 /* Do the dies look the same? Wrapper around same_die_p. */
6745 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6748 int ret = same_die_p (die1, die2, &mark);
6750 unmark_all_dies (die1);
6751 unmark_all_dies (die2);
6756 /* The prefix to attach to symbols on DIEs in the current comdat debug
6758 static const char *comdat_symbol_id;
6760 /* The index of the current symbol within the current comdat CU. */
6761 static unsigned int comdat_symbol_number;
6763 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6764 children, and set comdat_symbol_id accordingly. */
6767 compute_section_prefix (dw_die_ref unit_die)
6769 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6770 const char *base = die_name ? lbasename (die_name) : "anonymous";
6771 char *name = XALLOCAVEC (char, strlen (base) + 64);
6774 unsigned char checksum[16];
6777 /* Compute the checksum of the DIE, then append part of it as hex digits to
6778 the name filename of the unit. */
6780 md5_init_ctx (&ctx);
6782 die_checksum (unit_die, &ctx, &mark);
6783 unmark_all_dies (unit_die);
6784 md5_finish_ctx (&ctx, checksum);
6786 sprintf (name, "%s.", base);
6787 clean_symbol_name (name);
6789 p = name + strlen (name);
6790 for (i = 0; i < 4; i++)
6792 sprintf (p, "%.2x", checksum[i]);
6796 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
6797 comdat_symbol_number = 0;
6800 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6803 is_type_die (dw_die_ref die)
6805 switch (die->die_tag)
6807 case DW_TAG_array_type:
6808 case DW_TAG_class_type:
6809 case DW_TAG_interface_type:
6810 case DW_TAG_enumeration_type:
6811 case DW_TAG_pointer_type:
6812 case DW_TAG_reference_type:
6813 case DW_TAG_rvalue_reference_type:
6814 case DW_TAG_string_type:
6815 case DW_TAG_structure_type:
6816 case DW_TAG_subroutine_type:
6817 case DW_TAG_union_type:
6818 case DW_TAG_ptr_to_member_type:
6819 case DW_TAG_set_type:
6820 case DW_TAG_subrange_type:
6821 case DW_TAG_base_type:
6822 case DW_TAG_const_type:
6823 case DW_TAG_file_type:
6824 case DW_TAG_packed_type:
6825 case DW_TAG_volatile_type:
6826 case DW_TAG_typedef:
6833 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6834 Basically, we want to choose the bits that are likely to be shared between
6835 compilations (types) and leave out the bits that are specific to individual
6836 compilations (functions). */
6839 is_comdat_die (dw_die_ref c)
6841 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6842 we do for stabs. The advantage is a greater likelihood of sharing between
6843 objects that don't include headers in the same order (and therefore would
6844 put the base types in a different comdat). jason 8/28/00 */
6846 if (c->die_tag == DW_TAG_base_type)
6849 if (c->die_tag == DW_TAG_pointer_type
6850 || c->die_tag == DW_TAG_reference_type
6851 || c->die_tag == DW_TAG_rvalue_reference_type
6852 || c->die_tag == DW_TAG_const_type
6853 || c->die_tag == DW_TAG_volatile_type)
6855 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6857 return t ? is_comdat_die (t) : 0;
6860 return is_type_die (c);
6863 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6864 compilation unit. */
6867 is_symbol_die (dw_die_ref c)
6869 return (is_type_die (c)
6870 || is_declaration_die (c)
6871 || c->die_tag == DW_TAG_namespace
6872 || c->die_tag == DW_TAG_module);
6875 /* Returns true iff C is a compile-unit DIE. */
6878 is_cu_die (dw_die_ref c)
6880 return c && c->die_tag == DW_TAG_compile_unit;
6883 /* Returns true iff C is a unit DIE of some sort. */
6886 is_unit_die (dw_die_ref c)
6888 return c && (c->die_tag == DW_TAG_compile_unit
6889 || c->die_tag == DW_TAG_partial_unit
6890 || c->die_tag == DW_TAG_type_unit);
6893 /* Returns true iff C is a namespace DIE. */
6896 is_namespace_die (dw_die_ref c)
6898 return c && c->die_tag == DW_TAG_namespace;
6901 /* Returns true iff C is a class or structure DIE. */
6904 is_class_die (dw_die_ref c)
6906 return c && (c->die_tag == DW_TAG_class_type
6907 || c->die_tag == DW_TAG_structure_type);
6910 /* Return non-zero if this DIE is a template parameter. */
6913 is_template_parameter (dw_die_ref die)
6915 switch (die->die_tag)
6917 case DW_TAG_template_type_param:
6918 case DW_TAG_template_value_param:
6919 case DW_TAG_GNU_template_template_param:
6920 case DW_TAG_GNU_template_parameter_pack:
6927 /* Return non-zero if this DIE represents a template instantiation. */
6930 is_template_instantiation (dw_die_ref die)
6934 if (!is_type_die (die) && die->die_tag != DW_TAG_subprogram)
6936 FOR_EACH_CHILD (die, c, if (is_template_parameter (c)) return true);
6941 gen_internal_sym (const char *prefix)
6945 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6946 return xstrdup (buf);
6949 /* Assign symbols to all worthy DIEs under DIE. */
6952 assign_symbol_names (dw_die_ref die)
6956 if (is_symbol_die (die) && !die->comdat_type_p)
6958 if (comdat_symbol_id)
6960 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
6962 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6963 comdat_symbol_id, comdat_symbol_number++);
6964 die->die_id.die_symbol = xstrdup (p);
6967 die->die_id.die_symbol = gen_internal_sym ("LDIE");
6970 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6973 struct cu_hash_table_entry
6976 unsigned min_comdat_num, max_comdat_num;
6977 struct cu_hash_table_entry *next;
6980 /* Helpers to manipulate hash table of CUs. */
6982 struct cu_hash_table_entry_hasher : pointer_hash <cu_hash_table_entry>
6984 typedef die_struct *compare_type;
6985 static inline hashval_t hash (const cu_hash_table_entry *);
6986 static inline bool equal (const cu_hash_table_entry *, const die_struct *);
6987 static inline void remove (cu_hash_table_entry *);
6991 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry *entry)
6993 return htab_hash_string (entry->cu->die_id.die_symbol);
6997 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry *entry1,
6998 const die_struct *entry2)
7000 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
7004 cu_hash_table_entry_hasher::remove (cu_hash_table_entry *entry)
7006 struct cu_hash_table_entry *next;
7016 typedef hash_table<cu_hash_table_entry_hasher> cu_hash_type;
7018 /* Check whether we have already seen this CU and set up SYM_NUM
7021 check_duplicate_cu (dw_die_ref cu, cu_hash_type *htable, unsigned int *sym_num)
7023 struct cu_hash_table_entry dummy;
7024 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7026 dummy.max_comdat_num = 0;
7028 slot = htable->find_slot_with_hash (cu,
7029 htab_hash_string (cu->die_id.die_symbol),
7033 for (; entry; last = entry, entry = entry->next)
7035 if (same_die_p_wrap (cu, entry->cu))
7041 *sym_num = entry->min_comdat_num;
7045 entry = XCNEW (struct cu_hash_table_entry);
7047 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7048 entry->next = *slot;
7054 /* Record SYM_NUM to record of CU in HTABLE. */
7056 record_comdat_symbol_number (dw_die_ref cu, cu_hash_type *htable,
7057 unsigned int sym_num)
7059 struct cu_hash_table_entry **slot, *entry;
7061 slot = htable->find_slot_with_hash (cu,
7062 htab_hash_string (cu->die_id.die_symbol),
7066 entry->max_comdat_num = sym_num;
7069 /* Traverse the DIE (which is always comp_unit_die), and set up
7070 additional compilation units for each of the include files we see
7071 bracketed by BINCL/EINCL. */
7074 break_out_includes (dw_die_ref die)
7077 dw_die_ref unit = NULL;
7078 limbo_die_node *node, **pnode;
7082 dw_die_ref prev = c;
7084 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7085 || (unit && is_comdat_die (c)))
7087 dw_die_ref next = c->die_sib;
7089 /* This DIE is for a secondary CU; remove it from the main one. */
7090 remove_child_with_prev (c, prev);
7092 if (c->die_tag == DW_TAG_GNU_BINCL)
7093 unit = push_new_compile_unit (unit, c);
7094 else if (c->die_tag == DW_TAG_GNU_EINCL)
7095 unit = pop_compile_unit (unit);
7097 add_child_die (unit, c);
7099 if (c == die->die_child)
7102 } while (c != die->die_child);
7105 /* We can only use this in debugging, since the frontend doesn't check
7106 to make sure that we leave every include file we enter. */
7110 assign_symbol_names (die);
7111 cu_hash_type cu_hash_table (10);
7112 for (node = limbo_die_list, pnode = &limbo_die_list;
7118 compute_section_prefix (node->die);
7119 is_dupl = check_duplicate_cu (node->die, &cu_hash_table,
7120 &comdat_symbol_number);
7121 assign_symbol_names (node->die);
7123 *pnode = node->next;
7126 pnode = &node->next;
7127 record_comdat_symbol_number (node->die, &cu_hash_table,
7128 comdat_symbol_number);
7133 /* Return non-zero if this DIE is a declaration. */
7136 is_declaration_die (dw_die_ref die)
7141 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7142 if (a->dw_attr == DW_AT_declaration)
7148 /* Return non-zero if this DIE is nested inside a subprogram. */
7151 is_nested_in_subprogram (dw_die_ref die)
7153 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
7157 return local_scope_p (decl);
7160 /* Return non-zero if this DIE contains a defining declaration of a
7164 contains_subprogram_definition (dw_die_ref die)
7168 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
7170 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition (c)) return 1);
7174 /* Return non-zero if this is a type DIE that should be moved to a
7175 COMDAT .debug_types section. */
7178 should_move_die_to_comdat (dw_die_ref die)
7180 switch (die->die_tag)
7182 case DW_TAG_class_type:
7183 case DW_TAG_structure_type:
7184 case DW_TAG_enumeration_type:
7185 case DW_TAG_union_type:
7186 /* Don't move declarations, inlined instances, types nested in a
7187 subprogram, or types that contain subprogram definitions. */
7188 if (is_declaration_die (die)
7189 || get_AT (die, DW_AT_abstract_origin)
7190 || is_nested_in_subprogram (die)
7191 || contains_subprogram_definition (die))
7194 case DW_TAG_array_type:
7195 case DW_TAG_interface_type:
7196 case DW_TAG_pointer_type:
7197 case DW_TAG_reference_type:
7198 case DW_TAG_rvalue_reference_type:
7199 case DW_TAG_string_type:
7200 case DW_TAG_subroutine_type:
7201 case DW_TAG_ptr_to_member_type:
7202 case DW_TAG_set_type:
7203 case DW_TAG_subrange_type:
7204 case DW_TAG_base_type:
7205 case DW_TAG_const_type:
7206 case DW_TAG_file_type:
7207 case DW_TAG_packed_type:
7208 case DW_TAG_volatile_type:
7209 case DW_TAG_typedef:
7215 /* Make a clone of DIE. */
7218 clone_die (dw_die_ref die)
7224 clone = ggc_cleared_alloc<die_node> ();
7225 clone->die_tag = die->die_tag;
7227 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7228 add_dwarf_attr (clone, a);
7233 /* Make a clone of the tree rooted at DIE. */
7236 clone_tree (dw_die_ref die)
7239 dw_die_ref clone = clone_die (die);
7241 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree (c)));
7246 /* Make a clone of DIE as a declaration. */
7249 clone_as_declaration (dw_die_ref die)
7256 /* If the DIE is already a declaration, just clone it. */
7257 if (is_declaration_die (die))
7258 return clone_die (die);
7260 /* If the DIE is a specification, just clone its declaration DIE. */
7261 decl = get_AT_ref (die, DW_AT_specification);
7264 clone = clone_die (decl);
7265 if (die->comdat_type_p)
7266 add_AT_die_ref (clone, DW_AT_signature, die);
7270 clone = ggc_cleared_alloc<die_node> ();
7271 clone->die_tag = die->die_tag;
7273 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7275 /* We don't want to copy over all attributes.
7276 For example we don't want DW_AT_byte_size because otherwise we will no
7277 longer have a declaration and GDB will treat it as a definition. */
7281 case DW_AT_abstract_origin:
7282 case DW_AT_artificial:
7283 case DW_AT_containing_type:
7284 case DW_AT_external:
7287 case DW_AT_virtuality:
7288 case DW_AT_linkage_name:
7289 case DW_AT_MIPS_linkage_name:
7290 add_dwarf_attr (clone, a);
7292 case DW_AT_byte_size:
7298 if (die->comdat_type_p)
7299 add_AT_die_ref (clone, DW_AT_signature, die);
7301 add_AT_flag (clone, DW_AT_declaration, 1);
7306 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7308 struct decl_table_entry
7314 /* Helpers to manipulate hash table of copied declarations. */
7316 /* Hashtable helpers. */
7318 struct decl_table_entry_hasher : free_ptr_hash <decl_table_entry>
7320 typedef die_struct *compare_type;
7321 static inline hashval_t hash (const decl_table_entry *);
7322 static inline bool equal (const decl_table_entry *, const die_struct *);
7326 decl_table_entry_hasher::hash (const decl_table_entry *entry)
7328 return htab_hash_pointer (entry->orig);
7332 decl_table_entry_hasher::equal (const decl_table_entry *entry1,
7333 const die_struct *entry2)
7335 return entry1->orig == entry2;
7338 typedef hash_table<decl_table_entry_hasher> decl_hash_type;
7340 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7341 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7342 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7343 to check if the ancestor has already been copied into UNIT. */
7346 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die,
7347 decl_hash_type *decl_table)
7349 dw_die_ref parent = die->die_parent;
7350 dw_die_ref new_parent = unit;
7352 decl_table_entry **slot = NULL;
7353 struct decl_table_entry *entry = NULL;
7357 /* Check if the entry has already been copied to UNIT. */
7358 slot = decl_table->find_slot_with_hash (die, htab_hash_pointer (die),
7360 if (*slot != HTAB_EMPTY_ENTRY)
7366 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7367 entry = XCNEW (struct decl_table_entry);
7375 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
7378 if (!is_unit_die (parent))
7379 new_parent = copy_ancestor_tree (unit, parent, decl_table);
7382 copy = clone_as_declaration (die);
7383 add_child_die (new_parent, copy);
7387 /* Record the pointer to the copy. */
7393 /* Copy the declaration context to the new type unit DIE. This includes
7394 any surrounding namespace or type declarations. If the DIE has an
7395 AT_specification attribute, it also includes attributes and children
7396 attached to the specification, and returns a pointer to the original
7397 parent of the declaration DIE. Returns NULL otherwise. */
7400 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
7403 dw_die_ref new_decl;
7404 dw_die_ref orig_parent = NULL;
7406 decl = get_AT_ref (die, DW_AT_specification);
7415 /* The original DIE will be changed to a declaration, and must
7416 be moved to be a child of the original declaration DIE. */
7417 orig_parent = decl->die_parent;
7419 /* Copy the type node pointer from the new DIE to the original
7420 declaration DIE so we can forward references later. */
7421 decl->comdat_type_p = true;
7422 decl->die_id.die_type_node = die->die_id.die_type_node;
7424 remove_AT (die, DW_AT_specification);
7426 FOR_EACH_VEC_SAFE_ELT (decl->die_attr, ix, a)
7428 if (a->dw_attr != DW_AT_name
7429 && a->dw_attr != DW_AT_declaration
7430 && a->dw_attr != DW_AT_external)
7431 add_dwarf_attr (die, a);
7434 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree (c)));
7437 if (decl->die_parent != NULL
7438 && !is_unit_die (decl->die_parent))
7440 new_decl = copy_ancestor_tree (unit, decl, NULL);
7441 if (new_decl != NULL)
7443 remove_AT (new_decl, DW_AT_signature);
7444 add_AT_specification (die, new_decl);
7451 /* Generate the skeleton ancestor tree for the given NODE, then clone
7452 the DIE and add the clone into the tree. */
7455 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
7457 if (node->new_die != NULL)
7460 node->new_die = clone_as_declaration (node->old_die);
7462 if (node->parent != NULL)
7464 generate_skeleton_ancestor_tree (node->parent);
7465 add_child_die (node->parent->new_die, node->new_die);
7469 /* Generate a skeleton tree of DIEs containing any declarations that are
7470 found in the original tree. We traverse the tree looking for declaration
7471 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7474 generate_skeleton_bottom_up (skeleton_chain_node *parent)
7476 skeleton_chain_node node;
7479 dw_die_ref prev = NULL;
7480 dw_die_ref next = NULL;
7482 node.parent = parent;
7484 first = c = parent->old_die->die_child;
7488 if (prev == NULL || prev->die_sib == c)
7491 next = (c == first ? NULL : c->die_sib);
7493 node.new_die = NULL;
7494 if (is_declaration_die (c))
7496 if (is_template_instantiation (c))
7498 /* Instantiated templates do not need to be cloned into the
7499 type unit. Just move the DIE and its children back to
7500 the skeleton tree (in the main CU). */
7501 remove_child_with_prev (c, prev);
7502 add_child_die (parent->new_die, c);
7507 /* Clone the existing DIE, move the original to the skeleton
7508 tree (which is in the main CU), and put the clone, with
7509 all the original's children, where the original came from
7510 (which is about to be moved to the type unit). */
7511 dw_die_ref clone = clone_die (c);
7512 move_all_children (c, clone);
7514 /* If the original has a DW_AT_object_pointer attribute,
7515 it would now point to a child DIE just moved to the
7516 cloned tree, so we need to remove that attribute from
7518 remove_AT (c, DW_AT_object_pointer);
7520 replace_child (c, clone, prev);
7521 generate_skeleton_ancestor_tree (parent);
7522 add_child_die (parent->new_die, c);
7527 generate_skeleton_bottom_up (&node);
7528 } while (next != NULL);
7531 /* Wrapper function for generate_skeleton_bottom_up. */
7534 generate_skeleton (dw_die_ref die)
7536 skeleton_chain_node node;
7539 node.new_die = NULL;
7542 /* If this type definition is nested inside another type,
7543 and is not an instantiation of a template, always leave
7544 at least a declaration in its place. */
7545 if (die->die_parent != NULL
7546 && is_type_die (die->die_parent)
7547 && !is_template_instantiation (die))
7548 node.new_die = clone_as_declaration (die);
7550 generate_skeleton_bottom_up (&node);
7551 return node.new_die;
7554 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7555 declaration. The original DIE is moved to a new compile unit so that
7556 existing references to it follow it to the new location. If any of the
7557 original DIE's descendants is a declaration, we need to replace the
7558 original DIE with a skeleton tree and move the declarations back into the
7562 remove_child_or_replace_with_skeleton (dw_die_ref unit, dw_die_ref child,
7565 dw_die_ref skeleton, orig_parent;
7567 /* Copy the declaration context to the type unit DIE. If the returned
7568 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7570 orig_parent = copy_declaration_context (unit, child);
7572 skeleton = generate_skeleton (child);
7573 if (skeleton == NULL)
7574 remove_child_with_prev (child, prev);
7577 skeleton->comdat_type_p = true;
7578 skeleton->die_id.die_type_node = child->die_id.die_type_node;
7580 /* If the original DIE was a specification, we need to put
7581 the skeleton under the parent DIE of the declaration.
7582 This leaves the original declaration in the tree, but
7583 it will be pruned later since there are no longer any
7584 references to it. */
7585 if (orig_parent != NULL)
7587 remove_child_with_prev (child, prev);
7588 add_child_die (orig_parent, skeleton);
7591 replace_child (child, skeleton, prev);
7597 /* Traverse the DIE and set up additional .debug_types sections for each
7598 type worthy of being placed in a COMDAT section. */
7601 break_out_comdat_types (dw_die_ref die)
7605 dw_die_ref prev = NULL;
7606 dw_die_ref next = NULL;
7607 dw_die_ref unit = NULL;
7609 first = c = die->die_child;
7613 if (prev == NULL || prev->die_sib == c)
7616 next = (c == first ? NULL : c->die_sib);
7617 if (should_move_die_to_comdat (c))
7619 dw_die_ref replacement;
7620 comdat_type_node *type_node;
7622 /* Break out nested types into their own type units. */
7623 break_out_comdat_types (c);
7625 /* Create a new type unit DIE as the root for the new tree, and
7626 add it to the list of comdat types. */
7627 unit = new_die (DW_TAG_type_unit, NULL, NULL);
7628 add_AT_unsigned (unit, DW_AT_language,
7629 get_AT_unsigned (comp_unit_die (), DW_AT_language));
7630 type_node = ggc_cleared_alloc<comdat_type_node> ();
7631 type_node->root_die = unit;
7632 type_node->next = comdat_type_list;
7633 comdat_type_list = type_node;
7635 /* Generate the type signature. */
7636 generate_type_signature (c, type_node);
7638 /* Copy the declaration context, attributes, and children of the
7639 declaration into the new type unit DIE, then remove this DIE
7640 from the main CU (or replace it with a skeleton if necessary). */
7641 replacement = remove_child_or_replace_with_skeleton (unit, c, prev);
7642 type_node->skeleton_die = replacement;
7644 /* Add the DIE to the new compunit. */
7645 add_child_die (unit, c);
7647 if (replacement != NULL)
7650 else if (c->die_tag == DW_TAG_namespace
7651 || c->die_tag == DW_TAG_class_type
7652 || c->die_tag == DW_TAG_structure_type
7653 || c->die_tag == DW_TAG_union_type)
7655 /* Look for nested types that can be broken out. */
7656 break_out_comdat_types (c);
7658 } while (next != NULL);
7661 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7662 Enter all the cloned children into the hash table decl_table. */
7665 clone_tree_partial (dw_die_ref die, decl_hash_type *decl_table)
7669 struct decl_table_entry *entry;
7670 decl_table_entry **slot;
7672 if (die->die_tag == DW_TAG_subprogram)
7673 clone = clone_as_declaration (die);
7675 clone = clone_die (die);
7677 slot = decl_table->find_slot_with_hash (die,
7678 htab_hash_pointer (die), INSERT);
7680 /* Assert that DIE isn't in the hash table yet. If it would be there
7681 before, the ancestors would be necessarily there as well, therefore
7682 clone_tree_partial wouldn't be called. */
7683 gcc_assert (*slot == HTAB_EMPTY_ENTRY);
7685 entry = XCNEW (struct decl_table_entry);
7687 entry->copy = clone;
7690 if (die->die_tag != DW_TAG_subprogram)
7691 FOR_EACH_CHILD (die, c,
7692 add_child_die (clone, clone_tree_partial (c, decl_table)));
7697 /* Walk the DIE and its children, looking for references to incomplete
7698 or trivial types that are unmarked (i.e., that are not in the current
7702 copy_decls_walk (dw_die_ref unit, dw_die_ref die, decl_hash_type *decl_table)
7708 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7710 if (AT_class (a) == dw_val_class_die_ref)
7712 dw_die_ref targ = AT_ref (a);
7713 decl_table_entry **slot;
7714 struct decl_table_entry *entry;
7716 if (targ->die_mark != 0 || targ->comdat_type_p)
7719 slot = decl_table->find_slot_with_hash (targ,
7720 htab_hash_pointer (targ),
7723 if (*slot != HTAB_EMPTY_ENTRY)
7725 /* TARG has already been copied, so we just need to
7726 modify the reference to point to the copy. */
7728 a->dw_attr_val.v.val_die_ref.die = entry->copy;
7732 dw_die_ref parent = unit;
7733 dw_die_ref copy = clone_die (targ);
7735 /* Record in DECL_TABLE that TARG has been copied.
7736 Need to do this now, before the recursive call,
7737 because DECL_TABLE may be expanded and SLOT
7738 would no longer be a valid pointer. */
7739 entry = XCNEW (struct decl_table_entry);
7744 /* If TARG is not a declaration DIE, we need to copy its
7746 if (!is_declaration_die (targ))
7750 add_child_die (copy,
7751 clone_tree_partial (c, decl_table)));
7754 /* Make sure the cloned tree is marked as part of the
7758 /* If TARG has surrounding context, copy its ancestor tree
7759 into the new type unit. */
7760 if (targ->die_parent != NULL
7761 && !is_unit_die (targ->die_parent))
7762 parent = copy_ancestor_tree (unit, targ->die_parent,
7765 add_child_die (parent, copy);
7766 a->dw_attr_val.v.val_die_ref.die = copy;
7768 /* Make sure the newly-copied DIE is walked. If it was
7769 installed in a previously-added context, it won't
7770 get visited otherwise. */
7773 /* Find the highest point of the newly-added tree,
7774 mark each node along the way, and walk from there. */
7775 parent->die_mark = 1;
7776 while (parent->die_parent
7777 && parent->die_parent->die_mark == 0)
7779 parent = parent->die_parent;
7780 parent->die_mark = 1;
7782 copy_decls_walk (unit, parent, decl_table);
7788 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
7791 /* Copy declarations for "unworthy" types into the new comdat section.
7792 Incomplete types, modified types, and certain other types aren't broken
7793 out into comdat sections of their own, so they don't have a signature,
7794 and we need to copy the declaration into the same section so that we
7795 don't have an external reference. */
7798 copy_decls_for_unworthy_types (dw_die_ref unit)
7801 decl_hash_type decl_table (10);
7802 copy_decls_walk (unit, unit, &decl_table);
7806 /* Traverse the DIE and add a sibling attribute if it may have the
7807 effect of speeding up access to siblings. To save some space,
7808 avoid generating sibling attributes for DIE's without children. */
7811 add_sibling_attributes (dw_die_ref die)
7815 if (! die->die_child)
7818 if (die->die_parent && die != die->die_parent->die_child)
7819 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7821 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7824 /* Output all location lists for the DIE and its children. */
7827 output_location_lists (dw_die_ref die)
7833 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7834 if (AT_class (a) == dw_val_class_loc_list)
7835 output_loc_list (AT_loc_list (a));
7837 FOR_EACH_CHILD (die, c, output_location_lists (c));
7840 /* We want to limit the number of external references, because they are
7841 larger than local references: a relocation takes multiple words, and
7842 even a sig8 reference is always eight bytes, whereas a local reference
7843 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7844 So if we encounter multiple external references to the same type DIE, we
7845 make a local typedef stub for it and redirect all references there.
7847 This is the element of the hash table for keeping track of these
7857 /* Hashtable helpers. */
7859 struct external_ref_hasher : free_ptr_hash <external_ref>
7861 static inline hashval_t hash (const external_ref *);
7862 static inline bool equal (const external_ref *, const external_ref *);
7866 external_ref_hasher::hash (const external_ref *r)
7868 dw_die_ref die = r->type;
7871 /* We can't use the address of the DIE for hashing, because
7872 that will make the order of the stub DIEs non-deterministic. */
7873 if (! die->comdat_type_p)
7874 /* We have a symbol; use it to compute a hash. */
7875 h = htab_hash_string (die->die_id.die_symbol);
7878 /* We have a type signature; use a subset of the bits as the hash.
7879 The 8-byte signature is at least as large as hashval_t. */
7880 comdat_type_node *type_node = die->die_id.die_type_node;
7881 memcpy (&h, type_node->signature, sizeof (h));
7887 external_ref_hasher::equal (const external_ref *r1, const external_ref *r2)
7889 return r1->type == r2->type;
7892 typedef hash_table<external_ref_hasher> external_ref_hash_type;
7894 /* Return a pointer to the external_ref for references to DIE. */
7896 static struct external_ref *
7897 lookup_external_ref (external_ref_hash_type *map, dw_die_ref die)
7899 struct external_ref ref, *ref_p;
7900 external_ref **slot;
7903 slot = map->find_slot (&ref, INSERT);
7904 if (*slot != HTAB_EMPTY_ENTRY)
7907 ref_p = XCNEW (struct external_ref);
7913 /* Subroutine of optimize_external_refs, below.
7915 If we see a type skeleton, record it as our stub. If we see external
7916 references, remember how many we've seen. */
7919 optimize_external_refs_1 (dw_die_ref die, external_ref_hash_type *map)
7924 struct external_ref *ref_p;
7926 if (is_type_die (die)
7927 && (c = get_AT_ref (die, DW_AT_signature)))
7929 /* This is a local skeleton; use it for local references. */
7930 ref_p = lookup_external_ref (map, c);
7934 /* Scan the DIE references, and remember any that refer to DIEs from
7935 other CUs (i.e. those which are not marked). */
7936 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7937 if (AT_class (a) == dw_val_class_die_ref
7938 && (c = AT_ref (a))->die_mark == 0
7941 ref_p = lookup_external_ref (map, c);
7945 FOR_EACH_CHILD (die, c, optimize_external_refs_1 (c, map));
7948 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7949 points to an external_ref, DATA is the CU we're processing. If we don't
7950 already have a local stub, and we have multiple refs, build a stub. */
7953 dwarf2_build_local_stub (external_ref **slot, dw_die_ref data)
7955 struct external_ref *ref_p = *slot;
7957 if (ref_p->stub == NULL && ref_p->n_refs > 1 && !dwarf_strict)
7959 /* We have multiple references to this type, so build a small stub.
7960 Both of these forms are a bit dodgy from the perspective of the
7961 DWARF standard, since technically they should have names. */
7962 dw_die_ref cu = data;
7963 dw_die_ref type = ref_p->type;
7964 dw_die_ref stub = NULL;
7966 if (type->comdat_type_p)
7968 /* If we refer to this type via sig8, use AT_signature. */
7969 stub = new_die (type->die_tag, cu, NULL_TREE);
7970 add_AT_die_ref (stub, DW_AT_signature, type);
7974 /* Otherwise, use a typedef with no name. */
7975 stub = new_die (DW_TAG_typedef, cu, NULL_TREE);
7976 add_AT_die_ref (stub, DW_AT_type, type);
7985 /* DIE is a unit; look through all the DIE references to see if there are
7986 any external references to types, and if so, create local stubs for
7987 them which will be applied in build_abbrev_table. This is useful because
7988 references to local DIEs are smaller. */
7990 static external_ref_hash_type *
7991 optimize_external_refs (dw_die_ref die)
7993 external_ref_hash_type *map = new external_ref_hash_type (10);
7994 optimize_external_refs_1 (die, map);
7995 map->traverse <dw_die_ref, dwarf2_build_local_stub> (die);
7999 /* The format of each DIE (and its attribute value pairs) is encoded in an
8000 abbreviation table. This routine builds the abbreviation table and assigns
8001 a unique abbreviation id for each abbreviation entry. The children of each
8002 die are visited recursively. */
8005 build_abbrev_table (dw_die_ref die, external_ref_hash_type *extern_map)
8007 unsigned long abbrev_id;
8008 unsigned int n_alloc;
8013 /* Scan the DIE references, and replace any that refer to
8014 DIEs from other CUs (i.e. those which are not marked) with
8015 the local stubs we built in optimize_external_refs. */
8016 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8017 if (AT_class (a) == dw_val_class_die_ref
8018 && (c = AT_ref (a))->die_mark == 0)
8020 struct external_ref *ref_p;
8021 gcc_assert (AT_ref (a)->comdat_type_p || AT_ref (a)->die_id.die_symbol);
8023 ref_p = lookup_external_ref (extern_map, c);
8024 if (ref_p->stub && ref_p->stub != die)
8025 change_AT_die_ref (a, ref_p->stub);
8027 /* We aren't changing this reference, so mark it external. */
8028 set_AT_ref_external (a, 1);
8031 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8033 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8034 dw_attr_node *die_a, *abbrev_a;
8038 if (abbrev->die_tag != die->die_tag)
8040 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
8043 if (vec_safe_length (abbrev->die_attr) != vec_safe_length (die->die_attr))
8046 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, die_a)
8048 abbrev_a = &(*abbrev->die_attr)[ix];
8049 if ((abbrev_a->dw_attr != die_a->dw_attr)
8050 || (value_format (abbrev_a) != value_format (die_a)))
8060 if (abbrev_id >= abbrev_die_table_in_use)
8062 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
8064 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
8065 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8068 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8069 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8070 abbrev_die_table_allocated = n_alloc;
8073 ++abbrev_die_table_in_use;
8074 abbrev_die_table[abbrev_id] = die;
8077 die->die_abbrev = abbrev_id;
8078 FOR_EACH_CHILD (die, c, build_abbrev_table (c, extern_map));
8081 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8084 constant_size (unsigned HOST_WIDE_INT value)
8091 log = floor_log2 (value);
8094 log = 1 << (floor_log2 (log) + 1);
8099 /* Return the size of a DIE as it is represented in the
8100 .debug_info section. */
8102 static unsigned long
8103 size_of_die (dw_die_ref die)
8105 unsigned long size = 0;
8108 enum dwarf_form form;
8110 size += size_of_uleb128 (die->die_abbrev);
8111 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8113 switch (AT_class (a))
8115 case dw_val_class_addr:
8116 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8118 gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
8119 size += size_of_uleb128 (AT_index (a));
8122 size += DWARF2_ADDR_SIZE;
8124 case dw_val_class_offset:
8125 size += DWARF_OFFSET_SIZE;
8127 case dw_val_class_loc:
8129 unsigned long lsize = size_of_locs (AT_loc (a));
8132 if (dwarf_version >= 4)
8133 size += size_of_uleb128 (lsize);
8135 size += constant_size (lsize);
8139 case dw_val_class_loc_list:
8140 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8142 gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
8143 size += size_of_uleb128 (AT_index (a));
8146 size += DWARF_OFFSET_SIZE;
8148 case dw_val_class_range_list:
8149 size += DWARF_OFFSET_SIZE;
8151 case dw_val_class_const:
8152 size += size_of_sleb128 (AT_int (a));
8154 case dw_val_class_unsigned_const:
8156 int csize = constant_size (AT_unsigned (a));
8157 if (dwarf_version == 3
8158 && a->dw_attr == DW_AT_data_member_location
8160 size += size_of_uleb128 (AT_unsigned (a));
8165 case dw_val_class_const_double:
8166 size += HOST_BITS_PER_DOUBLE_INT / HOST_BITS_PER_CHAR;
8167 if (HOST_BITS_PER_WIDE_INT >= 64)
8170 case dw_val_class_wide_int:
8171 size += (get_full_len (*a->dw_attr_val.v.val_wide)
8172 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
8173 if (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT
8177 case dw_val_class_vec:
8178 size += constant_size (a->dw_attr_val.v.val_vec.length
8179 * a->dw_attr_val.v.val_vec.elt_size)
8180 + a->dw_attr_val.v.val_vec.length
8181 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8183 case dw_val_class_flag:
8184 if (dwarf_version >= 4)
8185 /* Currently all add_AT_flag calls pass in 1 as last argument,
8186 so DW_FORM_flag_present can be used. If that ever changes,
8187 we'll need to use DW_FORM_flag and have some optimization
8188 in build_abbrev_table that will change those to
8189 DW_FORM_flag_present if it is set to 1 in all DIEs using
8190 the same abbrev entry. */
8191 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8195 case dw_val_class_die_ref:
8196 if (AT_ref_external (a))
8198 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8199 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8200 is sized by target address length, whereas in DWARF3
8201 it's always sized as an offset. */
8202 if (use_debug_types)
8203 size += DWARF_TYPE_SIGNATURE_SIZE;
8204 else if (dwarf_version == 2)
8205 size += DWARF2_ADDR_SIZE;
8207 size += DWARF_OFFSET_SIZE;
8210 size += DWARF_OFFSET_SIZE;
8212 case dw_val_class_fde_ref:
8213 size += DWARF_OFFSET_SIZE;
8215 case dw_val_class_lbl_id:
8216 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8218 gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
8219 size += size_of_uleb128 (AT_index (a));
8222 size += DWARF2_ADDR_SIZE;
8224 case dw_val_class_lineptr:
8225 case dw_val_class_macptr:
8226 size += DWARF_OFFSET_SIZE;
8228 case dw_val_class_str:
8229 form = AT_string_form (a);
8230 if (form == DW_FORM_strp)
8231 size += DWARF_OFFSET_SIZE;
8232 else if (form == DW_FORM_GNU_str_index)
8233 size += size_of_uleb128 (AT_index (a));
8235 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8237 case dw_val_class_file:
8238 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8240 case dw_val_class_data8:
8243 case dw_val_class_vms_delta:
8244 size += DWARF_OFFSET_SIZE;
8246 case dw_val_class_high_pc:
8247 size += DWARF2_ADDR_SIZE;
8257 /* Size the debugging information associated with a given DIE. Visits the
8258 DIE's children recursively. Updates the global variable next_die_offset, on
8259 each time through. Uses the current value of next_die_offset to update the
8260 die_offset field in each DIE. */
8263 calc_die_sizes (dw_die_ref die)
8267 gcc_assert (die->die_offset == 0
8268 || (unsigned long int) die->die_offset == next_die_offset);
8269 die->die_offset = next_die_offset;
8270 next_die_offset += size_of_die (die);
8272 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8274 if (die->die_child != NULL)
8275 /* Count the null byte used to terminate sibling lists. */
8276 next_die_offset += 1;
8279 /* Size just the base type children at the start of the CU.
8280 This is needed because build_abbrev needs to size locs
8281 and sizing of type based stack ops needs to know die_offset
8282 values for the base types. */
8285 calc_base_type_die_sizes (void)
8287 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8289 dw_die_ref base_type;
8290 #if ENABLE_ASSERT_CHECKING
8291 dw_die_ref prev = comp_unit_die ()->die_child;
8294 die_offset += size_of_die (comp_unit_die ());
8295 for (i = 0; base_types.iterate (i, &base_type); i++)
8297 #if ENABLE_ASSERT_CHECKING
8298 gcc_assert (base_type->die_offset == 0
8299 && prev->die_sib == base_type
8300 && base_type->die_child == NULL
8301 && base_type->die_abbrev);
8304 base_type->die_offset = die_offset;
8305 die_offset += size_of_die (base_type);
8309 /* Set the marks for a die and its children. We do this so
8310 that we know whether or not a reference needs to use FORM_ref_addr; only
8311 DIEs in the same CU will be marked. We used to clear out the offset
8312 and use that as the flag, but ran into ordering problems. */
8315 mark_dies (dw_die_ref die)
8319 gcc_assert (!die->die_mark);
8322 FOR_EACH_CHILD (die, c, mark_dies (c));
8325 /* Clear the marks for a die and its children. */
8328 unmark_dies (dw_die_ref die)
8332 if (! use_debug_types)
8333 gcc_assert (die->die_mark);
8336 FOR_EACH_CHILD (die, c, unmark_dies (c));
8339 /* Clear the marks for a die, its children and referred dies. */
8342 unmark_all_dies (dw_die_ref die)
8352 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8354 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8355 if (AT_class (a) == dw_val_class_die_ref)
8356 unmark_all_dies (AT_ref (a));
8359 /* Calculate if the entry should appear in the final output file. It may be
8360 from a pruned a type. */
8363 include_pubname_in_output (vec<pubname_entry, va_gc> *table, pubname_entry *p)
8365 /* By limiting gnu pubnames to definitions only, gold can generate a
8366 gdb index without entries for declarations, which don't include
8367 enough information to be useful. */
8368 if (debug_generate_pub_sections == 2 && is_declaration_die (p->die))
8371 if (table == pubname_table)
8373 /* Enumerator names are part of the pubname table, but the
8374 parent DW_TAG_enumeration_type die may have been pruned.
8375 Don't output them if that is the case. */
8376 if (p->die->die_tag == DW_TAG_enumerator &&
8377 (p->die->die_parent == NULL
8378 || !p->die->die_parent->die_perennial_p))
8381 /* Everything else in the pubname table is included. */
8385 /* The pubtypes table shouldn't include types that have been
8387 return (p->die->die_offset != 0
8388 || !flag_eliminate_unused_debug_types);
8391 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8392 generated for the compilation unit. */
8394 static unsigned long
8395 size_of_pubnames (vec<pubname_entry, va_gc> *names)
8400 int space_for_flags = (debug_generate_pub_sections == 2) ? 1 : 0;
8402 size = DWARF_PUBNAMES_HEADER_SIZE;
8403 FOR_EACH_VEC_ELT (*names, i, p)
8404 if (include_pubname_in_output (names, p))
8405 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1 + space_for_flags;
8407 size += DWARF_OFFSET_SIZE;
8411 /* Return the size of the information in the .debug_aranges section. */
8413 static unsigned long
8414 size_of_aranges (void)
8418 size = DWARF_ARANGES_HEADER_SIZE;
8420 /* Count the address/length pair for this compilation unit. */
8421 if (text_section_used)
8422 size += 2 * DWARF2_ADDR_SIZE;
8423 if (cold_text_section_used)
8424 size += 2 * DWARF2_ADDR_SIZE;
8425 if (have_multiple_function_sections)
8430 FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
8432 if (DECL_IGNORED_P (fde->decl))
8434 if (!fde->in_std_section)
8435 size += 2 * DWARF2_ADDR_SIZE;
8436 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
8437 size += 2 * DWARF2_ADDR_SIZE;
8441 /* Count the two zero words used to terminated the address range table. */
8442 size += 2 * DWARF2_ADDR_SIZE;
8446 /* Select the encoding of an attribute value. */
8448 static enum dwarf_form
8449 value_format (dw_attr_node *a)
8451 switch (AT_class (a))
8453 case dw_val_class_addr:
8454 /* Only very few attributes allow DW_FORM_addr. */
8459 case DW_AT_entry_pc:
8460 case DW_AT_trampoline:
8461 return (AT_index (a) == NOT_INDEXED
8462 ? DW_FORM_addr : DW_FORM_GNU_addr_index);
8466 switch (DWARF2_ADDR_SIZE)
8469 return DW_FORM_data1;
8471 return DW_FORM_data2;
8473 return DW_FORM_data4;
8475 return DW_FORM_data8;
8479 case dw_val_class_range_list:
8480 case dw_val_class_loc_list:
8481 if (dwarf_version >= 4)
8482 return DW_FORM_sec_offset;
8484 case dw_val_class_vms_delta:
8485 case dw_val_class_offset:
8486 switch (DWARF_OFFSET_SIZE)
8489 return DW_FORM_data4;
8491 return DW_FORM_data8;
8495 case dw_val_class_loc:
8496 if (dwarf_version >= 4)
8497 return DW_FORM_exprloc;
8498 switch (constant_size (size_of_locs (AT_loc (a))))
8501 return DW_FORM_block1;
8503 return DW_FORM_block2;
8505 return DW_FORM_block4;
8509 case dw_val_class_const:
8510 return DW_FORM_sdata;
8511 case dw_val_class_unsigned_const:
8512 switch (constant_size (AT_unsigned (a)))
8515 return DW_FORM_data1;
8517 return DW_FORM_data2;
8519 /* In DWARF3 DW_AT_data_member_location with
8520 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8521 constant, so we need to use DW_FORM_udata if we need
8522 a large constant. */
8523 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
8524 return DW_FORM_udata;
8525 return DW_FORM_data4;
8527 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
8528 return DW_FORM_udata;
8529 return DW_FORM_data8;
8533 case dw_val_class_const_double:
8534 switch (HOST_BITS_PER_WIDE_INT)
8537 return DW_FORM_data2;
8539 return DW_FORM_data4;
8541 return DW_FORM_data8;
8544 return DW_FORM_block1;
8546 case dw_val_class_wide_int:
8547 switch (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT)
8550 return DW_FORM_data1;
8552 return DW_FORM_data2;
8554 return DW_FORM_data4;
8556 return DW_FORM_data8;
8558 return DW_FORM_block1;
8560 case dw_val_class_vec:
8561 switch (constant_size (a->dw_attr_val.v.val_vec.length
8562 * a->dw_attr_val.v.val_vec.elt_size))
8565 return DW_FORM_block1;
8567 return DW_FORM_block2;
8569 return DW_FORM_block4;
8573 case dw_val_class_flag:
8574 if (dwarf_version >= 4)
8576 /* Currently all add_AT_flag calls pass in 1 as last argument,
8577 so DW_FORM_flag_present can be used. If that ever changes,
8578 we'll need to use DW_FORM_flag and have some optimization
8579 in build_abbrev_table that will change those to
8580 DW_FORM_flag_present if it is set to 1 in all DIEs using
8581 the same abbrev entry. */
8582 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8583 return DW_FORM_flag_present;
8585 return DW_FORM_flag;
8586 case dw_val_class_die_ref:
8587 if (AT_ref_external (a))
8588 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
8591 case dw_val_class_fde_ref:
8592 return DW_FORM_data;
8593 case dw_val_class_lbl_id:
8594 return (AT_index (a) == NOT_INDEXED
8595 ? DW_FORM_addr : DW_FORM_GNU_addr_index);
8596 case dw_val_class_lineptr:
8597 case dw_val_class_macptr:
8598 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
8599 case dw_val_class_str:
8600 return AT_string_form (a);
8601 case dw_val_class_file:
8602 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8605 return DW_FORM_data1;
8607 return DW_FORM_data2;
8609 return DW_FORM_data4;
8614 case dw_val_class_data8:
8615 return DW_FORM_data8;
8617 case dw_val_class_high_pc:
8618 switch (DWARF2_ADDR_SIZE)
8621 return DW_FORM_data1;
8623 return DW_FORM_data2;
8625 return DW_FORM_data4;
8627 return DW_FORM_data8;
8637 /* Output the encoding of an attribute value. */
8640 output_value_format (dw_attr_node *a)
8642 enum dwarf_form form = value_format (a);
8644 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8647 /* Given a die and id, produce the appropriate abbreviations. */
8650 output_die_abbrevs (unsigned long abbrev_id, dw_die_ref abbrev)
8653 dw_attr_node *a_attr;
8655 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8656 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8657 dwarf_tag_name (abbrev->die_tag));
8659 if (abbrev->die_child != NULL)
8660 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8662 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8664 for (ix = 0; vec_safe_iterate (abbrev->die_attr, ix, &a_attr); ix++)
8666 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8667 dwarf_attr_name (a_attr->dw_attr));
8668 output_value_format (a_attr);
8671 dw2_asm_output_data (1, 0, NULL);
8672 dw2_asm_output_data (1, 0, NULL);
8676 /* Output the .debug_abbrev section which defines the DIE abbreviation
8680 output_abbrev_section (void)
8682 unsigned long abbrev_id;
8684 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8685 output_die_abbrevs (abbrev_id, abbrev_die_table[abbrev_id]);
8687 /* Terminate the table. */
8688 dw2_asm_output_data (1, 0, NULL);
8691 /* Output a symbol we can use to refer to this DIE from another CU. */
8694 output_die_symbol (dw_die_ref die)
8696 const char *sym = die->die_id.die_symbol;
8698 gcc_assert (!die->comdat_type_p);
8703 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8704 /* We make these global, not weak; if the target doesn't support
8705 .linkonce, it doesn't support combining the sections, so debugging
8707 targetm.asm_out.globalize_label (asm_out_file, sym);
8709 ASM_OUTPUT_LABEL (asm_out_file, sym);
8712 /* Return a new location list, given the begin and end range, and the
8715 static inline dw_loc_list_ref
8716 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8717 const char *section)
8719 dw_loc_list_ref retlist = ggc_cleared_alloc<dw_loc_list_node> ();
8721 retlist->begin = begin;
8722 retlist->begin_entry = NULL;
8724 retlist->expr = expr;
8725 retlist->section = section;
8730 /* Generate a new internal symbol for this location list node, if it
8731 hasn't got one yet. */
8734 gen_llsym (dw_loc_list_ref list)
8736 gcc_assert (!list->ll_symbol);
8737 list->ll_symbol = gen_internal_sym ("LLST");
8740 /* Output the location list given to us. */
8743 output_loc_list (dw_loc_list_ref list_head)
8745 dw_loc_list_ref curr = list_head;
8747 if (list_head->emitted)
8749 list_head->emitted = true;
8751 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8753 /* Walk the location list, and output each range + expression. */
8754 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8757 /* Don't output an entry that starts and ends at the same address. */
8758 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
8760 size = size_of_locs (curr->expr);
8761 /* If the expression is too large, drop it on the floor. We could
8762 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8763 in the expression, but >= 64KB expressions for a single value
8764 in a single range are unlikely very useful. */
8767 if (dwarf_split_debug_info)
8769 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry,
8770 "Location list start/length entry (%s)",
8771 list_head->ll_symbol);
8772 dw2_asm_output_data_uleb128 (curr->begin_entry->index,
8773 "Location list range start index (%s)",
8775 /* The length field is 4 bytes. If we ever need to support
8776 an 8-byte length, we can add a new DW_LLE code or fall back
8777 to DW_LLE_GNU_start_end_entry. */
8778 dw2_asm_output_delta (4, curr->end, curr->begin,
8779 "Location list range length (%s)",
8780 list_head->ll_symbol);
8782 else if (!have_multiple_function_sections)
8784 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8785 "Location list begin address (%s)",
8786 list_head->ll_symbol);
8787 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8788 "Location list end address (%s)",
8789 list_head->ll_symbol);
8793 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8794 "Location list begin address (%s)",
8795 list_head->ll_symbol);
8796 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8797 "Location list end address (%s)",
8798 list_head->ll_symbol);
8801 /* Output the block length for this list of location operations. */
8802 gcc_assert (size <= 0xffff);
8803 dw2_asm_output_data (2, size, "%s", "Location expression size");
8805 output_loc_sequence (curr->expr, -1);
8808 if (dwarf_split_debug_info)
8809 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry,
8810 "Location list terminator (%s)",
8811 list_head->ll_symbol);
8814 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8815 "Location list terminator begin (%s)",
8816 list_head->ll_symbol);
8817 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8818 "Location list terminator end (%s)",
8819 list_head->ll_symbol);
8823 /* Output a range_list offset into the debug_range section. Emit a
8824 relocated reference if val_entry is NULL, otherwise, emit an
8825 indirect reference. */
8828 output_range_list_offset (dw_attr_node *a)
8830 const char *name = dwarf_attr_name (a->dw_attr);
8832 if (a->dw_attr_val.val_entry == RELOCATED_OFFSET)
8834 char *p = strchr (ranges_section_label, '\0');
8835 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX, a->dw_attr_val.v.val_offset);
8836 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8837 debug_ranges_section, "%s", name);
8841 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8842 "%s (offset from %s)", name, ranges_section_label);
8845 /* Output the offset into the debug_loc section. */
8848 output_loc_list_offset (dw_attr_node *a)
8850 char *sym = AT_loc_list (a)->ll_symbol;
8853 if (dwarf_split_debug_info)
8854 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label,
8855 "%s", dwarf_attr_name (a->dw_attr));
8857 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8858 "%s", dwarf_attr_name (a->dw_attr));
8861 /* Output an attribute's index or value appropriately. */
8864 output_attr_index_or_value (dw_attr_node *a)
8866 const char *name = dwarf_attr_name (a->dw_attr);
8868 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8870 dw2_asm_output_data_uleb128 (AT_index (a), "%s", name);
8873 switch (AT_class (a))
8875 case dw_val_class_addr:
8876 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8878 case dw_val_class_high_pc:
8879 case dw_val_class_lbl_id:
8880 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8882 case dw_val_class_loc_list:
8883 output_loc_list_offset (a);
8890 /* Output a type signature. */
8893 output_signature (const char *sig, const char *name)
8897 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8898 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
8901 /* Output the DIE and its attributes. Called recursively to generate
8902 the definitions of each child DIE. */
8905 output_die (dw_die_ref die)
8912 /* If someone in another CU might refer to us, set up a symbol for
8913 them to point to. */
8914 if (! die->comdat_type_p && die->die_id.die_symbol)
8915 output_die_symbol (die);
8917 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
8918 (unsigned long)die->die_offset,
8919 dwarf_tag_name (die->die_tag));
8921 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8923 const char *name = dwarf_attr_name (a->dw_attr);
8925 switch (AT_class (a))
8927 case dw_val_class_addr:
8928 output_attr_index_or_value (a);
8931 case dw_val_class_offset:
8932 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8936 case dw_val_class_range_list:
8937 output_range_list_offset (a);
8940 case dw_val_class_loc:
8941 size = size_of_locs (AT_loc (a));
8943 /* Output the block length for this list of location operations. */
8944 if (dwarf_version >= 4)
8945 dw2_asm_output_data_uleb128 (size, "%s", name);
8947 dw2_asm_output_data (constant_size (size), size, "%s", name);
8949 output_loc_sequence (AT_loc (a), -1);
8952 case dw_val_class_const:
8953 /* ??? It would be slightly more efficient to use a scheme like is
8954 used for unsigned constants below, but gdb 4.x does not sign
8955 extend. Gdb 5.x does sign extend. */
8956 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8959 case dw_val_class_unsigned_const:
8961 int csize = constant_size (AT_unsigned (a));
8962 if (dwarf_version == 3
8963 && a->dw_attr == DW_AT_data_member_location
8965 dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name);
8967 dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
8971 case dw_val_class_const_double:
8973 unsigned HOST_WIDE_INT first, second;
8975 if (HOST_BITS_PER_WIDE_INT >= 64)
8976 dw2_asm_output_data (1,
8977 HOST_BITS_PER_DOUBLE_INT
8978 / HOST_BITS_PER_CHAR,
8981 if (WORDS_BIG_ENDIAN)
8983 first = a->dw_attr_val.v.val_double.high;
8984 second = a->dw_attr_val.v.val_double.low;
8988 first = a->dw_attr_val.v.val_double.low;
8989 second = a->dw_attr_val.v.val_double.high;
8992 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8994 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8999 case dw_val_class_wide_int:
9002 int len = get_full_len (*a->dw_attr_val.v.val_wide);
9003 int l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
9004 if (len * HOST_BITS_PER_WIDE_INT > 64)
9005 dw2_asm_output_data (1, get_full_len (*a->dw_attr_val.v.val_wide) * l,
9008 if (WORDS_BIG_ENDIAN)
9009 for (i = len - 1; i >= 0; --i)
9011 dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
9016 for (i = 0; i < len; ++i)
9018 dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
9025 case dw_val_class_vec:
9027 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
9028 unsigned int len = a->dw_attr_val.v.val_vec.length;
9032 dw2_asm_output_data (constant_size (len * elt_size),
9033 len * elt_size, "%s", name);
9034 if (elt_size > sizeof (HOST_WIDE_INT))
9039 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
9042 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
9043 "fp or vector constant word %u", i);
9047 case dw_val_class_flag:
9048 if (dwarf_version >= 4)
9050 /* Currently all add_AT_flag calls pass in 1 as last argument,
9051 so DW_FORM_flag_present can be used. If that ever changes,
9052 we'll need to use DW_FORM_flag and have some optimization
9053 in build_abbrev_table that will change those to
9054 DW_FORM_flag_present if it is set to 1 in all DIEs using
9055 the same abbrev entry. */
9056 gcc_assert (AT_flag (a) == 1);
9058 fprintf (asm_out_file, "\t\t\t%s %s\n",
9059 ASM_COMMENT_START, name);
9062 dw2_asm_output_data (1, AT_flag (a), "%s", name);
9065 case dw_val_class_loc_list:
9066 output_attr_index_or_value (a);
9069 case dw_val_class_die_ref:
9070 if (AT_ref_external (a))
9072 if (AT_ref (a)->comdat_type_p)
9074 comdat_type_node *type_node =
9075 AT_ref (a)->die_id.die_type_node;
9077 gcc_assert (type_node);
9078 output_signature (type_node->signature, name);
9082 const char *sym = AT_ref (a)->die_id.die_symbol;
9086 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9087 length, whereas in DWARF3 it's always sized as an
9089 if (dwarf_version == 2)
9090 size = DWARF2_ADDR_SIZE;
9092 size = DWARF_OFFSET_SIZE;
9093 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
9099 gcc_assert (AT_ref (a)->die_offset);
9100 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
9105 case dw_val_class_fde_ref:
9109 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
9110 a->dw_attr_val.v.val_fde_index * 2);
9111 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
9116 case dw_val_class_vms_delta:
9117 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9118 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
9119 AT_vms_delta2 (a), AT_vms_delta1 (a),
9122 dw2_asm_output_delta (DWARF_OFFSET_SIZE,
9123 AT_vms_delta2 (a), AT_vms_delta1 (a),
9128 case dw_val_class_lbl_id:
9129 output_attr_index_or_value (a);
9132 case dw_val_class_lineptr:
9133 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9134 debug_line_section, "%s", name);
9137 case dw_val_class_macptr:
9138 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9139 debug_macinfo_section, "%s", name);
9142 case dw_val_class_str:
9143 if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
9144 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
9145 a->dw_attr_val.v.val_str->label,
9147 "%s: \"%s\"", name, AT_string (a));
9148 else if (a->dw_attr_val.v.val_str->form == DW_FORM_GNU_str_index)
9149 dw2_asm_output_data_uleb128 (AT_index (a),
9150 "%s: \"%s\"", name, AT_string (a));
9152 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
9155 case dw_val_class_file:
9157 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
9159 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
9160 a->dw_attr_val.v.val_file->filename);
9164 case dw_val_class_data8:
9168 for (i = 0; i < 8; i++)
9169 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
9170 i == 0 ? "%s" : NULL, name);
9174 case dw_val_class_high_pc:
9175 dw2_asm_output_delta (DWARF2_ADDR_SIZE, AT_lbl (a),
9176 get_AT_low_pc (die), "DW_AT_high_pc");
9184 FOR_EACH_CHILD (die, c, output_die (c));
9186 /* Add null byte to terminate sibling list. */
9187 if (die->die_child != NULL)
9188 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9189 (unsigned long) die->die_offset);
9192 /* Output the compilation unit that appears at the beginning of the
9193 .debug_info section, and precedes the DIE descriptions. */
9196 output_compilation_unit_header (void)
9198 /* We don't support actual DWARFv5 units yet, we just use some
9199 DWARFv5 draft DIE tags in DWARFv4 format. */
9200 int ver = dwarf_version < 5 ? dwarf_version : 4;
9202 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9203 dw2_asm_output_data (4, 0xffffffff,
9204 "Initial length escape value indicating 64-bit DWARF extension");
9205 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9206 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
9207 "Length of Compilation Unit Info");
9208 dw2_asm_output_data (2, ver, "DWARF version number");
9209 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
9210 debug_abbrev_section,
9211 "Offset Into Abbrev. Section");
9212 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9215 /* Output the compilation unit DIE and its children. */
9218 output_comp_unit (dw_die_ref die, int output_if_empty)
9220 const char *secname, *oldsym;
9223 /* Unless we are outputting main CU, we may throw away empty ones. */
9224 if (!output_if_empty && die->die_child == NULL)
9227 /* Even if there are no children of this DIE, we must output the information
9228 about the compilation unit. Otherwise, on an empty translation unit, we
9229 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9230 will then complain when examining the file. First mark all the DIEs in
9231 this CU so we know which get local refs. */
9234 external_ref_hash_type *extern_map = optimize_external_refs (die);
9236 build_abbrev_table (die, extern_map);
9240 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9241 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9242 calc_die_sizes (die);
9244 oldsym = die->die_id.die_symbol;
9247 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
9249 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
9251 die->die_id.die_symbol = NULL;
9252 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9256 switch_to_section (debug_info_section);
9257 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9258 info_section_emitted = true;
9261 /* Output debugging information. */
9262 output_compilation_unit_header ();
9265 /* Leave the marks on the main CU, so we can check them in
9270 die->die_id.die_symbol = oldsym;
9274 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9275 and .debug_pubtypes. This is configured per-target, but can be
9276 overridden by the -gpubnames or -gno-pubnames options. */
9279 want_pubnames (void)
9281 if (debug_info_level <= DINFO_LEVEL_TERSE)
9283 if (debug_generate_pub_sections != -1)
9284 return debug_generate_pub_sections;
9285 return targetm.want_debug_pub_sections;
9288 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9291 add_AT_pubnames (dw_die_ref die)
9293 if (want_pubnames ())
9294 add_AT_flag (die, DW_AT_GNU_pubnames, 1);
9297 /* Add a string attribute value to a skeleton DIE. */
9300 add_skeleton_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
9304 struct indirect_string_node *node;
9306 if (! skeleton_debug_str_hash)
9307 skeleton_debug_str_hash
9308 = hash_table<indirect_string_hasher>::create_ggc (10);
9310 node = find_AT_string_in_table (str, skeleton_debug_str_hash);
9311 find_string_form (node);
9312 if (node->form == DW_FORM_GNU_str_index)
9313 node->form = DW_FORM_strp;
9315 attr.dw_attr = attr_kind;
9316 attr.dw_attr_val.val_class = dw_val_class_str;
9317 attr.dw_attr_val.val_entry = NULL;
9318 attr.dw_attr_val.v.val_str = node;
9319 add_dwarf_attr (die, &attr);
9322 /* Helper function to generate top-level dies for skeleton debug_info and
9326 add_top_level_skeleton_die_attrs (dw_die_ref die)
9328 const char *dwo_file_name = concat (aux_base_name, ".dwo", NULL);
9329 const char *comp_dir = comp_dir_string ();
9331 add_skeleton_AT_string (die, DW_AT_GNU_dwo_name, dwo_file_name);
9332 if (comp_dir != NULL)
9333 add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir);
9334 add_AT_pubnames (die);
9335 add_AT_lineptr (die, DW_AT_GNU_addr_base, debug_addr_section_label);
9338 /* Output skeleton debug sections that point to the dwo file. */
9341 output_skeleton_debug_sections (dw_die_ref comp_unit)
9343 /* We don't support actual DWARFv5 units yet, we just use some
9344 DWARFv5 draft DIE tags in DWARFv4 format. */
9345 int ver = dwarf_version < 5 ? dwarf_version : 4;
9347 /* These attributes will be found in the full debug_info section. */
9348 remove_AT (comp_unit, DW_AT_producer);
9349 remove_AT (comp_unit, DW_AT_language);
9351 switch_to_section (debug_skeleton_info_section);
9352 ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_info_section_label);
9354 /* Produce the skeleton compilation-unit header. This one differs enough from
9355 a normal CU header that it's better not to call output_compilation_unit
9357 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9358 dw2_asm_output_data (4, 0xffffffff,
9359 "Initial length escape value indicating 64-bit DWARF extension");
9361 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9362 DWARF_COMPILE_UNIT_HEADER_SIZE
9363 - DWARF_INITIAL_LENGTH_SIZE
9364 + size_of_die (comp_unit),
9365 "Length of Compilation Unit Info");
9366 dw2_asm_output_data (2, ver, "DWARF version number");
9367 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_abbrev_section_label,
9368 debug_abbrev_section,
9369 "Offset Into Abbrev. Section");
9370 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9372 comp_unit->die_abbrev = SKELETON_COMP_DIE_ABBREV;
9373 output_die (comp_unit);
9375 /* Build the skeleton debug_abbrev section. */
9376 switch_to_section (debug_skeleton_abbrev_section);
9377 ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_abbrev_section_label);
9379 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV, comp_unit);
9381 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9384 /* Output a comdat type unit DIE and its children. */
9387 output_comdat_type_unit (comdat_type_node *node)
9389 const char *secname;
9392 #if defined (OBJECT_FORMAT_ELF)
9396 /* First mark all the DIEs in this CU so we know which get local refs. */
9397 mark_dies (node->root_die);
9399 external_ref_hash_type *extern_map = optimize_external_refs (node->root_die);
9401 build_abbrev_table (node->root_die, extern_map);
9406 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9407 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
9408 calc_die_sizes (node->root_die);
9410 #if defined (OBJECT_FORMAT_ELF)
9411 if (!dwarf_split_debug_info)
9412 secname = ".debug_types";
9414 secname = ".debug_types.dwo";
9416 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
9417 sprintf (tmp, "wt.");
9418 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9419 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
9420 comdat_key = get_identifier (tmp);
9421 targetm.asm_out.named_section (secname,
9422 SECTION_DEBUG | SECTION_LINKONCE,
9425 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
9426 sprintf (tmp, ".gnu.linkonce.wt.");
9427 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9428 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
9430 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9433 /* Output debugging information. */
9434 output_compilation_unit_header ();
9435 output_signature (node->signature, "Type Signature");
9436 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
9437 "Offset to Type DIE");
9438 output_die (node->root_die);
9440 unmark_dies (node->root_die);
9443 /* Return the DWARF2/3 pubname associated with a decl. */
9446 dwarf2_name (tree decl, int scope)
9448 if (DECL_NAMELESS (decl))
9450 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
9453 /* Add a new entry to .debug_pubnames if appropriate. */
9456 add_pubname_string (const char *str, dw_die_ref die)
9461 e.name = xstrdup (str);
9462 vec_safe_push (pubname_table, e);
9466 add_pubname (tree decl, dw_die_ref die)
9468 if (!want_pubnames ())
9471 /* Don't add items to the table when we expect that the consumer will have
9472 just read the enclosing die. For example, if the consumer is looking at a
9473 class_member, it will either be inside the class already, or will have just
9474 looked up the class to find the member. Either way, searching the class is
9475 faster than searching the index. */
9476 if ((TREE_PUBLIC (decl) && !class_scope_p (die->die_parent))
9477 || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
9479 const char *name = dwarf2_name (decl, 1);
9482 add_pubname_string (name, die);
9486 /* Add an enumerator to the pubnames section. */
9489 add_enumerator_pubname (const char *scope_name, dw_die_ref die)
9493 gcc_assert (scope_name);
9494 e.name = concat (scope_name, get_AT_string (die, DW_AT_name), NULL);
9496 vec_safe_push (pubname_table, e);
9499 /* Add a new entry to .debug_pubtypes if appropriate. */
9502 add_pubtype (tree decl, dw_die_ref die)
9506 if (!want_pubnames ())
9509 if ((TREE_PUBLIC (decl)
9510 || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
9511 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
9514 const char *scope_name = "";
9515 const char *sep = is_cxx () ? "::" : ".";
9518 scope = TYPE_P (decl) ? TYPE_CONTEXT (decl) : NULL;
9519 if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
9521 scope_name = lang_hooks.dwarf_name (scope, 1);
9522 if (scope_name != NULL && scope_name[0] != '\0')
9523 scope_name = concat (scope_name, sep, NULL);
9529 name = type_tag (decl);
9531 name = lang_hooks.dwarf_name (decl, 1);
9533 /* If we don't have a name for the type, there's no point in adding
9535 if (name != NULL && name[0] != '\0')
9538 e.name = concat (scope_name, name, NULL);
9539 vec_safe_push (pubtype_table, e);
9542 /* Although it might be more consistent to add the pubinfo for the
9543 enumerators as their dies are created, they should only be added if the
9544 enum type meets the criteria above. So rather than re-check the parent
9545 enum type whenever an enumerator die is created, just output them all
9546 here. This isn't protected by the name conditional because anonymous
9547 enums don't have names. */
9548 if (die->die_tag == DW_TAG_enumeration_type)
9552 FOR_EACH_CHILD (die, c, add_enumerator_pubname (scope_name, c));
9557 /* Output a single entry in the pubnames table. */
9560 output_pubname (dw_offset die_offset, pubname_entry *entry)
9562 dw_die_ref die = entry->die;
9563 int is_static = get_AT_flag (die, DW_AT_external) ? 0 : 1;
9565 dw2_asm_output_data (DWARF_OFFSET_SIZE, die_offset, "DIE offset");
9567 if (debug_generate_pub_sections == 2)
9569 /* This logic follows gdb's method for determining the value of the flag
9571 uint32_t flags = GDB_INDEX_SYMBOL_KIND_NONE;
9572 switch (die->die_tag)
9574 case DW_TAG_typedef:
9575 case DW_TAG_base_type:
9576 case DW_TAG_subrange_type:
9577 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
9578 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
9580 case DW_TAG_enumerator:
9581 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9582 GDB_INDEX_SYMBOL_KIND_VARIABLE);
9583 if (!is_cxx () && !is_java ())
9584 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
9586 case DW_TAG_subprogram:
9587 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9588 GDB_INDEX_SYMBOL_KIND_FUNCTION);
9590 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
9592 case DW_TAG_constant:
9593 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9594 GDB_INDEX_SYMBOL_KIND_VARIABLE);
9595 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
9597 case DW_TAG_variable:
9598 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9599 GDB_INDEX_SYMBOL_KIND_VARIABLE);
9600 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
9602 case DW_TAG_namespace:
9603 case DW_TAG_imported_declaration:
9604 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
9606 case DW_TAG_class_type:
9607 case DW_TAG_interface_type:
9608 case DW_TAG_structure_type:
9609 case DW_TAG_union_type:
9610 case DW_TAG_enumeration_type:
9611 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
9612 if (!is_cxx () && !is_java ())
9613 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
9616 /* An unusual tag. Leave the flag-byte empty. */
9619 dw2_asm_output_data (1, flags >> GDB_INDEX_CU_BITSIZE,
9623 dw2_asm_output_nstring (entry->name, -1, "external name");
9627 /* Output the public names table used to speed up access to externally
9628 visible names; or the public types table used to find type definitions. */
9631 output_pubnames (vec<pubname_entry, va_gc> *names)
9634 unsigned long pubnames_length = size_of_pubnames (names);
9637 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9638 dw2_asm_output_data (4, 0xffffffff,
9639 "Initial length escape value indicating 64-bit DWARF extension");
9640 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, "Pub Info Length");
9642 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9643 dw2_asm_output_data (2, 2, "DWARF Version");
9645 if (dwarf_split_debug_info)
9646 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
9647 debug_skeleton_info_section,
9648 "Offset of Compilation Unit Info");
9650 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9652 "Offset of Compilation Unit Info");
9653 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
9654 "Compilation Unit Length");
9656 FOR_EACH_VEC_ELT (*names, i, pub)
9658 if (include_pubname_in_output (names, pub))
9660 dw_offset die_offset = pub->die->die_offset;
9662 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9663 if (names == pubname_table && pub->die->die_tag != DW_TAG_enumerator)
9664 gcc_assert (pub->die->die_mark);
9666 /* If we're putting types in their own .debug_types sections,
9667 the .debug_pubtypes table will still point to the compile
9668 unit (not the type unit), so we want to use the offset of
9669 the skeleton DIE (if there is one). */
9670 if (pub->die->comdat_type_p && names == pubtype_table)
9672 comdat_type_node *type_node = pub->die->die_id.die_type_node;
9674 if (type_node != NULL)
9675 die_offset = (type_node->skeleton_die != NULL
9676 ? type_node->skeleton_die->die_offset
9677 : comp_unit_die ()->die_offset);
9680 output_pubname (die_offset, pub);
9684 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
9687 /* Output public names and types tables if necessary. */
9690 output_pubtables (void)
9692 if (!want_pubnames () || !info_section_emitted)
9695 switch_to_section (debug_pubnames_section);
9696 output_pubnames (pubname_table);
9697 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9698 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9699 simply won't look for the section. */
9700 switch_to_section (debug_pubtypes_section);
9701 output_pubnames (pubtype_table);
9705 /* Output the information that goes into the .debug_aranges table.
9706 Namely, define the beginning and ending address range of the
9707 text section generated for this compilation unit. */
9710 output_aranges (unsigned long aranges_length)
9714 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9715 dw2_asm_output_data (4, 0xffffffff,
9716 "Initial length escape value indicating 64-bit DWARF extension");
9717 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
9718 "Length of Address Ranges Info");
9719 /* Version number for aranges is still 2, even up to DWARF5. */
9720 dw2_asm_output_data (2, 2, "DWARF Version");
9721 if (dwarf_split_debug_info)
9722 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
9723 debug_skeleton_info_section,
9724 "Offset of Compilation Unit Info");
9726 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9728 "Offset of Compilation Unit Info");
9729 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
9730 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9732 /* We need to align to twice the pointer size here. */
9733 if (DWARF_ARANGES_PAD_SIZE)
9735 /* Pad using a 2 byte words so that padding is correct for any
9737 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9738 2 * DWARF2_ADDR_SIZE);
9739 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
9740 dw2_asm_output_data (2, 0, NULL);
9743 /* It is necessary not to output these entries if the sections were
9744 not used; if the sections were not used, the length will be 0 and
9745 the address may end up as 0 if the section is discarded by ld
9746 --gc-sections, leaving an invalid (0, 0) entry that can be
9747 confused with the terminator. */
9748 if (text_section_used)
9750 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
9751 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
9752 text_section_label, "Length");
9754 if (cold_text_section_used)
9756 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
9758 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
9759 cold_text_section_label, "Length");
9762 if (have_multiple_function_sections)
9767 FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
9769 if (DECL_IGNORED_P (fde->decl))
9771 if (!fde->in_std_section)
9773 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
9775 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
9776 fde->dw_fde_begin, "Length");
9778 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
9780 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
9782 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
9783 fde->dw_fde_second_begin, "Length");
9788 /* Output the terminator words. */
9789 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9790 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9793 /* Add a new entry to .debug_ranges. Return the offset at which it
9797 add_ranges_num (int num)
9799 unsigned int in_use = ranges_table_in_use;
9801 if (in_use == ranges_table_allocated)
9803 ranges_table_allocated += RANGES_TABLE_INCREMENT;
9804 ranges_table = GGC_RESIZEVEC (dw_ranges, ranges_table,
9805 ranges_table_allocated);
9806 memset (ranges_table + ranges_table_in_use, 0,
9807 RANGES_TABLE_INCREMENT * sizeof (dw_ranges));
9810 ranges_table[in_use].num = num;
9811 ranges_table_in_use = in_use + 1;
9813 return in_use * 2 * DWARF2_ADDR_SIZE;
9816 /* Add a new entry to .debug_ranges corresponding to a block, or a
9817 range terminator if BLOCK is NULL. */
9820 add_ranges (const_tree block)
9822 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
9825 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9826 When using dwarf_split_debug_info, address attributes in dies destined
9827 for the final executable should be direct references--setting the
9828 parameter force_direct ensures this behavior. */
9831 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
9832 bool *added, bool force_direct)
9834 unsigned int in_use = ranges_by_label_in_use;
9835 unsigned int offset;
9837 if (in_use == ranges_by_label_allocated)
9839 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
9840 ranges_by_label = GGC_RESIZEVEC (dw_ranges_by_label, ranges_by_label,
9841 ranges_by_label_allocated);
9842 memset (ranges_by_label + ranges_by_label_in_use, 0,
9843 RANGES_TABLE_INCREMENT * sizeof (dw_ranges_by_label));
9846 ranges_by_label[in_use].begin = begin;
9847 ranges_by_label[in_use].end = end;
9848 ranges_by_label_in_use = in_use + 1;
9850 offset = add_ranges_num (-(int)in_use - 1);
9853 add_AT_range_list (die, DW_AT_ranges, offset, force_direct);
9859 output_ranges (void)
9862 static const char *const start_fmt = "Offset %#x";
9863 const char *fmt = start_fmt;
9865 for (i = 0; i < ranges_table_in_use; i++)
9867 int block_num = ranges_table[i].num;
9871 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9872 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9874 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9875 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9877 /* If all code is in the text section, then the compilation
9878 unit base address defaults to DW_AT_low_pc, which is the
9879 base of the text section. */
9880 if (!have_multiple_function_sections)
9882 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9884 fmt, i * 2 * DWARF2_ADDR_SIZE);
9885 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9886 text_section_label, NULL);
9889 /* Otherwise, the compilation unit base address is zero,
9890 which allows us to use absolute addresses, and not worry
9891 about whether the target supports cross-section
9895 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9896 fmt, i * 2 * DWARF2_ADDR_SIZE);
9897 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9903 /* Negative block_num stands for an index into ranges_by_label. */
9904 else if (block_num < 0)
9906 int lab_idx = - block_num - 1;
9908 if (!have_multiple_function_sections)
9912 /* If we ever use add_ranges_by_labels () for a single
9913 function section, all we have to do is to take out
9915 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9916 ranges_by_label[lab_idx].begin,
9918 fmt, i * 2 * DWARF2_ADDR_SIZE);
9919 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9920 ranges_by_label[lab_idx].end,
9921 text_section_label, NULL);
9926 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9927 ranges_by_label[lab_idx].begin,
9928 fmt, i * 2 * DWARF2_ADDR_SIZE);
9929 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9930 ranges_by_label[lab_idx].end,
9936 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9937 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9943 /* Data structure containing information about input files. */
9946 const char *path; /* Complete file name. */
9947 const char *fname; /* File name part. */
9948 int length; /* Length of entire string. */
9949 struct dwarf_file_data * file_idx; /* Index in input file table. */
9950 int dir_idx; /* Index in directory table. */
9953 /* Data structure containing information about directories with source
9957 const char *path; /* Path including directory name. */
9958 int length; /* Path length. */
9959 int prefix; /* Index of directory entry which is a prefix. */
9960 int count; /* Number of files in this directory. */
9961 int dir_idx; /* Index of directory used as base. */
9964 /* Callback function for file_info comparison. We sort by looking at
9965 the directories in the path. */
9968 file_info_cmp (const void *p1, const void *p2)
9970 const struct file_info *const s1 = (const struct file_info *) p1;
9971 const struct file_info *const s2 = (const struct file_info *) p2;
9972 const unsigned char *cp1;
9973 const unsigned char *cp2;
9975 /* Take care of file names without directories. We need to make sure that
9976 we return consistent values to qsort since some will get confused if
9977 we return the same value when identical operands are passed in opposite
9978 orders. So if neither has a directory, return 0 and otherwise return
9979 1 or -1 depending on which one has the directory. */
9980 if ((s1->path == s1->fname || s2->path == s2->fname))
9981 return (s2->path == s2->fname) - (s1->path == s1->fname);
9983 cp1 = (const unsigned char *) s1->path;
9984 cp2 = (const unsigned char *) s2->path;
9990 /* Reached the end of the first path? If so, handle like above. */
9991 if ((cp1 == (const unsigned char *) s1->fname)
9992 || (cp2 == (const unsigned char *) s2->fname))
9993 return ((cp2 == (const unsigned char *) s2->fname)
9994 - (cp1 == (const unsigned char *) s1->fname));
9996 /* Character of current path component the same? */
9997 else if (*cp1 != *cp2)
10002 struct file_name_acquire_data
10004 struct file_info *files;
10009 /* Traversal function for the hash table. */
10012 file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
10014 struct dwarf_file_data *d = *slot;
10015 struct file_info *fi;
10018 gcc_assert (fnad->max_files >= d->emitted_number);
10020 if (! d->emitted_number)
10023 gcc_assert (fnad->max_files != fnad->used_files);
10025 fi = fnad->files + fnad->used_files++;
10027 /* Skip all leading "./". */
10029 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
10032 /* Create a new array entry. */
10034 fi->length = strlen (f);
10037 /* Search for the file name part. */
10038 f = strrchr (f, DIR_SEPARATOR);
10039 #if defined (DIR_SEPARATOR_2)
10041 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
10045 if (f == NULL || f < g)
10051 fi->fname = f == NULL ? fi->path : f + 1;
10055 /* Output the directory table and the file name table. We try to minimize
10056 the total amount of memory needed. A heuristic is used to avoid large
10057 slowdowns with many input files. */
10060 output_file_names (void)
10062 struct file_name_acquire_data fnad;
10064 struct file_info *files;
10065 struct dir_info *dirs;
10073 if (!last_emitted_file)
10075 dw2_asm_output_data (1, 0, "End directory table");
10076 dw2_asm_output_data (1, 0, "End file name table");
10080 numfiles = last_emitted_file->emitted_number;
10082 /* Allocate the various arrays we need. */
10083 files = XALLOCAVEC (struct file_info, numfiles);
10084 dirs = XALLOCAVEC (struct dir_info, numfiles);
10086 fnad.files = files;
10087 fnad.used_files = 0;
10088 fnad.max_files = numfiles;
10089 file_table->traverse<file_name_acquire_data *, file_name_acquire> (&fnad);
10090 gcc_assert (fnad.used_files == fnad.max_files);
10092 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
10094 /* Find all the different directories used. */
10095 dirs[0].path = files[0].path;
10096 dirs[0].length = files[0].fname - files[0].path;
10097 dirs[0].prefix = -1;
10099 dirs[0].dir_idx = 0;
10100 files[0].dir_idx = 0;
10103 for (i = 1; i < numfiles; i++)
10104 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
10105 && memcmp (dirs[ndirs - 1].path, files[i].path,
10106 dirs[ndirs - 1].length) == 0)
10108 /* Same directory as last entry. */
10109 files[i].dir_idx = ndirs - 1;
10110 ++dirs[ndirs - 1].count;
10116 /* This is a new directory. */
10117 dirs[ndirs].path = files[i].path;
10118 dirs[ndirs].length = files[i].fname - files[i].path;
10119 dirs[ndirs].count = 1;
10120 dirs[ndirs].dir_idx = ndirs;
10121 files[i].dir_idx = ndirs;
10123 /* Search for a prefix. */
10124 dirs[ndirs].prefix = -1;
10125 for (j = 0; j < ndirs; j++)
10126 if (dirs[j].length < dirs[ndirs].length
10127 && dirs[j].length > 1
10128 && (dirs[ndirs].prefix == -1
10129 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
10130 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
10131 dirs[ndirs].prefix = j;
10136 /* Now to the actual work. We have to find a subset of the directories which
10137 allow expressing the file name using references to the directory table
10138 with the least amount of characters. We do not do an exhaustive search
10139 where we would have to check out every combination of every single
10140 possible prefix. Instead we use a heuristic which provides nearly optimal
10141 results in most cases and never is much off. */
10142 saved = XALLOCAVEC (int, ndirs);
10143 savehere = XALLOCAVEC (int, ndirs);
10145 memset (saved, '\0', ndirs * sizeof (saved[0]));
10146 for (i = 0; i < ndirs; i++)
10151 /* We can always save some space for the current directory. But this
10152 does not mean it will be enough to justify adding the directory. */
10153 savehere[i] = dirs[i].length;
10154 total = (savehere[i] - saved[i]) * dirs[i].count;
10156 for (j = i + 1; j < ndirs; j++)
10159 if (saved[j] < dirs[i].length)
10161 /* Determine whether the dirs[i] path is a prefix of the
10165 k = dirs[j].prefix;
10166 while (k != -1 && k != (int) i)
10167 k = dirs[k].prefix;
10171 /* Yes it is. We can possibly save some memory by
10172 writing the filenames in dirs[j] relative to
10174 savehere[j] = dirs[i].length;
10175 total += (savehere[j] - saved[j]) * dirs[j].count;
10180 /* Check whether we can save enough to justify adding the dirs[i]
10182 if (total > dirs[i].length + 1)
10184 /* It's worthwhile adding. */
10185 for (j = i; j < ndirs; j++)
10186 if (savehere[j] > 0)
10188 /* Remember how much we saved for this directory so far. */
10189 saved[j] = savehere[j];
10191 /* Remember the prefix directory. */
10192 dirs[j].dir_idx = i;
10197 /* Emit the directory name table. */
10198 idx_offset = dirs[0].length > 0 ? 1 : 0;
10199 for (i = 1 - idx_offset; i < ndirs; i++)
10200 dw2_asm_output_nstring (dirs[i].path,
10202 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
10203 "Directory Entry: %#x", i + idx_offset);
10205 dw2_asm_output_data (1, 0, "End directory table");
10207 /* We have to emit them in the order of emitted_number since that's
10208 used in the debug info generation. To do this efficiently we
10209 generate a back-mapping of the indices first. */
10210 backmap = XALLOCAVEC (int, numfiles);
10211 for (i = 0; i < numfiles; i++)
10212 backmap[files[i].file_idx->emitted_number - 1] = i;
10214 /* Now write all the file names. */
10215 for (i = 0; i < numfiles; i++)
10217 int file_idx = backmap[i];
10218 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
10220 #ifdef VMS_DEBUGGING_INFO
10221 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10223 /* Setting these fields can lead to debugger miscomparisons,
10224 but VMS Debug requires them to be set correctly. */
10229 int maxfilelen = strlen (files[file_idx].path)
10230 + dirs[dir_idx].length
10231 + MAX_VMS_VERSION_LEN + 1;
10232 char *filebuf = XALLOCAVEC (char, maxfilelen);
10234 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
10235 snprintf (filebuf, maxfilelen, "%s;%d",
10236 files[file_idx].path + dirs[dir_idx].length, ver);
10238 dw2_asm_output_nstring
10239 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
10241 /* Include directory index. */
10242 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
10244 /* Modification time. */
10245 dw2_asm_output_data_uleb128
10246 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
10250 /* File length in bytes. */
10251 dw2_asm_output_data_uleb128
10252 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
10256 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
10257 "File Entry: %#x", (unsigned) i + 1);
10259 /* Include directory index. */
10260 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
10262 /* Modification time. */
10263 dw2_asm_output_data_uleb128 (0, NULL);
10265 /* File length in bytes. */
10266 dw2_asm_output_data_uleb128 (0, NULL);
10267 #endif /* VMS_DEBUGGING_INFO */
10270 dw2_asm_output_data (1, 0, "End file name table");
10274 /* Output one line number table into the .debug_line section. */
10277 output_one_line_info_table (dw_line_info_table *table)
10279 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
10280 unsigned int current_line = 1;
10281 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
10282 dw_line_info_entry *ent;
10285 FOR_EACH_VEC_SAFE_ELT (table->entries, i, ent)
10287 switch (ent->opcode)
10289 case LI_set_address:
10290 /* ??? Unfortunately, we have little choice here currently, and
10291 must always use the most general form. GCC does not know the
10292 address delta itself, so we can't use DW_LNS_advance_pc. Many
10293 ports do have length attributes which will give an upper bound
10294 on the address range. We could perhaps use length attributes
10295 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10296 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
10298 /* This can handle any delta. This takes
10299 4+DWARF2_ADDR_SIZE bytes. */
10300 dw2_asm_output_data (1, 0, "set address %s", line_label);
10301 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10302 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10303 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10307 if (ent->val == current_line)
10309 /* We still need to start a new row, so output a copy insn. */
10310 dw2_asm_output_data (1, DW_LNS_copy,
10311 "copy line %u", current_line);
10315 int line_offset = ent->val - current_line;
10316 int line_delta = line_offset - DWARF_LINE_BASE;
10318 current_line = ent->val;
10319 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10321 /* This can handle deltas from -10 to 234, using the current
10322 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10323 This takes 1 byte. */
10324 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10325 "line %u", current_line);
10329 /* This can handle any delta. This takes at least 4 bytes,
10330 depending on the value being encoded. */
10331 dw2_asm_output_data (1, DW_LNS_advance_line,
10332 "advance to line %u", current_line);
10333 dw2_asm_output_data_sleb128 (line_offset, NULL);
10334 dw2_asm_output_data (1, DW_LNS_copy, NULL);
10340 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
10341 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
10344 case LI_set_column:
10345 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
10346 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
10349 case LI_negate_stmt:
10350 current_is_stmt = !current_is_stmt;
10351 dw2_asm_output_data (1, DW_LNS_negate_stmt,
10352 "is_stmt %d", current_is_stmt);
10355 case LI_set_prologue_end:
10356 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
10357 "set prologue end");
10360 case LI_set_epilogue_begin:
10361 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
10362 "set epilogue begin");
10365 case LI_set_discriminator:
10366 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
10367 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
10368 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
10369 dw2_asm_output_data_uleb128 (ent->val, NULL);
10374 /* Emit debug info for the address of the end of the table. */
10375 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
10376 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10377 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10378 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
10380 dw2_asm_output_data (1, 0, "end sequence");
10381 dw2_asm_output_data_uleb128 (1, NULL);
10382 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10385 /* Output the source line number correspondence information. This
10386 information goes into the .debug_line section. */
10389 output_line_info (bool prologue_only)
10391 char l1[20], l2[20], p1[20], p2[20];
10392 /* We don't support DWARFv5 line tables yet. */
10393 int ver = dwarf_version < 5 ? dwarf_version : 4;
10394 bool saw_one = false;
10397 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
10398 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
10399 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
10400 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
10402 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
10403 dw2_asm_output_data (4, 0xffffffff,
10404 "Initial length escape value indicating 64-bit DWARF extension");
10405 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
10406 "Length of Source Line Info");
10407 ASM_OUTPUT_LABEL (asm_out_file, l1);
10409 dw2_asm_output_data (2, ver, "DWARF Version");
10410 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
10411 ASM_OUTPUT_LABEL (asm_out_file, p1);
10413 /* Define the architecture-dependent minimum instruction length (in bytes).
10414 In this implementation of DWARF, this field is used for information
10415 purposes only. Since GCC generates assembly language, we have no
10416 a priori knowledge of how many instruction bytes are generated for each
10417 source line, and therefore can use only the DW_LNE_set_address and
10418 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10419 this as '1', which is "correct enough" for all architectures,
10420 and don't let the target override. */
10421 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10424 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
10425 "Maximum Operations Per Instruction");
10426 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
10427 "Default is_stmt_start flag");
10428 dw2_asm_output_data (1, DWARF_LINE_BASE,
10429 "Line Base Value (Special Opcodes)");
10430 dw2_asm_output_data (1, DWARF_LINE_RANGE,
10431 "Line Range Value (Special Opcodes)");
10432 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
10433 "Special Opcode Base");
10435 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
10440 case DW_LNS_advance_pc:
10441 case DW_LNS_advance_line:
10442 case DW_LNS_set_file:
10443 case DW_LNS_set_column:
10444 case DW_LNS_fixed_advance_pc:
10445 case DW_LNS_set_isa:
10453 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
10457 /* Write out the information about the files we use. */
10458 output_file_names ();
10459 ASM_OUTPUT_LABEL (asm_out_file, p2);
10462 /* Output the marker for the end of the line number info. */
10463 ASM_OUTPUT_LABEL (asm_out_file, l2);
10467 if (separate_line_info)
10469 dw_line_info_table *table;
10472 FOR_EACH_VEC_ELT (*separate_line_info, i, table)
10475 output_one_line_info_table (table);
10479 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
10481 output_one_line_info_table (cold_text_section_line_info);
10485 /* ??? Some Darwin linkers crash on a .debug_line section with no
10486 sequences. Further, merely a DW_LNE_end_sequence entry is not
10487 sufficient -- the address column must also be initialized.
10488 Make sure to output at least one set_address/end_sequence pair,
10489 choosing .text since that section is always present. */
10490 if (text_section_line_info->in_use || !saw_one)
10491 output_one_line_info_table (text_section_line_info);
10493 /* Output the marker for the end of the line number info. */
10494 ASM_OUTPUT_LABEL (asm_out_file, l2);
10497 /* Given a pointer to a tree node for some base type, return a pointer to
10498 a DIE that describes the given type.
10500 This routine must only be called for GCC type nodes that correspond to
10501 Dwarf base (fundamental) types. */
10504 base_type_die (tree type)
10506 dw_die_ref base_type_result;
10507 enum dwarf_type encoding;
10509 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
10512 /* If this is a subtype that should not be emitted as a subrange type,
10513 use the base type. See subrange_type_for_debug_p. */
10514 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
10515 type = TREE_TYPE (type);
10517 switch (TREE_CODE (type))
10520 if ((dwarf_version >= 4 || !dwarf_strict)
10521 && TYPE_NAME (type)
10522 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10523 && DECL_IS_BUILTIN (TYPE_NAME (type))
10524 && DECL_NAME (TYPE_NAME (type)))
10526 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
10527 if (strcmp (name, "char16_t") == 0
10528 || strcmp (name, "char32_t") == 0)
10530 encoding = DW_ATE_UTF;
10534 if (TYPE_STRING_FLAG (type))
10536 if (TYPE_UNSIGNED (type))
10537 encoding = DW_ATE_unsigned_char;
10539 encoding = DW_ATE_signed_char;
10541 else if (TYPE_UNSIGNED (type))
10542 encoding = DW_ATE_unsigned;
10544 encoding = DW_ATE_signed;
10548 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
10550 if (dwarf_version >= 3 || !dwarf_strict)
10551 encoding = DW_ATE_decimal_float;
10553 encoding = DW_ATE_lo_user;
10556 encoding = DW_ATE_float;
10559 case FIXED_POINT_TYPE:
10560 if (!(dwarf_version >= 3 || !dwarf_strict))
10561 encoding = DW_ATE_lo_user;
10562 else if (TYPE_UNSIGNED (type))
10563 encoding = DW_ATE_unsigned_fixed;
10565 encoding = DW_ATE_signed_fixed;
10568 /* Dwarf2 doesn't know anything about complex ints, so use
10569 a user defined type for it. */
10571 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
10572 encoding = DW_ATE_complex_float;
10574 encoding = DW_ATE_lo_user;
10578 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10579 encoding = DW_ATE_boolean;
10583 /* No other TREE_CODEs are Dwarf fundamental types. */
10584 gcc_unreachable ();
10587 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
10589 add_AT_unsigned (base_type_result, DW_AT_byte_size,
10590 int_size_in_bytes (type));
10591 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
10592 add_pubtype (type, base_type_result);
10594 return base_type_result;
10597 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10598 named 'auto' in its type: return true for it, false otherwise. */
10601 is_cxx_auto (tree type)
10605 tree name = TYPE_IDENTIFIER (type);
10606 if (name == get_identifier ("auto")
10607 || name == get_identifier ("decltype(auto)"))
10613 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10614 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10617 is_base_type (tree type)
10619 switch (TREE_CODE (type))
10625 case FIXED_POINT_TYPE:
10628 case POINTER_BOUNDS_TYPE:
10634 case QUAL_UNION_TYPE:
10635 case ENUMERAL_TYPE:
10636 case FUNCTION_TYPE:
10639 case REFERENCE_TYPE:
10647 if (is_cxx_auto (type))
10649 gcc_unreachable ();
10655 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10656 node, return the size in bits for the type if it is a constant, or else
10657 return the alignment for the type if the type's size is not constant, or
10658 else return BITS_PER_WORD if the type actually turns out to be an
10659 ERROR_MARK node. */
10661 static inline unsigned HOST_WIDE_INT
10662 simple_type_size_in_bits (const_tree type)
10664 if (TREE_CODE (type) == ERROR_MARK)
10665 return BITS_PER_WORD;
10666 else if (TYPE_SIZE (type) == NULL_TREE)
10668 else if (tree_fits_uhwi_p (TYPE_SIZE (type)))
10669 return tree_to_uhwi (TYPE_SIZE (type));
10671 return TYPE_ALIGN (type);
10674 /* Similarly, but return an offset_int instead of UHWI. */
10676 static inline offset_int
10677 offset_int_type_size_in_bits (const_tree type)
10679 if (TREE_CODE (type) == ERROR_MARK)
10680 return BITS_PER_WORD;
10681 else if (TYPE_SIZE (type) == NULL_TREE)
10683 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
10684 return wi::to_offset (TYPE_SIZE (type));
10686 return TYPE_ALIGN (type);
10689 /* Given a pointer to a tree node for a subrange type, return a pointer
10690 to a DIE that describes the given type. */
10693 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
10695 dw_die_ref subrange_die;
10696 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
10698 if (context_die == NULL)
10699 context_die = comp_unit_die ();
10701 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
10703 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
10705 /* The size of the subrange type and its base type do not match,
10706 so we need to generate a size attribute for the subrange type. */
10707 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
10711 add_bound_info (subrange_die, DW_AT_lower_bound, low, NULL);
10713 add_bound_info (subrange_die, DW_AT_upper_bound, high, NULL);
10715 return subrange_die;
10718 /* Returns the (const and/or volatile) cv_qualifiers associated with
10719 the decl node. This will normally be augmented with the
10720 cv_qualifiers of the underlying type in add_type_attribute. */
10723 decl_quals (const_tree decl)
10725 return ((TREE_READONLY (decl)
10726 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
10727 | (TREE_THIS_VOLATILE (decl)
10728 ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED));
10731 /* Determine the TYPE whose qualifiers match the largest strict subset
10732 of the given TYPE_QUALS, and return its qualifiers. Ignore all
10733 qualifiers outside QUAL_MASK. */
10736 get_nearest_type_subqualifiers (tree type, int type_quals, int qual_mask)
10739 int best_rank = 0, best_qual = 0, max_rank;
10741 type_quals &= qual_mask;
10742 max_rank = popcount_hwi (type_quals) - 1;
10744 for (t = TYPE_MAIN_VARIANT (type); t && best_rank < max_rank;
10745 t = TYPE_NEXT_VARIANT (t))
10747 int q = TYPE_QUALS (t) & qual_mask;
10749 if ((q & type_quals) == q && q != type_quals
10750 && check_base_type (t, type))
10752 int rank = popcount_hwi (q);
10754 if (rank > best_rank)
10765 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10766 entry that chains various modifiers in front of the given type. */
10769 modified_type_die (tree type, int cv_quals, dw_die_ref context_die)
10771 enum tree_code code = TREE_CODE (type);
10772 dw_die_ref mod_type_die;
10773 dw_die_ref sub_die = NULL;
10774 tree item_type = NULL;
10775 tree qualified_type;
10776 tree name, low, high;
10777 dw_die_ref mod_scope;
10778 /* Only these cv-qualifiers are currently handled. */
10779 const int cv_qual_mask = (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE
10780 | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC);
10782 if (code == ERROR_MARK)
10785 cv_quals &= cv_qual_mask;
10787 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
10788 tag modifier (and not an attribute) old consumers won't be able
10790 if (dwarf_version < 3)
10791 cv_quals &= ~TYPE_QUAL_RESTRICT;
10793 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
10794 if (dwarf_version < 5)
10795 cv_quals &= ~TYPE_QUAL_ATOMIC;
10797 /* See if we already have the appropriately qualified variant of
10799 qualified_type = get_qualified_type (type, cv_quals);
10801 if (qualified_type == sizetype
10802 && TYPE_NAME (qualified_type)
10803 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
10805 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
10807 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
10808 && TYPE_PRECISION (t)
10809 == TYPE_PRECISION (qualified_type)
10810 && TYPE_UNSIGNED (t)
10811 == TYPE_UNSIGNED (qualified_type));
10812 qualified_type = t;
10815 /* If we do, then we can just use its DIE, if it exists. */
10816 if (qualified_type)
10818 mod_type_die = lookup_type_die (qualified_type);
10820 return mod_type_die;
10823 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
10825 /* Handle C typedef types. */
10826 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
10827 && !DECL_ARTIFICIAL (name))
10829 tree dtype = TREE_TYPE (name);
10831 if (qualified_type == dtype)
10833 /* For a named type, use the typedef. */
10834 gen_type_die (qualified_type, context_die);
10835 return lookup_type_die (qualified_type);
10839 int dquals = TYPE_QUALS_NO_ADDR_SPACE (dtype);
10840 dquals &= cv_qual_mask;
10841 if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
10842 || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
10843 /* cv-unqualified version of named type. Just use
10844 the unnamed type to which it refers. */
10845 return modified_type_die (DECL_ORIGINAL_TYPE (name),
10846 cv_quals, context_die);
10847 /* Else cv-qualified version of named type; fall through. */
10851 mod_scope = scope_die_for (type, context_die);
10855 struct qual_info { int q; enum dwarf_tag t; };
10856 static const struct qual_info qual_info[] =
10858 { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type },
10859 { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
10860 { TYPE_QUAL_VOLATILE, DW_TAG_volatile_type },
10861 { TYPE_QUAL_CONST, DW_TAG_const_type },
10866 /* Determine a lesser qualified type that most closely matches
10867 this one. Then generate DW_TAG_* entries for the remaining
10869 sub_quals = get_nearest_type_subqualifiers (type, cv_quals,
10871 mod_type_die = modified_type_die (type, sub_quals, context_die);
10873 for (i = 0; i < sizeof (qual_info) / sizeof (qual_info[0]); i++)
10874 if (qual_info[i].q & cv_quals & ~sub_quals)
10876 dw_die_ref d = new_die (qual_info[i].t, mod_scope, type);
10878 add_AT_die_ref (d, DW_AT_type, mod_type_die);
10882 else if (code == POINTER_TYPE)
10884 mod_type_die = new_die (DW_TAG_pointer_type, mod_scope, type);
10885 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10886 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10887 item_type = TREE_TYPE (type);
10888 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
10889 add_AT_unsigned (mod_type_die, DW_AT_address_class,
10890 TYPE_ADDR_SPACE (item_type));
10892 else if (code == REFERENCE_TYPE)
10894 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
10895 mod_type_die = new_die (DW_TAG_rvalue_reference_type, mod_scope,
10898 mod_type_die = new_die (DW_TAG_reference_type, mod_scope, type);
10899 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10900 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10901 item_type = TREE_TYPE (type);
10902 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
10903 add_AT_unsigned (mod_type_die, DW_AT_address_class,
10904 TYPE_ADDR_SPACE (item_type));
10906 else if (code == INTEGER_TYPE
10907 && TREE_TYPE (type) != NULL_TREE
10908 && subrange_type_for_debug_p (type, &low, &high))
10910 mod_type_die = subrange_type_die (type, low, high, context_die);
10911 item_type = TREE_TYPE (type);
10913 else if (is_base_type (type))
10914 mod_type_die = base_type_die (type);
10917 gen_type_die (type, context_die);
10919 /* We have to get the type_main_variant here (and pass that to the
10920 `lookup_type_die' routine) because the ..._TYPE node we have
10921 might simply be a *copy* of some original type node (where the
10922 copy was created to help us keep track of typedef names) and
10923 that copy might have a different TYPE_UID from the original
10925 if (TREE_CODE (type) != VECTOR_TYPE)
10926 return lookup_type_die (type_main_variant (type));
10928 /* Vectors have the debugging information in the type,
10929 not the main variant. */
10930 return lookup_type_die (type);
10933 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10934 don't output a DW_TAG_typedef, since there isn't one in the
10935 user's program; just attach a DW_AT_name to the type.
10936 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10937 if the base type already has the same name. */
10939 && ((TREE_CODE (name) != TYPE_DECL
10940 && (qualified_type == TYPE_MAIN_VARIANT (type)
10941 || (cv_quals == TYPE_UNQUALIFIED)))
10942 || (TREE_CODE (name) == TYPE_DECL
10943 && TREE_TYPE (name) == qualified_type
10944 && DECL_NAME (name))))
10946 if (TREE_CODE (name) == TYPE_DECL)
10947 /* Could just call add_name_and_src_coords_attributes here,
10948 but since this is a builtin type it doesn't have any
10949 useful source coordinates anyway. */
10950 name = DECL_NAME (name);
10951 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
10953 /* This probably indicates a bug. */
10954 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
10956 name = TYPE_IDENTIFIER (type);
10957 add_name_attribute (mod_type_die,
10958 name ? IDENTIFIER_POINTER (name) : "__unknown__");
10961 if (qualified_type)
10962 equate_type_number_to_die (qualified_type, mod_type_die);
10965 /* We must do this after the equate_type_number_to_die call, in case
10966 this is a recursive type. This ensures that the modified_type_die
10967 recursion will terminate even if the type is recursive. Recursive
10968 types are possible in Ada. */
10969 sub_die = modified_type_die (item_type,
10970 TYPE_QUALS_NO_ADDR_SPACE (item_type),
10973 if (sub_die != NULL)
10974 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10976 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
10977 if (TYPE_ARTIFICIAL (type))
10978 add_AT_flag (mod_type_die, DW_AT_artificial, 1);
10980 return mod_type_die;
10983 /* Generate DIEs for the generic parameters of T.
10984 T must be either a generic type or a generic function.
10985 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10988 gen_generic_params_dies (tree t)
10992 dw_die_ref die = NULL;
10995 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
10999 die = lookup_type_die (t);
11000 else if (DECL_P (t))
11001 die = lookup_decl_die (t);
11005 parms = lang_hooks.get_innermost_generic_parms (t);
11007 /* T has no generic parameter. It means T is neither a generic type
11008 or function. End of story. */
11011 parms_num = TREE_VEC_LENGTH (parms);
11012 args = lang_hooks.get_innermost_generic_args (t);
11013 if (TREE_CHAIN (args) && TREE_CODE (TREE_CHAIN (args)) == INTEGER_CST)
11014 non_default = int_cst_value (TREE_CHAIN (args));
11016 non_default = TREE_VEC_LENGTH (args);
11017 for (i = 0; i < parms_num; i++)
11019 tree parm, arg, arg_pack_elems;
11020 dw_die_ref parm_die;
11022 parm = TREE_VEC_ELT (parms, i);
11023 arg = TREE_VEC_ELT (args, i);
11024 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
11025 gcc_assert (parm && TREE_VALUE (parm) && arg);
11027 if (parm && TREE_VALUE (parm) && arg)
11029 /* If PARM represents a template parameter pack,
11030 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11031 by DW_TAG_template_*_parameter DIEs for the argument
11032 pack elements of ARG. Note that ARG would then be
11033 an argument pack. */
11034 if (arg_pack_elems)
11035 parm_die = template_parameter_pack_die (TREE_VALUE (parm),
11039 parm_die = generic_parameter_die (TREE_VALUE (parm), arg,
11040 true /* emit name */, die);
11041 if (i >= non_default)
11042 add_AT_flag (parm_die, DW_AT_default_value, 1);
11047 /* Create and return a DIE for PARM which should be
11048 the representation of a generic type parameter.
11049 For instance, in the C++ front end, PARM would be a template parameter.
11050 ARG is the argument to PARM.
11051 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11053 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11054 as a child node. */
11057 generic_parameter_die (tree parm, tree arg,
11059 dw_die_ref parent_die)
11061 dw_die_ref tmpl_die = NULL;
11062 const char *name = NULL;
11064 if (!parm || !DECL_NAME (parm) || !arg)
11067 /* We support non-type generic parameters and arguments,
11068 type generic parameters and arguments, as well as
11069 generic generic parameters (a.k.a. template template parameters in C++)
11071 if (TREE_CODE (parm) == PARM_DECL)
11072 /* PARM is a nontype generic parameter */
11073 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
11074 else if (TREE_CODE (parm) == TYPE_DECL)
11075 /* PARM is a type generic parameter. */
11076 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
11077 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
11078 /* PARM is a generic generic parameter.
11079 Its DIE is a GNU extension. It shall have a
11080 DW_AT_name attribute to represent the name of the template template
11081 parameter, and a DW_AT_GNU_template_name attribute to represent the
11082 name of the template template argument. */
11083 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
11086 gcc_unreachable ();
11092 /* If PARM is a generic parameter pack, it means we are
11093 emitting debug info for a template argument pack element.
11094 In other terms, ARG is a template argument pack element.
11095 In that case, we don't emit any DW_AT_name attribute for
11099 name = IDENTIFIER_POINTER (DECL_NAME (parm));
11101 add_AT_string (tmpl_die, DW_AT_name, name);
11104 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
11106 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11107 TMPL_DIE should have a child DW_AT_type attribute that is set
11108 to the type of the argument to PARM, which is ARG.
11109 If PARM is a type generic parameter, TMPL_DIE should have a
11110 child DW_AT_type that is set to ARG. */
11111 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
11112 add_type_attribute (tmpl_die, tmpl_type,
11113 (TREE_THIS_VOLATILE (tmpl_type)
11114 ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED),
11119 /* So TMPL_DIE is a DIE representing a
11120 a generic generic template parameter, a.k.a template template
11121 parameter in C++ and arg is a template. */
11123 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11124 to the name of the argument. */
11125 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
11127 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
11130 if (TREE_CODE (parm) == PARM_DECL)
11131 /* So PARM is a non-type generic parameter.
11132 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11133 attribute of TMPL_DIE which value represents the value
11135 We must be careful here:
11136 The value of ARG might reference some function decls.
11137 We might currently be emitting debug info for a generic
11138 type and types are emitted before function decls, we don't
11139 know if the function decls referenced by ARG will actually be
11140 emitted after cgraph computations.
11141 So must defer the generation of the DW_AT_const_value to
11142 after cgraph is ready. */
11143 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
11149 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11150 PARM_PACK must be a template parameter pack. The returned DIE
11151 will be child DIE of PARENT_DIE. */
11154 template_parameter_pack_die (tree parm_pack,
11155 tree parm_pack_args,
11156 dw_die_ref parent_die)
11161 gcc_assert (parent_die && parm_pack);
11163 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
11164 add_name_and_src_coords_attributes (die, parm_pack);
11165 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
11166 generic_parameter_die (parm_pack,
11167 TREE_VEC_ELT (parm_pack_args, j),
11168 false /* Don't emit DW_AT_name */,
11173 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11174 an enumerated type. */
11177 type_is_enum (const_tree type)
11179 return TREE_CODE (type) == ENUMERAL_TYPE;
11182 /* Return the DBX register number described by a given RTL node. */
11184 static unsigned int
11185 dbx_reg_number (const_rtx rtl)
11187 unsigned regno = REGNO (rtl);
11189 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
11191 #ifdef LEAF_REG_REMAP
11192 if (crtl->uses_only_leaf_regs)
11194 int leaf_reg = LEAF_REG_REMAP (regno);
11195 if (leaf_reg != -1)
11196 regno = (unsigned) leaf_reg;
11200 regno = DBX_REGISTER_NUMBER (regno);
11201 gcc_assert (regno != INVALID_REGNUM);
11205 /* Optionally add a DW_OP_piece term to a location description expression.
11206 DW_OP_piece is only added if the location description expression already
11207 doesn't end with DW_OP_piece. */
11210 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
11212 dw_loc_descr_ref loc;
11214 if (*list_head != NULL)
11216 /* Find the end of the chain. */
11217 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
11220 if (loc->dw_loc_opc != DW_OP_piece)
11221 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
11225 /* Return a location descriptor that designates a machine register or
11226 zero if there is none. */
11228 static dw_loc_descr_ref
11229 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
11233 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
11236 /* We only use "frame base" when we're sure we're talking about the
11237 post-prologue local stack frame. We do this by *not* running
11238 register elimination until this point, and recognizing the special
11239 argument pointer and soft frame pointer rtx's.
11240 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11241 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
11242 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
11244 dw_loc_descr_ref result = NULL;
11246 if (dwarf_version >= 4 || !dwarf_strict)
11248 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
11251 add_loc_descr (&result,
11252 new_loc_descr (DW_OP_stack_value, 0, 0));
11257 regs = targetm.dwarf_register_span (rtl);
11259 if (REG_NREGS (rtl) > 1 || regs)
11260 return multiple_reg_loc_descriptor (rtl, regs, initialized);
11263 unsigned int dbx_regnum = dbx_reg_number (rtl);
11264 if (dbx_regnum == IGNORED_DWARF_REGNUM)
11266 return one_reg_loc_descriptor (dbx_regnum, initialized);
11270 /* Return a location descriptor that designates a machine register for
11271 a given hard register number. */
11273 static dw_loc_descr_ref
11274 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
11276 dw_loc_descr_ref reg_loc_descr;
11280 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
11282 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
11284 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11285 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11287 return reg_loc_descr;
11290 /* Given an RTL of a register, return a location descriptor that
11291 designates a value that spans more than one register. */
11293 static dw_loc_descr_ref
11294 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
11295 enum var_init_status initialized)
11298 dw_loc_descr_ref loc_result = NULL;
11300 /* Simple, contiguous registers. */
11301 if (regs == NULL_RTX)
11303 unsigned reg = REGNO (rtl);
11306 #ifdef LEAF_REG_REMAP
11307 if (crtl->uses_only_leaf_regs)
11309 int leaf_reg = LEAF_REG_REMAP (reg);
11310 if (leaf_reg != -1)
11311 reg = (unsigned) leaf_reg;
11315 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
11316 nregs = REG_NREGS (rtl);
11318 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
11323 dw_loc_descr_ref t;
11325 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
11326 VAR_INIT_STATUS_INITIALIZED);
11327 add_loc_descr (&loc_result, t);
11328 add_loc_descr_op_piece (&loc_result, size);
11334 /* Now onto stupid register sets in non contiguous locations. */
11336 gcc_assert (GET_CODE (regs) == PARALLEL);
11338 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
11341 for (i = 0; i < XVECLEN (regs, 0); ++i)
11343 dw_loc_descr_ref t;
11345 t = one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs, 0, i)),
11346 VAR_INIT_STATUS_INITIALIZED);
11347 add_loc_descr (&loc_result, t);
11348 add_loc_descr_op_piece (&loc_result, size);
11351 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11352 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11356 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
11358 /* Return a location descriptor that designates a constant i,
11359 as a compound operation from constant (i >> shift), constant shift
11362 static dw_loc_descr_ref
11363 int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
11365 dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
11366 add_loc_descr (&ret, int_loc_descriptor (shift));
11367 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11371 /* Return a location descriptor that designates a constant. */
11373 static dw_loc_descr_ref
11374 int_loc_descriptor (HOST_WIDE_INT i)
11376 enum dwarf_location_atom op;
11378 /* Pick the smallest representation of a constant, rather than just
11379 defaulting to the LEB encoding. */
11382 int clz = clz_hwi (i);
11383 int ctz = ctz_hwi (i);
11385 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
11386 else if (i <= 0xff)
11387 op = DW_OP_const1u;
11388 else if (i <= 0xffff)
11389 op = DW_OP_const2u;
11390 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
11391 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
11392 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11393 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11394 while DW_OP_const4u is 5 bytes. */
11395 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
11396 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
11397 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
11398 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11399 while DW_OP_const4u is 5 bytes. */
11400 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
11401 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
11402 op = DW_OP_const4u;
11403 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
11404 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
11405 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11406 while DW_OP_constu of constant >= 0x100000000 takes at least
11408 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
11409 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
11410 && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
11411 >= HOST_BITS_PER_WIDE_INT)
11412 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11413 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11414 while DW_OP_constu takes in this case at least 6 bytes. */
11415 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
11416 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
11417 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
11418 && size_of_uleb128 (i) > 6)
11419 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11420 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
11427 op = DW_OP_const1s;
11428 else if (i >= -0x8000)
11429 op = DW_OP_const2s;
11430 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
11432 if (size_of_int_loc_descriptor (i) < 5)
11434 dw_loc_descr_ref ret = int_loc_descriptor (-i);
11435 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11438 op = DW_OP_const4s;
11442 if (size_of_int_loc_descriptor (i)
11443 < (unsigned long) 1 + size_of_sleb128 (i))
11445 dw_loc_descr_ref ret = int_loc_descriptor (-i);
11446 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11453 return new_loc_descr (op, i, 0);
11456 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11457 without actually allocating it. */
11459 static unsigned long
11460 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
11462 return size_of_int_loc_descriptor (i >> shift)
11463 + size_of_int_loc_descriptor (shift)
11467 /* Return size_of_locs (int_loc_descriptor (i)) without
11468 actually allocating it. */
11470 static unsigned long
11471 size_of_int_loc_descriptor (HOST_WIDE_INT i)
11480 else if (i <= 0xff)
11482 else if (i <= 0xffff)
11486 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
11487 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
11488 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
11490 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
11491 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
11492 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
11494 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
11496 s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
11497 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
11498 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
11499 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
11501 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
11502 && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
11503 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
11505 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
11506 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
11508 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
11517 else if (i >= -0x8000)
11519 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
11521 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
11523 s = size_of_int_loc_descriptor (-i) + 1;
11531 unsigned long r = 1 + size_of_sleb128 (i);
11532 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
11534 s = size_of_int_loc_descriptor (-i) + 1;
11543 /* Return loc description representing "address" of integer value.
11544 This can appear only as toplevel expression. */
11546 static dw_loc_descr_ref
11547 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
11550 dw_loc_descr_ref loc_result = NULL;
11552 if (!(dwarf_version >= 4 || !dwarf_strict))
11555 litsize = size_of_int_loc_descriptor (i);
11556 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11557 is more compact. For DW_OP_stack_value we need:
11558 litsize + 1 (DW_OP_stack_value)
11559 and for DW_OP_implicit_value:
11560 1 (DW_OP_implicit_value) + 1 (length) + size. */
11561 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
11563 loc_result = int_loc_descriptor (i);
11564 add_loc_descr (&loc_result,
11565 new_loc_descr (DW_OP_stack_value, 0, 0));
11569 loc_result = new_loc_descr (DW_OP_implicit_value,
11571 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
11572 loc_result->dw_loc_oprnd2.v.val_int = i;
11576 /* Return a location descriptor that designates a base+offset location. */
11578 static dw_loc_descr_ref
11579 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
11580 enum var_init_status initialized)
11582 unsigned int regno;
11583 dw_loc_descr_ref result;
11584 dw_fde_ref fde = cfun->fde;
11586 /* We only use "frame base" when we're sure we're talking about the
11587 post-prologue local stack frame. We do this by *not* running
11588 register elimination until this point, and recognizing the special
11589 argument pointer and soft frame pointer rtx's. */
11590 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
11592 rtx elim = (ira_use_lra_p
11593 ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
11594 : eliminate_regs (reg, VOIDmode, NULL_RTX));
11598 if (GET_CODE (elim) == PLUS)
11600 offset += INTVAL (XEXP (elim, 1));
11601 elim = XEXP (elim, 0);
11603 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11604 && (elim == hard_frame_pointer_rtx
11605 || elim == stack_pointer_rtx))
11606 || elim == (frame_pointer_needed
11607 ? hard_frame_pointer_rtx
11608 : stack_pointer_rtx));
11610 /* If drap register is used to align stack, use frame
11611 pointer + offset to access stack variables. If stack
11612 is aligned without drap, use stack pointer + offset to
11613 access stack variables. */
11614 if (crtl->stack_realign_tried
11615 && reg == frame_pointer_rtx)
11618 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
11619 ? HARD_FRAME_POINTER_REGNUM
11621 return new_reg_loc_descr (base_reg, offset);
11624 gcc_assert (frame_pointer_fb_offset_valid);
11625 offset += frame_pointer_fb_offset;
11626 return new_loc_descr (DW_OP_fbreg, offset, 0);
11630 regno = REGNO (reg);
11631 #ifdef LEAF_REG_REMAP
11632 if (crtl->uses_only_leaf_regs)
11634 int leaf_reg = LEAF_REG_REMAP (regno);
11635 if (leaf_reg != -1)
11636 regno = (unsigned) leaf_reg;
11639 regno = DWARF_FRAME_REGNUM (regno);
11641 if (!optimize && fde
11642 && (fde->drap_reg == regno || fde->vdrap_reg == regno))
11644 /* Use cfa+offset to represent the location of arguments passed
11645 on the stack when drap is used to align stack.
11646 Only do this when not optimizing, for optimized code var-tracking
11647 is supposed to track where the arguments live and the register
11648 used as vdrap or drap in some spot might be used for something
11649 else in other part of the routine. */
11650 return new_loc_descr (DW_OP_fbreg, offset, 0);
11654 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
11657 result = new_loc_descr (DW_OP_bregx, regno, offset);
11659 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11660 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11665 /* Return true if this RTL expression describes a base+offset calculation. */
11668 is_based_loc (const_rtx rtl)
11670 return (GET_CODE (rtl) == PLUS
11671 && ((REG_P (XEXP (rtl, 0))
11672 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
11673 && CONST_INT_P (XEXP (rtl, 1)))));
11676 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11679 static dw_loc_descr_ref
11680 tls_mem_loc_descriptor (rtx mem)
11683 dw_loc_descr_ref loc_result;
11685 if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
11688 base = get_base_address (MEM_EXPR (mem));
11690 || TREE_CODE (base) != VAR_DECL
11691 || !DECL_THREAD_LOCAL_P (base))
11694 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1, NULL);
11695 if (loc_result == NULL)
11698 if (MEM_OFFSET (mem))
11699 loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
11704 /* Output debug info about reason why we failed to expand expression as dwarf
11708 expansion_failed (tree expr, rtx rtl, char const *reason)
11710 if (dump_file && (dump_flags & TDF_DETAILS))
11712 fprintf (dump_file, "Failed to expand as dwarf: ");
11714 print_generic_expr (dump_file, expr, dump_flags);
11717 fprintf (dump_file, "\n");
11718 print_rtl (dump_file, rtl);
11720 fprintf (dump_file, "\nReason: %s\n", reason);
11724 /* Helper function for const_ok_for_output. */
11727 const_ok_for_output_1 (rtx rtl)
11729 if (GET_CODE (rtl) == UNSPEC)
11731 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11732 we can't express it in the debug info. */
11733 #ifdef ENABLE_CHECKING
11734 /* Don't complain about TLS UNSPECs, those are just too hard to
11735 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11736 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11737 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11738 if (XVECLEN (rtl, 0) == 0
11739 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
11740 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl, 0, 0)) == TLS_MODEL_NONE)
11741 inform (current_function_decl
11742 ? DECL_SOURCE_LOCATION (current_function_decl)
11743 : UNKNOWN_LOCATION,
11744 #if NUM_UNSPEC_VALUES > 0
11745 "non-delegitimized UNSPEC %s (%d) found in variable location",
11746 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
11747 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
11750 "non-delegitimized UNSPEC %d found in variable location",
11754 expansion_failed (NULL_TREE, rtl,
11755 "UNSPEC hasn't been delegitimized.\n");
11759 if (targetm.const_not_ok_for_debug_p (rtl))
11761 expansion_failed (NULL_TREE, rtl,
11762 "Expression rejected for debug by the backend.\n");
11766 /* FIXME: Refer to PR60655. It is possible for simplification
11767 of rtl expressions in var tracking to produce such expressions.
11768 We should really identify / validate expressions
11769 enclosed in CONST that can be handled by assemblers on various
11770 targets and only handle legitimate cases here. */
11771 if (GET_CODE (rtl) != SYMBOL_REF)
11773 if (GET_CODE (rtl) == NOT)
11778 if (CONSTANT_POOL_ADDRESS_P (rtl))
11781 get_pool_constant_mark (rtl, &marked);
11782 /* If all references to this pool constant were optimized away,
11783 it was not output and thus we can't represent it. */
11786 expansion_failed (NULL_TREE, rtl,
11787 "Constant was removed from constant pool.\n");
11792 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11795 /* Avoid references to external symbols in debug info, on several targets
11796 the linker might even refuse to link when linking a shared library,
11797 and in many other cases the relocations for .debug_info/.debug_loc are
11798 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11799 to be defined within the same shared library or executable are fine. */
11800 if (SYMBOL_REF_EXTERNAL_P (rtl))
11802 tree decl = SYMBOL_REF_DECL (rtl);
11804 if (decl == NULL || !targetm.binds_local_p (decl))
11806 expansion_failed (NULL_TREE, rtl,
11807 "Symbol not defined in current TU.\n");
11815 /* Return true if constant RTL can be emitted in DW_OP_addr or
11816 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11817 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11820 const_ok_for_output (rtx rtl)
11822 if (GET_CODE (rtl) == SYMBOL_REF)
11823 return const_ok_for_output_1 (rtl);
11825 if (GET_CODE (rtl) == CONST)
11827 subrtx_var_iterator::array_type array;
11828 FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
11829 if (!const_ok_for_output_1 (*iter))
11837 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11838 if possible, NULL otherwise. */
11841 base_type_for_mode (machine_mode mode, bool unsignedp)
11843 dw_die_ref type_die;
11844 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
11848 switch (TREE_CODE (type))
11856 type_die = lookup_type_die (type);
11858 type_die = modified_type_die (type, TYPE_UNQUALIFIED, comp_unit_die ());
11859 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
11864 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11865 type matching MODE, or, if MODE is narrower than or as wide as
11866 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11869 static dw_loc_descr_ref
11870 convert_descriptor_to_mode (machine_mode mode, dw_loc_descr_ref op)
11872 machine_mode outer_mode = mode;
11873 dw_die_ref type_die;
11874 dw_loc_descr_ref cvt;
11876 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11878 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
11881 type_die = base_type_for_mode (outer_mode, 1);
11882 if (type_die == NULL)
11884 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11885 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11886 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11887 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11888 add_loc_descr (&op, cvt);
11892 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11894 static dw_loc_descr_ref
11895 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
11896 dw_loc_descr_ref op1)
11898 dw_loc_descr_ref ret = op0;
11899 add_loc_descr (&ret, op1);
11900 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11901 if (STORE_FLAG_VALUE != 1)
11903 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
11904 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
11909 /* Return location descriptor for signed comparison OP RTL. */
11911 static dw_loc_descr_ref
11912 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
11913 machine_mode mem_mode)
11915 machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
11916 dw_loc_descr_ref op0, op1;
11919 if (op_mode == VOIDmode)
11920 op_mode = GET_MODE (XEXP (rtl, 1));
11921 if (op_mode == VOIDmode)
11925 && (GET_MODE_CLASS (op_mode) != MODE_INT
11926 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
11929 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
11930 VAR_INIT_STATUS_INITIALIZED);
11931 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
11932 VAR_INIT_STATUS_INITIALIZED);
11934 if (op0 == NULL || op1 == NULL)
11937 if (GET_MODE_CLASS (op_mode) != MODE_INT
11938 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
11939 return compare_loc_descriptor (op, op0, op1);
11941 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
11943 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
11944 dw_loc_descr_ref cvt;
11946 if (type_die == NULL)
11948 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11949 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11950 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11951 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11952 add_loc_descr (&op0, cvt);
11953 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11954 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11955 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11956 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11957 add_loc_descr (&op1, cvt);
11958 return compare_loc_descriptor (op, op0, op1);
11961 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
11962 /* For eq/ne, if the operands are known to be zero-extended,
11963 there is no need to do the fancy shifting up. */
11964 if (op == DW_OP_eq || op == DW_OP_ne)
11966 dw_loc_descr_ref last0, last1;
11967 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
11969 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
11971 /* deref_size zero extends, and for constants we can check
11972 whether they are zero extended or not. */
11973 if (((last0->dw_loc_opc == DW_OP_deref_size
11974 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
11975 || (CONST_INT_P (XEXP (rtl, 0))
11976 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
11977 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
11978 && ((last1->dw_loc_opc == DW_OP_deref_size
11979 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
11980 || (CONST_INT_P (XEXP (rtl, 1))
11981 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
11982 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
11983 return compare_loc_descriptor (op, op0, op1);
11985 /* EQ/NE comparison against constant in narrower type than
11986 DWARF2_ADDR_SIZE can be performed either as
11987 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11990 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11991 DW_OP_{eq,ne}. Pick whatever is shorter. */
11992 if (CONST_INT_P (XEXP (rtl, 1))
11993 && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
11994 && (size_of_int_loc_descriptor (shift) + 1
11995 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift)
11996 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
11997 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
11998 & GET_MODE_MASK (op_mode))))
12000 add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
12001 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
12002 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
12003 & GET_MODE_MASK (op_mode));
12004 return compare_loc_descriptor (op, op0, op1);
12007 add_loc_descr (&op0, int_loc_descriptor (shift));
12008 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
12009 if (CONST_INT_P (XEXP (rtl, 1)))
12010 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
12013 add_loc_descr (&op1, int_loc_descriptor (shift));
12014 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
12016 return compare_loc_descriptor (op, op0, op1);
12019 /* Return location descriptor for unsigned comparison OP RTL. */
12021 static dw_loc_descr_ref
12022 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
12023 machine_mode mem_mode)
12025 machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
12026 dw_loc_descr_ref op0, op1;
12028 if (op_mode == VOIDmode)
12029 op_mode = GET_MODE (XEXP (rtl, 1));
12030 if (op_mode == VOIDmode)
12032 if (GET_MODE_CLASS (op_mode) != MODE_INT)
12035 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
12038 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
12039 VAR_INIT_STATUS_INITIALIZED);
12040 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
12041 VAR_INIT_STATUS_INITIALIZED);
12043 if (op0 == NULL || op1 == NULL)
12046 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
12048 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
12049 dw_loc_descr_ref last0, last1;
12050 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
12052 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
12054 if (CONST_INT_P (XEXP (rtl, 0)))
12055 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
12056 /* deref_size zero extends, so no need to mask it again. */
12057 else if (last0->dw_loc_opc != DW_OP_deref_size
12058 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
12060 add_loc_descr (&op0, int_loc_descriptor (mask));
12061 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
12063 if (CONST_INT_P (XEXP (rtl, 1)))
12064 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
12065 /* deref_size zero extends, so no need to mask it again. */
12066 else if (last1->dw_loc_opc != DW_OP_deref_size
12067 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
12069 add_loc_descr (&op1, int_loc_descriptor (mask));
12070 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
12073 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
12075 HOST_WIDE_INT bias = 1;
12076 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
12077 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
12078 if (CONST_INT_P (XEXP (rtl, 1)))
12079 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
12080 + INTVAL (XEXP (rtl, 1)));
12082 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
12085 return compare_loc_descriptor (op, op0, op1);
12088 /* Return location descriptor for {U,S}{MIN,MAX}. */
12090 static dw_loc_descr_ref
12091 minmax_loc_descriptor (rtx rtl, machine_mode mode,
12092 machine_mode mem_mode)
12094 enum dwarf_location_atom op;
12095 dw_loc_descr_ref op0, op1, ret;
12096 dw_loc_descr_ref bra_node, drop_node;
12099 && (GET_MODE_CLASS (mode) != MODE_INT
12100 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
12103 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12104 VAR_INIT_STATUS_INITIALIZED);
12105 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12106 VAR_INIT_STATUS_INITIALIZED);
12108 if (op0 == NULL || op1 == NULL)
12111 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
12112 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
12113 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
12114 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
12116 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
12118 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
12119 add_loc_descr (&op0, int_loc_descriptor (mask));
12120 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
12121 add_loc_descr (&op1, int_loc_descriptor (mask));
12122 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
12124 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
12126 HOST_WIDE_INT bias = 1;
12127 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
12128 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
12129 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
12132 else if (GET_MODE_CLASS (mode) == MODE_INT
12133 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
12135 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
12136 add_loc_descr (&op0, int_loc_descriptor (shift));
12137 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
12138 add_loc_descr (&op1, int_loc_descriptor (shift));
12139 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
12141 else if (GET_MODE_CLASS (mode) == MODE_INT
12142 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12144 dw_die_ref type_die = base_type_for_mode (mode, 0);
12145 dw_loc_descr_ref cvt;
12146 if (type_die == NULL)
12148 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12149 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12150 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12151 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12152 add_loc_descr (&op0, cvt);
12153 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12154 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12155 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12156 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12157 add_loc_descr (&op1, cvt);
12160 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
12165 add_loc_descr (&ret, op1);
12166 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
12167 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12168 add_loc_descr (&ret, bra_node);
12169 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12170 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
12171 add_loc_descr (&ret, drop_node);
12172 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12173 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
12174 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
12175 && GET_MODE_CLASS (mode) == MODE_INT
12176 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12177 ret = convert_descriptor_to_mode (mode, ret);
12181 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12182 but after converting arguments to type_die, afterwards
12183 convert back to unsigned. */
12185 static dw_loc_descr_ref
12186 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
12187 machine_mode mode, machine_mode mem_mode)
12189 dw_loc_descr_ref cvt, op0, op1;
12191 if (type_die == NULL)
12193 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12194 VAR_INIT_STATUS_INITIALIZED);
12195 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12196 VAR_INIT_STATUS_INITIALIZED);
12197 if (op0 == NULL || op1 == NULL)
12199 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12200 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12201 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12202 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12203 add_loc_descr (&op0, cvt);
12204 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12205 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12206 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12207 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12208 add_loc_descr (&op1, cvt);
12209 add_loc_descr (&op0, op1);
12210 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
12211 return convert_descriptor_to_mode (mode, op0);
12214 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12215 const0 is DW_OP_lit0 or corresponding typed constant,
12216 const1 is DW_OP_lit1 or corresponding typed constant
12217 and constMSB is constant with just the MSB bit set
12219 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12220 L1: const0 DW_OP_swap
12221 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12222 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12227 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12228 L1: const0 DW_OP_swap
12229 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12230 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12235 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12236 L1: const1 DW_OP_swap
12237 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12238 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12242 static dw_loc_descr_ref
12243 clz_loc_descriptor (rtx rtl, machine_mode mode,
12244 machine_mode mem_mode)
12246 dw_loc_descr_ref op0, ret, tmp;
12247 HOST_WIDE_INT valv;
12248 dw_loc_descr_ref l1jump, l1label;
12249 dw_loc_descr_ref l2jump, l2label;
12250 dw_loc_descr_ref l3jump, l3label;
12251 dw_loc_descr_ref l4jump, l4label;
12254 if (GET_MODE_CLASS (mode) != MODE_INT
12255 || GET_MODE (XEXP (rtl, 0)) != mode)
12258 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12259 VAR_INIT_STATUS_INITIALIZED);
12263 if (GET_CODE (rtl) == CLZ)
12265 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
12266 valv = GET_MODE_BITSIZE (mode);
12268 else if (GET_CODE (rtl) == FFS)
12270 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
12271 valv = GET_MODE_BITSIZE (mode);
12272 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
12273 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
12274 add_loc_descr (&ret, l1jump);
12275 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
12276 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
12277 VAR_INIT_STATUS_INITIALIZED);
12280 add_loc_descr (&ret, tmp);
12281 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
12282 add_loc_descr (&ret, l4jump);
12283 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
12284 ? const1_rtx : const0_rtx,
12286 VAR_INIT_STATUS_INITIALIZED);
12287 if (l1label == NULL)
12289 add_loc_descr (&ret, l1label);
12290 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12291 l2label = new_loc_descr (DW_OP_dup, 0, 0);
12292 add_loc_descr (&ret, l2label);
12293 if (GET_CODE (rtl) != CLZ)
12295 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
12296 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
12297 << (GET_MODE_BITSIZE (mode) - 1));
12299 msb = immed_wide_int_const
12300 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode) - 1,
12301 GET_MODE_PRECISION (mode)), mode);
12302 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
12303 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
12304 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
12305 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
12307 tmp = mem_loc_descriptor (msb, mode, mem_mode,
12308 VAR_INIT_STATUS_INITIALIZED);
12311 add_loc_descr (&ret, tmp);
12312 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
12313 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
12314 add_loc_descr (&ret, l3jump);
12315 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
12316 VAR_INIT_STATUS_INITIALIZED);
12319 add_loc_descr (&ret, tmp);
12320 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
12321 ? DW_OP_shl : DW_OP_shr, 0, 0));
12322 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12323 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
12324 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12325 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
12326 add_loc_descr (&ret, l2jump);
12327 l3label = new_loc_descr (DW_OP_drop, 0, 0);
12328 add_loc_descr (&ret, l3label);
12329 l4label = new_loc_descr (DW_OP_nop, 0, 0);
12330 add_loc_descr (&ret, l4label);
12331 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12332 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
12333 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12334 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
12335 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12336 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
12337 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12338 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
12342 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
12343 const1 is DW_OP_lit1 or corresponding typed constant):
12345 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12346 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12350 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12351 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12354 static dw_loc_descr_ref
12355 popcount_loc_descriptor (rtx rtl, machine_mode mode,
12356 machine_mode mem_mode)
12358 dw_loc_descr_ref op0, ret, tmp;
12359 dw_loc_descr_ref l1jump, l1label;
12360 dw_loc_descr_ref l2jump, l2label;
12362 if (GET_MODE_CLASS (mode) != MODE_INT
12363 || GET_MODE (XEXP (rtl, 0)) != mode)
12366 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12367 VAR_INIT_STATUS_INITIALIZED);
12371 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
12372 VAR_INIT_STATUS_INITIALIZED);
12375 add_loc_descr (&ret, tmp);
12376 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12377 l1label = new_loc_descr (DW_OP_dup, 0, 0);
12378 add_loc_descr (&ret, l1label);
12379 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
12380 add_loc_descr (&ret, l2jump);
12381 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
12382 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
12383 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
12384 VAR_INIT_STATUS_INITIALIZED);
12387 add_loc_descr (&ret, tmp);
12388 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
12389 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
12390 ? DW_OP_plus : DW_OP_xor, 0, 0));
12391 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12392 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
12393 VAR_INIT_STATUS_INITIALIZED);
12394 add_loc_descr (&ret, tmp);
12395 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
12396 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
12397 add_loc_descr (&ret, l1jump);
12398 l2label = new_loc_descr (DW_OP_drop, 0, 0);
12399 add_loc_descr (&ret, l2label);
12400 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12401 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
12402 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12403 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
12407 /* BSWAP (constS is initial shift count, either 56 or 24):
12409 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12410 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12411 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12412 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12413 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12415 static dw_loc_descr_ref
12416 bswap_loc_descriptor (rtx rtl, machine_mode mode,
12417 machine_mode mem_mode)
12419 dw_loc_descr_ref op0, ret, tmp;
12420 dw_loc_descr_ref l1jump, l1label;
12421 dw_loc_descr_ref l2jump, l2label;
12423 if (GET_MODE_CLASS (mode) != MODE_INT
12424 || BITS_PER_UNIT != 8
12425 || (GET_MODE_BITSIZE (mode) != 32
12426 && GET_MODE_BITSIZE (mode) != 64))
12429 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12430 VAR_INIT_STATUS_INITIALIZED);
12435 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
12437 VAR_INIT_STATUS_INITIALIZED);
12440 add_loc_descr (&ret, tmp);
12441 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
12442 VAR_INIT_STATUS_INITIALIZED);
12445 add_loc_descr (&ret, tmp);
12446 l1label = new_loc_descr (DW_OP_pick, 2, 0);
12447 add_loc_descr (&ret, l1label);
12448 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
12450 VAR_INIT_STATUS_INITIALIZED);
12451 add_loc_descr (&ret, tmp);
12452 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
12453 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
12454 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
12455 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
12456 VAR_INIT_STATUS_INITIALIZED);
12459 add_loc_descr (&ret, tmp);
12460 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
12461 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
12462 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
12463 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
12464 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12465 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
12466 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
12467 VAR_INIT_STATUS_INITIALIZED);
12468 add_loc_descr (&ret, tmp);
12469 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
12470 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
12471 add_loc_descr (&ret, l2jump);
12472 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
12473 VAR_INIT_STATUS_INITIALIZED);
12474 add_loc_descr (&ret, tmp);
12475 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
12476 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12477 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
12478 add_loc_descr (&ret, l1jump);
12479 l2label = new_loc_descr (DW_OP_drop, 0, 0);
12480 add_loc_descr (&ret, l2label);
12481 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12482 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
12483 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12484 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
12485 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12486 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
12490 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12491 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12492 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12493 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12495 ROTATERT is similar:
12496 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12497 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12498 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12500 static dw_loc_descr_ref
12501 rotate_loc_descriptor (rtx rtl, machine_mode mode,
12502 machine_mode mem_mode)
12504 rtx rtlop1 = XEXP (rtl, 1);
12505 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
12508 if (GET_MODE_CLASS (mode) != MODE_INT)
12511 if (GET_MODE (rtlop1) != VOIDmode
12512 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
12513 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
12514 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12515 VAR_INIT_STATUS_INITIALIZED);
12516 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
12517 VAR_INIT_STATUS_INITIALIZED);
12518 if (op0 == NULL || op1 == NULL)
12520 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
12521 for (i = 0; i < 2; i++)
12523 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
12524 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
12526 VAR_INIT_STATUS_INITIALIZED);
12527 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
12528 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
12530 : HOST_BITS_PER_WIDE_INT == 64
12531 ? DW_OP_const8u : DW_OP_constu,
12532 GET_MODE_MASK (mode), 0);
12535 if (mask[i] == NULL)
12537 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
12540 add_loc_descr (&ret, op1);
12541 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
12542 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
12543 if (GET_CODE (rtl) == ROTATERT)
12545 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
12546 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
12547 GET_MODE_BITSIZE (mode), 0));
12549 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
12550 if (mask[0] != NULL)
12551 add_loc_descr (&ret, mask[0]);
12552 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
12553 if (mask[1] != NULL)
12555 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12556 add_loc_descr (&ret, mask[1]);
12557 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12559 if (GET_CODE (rtl) == ROTATE)
12561 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
12562 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
12563 GET_MODE_BITSIZE (mode), 0));
12565 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
12566 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
12570 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12571 for DEBUG_PARAMETER_REF RTL. */
12573 static dw_loc_descr_ref
12574 parameter_ref_descriptor (rtx rtl)
12576 dw_loc_descr_ref ret;
12581 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
12582 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
12583 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
12586 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12587 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
12588 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
12592 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
12593 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
12598 /* The following routine converts the RTL for a variable or parameter
12599 (resident in memory) into an equivalent Dwarf representation of a
12600 mechanism for getting the address of that same variable onto the top of a
12601 hypothetical "address evaluation" stack.
12603 When creating memory location descriptors, we are effectively transforming
12604 the RTL for a memory-resident object into its Dwarf postfix expression
12605 equivalent. This routine recursively descends an RTL tree, turning
12606 it into Dwarf postfix code as it goes.
12608 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12610 MEM_MODE is the mode of the memory reference, needed to handle some
12611 autoincrement addressing modes.
12613 Return 0 if we can't represent the location. */
12616 mem_loc_descriptor (rtx rtl, machine_mode mode,
12617 machine_mode mem_mode,
12618 enum var_init_status initialized)
12620 dw_loc_descr_ref mem_loc_result = NULL;
12621 enum dwarf_location_atom op;
12622 dw_loc_descr_ref op0, op1;
12623 rtx inner = NULL_RTX;
12625 if (mode == VOIDmode)
12626 mode = GET_MODE (rtl);
12628 /* Note that for a dynamically sized array, the location we will generate a
12629 description of here will be the lowest numbered location which is
12630 actually within the array. That's *not* necessarily the same as the
12631 zeroth element of the array. */
12633 rtl = targetm.delegitimize_address (rtl);
12635 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
12638 switch (GET_CODE (rtl))
12643 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
12646 /* The case of a subreg may arise when we have a local (register)
12647 variable or a formal (register) parameter which doesn't quite fill
12648 up an entire register. For now, just assume that it is
12649 legitimate to make the Dwarf info refer to the whole register which
12650 contains the given subreg. */
12651 if (!subreg_lowpart_p (rtl))
12653 inner = SUBREG_REG (rtl);
12655 if (inner == NULL_RTX)
12656 inner = XEXP (rtl, 0);
12657 if (GET_MODE_CLASS (mode) == MODE_INT
12658 && GET_MODE_CLASS (GET_MODE (inner)) == MODE_INT
12659 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12660 #ifdef POINTERS_EXTEND_UNSIGNED
12661 || (mode == Pmode && mem_mode != VOIDmode)
12664 && GET_MODE_SIZE (GET_MODE (inner)) <= DWARF2_ADDR_SIZE)
12666 mem_loc_result = mem_loc_descriptor (inner,
12668 mem_mode, initialized);
12673 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (inner)))
12675 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (inner))
12676 && (GET_MODE_CLASS (mode) != MODE_INT
12677 || GET_MODE_CLASS (GET_MODE (inner)) != MODE_INT))
12681 dw_die_ref type_die;
12682 dw_loc_descr_ref cvt;
12684 mem_loc_result = mem_loc_descriptor (inner,
12686 mem_mode, initialized);
12687 if (mem_loc_result == NULL)
12689 type_die = base_type_for_mode (mode,
12690 GET_MODE_CLASS (mode) == MODE_INT);
12691 if (type_die == NULL)
12693 mem_loc_result = NULL;
12696 if (GET_MODE_SIZE (mode)
12697 != GET_MODE_SIZE (GET_MODE (inner)))
12698 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12700 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
12701 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12702 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12703 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12704 add_loc_descr (&mem_loc_result, cvt);
12709 if (GET_MODE_CLASS (mode) != MODE_INT
12710 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12711 && rtl != arg_pointer_rtx
12712 && rtl != frame_pointer_rtx
12713 #ifdef POINTERS_EXTEND_UNSIGNED
12714 && (mode != Pmode || mem_mode == VOIDmode)
12718 dw_die_ref type_die;
12719 unsigned int dbx_regnum;
12723 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
12725 type_die = base_type_for_mode (mode,
12726 GET_MODE_CLASS (mode) == MODE_INT);
12727 if (type_die == NULL)
12730 dbx_regnum = dbx_reg_number (rtl);
12731 if (dbx_regnum == IGNORED_DWARF_REGNUM)
12733 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
12735 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
12736 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
12737 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
12740 /* Whenever a register number forms a part of the description of the
12741 method for calculating the (dynamic) address of a memory resident
12742 object, DWARF rules require the register number be referred to as
12743 a "base register". This distinction is not based in any way upon
12744 what category of register the hardware believes the given register
12745 belongs to. This is strictly DWARF terminology we're dealing with
12746 here. Note that in cases where the location of a memory-resident
12747 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12748 OP_CONST (0)) the actual DWARF location descriptor that we generate
12749 may just be OP_BASEREG (basereg). This may look deceptively like
12750 the object in question was allocated to a register (rather than in
12751 memory) so DWARF consumers need to be aware of the subtle
12752 distinction between OP_REG and OP_BASEREG. */
12753 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
12754 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
12755 else if (stack_realign_drap
12757 && crtl->args.internal_arg_pointer == rtl
12758 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
12760 /* If RTL is internal_arg_pointer, which has been optimized
12761 out, use DRAP instead. */
12762 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
12763 VAR_INIT_STATUS_INITIALIZED);
12769 if (GET_MODE_CLASS (mode) != MODE_INT)
12771 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12772 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12775 else if (GET_CODE (rtl) == ZERO_EXTEND
12776 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12777 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
12778 < HOST_BITS_PER_WIDE_INT
12779 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12780 to expand zero extend as two shifts instead of
12782 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
12784 machine_mode imode = GET_MODE (XEXP (rtl, 0));
12785 mem_loc_result = op0;
12786 add_loc_descr (&mem_loc_result,
12787 int_loc_descriptor (GET_MODE_MASK (imode)));
12788 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
12790 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
12792 int shift = DWARF2_ADDR_SIZE
12793 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
12794 shift *= BITS_PER_UNIT;
12795 if (GET_CODE (rtl) == SIGN_EXTEND)
12799 mem_loc_result = op0;
12800 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
12801 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
12802 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
12803 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12805 else if (!dwarf_strict)
12807 dw_die_ref type_die1, type_die2;
12808 dw_loc_descr_ref cvt;
12810 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12811 GET_CODE (rtl) == ZERO_EXTEND);
12812 if (type_die1 == NULL)
12814 type_die2 = base_type_for_mode (mode, 1);
12815 if (type_die2 == NULL)
12817 mem_loc_result = op0;
12818 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12819 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12820 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
12821 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12822 add_loc_descr (&mem_loc_result, cvt);
12823 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12824 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12825 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
12826 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12827 add_loc_descr (&mem_loc_result, cvt);
12833 rtx new_rtl = avoid_constant_pool_reference (rtl);
12834 if (new_rtl != rtl)
12836 mem_loc_result = mem_loc_descriptor (new_rtl, mode, mem_mode,
12838 if (mem_loc_result != NULL)
12839 return mem_loc_result;
12842 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
12843 get_address_mode (rtl), mode,
12844 VAR_INIT_STATUS_INITIALIZED);
12845 if (mem_loc_result == NULL)
12846 mem_loc_result = tls_mem_loc_descriptor (rtl);
12847 if (mem_loc_result != NULL)
12849 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12850 || GET_MODE_CLASS (mode) != MODE_INT)
12852 dw_die_ref type_die;
12853 dw_loc_descr_ref deref;
12858 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
12859 if (type_die == NULL)
12861 deref = new_loc_descr (DW_OP_GNU_deref_type,
12862 GET_MODE_SIZE (mode), 0);
12863 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
12864 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
12865 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
12866 add_loc_descr (&mem_loc_result, deref);
12868 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
12869 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
12871 add_loc_descr (&mem_loc_result,
12872 new_loc_descr (DW_OP_deref_size,
12873 GET_MODE_SIZE (mode), 0));
12878 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
12881 /* Some ports can transform a symbol ref into a label ref, because
12882 the symbol ref is too far away and has to be dumped into a constant
12886 if ((GET_MODE_CLASS (mode) != MODE_INT
12887 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
12888 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12889 #ifdef POINTERS_EXTEND_UNSIGNED
12890 && (mode != Pmode || mem_mode == VOIDmode)
12894 if (GET_CODE (rtl) == SYMBOL_REF
12895 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
12897 dw_loc_descr_ref temp;
12899 /* If this is not defined, we have no way to emit the data. */
12900 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
12903 temp = new_addr_loc_descr (rtl, dtprel_true);
12905 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
12906 add_loc_descr (&mem_loc_result, temp);
12911 if (!const_ok_for_output (rtl))
12913 if (GET_CODE (rtl) == CONST)
12914 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12920 mem_loc_result = new_addr_loc_descr (rtl, dtprel_false);
12921 vec_safe_push (used_rtx_array, rtl);
12927 case DEBUG_IMPLICIT_PTR:
12928 expansion_failed (NULL_TREE, rtl,
12929 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12935 if (REG_P (ENTRY_VALUE_EXP (rtl)))
12937 if (GET_MODE_CLASS (mode) != MODE_INT
12938 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12939 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
12940 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12943 unsigned int dbx_regnum = dbx_reg_number (ENTRY_VALUE_EXP (rtl));
12944 if (dbx_regnum == IGNORED_DWARF_REGNUM)
12946 op0 = one_reg_loc_descriptor (dbx_regnum,
12947 VAR_INIT_STATUS_INITIALIZED);
12950 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
12951 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
12953 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
12954 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12955 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
12959 gcc_unreachable ();
12962 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
12963 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
12964 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
12967 case DEBUG_PARAMETER_REF:
12968 mem_loc_result = parameter_ref_descriptor (rtl);
12972 /* Extract the PLUS expression nested inside and fall into
12973 PLUS code below. */
12974 rtl = XEXP (rtl, 1);
12979 /* Turn these into a PLUS expression and fall into the PLUS code
12981 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
12982 gen_int_mode (GET_CODE (rtl) == PRE_INC
12983 ? GET_MODE_UNIT_SIZE (mem_mode)
12984 : -GET_MODE_UNIT_SIZE (mem_mode),
12987 /* ... fall through ... */
12991 if (is_based_loc (rtl)
12992 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12993 || XEXP (rtl, 0) == arg_pointer_rtx
12994 || XEXP (rtl, 0) == frame_pointer_rtx)
12995 && GET_MODE_CLASS (mode) == MODE_INT)
12996 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
12997 INTVAL (XEXP (rtl, 1)),
12998 VAR_INIT_STATUS_INITIALIZED);
13001 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13002 VAR_INIT_STATUS_INITIALIZED);
13003 if (mem_loc_result == 0)
13006 if (CONST_INT_P (XEXP (rtl, 1))
13007 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
13008 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13011 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13012 VAR_INIT_STATUS_INITIALIZED);
13015 add_loc_descr (&mem_loc_result, op1);
13016 add_loc_descr (&mem_loc_result,
13017 new_loc_descr (DW_OP_plus, 0, 0));
13022 /* If a pseudo-reg is optimized away, it is possible for it to
13023 be replaced with a MEM containing a multiply or shift. */
13034 && GET_MODE_CLASS (mode) == MODE_INT
13035 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
13037 mem_loc_result = typed_binop (DW_OP_div, rtl,
13038 base_type_for_mode (mode, 0),
13062 if (GET_MODE_CLASS (mode) != MODE_INT)
13064 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13065 VAR_INIT_STATUS_INITIALIZED);
13067 rtx rtlop1 = XEXP (rtl, 1);
13068 if (GET_MODE (rtlop1) != VOIDmode
13069 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
13070 < GET_MODE_BITSIZE (mode))
13071 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
13072 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
13073 VAR_INIT_STATUS_INITIALIZED);
13076 if (op0 == 0 || op1 == 0)
13079 mem_loc_result = op0;
13080 add_loc_descr (&mem_loc_result, op1);
13081 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13097 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13098 VAR_INIT_STATUS_INITIALIZED);
13099 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13100 VAR_INIT_STATUS_INITIALIZED);
13102 if (op0 == 0 || op1 == 0)
13105 mem_loc_result = op0;
13106 add_loc_descr (&mem_loc_result, op1);
13107 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13111 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
13113 mem_loc_result = typed_binop (DW_OP_mod, rtl,
13114 base_type_for_mode (mode, 0),
13119 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13120 VAR_INIT_STATUS_INITIALIZED);
13121 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13122 VAR_INIT_STATUS_INITIALIZED);
13124 if (op0 == 0 || op1 == 0)
13127 mem_loc_result = op0;
13128 add_loc_descr (&mem_loc_result, op1);
13129 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13130 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13131 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
13132 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13133 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
13137 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
13139 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
13144 mem_loc_result = typed_binop (DW_OP_div, rtl,
13145 base_type_for_mode (mode, 1),
13163 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13164 VAR_INIT_STATUS_INITIALIZED);
13169 mem_loc_result = op0;
13170 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13174 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
13175 #ifdef POINTERS_EXTEND_UNSIGNED
13177 && mem_mode != VOIDmode
13178 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
13182 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13186 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
13187 || GET_MODE_BITSIZE (mode) == HOST_BITS_PER_DOUBLE_INT))
13189 dw_die_ref type_die = base_type_for_mode (mode, 1);
13190 machine_mode amode;
13191 if (type_die == NULL)
13193 amode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
13195 if (INTVAL (rtl) >= 0
13196 && amode != BLKmode
13197 && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
13198 /* const DW_OP_GNU_convert <XXX> vs.
13199 DW_OP_GNU_const_type <XXX, 1, const>. */
13200 && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
13201 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode))
13203 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13204 op0 = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13205 op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13206 op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13207 op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
13208 add_loc_descr (&mem_loc_result, op0);
13209 return mem_loc_result;
13211 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
13213 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13214 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13215 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
13216 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
13217 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13220 mem_loc_result->dw_loc_oprnd2.val_class
13221 = dw_val_class_const_double;
13222 mem_loc_result->dw_loc_oprnd2.v.val_double
13223 = double_int::from_shwi (INTVAL (rtl));
13231 dw_die_ref type_die;
13233 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13234 CONST_DOUBLE rtx could represent either a large integer
13235 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13236 the value is always a floating point constant.
13238 When it is an integer, a CONST_DOUBLE is used whenever
13239 the constant requires 2 HWIs to be adequately represented.
13240 We output CONST_DOUBLEs as blocks. */
13241 if (mode == VOIDmode
13242 || (GET_MODE (rtl) == VOIDmode
13243 && GET_MODE_BITSIZE (mode) != HOST_BITS_PER_DOUBLE_INT))
13245 type_die = base_type_for_mode (mode,
13246 GET_MODE_CLASS (mode) == MODE_INT);
13247 if (type_die == NULL)
13249 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
13250 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13251 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13252 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
13253 #if TARGET_SUPPORTS_WIDE_INT == 0
13254 if (!SCALAR_FLOAT_MODE_P (mode))
13256 mem_loc_result->dw_loc_oprnd2.val_class
13257 = dw_val_class_const_double;
13258 mem_loc_result->dw_loc_oprnd2.v.val_double
13259 = rtx_to_double_int (rtl);
13264 unsigned int length = GET_MODE_SIZE (mode);
13265 unsigned char *array = ggc_vec_alloc<unsigned char> (length);
13267 insert_float (rtl, array);
13268 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13269 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
13270 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
13271 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13276 case CONST_WIDE_INT:
13279 dw_die_ref type_die;
13281 type_die = base_type_for_mode (mode,
13282 GET_MODE_CLASS (mode) == MODE_INT);
13283 if (type_die == NULL)
13285 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
13286 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13287 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13288 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
13289 mem_loc_result->dw_loc_oprnd2.val_class
13290 = dw_val_class_wide_int;
13291 mem_loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc<wide_int> ();
13292 *mem_loc_result->dw_loc_oprnd2.v.val_wide = std::make_pair (rtl, mode);
13297 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
13301 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
13305 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
13309 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
13313 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
13317 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
13321 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
13325 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
13329 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
13333 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
13338 if (GET_MODE_CLASS (mode) != MODE_INT)
13343 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
13348 if (CONST_INT_P (XEXP (rtl, 1))
13349 && CONST_INT_P (XEXP (rtl, 2))
13350 && ((unsigned) INTVAL (XEXP (rtl, 1))
13351 + (unsigned) INTVAL (XEXP (rtl, 2))
13352 <= GET_MODE_BITSIZE (mode))
13353 && GET_MODE_CLASS (mode) == MODE_INT
13354 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
13355 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
13358 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
13359 mem_mode, VAR_INIT_STATUS_INITIALIZED);
13362 if (GET_CODE (rtl) == SIGN_EXTRACT)
13366 mem_loc_result = op0;
13367 size = INTVAL (XEXP (rtl, 1));
13368 shift = INTVAL (XEXP (rtl, 2));
13369 if (BITS_BIG_ENDIAN)
13370 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
13372 if (shift + size != (int) DWARF2_ADDR_SIZE)
13374 add_loc_descr (&mem_loc_result,
13375 int_loc_descriptor (DWARF2_ADDR_SIZE
13377 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13379 if (size != (int) DWARF2_ADDR_SIZE)
13381 add_loc_descr (&mem_loc_result,
13382 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
13383 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13390 dw_loc_descr_ref op2, bra_node, drop_node;
13391 op0 = mem_loc_descriptor (XEXP (rtl, 0),
13392 GET_MODE (XEXP (rtl, 0)) == VOIDmode
13393 ? word_mode : GET_MODE (XEXP (rtl, 0)),
13394 mem_mode, VAR_INIT_STATUS_INITIALIZED);
13395 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13396 VAR_INIT_STATUS_INITIALIZED);
13397 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
13398 VAR_INIT_STATUS_INITIALIZED);
13399 if (op0 == NULL || op1 == NULL || op2 == NULL)
13402 mem_loc_result = op1;
13403 add_loc_descr (&mem_loc_result, op2);
13404 add_loc_descr (&mem_loc_result, op0);
13405 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
13406 add_loc_descr (&mem_loc_result, bra_node);
13407 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
13408 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
13409 add_loc_descr (&mem_loc_result, drop_node);
13410 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13411 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
13416 case FLOAT_TRUNCATE:
13418 case UNSIGNED_FLOAT:
13423 dw_die_ref type_die;
13424 dw_loc_descr_ref cvt;
13426 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
13427 mem_mode, VAR_INIT_STATUS_INITIALIZED);
13430 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
13431 && (GET_CODE (rtl) == FLOAT
13432 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
13433 <= DWARF2_ADDR_SIZE))
13435 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
13436 GET_CODE (rtl) == UNSIGNED_FLOAT);
13437 if (type_die == NULL)
13439 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13440 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13441 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13442 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13443 add_loc_descr (&op0, cvt);
13445 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
13446 if (type_die == NULL)
13448 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13449 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13450 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13451 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13452 add_loc_descr (&op0, cvt);
13453 if (GET_MODE_CLASS (mode) == MODE_INT
13454 && (GET_CODE (rtl) == FIX
13455 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
13457 op0 = convert_descriptor_to_mode (mode, op0);
13461 mem_loc_result = op0;
13468 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
13473 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
13477 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
13482 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
13486 /* In theory, we could implement the above. */
13487 /* DWARF cannot represent the unsigned compare operations
13512 case FRACT_CONVERT:
13513 case UNSIGNED_FRACT_CONVERT:
13515 case UNSIGNED_SAT_FRACT:
13521 case VEC_DUPLICATE:
13525 case STRICT_LOW_PART:
13530 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13531 can't express it in the debug info. This can happen e.g. with some
13536 resolve_one_addr (&rtl);
13540 #ifdef ENABLE_CHECKING
13541 print_rtl (stderr, rtl);
13542 gcc_unreachable ();
13548 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13549 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13551 return mem_loc_result;
13554 /* Return a descriptor that describes the concatenation of two locations.
13555 This is typically a complex variable. */
13557 static dw_loc_descr_ref
13558 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
13560 dw_loc_descr_ref cc_loc_result = NULL;
13561 dw_loc_descr_ref x0_ref
13562 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
13563 dw_loc_descr_ref x1_ref
13564 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
13566 if (x0_ref == 0 || x1_ref == 0)
13569 cc_loc_result = x0_ref;
13570 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
13572 add_loc_descr (&cc_loc_result, x1_ref);
13573 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
13575 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13576 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13578 return cc_loc_result;
13581 /* Return a descriptor that describes the concatenation of N
13584 static dw_loc_descr_ref
13585 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
13588 dw_loc_descr_ref cc_loc_result = NULL;
13589 unsigned int n = XVECLEN (concatn, 0);
13591 for (i = 0; i < n; ++i)
13593 dw_loc_descr_ref ref;
13594 rtx x = XVECEXP (concatn, 0, i);
13596 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
13600 add_loc_descr (&cc_loc_result, ref);
13601 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
13604 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13605 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13607 return cc_loc_result;
13610 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13611 for DEBUG_IMPLICIT_PTR RTL. */
13613 static dw_loc_descr_ref
13614 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
13616 dw_loc_descr_ref ret;
13621 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
13622 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
13623 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
13624 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
13625 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
13626 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
13629 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13630 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
13631 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
13635 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
13636 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
13641 /* Output a proper Dwarf location descriptor for a variable or parameter
13642 which is either allocated in a register or in a memory location. For a
13643 register, we just generate an OP_REG and the register number. For a
13644 memory location we provide a Dwarf postfix expression describing how to
13645 generate the (dynamic) address of the object onto the address stack.
13647 MODE is mode of the decl if this loc_descriptor is going to be used in
13648 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13649 allowed, VOIDmode otherwise.
13651 If we don't know how to describe it, return 0. */
13653 static dw_loc_descr_ref
13654 loc_descriptor (rtx rtl, machine_mode mode,
13655 enum var_init_status initialized)
13657 dw_loc_descr_ref loc_result = NULL;
13659 switch (GET_CODE (rtl))
13662 /* The case of a subreg may arise when we have a local (register)
13663 variable or a formal (register) parameter which doesn't quite fill
13664 up an entire register. For now, just assume that it is
13665 legitimate to make the Dwarf info refer to the whole register which
13666 contains the given subreg. */
13667 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
13668 loc_result = loc_descriptor (SUBREG_REG (rtl),
13669 GET_MODE (SUBREG_REG (rtl)), initialized);
13675 loc_result = reg_loc_descriptor (rtl, initialized);
13679 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
13680 GET_MODE (rtl), initialized);
13681 if (loc_result == NULL)
13682 loc_result = tls_mem_loc_descriptor (rtl);
13683 if (loc_result == NULL)
13685 rtx new_rtl = avoid_constant_pool_reference (rtl);
13686 if (new_rtl != rtl)
13687 loc_result = loc_descriptor (new_rtl, mode, initialized);
13692 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
13697 loc_result = concatn_loc_descriptor (rtl, initialized);
13702 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
13704 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
13705 if (GET_CODE (loc) == EXPR_LIST)
13706 loc = XEXP (loc, 0);
13707 loc_result = loc_descriptor (loc, mode, initialized);
13711 rtl = XEXP (rtl, 1);
13716 rtvec par_elems = XVEC (rtl, 0);
13717 int num_elem = GET_NUM_ELEM (par_elems);
13721 /* Create the first one, so we have something to add to. */
13722 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
13723 VOIDmode, initialized);
13724 if (loc_result == NULL)
13726 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
13727 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
13728 for (i = 1; i < num_elem; i++)
13730 dw_loc_descr_ref temp;
13732 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
13733 VOIDmode, initialized);
13736 add_loc_descr (&loc_result, temp);
13737 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
13738 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
13744 if (mode != VOIDmode && mode != BLKmode)
13745 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
13750 if (mode == VOIDmode)
13751 mode = GET_MODE (rtl);
13753 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
13755 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
13757 /* Note that a CONST_DOUBLE rtx could represent either an integer
13758 or a floating-point constant. A CONST_DOUBLE is used whenever
13759 the constant requires more than one word in order to be
13760 adequately represented. We output CONST_DOUBLEs as blocks. */
13761 loc_result = new_loc_descr (DW_OP_implicit_value,
13762 GET_MODE_SIZE (mode), 0);
13763 #if TARGET_SUPPORTS_WIDE_INT == 0
13764 if (!SCALAR_FLOAT_MODE_P (mode))
13766 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
13767 loc_result->dw_loc_oprnd2.v.val_double
13768 = rtx_to_double_int (rtl);
13773 unsigned int length = GET_MODE_SIZE (mode);
13774 unsigned char *array = ggc_vec_alloc<unsigned char> (length);
13776 insert_float (rtl, array);
13777 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13778 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
13779 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
13780 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13785 case CONST_WIDE_INT:
13786 if (mode == VOIDmode)
13787 mode = GET_MODE (rtl);
13789 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
13791 loc_result = new_loc_descr (DW_OP_implicit_value,
13792 GET_MODE_SIZE (mode), 0);
13793 loc_result->dw_loc_oprnd2.val_class = dw_val_class_wide_int;
13794 loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc<wide_int> ();
13795 *loc_result->dw_loc_oprnd2.v.val_wide = std::make_pair (rtl, mode);
13800 if (mode == VOIDmode)
13801 mode = GET_MODE (rtl);
13803 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
13805 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
13806 unsigned int length = CONST_VECTOR_NUNITS (rtl);
13807 unsigned char *array
13808 = ggc_vec_alloc<unsigned char> (length * elt_size);
13811 machine_mode imode = GET_MODE_INNER (mode);
13813 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
13814 switch (GET_MODE_CLASS (mode))
13816 case MODE_VECTOR_INT:
13817 for (i = 0, p = array; i < length; i++, p += elt_size)
13819 rtx elt = CONST_VECTOR_ELT (rtl, i);
13820 insert_wide_int (std::make_pair (elt, imode), p, elt_size);
13824 case MODE_VECTOR_FLOAT:
13825 for (i = 0, p = array; i < length; i++, p += elt_size)
13827 rtx elt = CONST_VECTOR_ELT (rtl, i);
13828 insert_float (elt, p);
13833 gcc_unreachable ();
13836 loc_result = new_loc_descr (DW_OP_implicit_value,
13837 length * elt_size, 0);
13838 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13839 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
13840 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
13841 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13846 if (mode == VOIDmode
13847 || CONST_SCALAR_INT_P (XEXP (rtl, 0))
13848 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl, 0))
13849 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
13851 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
13856 if (!const_ok_for_output (rtl))
13859 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
13860 && (dwarf_version >= 4 || !dwarf_strict))
13862 loc_result = new_addr_loc_descr (rtl, dtprel_false);
13863 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
13864 vec_safe_push (used_rtx_array, rtl);
13868 case DEBUG_IMPLICIT_PTR:
13869 loc_result = implicit_ptr_descriptor (rtl, 0);
13873 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
13874 && CONST_INT_P (XEXP (rtl, 1)))
13877 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
13883 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
13884 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
13885 && dwarf_version >= 4)
13886 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
13888 /* Value expression. */
13889 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
13891 add_loc_descr (&loc_result,
13892 new_loc_descr (DW_OP_stack_value, 0, 0));
13900 /* We need to figure out what section we should use as the base for the
13901 address ranges where a given location is valid.
13902 1. If this particular DECL has a section associated with it, use that.
13903 2. If this function has a section associated with it, use that.
13904 3. Otherwise, use the text section.
13905 XXX: If you split a variable across multiple sections, we won't notice. */
13907 static const char *
13908 secname_for_decl (const_tree decl)
13910 const char *secname;
13912 if (VAR_OR_FUNCTION_DECL_P (decl)
13913 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl) || TREE_STATIC (decl))
13914 && DECL_SECTION_NAME (decl))
13915 secname = DECL_SECTION_NAME (decl);
13916 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
13917 secname = DECL_SECTION_NAME (current_function_decl);
13918 else if (cfun && in_cold_section_p)
13919 secname = crtl->subsections.cold_section_label;
13921 secname = text_section_label;
13926 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13929 decl_by_reference_p (tree decl)
13931 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
13932 || TREE_CODE (decl) == VAR_DECL)
13933 && DECL_BY_REFERENCE (decl));
13936 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13939 static dw_loc_descr_ref
13940 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
13941 enum var_init_status initialized)
13943 int have_address = 0;
13944 dw_loc_descr_ref descr;
13947 if (want_address != 2)
13949 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
13951 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
13953 varloc = PAT_VAR_LOCATION_LOC (varloc);
13954 if (GET_CODE (varloc) == EXPR_LIST)
13955 varloc = XEXP (varloc, 0);
13956 mode = GET_MODE (varloc);
13957 if (MEM_P (varloc))
13959 rtx addr = XEXP (varloc, 0);
13960 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
13961 mode, initialized);
13966 rtx x = avoid_constant_pool_reference (varloc);
13968 descr = mem_loc_descriptor (x, mode, VOIDmode,
13973 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
13980 if (GET_CODE (varloc) == VAR_LOCATION)
13981 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
13983 mode = DECL_MODE (loc);
13984 descr = loc_descriptor (varloc, mode, initialized);
13991 if (want_address == 2 && !have_address
13992 && (dwarf_version >= 4 || !dwarf_strict))
13994 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
13996 expansion_failed (loc, NULL_RTX,
13997 "DWARF address size mismatch");
14000 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14003 /* Show if we can't fill the request for an address. */
14004 if (want_address && !have_address)
14006 expansion_failed (loc, NULL_RTX,
14007 "Want address and only have value");
14011 /* If we've got an address and don't want one, dereference. */
14012 if (!want_address && have_address)
14014 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14015 enum dwarf_location_atom op;
14017 if (size > DWARF2_ADDR_SIZE || size == -1)
14019 expansion_failed (loc, NULL_RTX,
14020 "DWARF address size mismatch");
14023 else if (size == DWARF2_ADDR_SIZE)
14026 op = DW_OP_deref_size;
14028 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14034 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14035 if it is not possible. */
14037 static dw_loc_descr_ref
14038 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14040 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14041 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14042 else if (dwarf_version >= 3 || !dwarf_strict)
14043 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14048 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14049 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14051 static dw_loc_descr_ref
14052 dw_sra_loc_expr (tree decl, rtx loc)
14055 unsigned HOST_WIDE_INT padsize = 0;
14056 dw_loc_descr_ref descr, *descr_tail;
14057 unsigned HOST_WIDE_INT decl_size;
14059 enum var_init_status initialized;
14061 if (DECL_SIZE (decl) == NULL
14062 || !tree_fits_uhwi_p (DECL_SIZE (decl)))
14065 decl_size = tree_to_uhwi (DECL_SIZE (decl));
14067 descr_tail = &descr;
14069 for (p = loc; p; p = XEXP (p, 1))
14071 unsigned HOST_WIDE_INT bitsize = decl_piece_bitsize (p);
14072 rtx loc_note = *decl_piece_varloc_ptr (p);
14073 dw_loc_descr_ref cur_descr;
14074 dw_loc_descr_ref *tail, last = NULL;
14075 unsigned HOST_WIDE_INT opsize = 0;
14077 if (loc_note == NULL_RTX
14078 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14080 padsize += bitsize;
14083 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14084 varloc = NOTE_VAR_LOCATION (loc_note);
14085 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14086 if (cur_descr == NULL)
14088 padsize += bitsize;
14092 /* Check that cur_descr either doesn't use
14093 DW_OP_*piece operations, or their sum is equal
14094 to bitsize. Otherwise we can't embed it. */
14095 for (tail = &cur_descr; *tail != NULL;
14096 tail = &(*tail)->dw_loc_next)
14097 if ((*tail)->dw_loc_opc == DW_OP_piece)
14099 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14103 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14105 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14109 if (last != NULL && opsize != bitsize)
14111 padsize += bitsize;
14112 /* Discard the current piece of the descriptor and release any
14113 addr_table entries it uses. */
14114 remove_loc_list_addr_table_entries (cur_descr);
14118 /* If there is a hole, add DW_OP_*piece after empty DWARF
14119 expression, which means that those bits are optimized out. */
14122 if (padsize > decl_size)
14124 remove_loc_list_addr_table_entries (cur_descr);
14125 goto discard_descr;
14127 decl_size -= padsize;
14128 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14129 if (*descr_tail == NULL)
14131 remove_loc_list_addr_table_entries (cur_descr);
14132 goto discard_descr;
14134 descr_tail = &(*descr_tail)->dw_loc_next;
14137 *descr_tail = cur_descr;
14139 if (bitsize > decl_size)
14140 goto discard_descr;
14141 decl_size -= bitsize;
14144 HOST_WIDE_INT offset = 0;
14145 if (GET_CODE (varloc) == VAR_LOCATION
14146 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14148 varloc = PAT_VAR_LOCATION_LOC (varloc);
14149 if (GET_CODE (varloc) == EXPR_LIST)
14150 varloc = XEXP (varloc, 0);
14154 if (GET_CODE (varloc) == CONST
14155 || GET_CODE (varloc) == SIGN_EXTEND
14156 || GET_CODE (varloc) == ZERO_EXTEND)
14157 varloc = XEXP (varloc, 0);
14158 else if (GET_CODE (varloc) == SUBREG)
14159 varloc = SUBREG_REG (varloc);
14164 /* DW_OP_bit_size offset should be zero for register
14165 or implicit location descriptions and empty location
14166 descriptions, but for memory addresses needs big endian
14168 if (MEM_P (varloc))
14170 unsigned HOST_WIDE_INT memsize
14171 = MEM_SIZE (varloc) * BITS_PER_UNIT;
14172 if (memsize != bitsize)
14174 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
14175 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
14176 goto discard_descr;
14177 if (memsize < bitsize)
14178 goto discard_descr;
14179 if (BITS_BIG_ENDIAN)
14180 offset = memsize - bitsize;
14184 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
14185 if (*descr_tail == NULL)
14186 goto discard_descr;
14187 descr_tail = &(*descr_tail)->dw_loc_next;
14191 /* If there were any non-empty expressions, add padding till the end of
14193 if (descr != NULL && decl_size != 0)
14195 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
14196 if (*descr_tail == NULL)
14197 goto discard_descr;
14202 /* Discard the descriptor and release any addr_table entries it uses. */
14203 remove_loc_list_addr_table_entries (descr);
14207 /* Return the dwarf representation of the location list LOC_LIST of
14208 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14211 static dw_loc_list_ref
14212 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
14214 const char *endname, *secname;
14216 enum var_init_status initialized;
14217 struct var_loc_node *node;
14218 dw_loc_descr_ref descr;
14219 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
14220 dw_loc_list_ref list = NULL;
14221 dw_loc_list_ref *listp = &list;
14223 /* Now that we know what section we are using for a base,
14224 actually construct the list of locations.
14225 The first location information is what is passed to the
14226 function that creates the location list, and the remaining
14227 locations just get added on to that list.
14228 Note that we only know the start address for a location
14229 (IE location changes), so to build the range, we use
14230 the range [current location start, next location start].
14231 This means we have to special case the last node, and generate
14232 a range of [last location start, end of function label]. */
14234 secname = secname_for_decl (decl);
14236 for (node = loc_list->first; node; node = node->next)
14237 if (GET_CODE (node->loc) == EXPR_LIST
14238 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
14240 if (GET_CODE (node->loc) == EXPR_LIST)
14242 /* This requires DW_OP_{,bit_}piece, which is not usable
14243 inside DWARF expressions. */
14244 if (want_address != 2)
14246 descr = dw_sra_loc_expr (decl, node->loc);
14252 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
14253 varloc = NOTE_VAR_LOCATION (node->loc);
14254 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
14258 bool range_across_switch = false;
14259 /* If section switch happens in between node->label
14260 and node->next->label (or end of function) and
14261 we can't emit it as a single entry list,
14262 emit two ranges, first one ending at the end
14263 of first partition and second one starting at the
14264 beginning of second partition. */
14265 if (node == loc_list->last_before_switch
14266 && (node != loc_list->first || loc_list->first->next)
14267 && current_function_decl)
14269 endname = cfun->fde->dw_fde_end;
14270 range_across_switch = true;
14272 /* The variable has a location between NODE->LABEL and
14273 NODE->NEXT->LABEL. */
14274 else if (node->next)
14275 endname = node->next->label;
14276 /* If the variable has a location at the last label
14277 it keeps its location until the end of function. */
14278 else if (!current_function_decl)
14279 endname = text_end_label;
14282 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
14283 current_function_funcdef_no);
14284 endname = ggc_strdup (label_id);
14287 *listp = new_loc_list (descr, node->label, endname, secname);
14288 if (TREE_CODE (decl) == PARM_DECL
14289 && node == loc_list->first
14290 && NOTE_P (node->loc)
14291 && strcmp (node->label, endname) == 0)
14292 (*listp)->force = true;
14293 listp = &(*listp)->dw_loc_next;
14295 if (range_across_switch)
14297 if (GET_CODE (node->loc) == EXPR_LIST)
14298 descr = dw_sra_loc_expr (decl, node->loc);
14301 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
14302 varloc = NOTE_VAR_LOCATION (node->loc);
14303 descr = dw_loc_list_1 (decl, varloc, want_address,
14306 gcc_assert (descr);
14307 /* The variable has a location between NODE->LABEL and
14308 NODE->NEXT->LABEL. */
14310 endname = node->next->label;
14312 endname = cfun->fde->dw_fde_second_end;
14313 *listp = new_loc_list (descr,
14314 cfun->fde->dw_fde_second_begin,
14316 listp = &(*listp)->dw_loc_next;
14321 /* Try to avoid the overhead of a location list emitting a location
14322 expression instead, but only if we didn't have more than one
14323 location entry in the first place. If some entries were not
14324 representable, we don't want to pretend a single entry that was
14325 applies to the entire scope in which the variable is
14327 if (list && loc_list->first->next)
14333 /* Return if the loc_list has only single element and thus can be represented
14334 as location description. */
14337 single_element_loc_list_p (dw_loc_list_ref list)
14339 gcc_assert (!list->dw_loc_next || list->ll_symbol);
14340 return !list->ll_symbol;
14343 /* To each location in list LIST add loc descr REF. */
14346 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
14348 dw_loc_descr_ref copy;
14349 add_loc_descr (&list->expr, ref);
14350 list = list->dw_loc_next;
14353 copy = ggc_alloc<dw_loc_descr_node> ();
14354 memcpy (copy, ref, sizeof (dw_loc_descr_node));
14355 add_loc_descr (&list->expr, copy);
14356 while (copy->dw_loc_next)
14358 dw_loc_descr_ref new_copy = ggc_alloc<dw_loc_descr_node> ();
14359 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
14360 copy->dw_loc_next = new_copy;
14363 list = list->dw_loc_next;
14367 /* Given two lists RET and LIST
14368 produce location list that is result of adding expression in LIST
14369 to expression in RET on each position in program.
14370 Might be destructive on both RET and LIST.
14372 TODO: We handle only simple cases of RET or LIST having at most one
14373 element. General case would inolve sorting the lists in program order
14374 and merging them that will need some additional work.
14375 Adding that will improve quality of debug info especially for SRA-ed
14379 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
14388 if (!list->dw_loc_next)
14390 add_loc_descr_to_each (*ret, list->expr);
14393 if (!(*ret)->dw_loc_next)
14395 add_loc_descr_to_each (list, (*ret)->expr);
14399 expansion_failed (NULL_TREE, NULL_RTX,
14400 "Don't know how to merge two non-trivial"
14401 " location lists.\n");
14406 /* LOC is constant expression. Try a luck, look it up in constant
14407 pool and return its loc_descr of its address. */
14409 static dw_loc_descr_ref
14410 cst_pool_loc_descr (tree loc)
14412 /* Get an RTL for this, if something has been emitted. */
14413 rtx rtl = lookup_constant_def (loc);
14415 if (!rtl || !MEM_P (rtl))
14420 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
14422 /* TODO: We might get more coverage if we was actually delaying expansion
14423 of all expressions till end of compilation when constant pools are fully
14425 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
14427 expansion_failed (loc, NULL_RTX,
14428 "CST value in contant pool but not marked.");
14431 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
14432 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
14435 /* Return dw_loc_list representing address of addr_expr LOC
14436 by looking for inner INDIRECT_REF expression and turning
14437 it into simple arithmetics.
14439 See loc_list_from_tree for the meaning of CONTEXT. */
14441 static dw_loc_list_ref
14442 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev,
14443 const loc_descr_context *context)
14446 HOST_WIDE_INT bitsize, bitpos, bytepos;
14448 int unsignedp, volatilep = 0;
14449 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
14451 obj = get_inner_reference (TREE_OPERAND (loc, 0),
14452 &bitsize, &bitpos, &offset, &mode,
14453 &unsignedp, &volatilep, false);
14455 if (bitpos % BITS_PER_UNIT)
14457 expansion_failed (loc, NULL_RTX, "bitfield access");
14460 if (!INDIRECT_REF_P (obj))
14462 expansion_failed (obj,
14463 NULL_RTX, "no indirect ref in inner refrence");
14466 if (!offset && !bitpos)
14467 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1,
14470 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
14471 && (dwarf_version >= 4 || !dwarf_strict))
14473 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0, context);
14478 /* Variable offset. */
14479 list_ret1 = loc_list_from_tree (offset, 0, context);
14480 if (list_ret1 == 0)
14482 add_loc_list (&list_ret, list_ret1);
14485 add_loc_descr_to_each (list_ret,
14486 new_loc_descr (DW_OP_plus, 0, 0));
14488 bytepos = bitpos / BITS_PER_UNIT;
14490 add_loc_descr_to_each (list_ret,
14491 new_loc_descr (DW_OP_plus_uconst,
14493 else if (bytepos < 0)
14494 loc_list_plus_const (list_ret, bytepos);
14495 add_loc_descr_to_each (list_ret,
14496 new_loc_descr (DW_OP_stack_value, 0, 0));
14502 /* Helper structure for location descriptions generation. */
14503 struct loc_descr_context
14505 /* The type that is implicitly referenced by DW_OP_push_object_address, or
14506 NULL_TREE if DW_OP_push_object_address in invalid for this location
14507 description. This is used when processing PLACEHOLDER_EXPR nodes. */
14509 /* The ..._DECL node that should be translated as a
14510 DW_OP_push_object_address operation. */
14514 /* Generate Dwarf location list representing LOC.
14515 If WANT_ADDRESS is false, expression computing LOC will be computed
14516 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14517 if WANT_ADDRESS is 2, expression computing address useable in location
14518 will be returned (i.e. DW_OP_reg can be used
14519 to refer to register values).
14521 CONTEXT provides information to customize the location descriptions
14522 generation. Its context_type field specifies what type is implicitly
14523 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
14524 will not be generated.
14526 If CONTEXT is NULL, the behavior is the same as if both context_type and
14527 base_decl fields were NULL_TREE. */
14529 static dw_loc_list_ref
14530 loc_list_from_tree (tree loc, int want_address,
14531 const struct loc_descr_context *context)
14533 dw_loc_descr_ref ret = NULL, ret1 = NULL;
14534 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
14535 int have_address = 0;
14536 enum dwarf_location_atom op;
14538 /* ??? Most of the time we do not take proper care for sign/zero
14539 extending the values properly. Hopefully this won't be a real
14542 if (context != NULL
14543 && context->base_decl == loc
14544 && want_address == 0)
14546 if (dwarf_version >= 3 || !dwarf_strict)
14547 return new_loc_list (new_loc_descr (DW_OP_push_object_address, 0, 0),
14553 switch (TREE_CODE (loc))
14556 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
14559 case PLACEHOLDER_EXPR:
14560 /* This case involves extracting fields from an object to determine the
14561 position of other fields. It is supposed to appear only as the first
14562 operand of COMPONENT_REF nodes and to reference precisely the type
14563 that the context allows. */
14564 if (context != NULL
14565 && TREE_TYPE (loc) == context->context_type
14566 && want_address >= 1)
14568 if (dwarf_version >= 3 || !dwarf_strict)
14570 ret = new_loc_descr (DW_OP_push_object_address, 0, 0);
14578 expansion_failed (loc, NULL_RTX,
14579 "PLACEHOLDER_EXPR for an unexpected type");
14583 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
14584 /* There are no opcodes for these operations. */
14587 case PREINCREMENT_EXPR:
14588 case PREDECREMENT_EXPR:
14589 case POSTINCREMENT_EXPR:
14590 case POSTDECREMENT_EXPR:
14591 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
14592 /* There are no opcodes for these operations. */
14596 /* If we already want an address, see if there is INDIRECT_REF inside
14597 e.g. for &this->field. */
14600 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
14601 (loc, want_address == 2, context);
14604 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
14605 && (ret = cst_pool_loc_descr (loc)))
14608 /* Otherwise, process the argument and look for the address. */
14609 if (!list_ret && !ret)
14610 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1, context);
14614 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
14620 if (DECL_THREAD_LOCAL_P (loc))
14623 enum dwarf_location_atom tls_op;
14624 enum dtprel_bool dtprel = dtprel_false;
14626 if (targetm.have_tls)
14628 /* If this is not defined, we have no way to emit the
14630 if (!targetm.asm_out.output_dwarf_dtprel)
14633 /* The way DW_OP_GNU_push_tls_address is specified, we
14634 can only look up addresses of objects in the current
14635 module. We used DW_OP_addr as first op, but that's
14636 wrong, because DW_OP_addr is relocated by the debug
14637 info consumer, while DW_OP_GNU_push_tls_address
14638 operand shouldn't be. */
14639 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
14641 dtprel = dtprel_true;
14642 tls_op = DW_OP_GNU_push_tls_address;
14646 if (!targetm.emutls.debug_form_tls_address
14647 || !(dwarf_version >= 3 || !dwarf_strict))
14649 /* We stuffed the control variable into the DECL_VALUE_EXPR
14650 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14651 no longer appear in gimple code. We used the control
14652 variable in specific so that we could pick it up here. */
14653 loc = DECL_VALUE_EXPR (loc);
14654 tls_op = DW_OP_form_tls_address;
14657 rtl = rtl_for_decl_location (loc);
14658 if (rtl == NULL_RTX)
14663 rtl = XEXP (rtl, 0);
14664 if (! CONSTANT_P (rtl))
14667 ret = new_addr_loc_descr (rtl, dtprel);
14668 ret1 = new_loc_descr (tls_op, 0, 0);
14669 add_loc_descr (&ret, ret1);
14678 if (DECL_HAS_VALUE_EXPR_P (loc))
14679 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
14680 want_address, context);
14683 case FUNCTION_DECL:
14686 var_loc_list *loc_list = lookup_decl_loc (loc);
14688 if (loc_list && loc_list->first)
14690 list_ret = dw_loc_list (loc_list, loc, want_address);
14691 have_address = want_address != 0;
14694 rtl = rtl_for_decl_location (loc);
14695 if (rtl == NULL_RTX)
14697 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
14700 else if (CONST_INT_P (rtl))
14702 HOST_WIDE_INT val = INTVAL (rtl);
14703 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
14704 val &= GET_MODE_MASK (DECL_MODE (loc));
14705 ret = int_loc_descriptor (val);
14707 else if (GET_CODE (rtl) == CONST_STRING)
14709 expansion_failed (loc, NULL_RTX, "CONST_STRING");
14712 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
14713 ret = new_addr_loc_descr (rtl, dtprel_false);
14716 machine_mode mode, mem_mode;
14718 /* Certain constructs can only be represented at top-level. */
14719 if (want_address == 2)
14721 ret = loc_descriptor (rtl, VOIDmode,
14722 VAR_INIT_STATUS_INITIALIZED);
14727 mode = GET_MODE (rtl);
14728 mem_mode = VOIDmode;
14732 mode = get_address_mode (rtl);
14733 rtl = XEXP (rtl, 0);
14736 ret = mem_loc_descriptor (rtl, mode, mem_mode,
14737 VAR_INIT_STATUS_INITIALIZED);
14740 expansion_failed (loc, rtl,
14741 "failed to produce loc descriptor for rtl");
14747 if (!integer_zerop (TREE_OPERAND (loc, 1)))
14754 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
14758 case TARGET_MEM_REF:
14760 case DEBUG_EXPR_DECL:
14763 case COMPOUND_EXPR:
14764 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address, context);
14767 case VIEW_CONVERT_EXPR:
14770 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address, context);
14772 case COMPONENT_REF:
14773 case BIT_FIELD_REF:
14775 case ARRAY_RANGE_REF:
14776 case REALPART_EXPR:
14777 case IMAGPART_EXPR:
14780 HOST_WIDE_INT bitsize, bitpos, bytepos;
14782 int unsignedp, volatilep = 0;
14784 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
14785 &unsignedp, &volatilep, false);
14787 gcc_assert (obj != loc);
14789 list_ret = loc_list_from_tree (obj,
14791 && !bitpos && !offset ? 2 : 1,
14793 /* TODO: We can extract value of the small expression via shifting even
14794 for nonzero bitpos. */
14797 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
14799 expansion_failed (loc, NULL_RTX,
14800 "bitfield access");
14804 if (offset != NULL_TREE)
14806 /* Variable offset. */
14807 list_ret1 = loc_list_from_tree (offset, 0, context);
14808 if (list_ret1 == 0)
14810 add_loc_list (&list_ret, list_ret1);
14813 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
14816 bytepos = bitpos / BITS_PER_UNIT;
14818 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
14819 else if (bytepos < 0)
14820 loc_list_plus_const (list_ret, bytepos);
14827 if ((want_address || !tree_fits_shwi_p (loc))
14828 && (ret = cst_pool_loc_descr (loc)))
14830 else if (want_address == 2
14831 && tree_fits_shwi_p (loc)
14832 && (ret = address_of_int_loc_descriptor
14833 (int_size_in_bytes (TREE_TYPE (loc)),
14834 tree_to_shwi (loc))))
14836 else if (tree_fits_shwi_p (loc))
14837 ret = int_loc_descriptor (tree_to_shwi (loc));
14840 expansion_failed (loc, NULL_RTX,
14841 "Integer operand is not host integer");
14850 if ((ret = cst_pool_loc_descr (loc)))
14853 /* We can construct small constants here using int_loc_descriptor. */
14854 expansion_failed (loc, NULL_RTX,
14855 "constructor or constant not in constant pool");
14858 case TRUTH_AND_EXPR:
14859 case TRUTH_ANDIF_EXPR:
14864 case TRUTH_XOR_EXPR:
14869 case TRUTH_OR_EXPR:
14870 case TRUTH_ORIF_EXPR:
14875 case FLOOR_DIV_EXPR:
14876 case CEIL_DIV_EXPR:
14877 case ROUND_DIV_EXPR:
14878 case TRUNC_DIV_EXPR:
14879 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
14888 case FLOOR_MOD_EXPR:
14889 case CEIL_MOD_EXPR:
14890 case ROUND_MOD_EXPR:
14891 case TRUNC_MOD_EXPR:
14892 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
14897 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
14898 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
14899 if (list_ret == 0 || list_ret1 == 0)
14902 add_loc_list (&list_ret, list_ret1);
14905 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
14906 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
14907 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
14908 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
14909 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
14921 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
14924 case POINTER_PLUS_EXPR:
14927 if (tree_fits_shwi_p (TREE_OPERAND (loc, 1)))
14929 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
14933 loc_list_plus_const (list_ret, tree_to_shwi (TREE_OPERAND (loc, 1)));
14941 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14948 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14955 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14962 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14977 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
14978 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
14979 if (list_ret == 0 || list_ret1 == 0)
14982 add_loc_list (&list_ret, list_ret1);
14985 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
14988 case TRUTH_NOT_EXPR:
15002 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
15006 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15012 const enum tree_code code =
15013 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15015 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15016 build2 (code, integer_type_node,
15017 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15018 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15021 /* ... fall through ... */
15025 dw_loc_descr_ref lhs
15026 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0, context);
15027 dw_loc_list_ref rhs
15028 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0, context);
15029 dw_loc_descr_ref bra_node, jump_node, tmp;
15031 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
15032 if (list_ret == 0 || lhs == 0 || rhs == 0)
15035 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15036 add_loc_descr_to_each (list_ret, bra_node);
15038 add_loc_list (&list_ret, rhs);
15039 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15040 add_loc_descr_to_each (list_ret, jump_node);
15042 add_loc_descr_to_each (list_ret, lhs);
15043 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15044 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15046 /* ??? Need a node to point the skip at. Use a nop. */
15047 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15048 add_loc_descr_to_each (list_ret, tmp);
15049 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15050 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15054 case FIX_TRUNC_EXPR:
15058 /* Leave front-end specific codes as simply unknown. This comes
15059 up, for instance, with the C STMT_EXPR. */
15060 if ((unsigned int) TREE_CODE (loc)
15061 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15063 expansion_failed (loc, NULL_RTX,
15064 "language specific tree node");
15068 #ifdef ENABLE_CHECKING
15069 /* Otherwise this is a generic code; we should just lists all of
15070 these explicitly. We forgot one. */
15071 gcc_unreachable ();
15073 /* In a release build, we want to degrade gracefully: better to
15074 generate incomplete debugging information than to crash. */
15079 if (!ret && !list_ret)
15082 if (want_address == 2 && !have_address
15083 && (dwarf_version >= 4 || !dwarf_strict))
15085 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15087 expansion_failed (loc, NULL_RTX,
15088 "DWARF address size mismatch");
15092 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15094 add_loc_descr_to_each (list_ret,
15095 new_loc_descr (DW_OP_stack_value, 0, 0));
15098 /* Show if we can't fill the request for an address. */
15099 if (want_address && !have_address)
15101 expansion_failed (loc, NULL_RTX,
15102 "Want address and only have value");
15106 gcc_assert (!ret || !list_ret);
15108 /* If we've got an address and don't want one, dereference. */
15109 if (!want_address && have_address)
15111 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15113 if (size > DWARF2_ADDR_SIZE || size == -1)
15115 expansion_failed (loc, NULL_RTX,
15116 "DWARF address size mismatch");
15119 else if (size == DWARF2_ADDR_SIZE)
15122 op = DW_OP_deref_size;
15125 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15127 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15130 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15135 /* Same as above but return only single location expression. */
15136 static dw_loc_descr_ref
15137 loc_descriptor_from_tree (tree loc, int want_address,
15138 const struct loc_descr_context *context)
15140 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address, context);
15143 if (ret->dw_loc_next)
15145 expansion_failed (loc, NULL_RTX,
15146 "Location list where only loc descriptor needed");
15152 /* Given a value, round it up to the lowest multiple of `boundary'
15153 which is not less than the value itself. */
15155 static inline HOST_WIDE_INT
15156 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15158 return (((value + boundary - 1) / boundary) * boundary);
15161 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15162 pointer to the declared type for the relevant field variable, or return
15163 `integer_type_node' if the given node turns out to be an
15164 ERROR_MARK node. */
15167 field_type (const_tree decl)
15171 if (TREE_CODE (decl) == ERROR_MARK)
15172 return integer_type_node;
15174 type = DECL_BIT_FIELD_TYPE (decl);
15175 if (type == NULL_TREE)
15176 type = TREE_TYPE (decl);
15181 /* Given a pointer to a tree node, return the alignment in bits for
15182 it, or else return BITS_PER_WORD if the node actually turns out to
15183 be an ERROR_MARK node. */
15185 static inline unsigned
15186 simple_type_align_in_bits (const_tree type)
15188 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15191 static inline unsigned
15192 simple_decl_align_in_bits (const_tree decl)
15194 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15197 /* Return the result of rounding T up to ALIGN. */
15199 static inline offset_int
15200 round_up_to_align (const offset_int &t, unsigned int align)
15202 return wi::udiv_trunc (t + align - 1, align) * align;
15205 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15206 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15207 or return 0 if we are unable to determine what that offset is, either
15208 because the argument turns out to be a pointer to an ERROR_MARK node, or
15209 because the offset is actually variable. (We can't handle the latter case
15212 static HOST_WIDE_INT
15213 field_byte_offset (const_tree decl)
15215 offset_int object_offset_in_bits;
15216 offset_int object_offset_in_bytes;
15217 offset_int bitpos_int;
15219 if (TREE_CODE (decl) == ERROR_MARK)
15222 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
15224 /* We cannot yet cope with fields whose positions are variable, so
15225 for now, when we see such things, we simply return 0. Someday, we may
15226 be able to handle such cases, but it will be damn difficult. */
15227 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
15230 bitpos_int = wi::to_offset (bit_position (decl));
15232 if (PCC_BITFIELD_TYPE_MATTERS)
15235 tree field_size_tree;
15236 offset_int deepest_bitpos;
15237 offset_int field_size_in_bits;
15238 unsigned int type_align_in_bits;
15239 unsigned int decl_align_in_bits;
15240 offset_int type_size_in_bits;
15242 type = field_type (decl);
15243 type_size_in_bits = offset_int_type_size_in_bits (type);
15244 type_align_in_bits = simple_type_align_in_bits (type);
15246 field_size_tree = DECL_SIZE (decl);
15248 /* The size could be unspecified if there was an error, or for
15249 a flexible array member. */
15250 if (!field_size_tree)
15251 field_size_tree = bitsize_zero_node;
15253 /* If the size of the field is not constant, use the type size. */
15254 if (TREE_CODE (field_size_tree) == INTEGER_CST)
15255 field_size_in_bits = wi::to_offset (field_size_tree);
15257 field_size_in_bits = type_size_in_bits;
15259 decl_align_in_bits = simple_decl_align_in_bits (decl);
15261 /* The GCC front-end doesn't make any attempt to keep track of the
15262 starting bit offset (relative to the start of the containing
15263 structure type) of the hypothetical "containing object" for a
15264 bit-field. Thus, when computing the byte offset value for the
15265 start of the "containing object" of a bit-field, we must deduce
15266 this information on our own. This can be rather tricky to do in
15267 some cases. For example, handling the following structure type
15268 definition when compiling for an i386/i486 target (which only
15269 aligns long long's to 32-bit boundaries) can be very tricky:
15271 struct S { int field1; long long field2:31; };
15273 Fortunately, there is a simple rule-of-thumb which can be used
15274 in such cases. When compiling for an i386/i486, GCC will
15275 allocate 8 bytes for the structure shown above. It decides to
15276 do this based upon one simple rule for bit-field allocation.
15277 GCC allocates each "containing object" for each bit-field at
15278 the first (i.e. lowest addressed) legitimate alignment boundary
15279 (based upon the required minimum alignment for the declared
15280 type of the field) which it can possibly use, subject to the
15281 condition that there is still enough available space remaining
15282 in the containing object (when allocated at the selected point)
15283 to fully accommodate all of the bits of the bit-field itself.
15285 This simple rule makes it obvious why GCC allocates 8 bytes for
15286 each object of the structure type shown above. When looking
15287 for a place to allocate the "containing object" for `field2',
15288 the compiler simply tries to allocate a 64-bit "containing
15289 object" at each successive 32-bit boundary (starting at zero)
15290 until it finds a place to allocate that 64- bit field such that
15291 at least 31 contiguous (and previously unallocated) bits remain
15292 within that selected 64 bit field. (As it turns out, for the
15293 example above, the compiler finds it is OK to allocate the
15294 "containing object" 64-bit field at bit-offset zero within the
15297 Here we attempt to work backwards from the limited set of facts
15298 we're given, and we try to deduce from those facts, where GCC
15299 must have believed that the containing object started (within
15300 the structure type). The value we deduce is then used (by the
15301 callers of this routine) to generate DW_AT_location and
15302 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15303 the case of DW_AT_location, regular fields as well). */
15305 /* Figure out the bit-distance from the start of the structure to
15306 the "deepest" bit of the bit-field. */
15307 deepest_bitpos = bitpos_int + field_size_in_bits;
15309 /* This is the tricky part. Use some fancy footwork to deduce
15310 where the lowest addressed bit of the containing object must
15312 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
15314 /* Round up to type_align by default. This works best for
15316 object_offset_in_bits
15317 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
15319 if (wi::gtu_p (object_offset_in_bits, bitpos_int))
15321 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
15323 /* Round up to decl_align instead. */
15324 object_offset_in_bits
15325 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
15329 object_offset_in_bits = bitpos_int;
15331 object_offset_in_bytes
15332 = wi::lrshift (object_offset_in_bits, LOG2_BITS_PER_UNIT);
15333 return object_offset_in_bytes.to_shwi ();
15336 /* The following routines define various Dwarf attributes and any data
15337 associated with them. */
15339 /* Add a location description attribute value to a DIE.
15341 This emits location attributes suitable for whole variables and
15342 whole parameters. Note that the location attributes for struct fields are
15343 generated by the routine `data_member_location_attribute' below. */
15346 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
15347 dw_loc_list_ref descr)
15351 if (single_element_loc_list_p (descr))
15352 add_AT_loc (die, attr_kind, descr->expr);
15354 add_AT_loc_list (die, attr_kind, descr);
15357 /* Add DW_AT_accessibility attribute to DIE if needed. */
15360 add_accessibility_attribute (dw_die_ref die, tree decl)
15362 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
15363 children, otherwise the default is DW_ACCESS_public. In DWARF2
15364 the default has always been DW_ACCESS_public. */
15365 if (TREE_PROTECTED (decl))
15366 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
15367 else if (TREE_PRIVATE (decl))
15369 if (dwarf_version == 2
15370 || die->die_parent == NULL
15371 || die->die_parent->die_tag != DW_TAG_class_type)
15372 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
15374 else if (dwarf_version > 2
15376 && die->die_parent->die_tag == DW_TAG_class_type)
15377 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
15380 /* Attach the specialized form of location attribute used for data members of
15381 struct and union types. In the special case of a FIELD_DECL node which
15382 represents a bit-field, the "offset" part of this special location
15383 descriptor must indicate the distance in bytes from the lowest-addressed
15384 byte of the containing struct or union type to the lowest-addressed byte of
15385 the "containing object" for the bit-field. (See the `field_byte_offset'
15388 For any given bit-field, the "containing object" is a hypothetical object
15389 (of some integral or enum type) within which the given bit-field lives. The
15390 type of this hypothetical "containing object" is always the same as the
15391 declared type of the individual bit-field itself (for GCC anyway... the
15392 DWARF spec doesn't actually mandate this). Note that it is the size (in
15393 bytes) of the hypothetical "containing object" which will be given in the
15394 DW_AT_byte_size attribute for this bit-field. (See the
15395 `byte_size_attribute' function below.) It is also used when calculating the
15396 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15397 function below.) */
15400 add_data_member_location_attribute (dw_die_ref die, tree decl)
15402 HOST_WIDE_INT offset;
15403 dw_loc_descr_ref loc_descr = 0;
15405 if (TREE_CODE (decl) == TREE_BINFO)
15407 /* We're working on the TAG_inheritance for a base class. */
15408 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
15410 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15411 aren't at a fixed offset from all (sub)objects of the same
15412 type. We need to extract the appropriate offset from our
15413 vtable. The following dwarf expression means
15415 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15417 This is specific to the V3 ABI, of course. */
15419 dw_loc_descr_ref tmp;
15421 /* Make a copy of the object address. */
15422 tmp = new_loc_descr (DW_OP_dup, 0, 0);
15423 add_loc_descr (&loc_descr, tmp);
15425 /* Extract the vtable address. */
15426 tmp = new_loc_descr (DW_OP_deref, 0, 0);
15427 add_loc_descr (&loc_descr, tmp);
15429 /* Calculate the address of the offset. */
15430 offset = tree_to_shwi (BINFO_VPTR_FIELD (decl));
15431 gcc_assert (offset < 0);
15433 tmp = int_loc_descriptor (-offset);
15434 add_loc_descr (&loc_descr, tmp);
15435 tmp = new_loc_descr (DW_OP_minus, 0, 0);
15436 add_loc_descr (&loc_descr, tmp);
15438 /* Extract the offset. */
15439 tmp = new_loc_descr (DW_OP_deref, 0, 0);
15440 add_loc_descr (&loc_descr, tmp);
15442 /* Add it to the object address. */
15443 tmp = new_loc_descr (DW_OP_plus, 0, 0);
15444 add_loc_descr (&loc_descr, tmp);
15447 offset = tree_to_shwi (BINFO_OFFSET (decl));
15450 offset = field_byte_offset (decl);
15454 if (dwarf_version > 2)
15456 /* Don't need to output a location expression, just the constant. */
15458 add_AT_int (die, DW_AT_data_member_location, offset);
15460 add_AT_unsigned (die, DW_AT_data_member_location, offset);
15465 enum dwarf_location_atom op;
15467 /* The DWARF2 standard says that we should assume that the structure
15468 address is already on the stack, so we can specify a structure
15469 field address by using DW_OP_plus_uconst. */
15470 op = DW_OP_plus_uconst;
15471 loc_descr = new_loc_descr (op, offset, 0);
15475 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
15478 /* Writes integer values to dw_vec_const array. */
15481 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
15485 *dest++ = val & 0xff;
15491 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15493 static HOST_WIDE_INT
15494 extract_int (const unsigned char *src, unsigned int size)
15496 HOST_WIDE_INT val = 0;
15502 val |= *--src & 0xff;
15508 /* Writes wide_int values to dw_vec_const array. */
15511 insert_wide_int (const wide_int &val, unsigned char *dest, int elt_size)
15515 if (elt_size <= HOST_BITS_PER_WIDE_INT/BITS_PER_UNIT)
15517 insert_int ((HOST_WIDE_INT) val.elt (0), elt_size, dest);
15521 /* We'd have to extend this code to support odd sizes. */
15522 gcc_assert (elt_size % (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT) == 0);
15524 int n = elt_size / (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
15526 if (WORDS_BIG_ENDIAN)
15527 for (i = n - 1; i >= 0; i--)
15529 insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
15530 dest += sizeof (HOST_WIDE_INT);
15533 for (i = 0; i < n; i++)
15535 insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
15536 dest += sizeof (HOST_WIDE_INT);
15540 /* Writes floating point values to dw_vec_const array. */
15543 insert_float (const_rtx rtl, unsigned char *array)
15545 REAL_VALUE_TYPE rv;
15549 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
15550 real_to_target (val, &rv, GET_MODE (rtl));
15552 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15553 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
15555 insert_int (val[i], 4, array);
15560 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15561 does not have a "location" either in memory or in a register. These
15562 things can arise in GNU C when a constant is passed as an actual parameter
15563 to an inlined function. They can also arise in C++ where declared
15564 constants do not necessarily get memory "homes". */
15567 add_const_value_attribute (dw_die_ref die, rtx rtl)
15569 switch (GET_CODE (rtl))
15573 HOST_WIDE_INT val = INTVAL (rtl);
15576 add_AT_int (die, DW_AT_const_value, val);
15578 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
15582 case CONST_WIDE_INT:
15583 add_AT_wide (die, DW_AT_const_value,
15584 std::make_pair (rtl, GET_MODE (rtl)));
15588 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15589 floating-point constant. A CONST_DOUBLE is used whenever the
15590 constant requires more than one word in order to be adequately
15593 machine_mode mode = GET_MODE (rtl);
15595 if (TARGET_SUPPORTS_WIDE_INT == 0 && !SCALAR_FLOAT_MODE_P (mode))
15596 add_AT_double (die, DW_AT_const_value,
15597 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
15600 unsigned int length = GET_MODE_SIZE (mode);
15601 unsigned char *array = ggc_vec_alloc<unsigned char> (length);
15603 insert_float (rtl, array);
15604 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
15611 machine_mode mode = GET_MODE (rtl);
15612 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
15613 unsigned int length = CONST_VECTOR_NUNITS (rtl);
15614 unsigned char *array
15615 = ggc_vec_alloc<unsigned char> (length * elt_size);
15618 machine_mode imode = GET_MODE_INNER (mode);
15620 switch (GET_MODE_CLASS (mode))
15622 case MODE_VECTOR_INT:
15623 for (i = 0, p = array; i < length; i++, p += elt_size)
15625 rtx elt = CONST_VECTOR_ELT (rtl, i);
15626 insert_wide_int (std::make_pair (elt, imode), p, elt_size);
15630 case MODE_VECTOR_FLOAT:
15631 for (i = 0, p = array; i < length; i++, p += elt_size)
15633 rtx elt = CONST_VECTOR_ELT (rtl, i);
15634 insert_float (elt, p);
15639 gcc_unreachable ();
15642 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
15647 if (dwarf_version >= 4 || !dwarf_strict)
15649 dw_loc_descr_ref loc_result;
15650 resolve_one_addr (&rtl);
15652 loc_result = new_addr_loc_descr (rtl, dtprel_false);
15653 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
15654 add_AT_loc (die, DW_AT_location, loc_result);
15655 vec_safe_push (used_rtx_array, rtl);
15661 if (CONSTANT_P (XEXP (rtl, 0)))
15662 return add_const_value_attribute (die, XEXP (rtl, 0));
15665 if (!const_ok_for_output (rtl))
15668 if (dwarf_version >= 4 || !dwarf_strict)
15673 /* In cases where an inlined instance of an inline function is passed
15674 the address of an `auto' variable (which is local to the caller) we
15675 can get a situation where the DECL_RTL of the artificial local
15676 variable (for the inlining) which acts as a stand-in for the
15677 corresponding formal parameter (of the inline function) will look
15678 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15679 exactly a compile-time constant expression, but it isn't the address
15680 of the (artificial) local variable either. Rather, it represents the
15681 *value* which the artificial local variable always has during its
15682 lifetime. We currently have no way to represent such quasi-constant
15683 values in Dwarf, so for now we just punt and generate nothing. */
15691 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
15692 && MEM_READONLY_P (rtl)
15693 && GET_MODE (rtl) == BLKmode)
15695 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
15701 /* No other kinds of rtx should be possible here. */
15702 gcc_unreachable ();
15707 /* Determine whether the evaluation of EXPR references any variables
15708 or functions which aren't otherwise used (and therefore may not be
15711 reference_to_unused (tree * tp, int * walk_subtrees,
15712 void * data ATTRIBUTE_UNUSED)
15714 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
15715 *walk_subtrees = 0;
15717 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
15718 && ! TREE_ASM_WRITTEN (*tp))
15720 /* ??? The C++ FE emits debug information for using decls, so
15721 putting gcc_unreachable here falls over. See PR31899. For now
15722 be conservative. */
15723 else if (!symtab->global_info_ready
15724 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
15726 else if (TREE_CODE (*tp) == VAR_DECL)
15728 varpool_node *node = varpool_node::get (*tp);
15729 if (!node || !node->definition)
15732 else if (TREE_CODE (*tp) == FUNCTION_DECL
15733 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
15735 /* The call graph machinery must have finished analyzing,
15736 optimizing and gimplifying the CU by now.
15737 So if *TP has no call graph node associated
15738 to it, it means *TP will not be emitted. */
15739 if (!cgraph_node::get (*tp))
15742 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
15748 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15749 for use in a later add_const_value_attribute call. */
15752 rtl_for_decl_init (tree init, tree type)
15754 rtx rtl = NULL_RTX;
15758 /* If a variable is initialized with a string constant without embedded
15759 zeros, build CONST_STRING. */
15760 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
15762 tree enttype = TREE_TYPE (type);
15763 tree domain = TYPE_DOMAIN (type);
15764 machine_mode mode = TYPE_MODE (enttype);
15766 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
15768 && integer_zerop (TYPE_MIN_VALUE (domain))
15769 && compare_tree_int (TYPE_MAX_VALUE (domain),
15770 TREE_STRING_LENGTH (init) - 1) == 0
15771 && ((size_t) TREE_STRING_LENGTH (init)
15772 == strlen (TREE_STRING_POINTER (init)) + 1))
15774 rtl = gen_rtx_CONST_STRING (VOIDmode,
15775 ggc_strdup (TREE_STRING_POINTER (init)));
15776 rtl = gen_rtx_MEM (BLKmode, rtl);
15777 MEM_READONLY_P (rtl) = 1;
15780 /* Other aggregates, and complex values, could be represented using
15782 else if (AGGREGATE_TYPE_P (type)
15783 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
15784 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
15785 || TREE_CODE (type) == COMPLEX_TYPE)
15787 /* Vectors only work if their mode is supported by the target.
15788 FIXME: generic vectors ought to work too. */
15789 else if (TREE_CODE (type) == VECTOR_TYPE
15790 && !VECTOR_MODE_P (TYPE_MODE (type)))
15792 /* If the initializer is something that we know will expand into an
15793 immediate RTL constant, expand it now. We must be careful not to
15794 reference variables which won't be output. */
15795 else if (initializer_constant_valid_p (init, type)
15796 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
15798 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15800 if (TREE_CODE (type) == VECTOR_TYPE)
15801 switch (TREE_CODE (init))
15806 if (TREE_CONSTANT (init))
15808 vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (init);
15809 bool constant_p = true;
15811 unsigned HOST_WIDE_INT ix;
15813 /* Even when ctor is constant, it might contain non-*_CST
15814 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15815 belong into VECTOR_CST nodes. */
15816 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
15817 if (!CONSTANT_CLASS_P (value))
15819 constant_p = false;
15825 init = build_vector_from_ctor (type, elts);
15835 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
15837 /* If expand_expr returns a MEM, it wasn't immediate. */
15838 gcc_assert (!rtl || !MEM_P (rtl));
15844 /* Generate RTL for the variable DECL to represent its location. */
15847 rtl_for_decl_location (tree decl)
15851 /* Here we have to decide where we are going to say the parameter "lives"
15852 (as far as the debugger is concerned). We only have a couple of
15853 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15855 DECL_RTL normally indicates where the parameter lives during most of the
15856 activation of the function. If optimization is enabled however, this
15857 could be either NULL or else a pseudo-reg. Both of those cases indicate
15858 that the parameter doesn't really live anywhere (as far as the code
15859 generation parts of GCC are concerned) during most of the function's
15860 activation. That will happen (for example) if the parameter is never
15861 referenced within the function.
15863 We could just generate a location descriptor here for all non-NULL
15864 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15865 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15866 where DECL_RTL is NULL or is a pseudo-reg.
15868 Note however that we can only get away with using DECL_INCOMING_RTL as
15869 a backup substitute for DECL_RTL in certain limited cases. In cases
15870 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15871 we can be sure that the parameter was passed using the same type as it is
15872 declared to have within the function, and that its DECL_INCOMING_RTL
15873 points us to a place where a value of that type is passed.
15875 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15876 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15877 because in these cases DECL_INCOMING_RTL points us to a value of some
15878 type which is *different* from the type of the parameter itself. Thus,
15879 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15880 such cases, the debugger would end up (for example) trying to fetch a
15881 `float' from a place which actually contains the first part of a
15882 `double'. That would lead to really incorrect and confusing
15883 output at debug-time.
15885 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15886 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15887 are a couple of exceptions however. On little-endian machines we can
15888 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15889 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15890 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15891 when (on a little-endian machine) a non-prototyped function has a
15892 parameter declared to be of type `short' or `char'. In such cases,
15893 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15894 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15895 passed `int' value. If the debugger then uses that address to fetch
15896 a `short' or a `char' (on a little-endian machine) the result will be
15897 the correct data, so we allow for such exceptional cases below.
15899 Note that our goal here is to describe the place where the given formal
15900 parameter lives during most of the function's activation (i.e. between the
15901 end of the prologue and the start of the epilogue). We'll do that as best
15902 as we can. Note however that if the given formal parameter is modified
15903 sometime during the execution of the function, then a stack backtrace (at
15904 debug-time) will show the function as having been called with the *new*
15905 value rather than the value which was originally passed in. This happens
15906 rarely enough that it is not a major problem, but it *is* a problem, and
15907 I'd like to fix it.
15909 A future version of dwarf2out.c may generate two additional attributes for
15910 any given DW_TAG_formal_parameter DIE which will describe the "passed
15911 type" and the "passed location" for the given formal parameter in addition
15912 to the attributes we now generate to indicate the "declared type" and the
15913 "active location" for each parameter. This additional set of attributes
15914 could be used by debuggers for stack backtraces. Separately, note that
15915 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15916 This happens (for example) for inlined-instances of inline function formal
15917 parameters which are never referenced. This really shouldn't be
15918 happening. All PARM_DECL nodes should get valid non-NULL
15919 DECL_INCOMING_RTL values. FIXME. */
15921 /* Use DECL_RTL as the "location" unless we find something better. */
15922 rtl = DECL_RTL_IF_SET (decl);
15924 /* When generating abstract instances, ignore everything except
15925 constants, symbols living in memory, and symbols living in
15926 fixed registers. */
15927 if (! reload_completed)
15930 && (CONSTANT_P (rtl)
15932 && CONSTANT_P (XEXP (rtl, 0)))
15934 && TREE_CODE (decl) == VAR_DECL
15935 && TREE_STATIC (decl))))
15937 rtl = targetm.delegitimize_address (rtl);
15942 else if (TREE_CODE (decl) == PARM_DECL)
15944 if (rtl == NULL_RTX
15945 || is_pseudo_reg (rtl)
15947 && is_pseudo_reg (XEXP (rtl, 0))
15948 && DECL_INCOMING_RTL (decl)
15949 && MEM_P (DECL_INCOMING_RTL (decl))
15950 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
15952 tree declared_type = TREE_TYPE (decl);
15953 tree passed_type = DECL_ARG_TYPE (decl);
15954 machine_mode dmode = TYPE_MODE (declared_type);
15955 machine_mode pmode = TYPE_MODE (passed_type);
15957 /* This decl represents a formal parameter which was optimized out.
15958 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15959 all cases where (rtl == NULL_RTX) just below. */
15960 if (dmode == pmode)
15961 rtl = DECL_INCOMING_RTL (decl);
15962 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
15963 && SCALAR_INT_MODE_P (dmode)
15964 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
15965 && DECL_INCOMING_RTL (decl))
15967 rtx inc = DECL_INCOMING_RTL (decl);
15970 else if (MEM_P (inc))
15972 if (BYTES_BIG_ENDIAN)
15973 rtl = adjust_address_nv (inc, dmode,
15974 GET_MODE_SIZE (pmode)
15975 - GET_MODE_SIZE (dmode));
15982 /* If the parm was passed in registers, but lives on the stack, then
15983 make a big endian correction if the mode of the type of the
15984 parameter is not the same as the mode of the rtl. */
15985 /* ??? This is the same series of checks that are made in dbxout.c before
15986 we reach the big endian correction code there. It isn't clear if all
15987 of these checks are necessary here, but keeping them all is the safe
15989 else if (MEM_P (rtl)
15990 && XEXP (rtl, 0) != const0_rtx
15991 && ! CONSTANT_P (XEXP (rtl, 0))
15992 /* Not passed in memory. */
15993 && !MEM_P (DECL_INCOMING_RTL (decl))
15994 /* Not passed by invisible reference. */
15995 && (!REG_P (XEXP (rtl, 0))
15996 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
15997 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
15998 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15999 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16002 /* Big endian correction check. */
16003 && BYTES_BIG_ENDIAN
16004 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16005 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16008 machine_mode addr_mode = get_address_mode (rtl);
16009 int offset = (UNITS_PER_WORD
16010 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16012 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16013 plus_constant (addr_mode, XEXP (rtl, 0), offset));
16016 else if (TREE_CODE (decl) == VAR_DECL
16019 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16020 && BYTES_BIG_ENDIAN)
16022 machine_mode addr_mode = get_address_mode (rtl);
16023 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16024 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16026 /* If a variable is declared "register" yet is smaller than
16027 a register, then if we store the variable to memory, it
16028 looks like we're storing a register-sized value, when in
16029 fact we are not. We need to adjust the offset of the
16030 storage location to reflect the actual value's bytes,
16031 else gdb will not be able to display it. */
16033 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16034 plus_constant (addr_mode, XEXP (rtl, 0),
16038 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16039 and will have been substituted directly into all expressions that use it.
16040 C does not have such a concept, but C++ and other languages do. */
16041 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16042 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16045 rtl = targetm.delegitimize_address (rtl);
16047 /* If we don't look past the constant pool, we risk emitting a
16048 reference to a constant pool entry that isn't referenced from
16049 code, and thus is not emitted. */
16051 rtl = avoid_constant_pool_reference (rtl);
16053 /* Try harder to get a rtl. If this symbol ends up not being emitted
16054 in the current CU, resolve_addr will remove the expression referencing
16056 if (rtl == NULL_RTX
16057 && TREE_CODE (decl) == VAR_DECL
16058 && !DECL_EXTERNAL (decl)
16059 && TREE_STATIC (decl)
16060 && DECL_NAME (decl)
16061 && !DECL_HARD_REGISTER (decl)
16062 && DECL_MODE (decl) != VOIDmode)
16064 rtl = make_decl_rtl_for_debug (decl);
16066 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16067 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16074 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16075 returned. If so, the decl for the COMMON block is returned, and the
16076 value is the offset into the common block for the symbol. */
16079 fortran_common (tree decl, HOST_WIDE_INT *value)
16081 tree val_expr, cvar;
16083 HOST_WIDE_INT bitsize, bitpos;
16085 int unsignedp, volatilep = 0;
16087 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16088 it does not have a value (the offset into the common area), or if it
16089 is thread local (as opposed to global) then it isn't common, and shouldn't
16090 be handled as such. */
16091 if (TREE_CODE (decl) != VAR_DECL
16092 || !TREE_STATIC (decl)
16093 || !DECL_HAS_VALUE_EXPR_P (decl)
16097 val_expr = DECL_VALUE_EXPR (decl);
16098 if (TREE_CODE (val_expr) != COMPONENT_REF)
16101 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16102 &mode, &unsignedp, &volatilep, true);
16104 if (cvar == NULL_TREE
16105 || TREE_CODE (cvar) != VAR_DECL
16106 || DECL_ARTIFICIAL (cvar)
16107 || !TREE_PUBLIC (cvar))
16111 if (offset != NULL)
16113 if (!tree_fits_shwi_p (offset))
16115 *value = tree_to_shwi (offset);
16118 *value += bitpos / BITS_PER_UNIT;
16123 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16124 data attribute for a variable or a parameter. We generate the
16125 DW_AT_const_value attribute only in those cases where the given variable
16126 or parameter does not have a true "location" either in memory or in a
16127 register. This can happen (for example) when a constant is passed as an
16128 actual argument in a call to an inline function. (It's possible that
16129 these things can crop up in other ways also.) Note that one type of
16130 constant value which can be passed into an inlined function is a constant
16131 pointer. This can happen for example if an actual argument in an inlined
16132 function call evaluates to a compile-time constant address.
16134 CACHE_P is true if it is worth caching the location list for DECL,
16135 so that future calls can reuse it rather than regenerate it from scratch.
16136 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16137 since we will need to refer to them each time the function is inlined. */
16140 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
16141 enum dwarf_attribute attr)
16144 dw_loc_list_ref list;
16145 var_loc_list *loc_list;
16146 cached_dw_loc_list *cache;
16151 if (TREE_CODE (decl) == ERROR_MARK)
16154 if (get_AT (die, attr))
16157 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16158 || TREE_CODE (decl) == RESULT_DECL);
16160 /* Try to get some constant RTL for this decl, and use that as the value of
16163 rtl = rtl_for_decl_location (decl);
16164 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16165 && add_const_value_attribute (die, rtl))
16168 /* See if we have single element location list that is equivalent to
16169 a constant value. That way we are better to use add_const_value_attribute
16170 rather than expanding constant value equivalent. */
16171 loc_list = lookup_decl_loc (decl);
16174 && loc_list->first->next == NULL
16175 && NOTE_P (loc_list->first->loc)
16176 && NOTE_VAR_LOCATION (loc_list->first->loc)
16177 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16179 struct var_loc_node *node;
16181 node = loc_list->first;
16182 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16183 if (GET_CODE (rtl) == EXPR_LIST)
16184 rtl = XEXP (rtl, 0);
16185 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16186 && add_const_value_attribute (die, rtl))
16189 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16190 list several times. See if we've already cached the contents. */
16192 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
16196 cache = cached_dw_loc_list_table->find_with_hash (decl, DECL_UID (decl));
16198 list = cache->loc_list;
16202 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2,
16204 /* It is usually worth caching this result if the decl is from
16205 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
16206 if (cache_p && list && list->dw_loc_next)
16208 cached_dw_loc_list **slot
16209 = cached_dw_loc_list_table->find_slot_with_hash (decl,
16212 cache = ggc_cleared_alloc<cached_dw_loc_list> ();
16213 cache->decl_id = DECL_UID (decl);
16214 cache->loc_list = list;
16220 add_AT_location_description (die, attr, list);
16223 /* None of that worked, so it must not really have a location;
16224 try adding a constant value attribute from the DECL_INITIAL. */
16225 return tree_add_const_value_attribute_for_decl (die, decl);
16228 /* Helper function for tree_add_const_value_attribute. Natively encode
16229 initializer INIT into an array. Return true if successful. */
16232 native_encode_initializer (tree init, unsigned char *array, int size)
16236 if (init == NULL_TREE)
16240 switch (TREE_CODE (init))
16243 type = TREE_TYPE (init);
16244 if (TREE_CODE (type) == ARRAY_TYPE)
16246 tree enttype = TREE_TYPE (type);
16247 machine_mode mode = TYPE_MODE (enttype);
16249 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
16251 if (int_size_in_bytes (type) != size)
16253 if (size > TREE_STRING_LENGTH (init))
16255 memcpy (array, TREE_STRING_POINTER (init),
16256 TREE_STRING_LENGTH (init));
16257 memset (array + TREE_STRING_LENGTH (init),
16258 '\0', size - TREE_STRING_LENGTH (init));
16261 memcpy (array, TREE_STRING_POINTER (init), size);
16266 type = TREE_TYPE (init);
16267 if (int_size_in_bytes (type) != size)
16269 if (TREE_CODE (type) == ARRAY_TYPE)
16271 HOST_WIDE_INT min_index;
16272 unsigned HOST_WIDE_INT cnt;
16273 int curpos = 0, fieldsize;
16274 constructor_elt *ce;
16276 if (TYPE_DOMAIN (type) == NULL_TREE
16277 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type))))
16280 fieldsize = int_size_in_bytes (TREE_TYPE (type));
16281 if (fieldsize <= 0)
16284 min_index = tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type)));
16285 memset (array, '\0', size);
16286 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init), cnt, ce)
16288 tree val = ce->value;
16289 tree index = ce->index;
16291 if (index && TREE_CODE (index) == RANGE_EXPR)
16292 pos = (tree_to_shwi (TREE_OPERAND (index, 0)) - min_index)
16295 pos = (tree_to_shwi (index) - min_index) * fieldsize;
16300 if (!native_encode_initializer (val, array + pos, fieldsize))
16303 curpos = pos + fieldsize;
16304 if (index && TREE_CODE (index) == RANGE_EXPR)
16306 int count = tree_to_shwi (TREE_OPERAND (index, 1))
16307 - tree_to_shwi (TREE_OPERAND (index, 0));
16308 while (count-- > 0)
16311 memcpy (array + curpos, array + pos, fieldsize);
16312 curpos += fieldsize;
16315 gcc_assert (curpos <= size);
16319 else if (TREE_CODE (type) == RECORD_TYPE
16320 || TREE_CODE (type) == UNION_TYPE)
16322 tree field = NULL_TREE;
16323 unsigned HOST_WIDE_INT cnt;
16324 constructor_elt *ce;
16326 if (int_size_in_bytes (type) != size)
16329 if (TREE_CODE (type) == RECORD_TYPE)
16330 field = TYPE_FIELDS (type);
16332 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init), cnt, ce)
16334 tree val = ce->value;
16335 int pos, fieldsize;
16337 if (ce->index != 0)
16343 if (field == NULL_TREE || DECL_BIT_FIELD (field))
16346 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
16347 && TYPE_DOMAIN (TREE_TYPE (field))
16348 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
16350 else if (DECL_SIZE_UNIT (field) == NULL_TREE
16351 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field)))
16353 fieldsize = tree_to_shwi (DECL_SIZE_UNIT (field));
16354 pos = int_byte_position (field);
16355 gcc_assert (pos + fieldsize <= size);
16357 && !native_encode_initializer (val, array + pos, fieldsize))
16363 case VIEW_CONVERT_EXPR:
16364 case NON_LVALUE_EXPR:
16365 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
16367 return native_encode_expr (init, array, size) == size;
16371 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16372 attribute is the const value T. */
16375 tree_add_const_value_attribute (dw_die_ref die, tree t)
16378 tree type = TREE_TYPE (t);
16381 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
16385 gcc_assert (!DECL_P (init));
16387 rtl = rtl_for_decl_init (init, type);
16389 return add_const_value_attribute (die, rtl);
16390 /* If the host and target are sane, try harder. */
16391 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
16392 && initializer_constant_valid_p (init, type))
16394 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
16395 if (size > 0 && (int) size == size)
16397 unsigned char *array = ggc_cleared_vec_alloc<unsigned char> (size);
16399 if (native_encode_initializer (init, array, size))
16401 add_AT_vec (die, DW_AT_const_value, size, 1, array);
16410 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16411 attribute is the const value of T, where T is an integral constant
16412 variable with static storage duration
16413 (so it can't be a PARM_DECL or a RESULT_DECL). */
16416 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
16420 || (TREE_CODE (decl) != VAR_DECL
16421 && TREE_CODE (decl) != CONST_DECL)
16422 || (TREE_CODE (decl) == VAR_DECL
16423 && !TREE_STATIC (decl)))
16426 if (TREE_READONLY (decl)
16427 && ! TREE_THIS_VOLATILE (decl)
16428 && DECL_INITIAL (decl))
16433 /* Don't add DW_AT_const_value if abstract origin already has one. */
16434 if (get_AT (var_die, DW_AT_const_value))
16437 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
16440 /* Convert the CFI instructions for the current function into a
16441 location list. This is used for DW_AT_frame_base when we targeting
16442 a dwarf2 consumer that does not support the dwarf3
16443 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16446 static dw_loc_list_ref
16447 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
16451 dw_loc_list_ref list, *list_tail;
16453 dw_cfa_location last_cfa, next_cfa;
16454 const char *start_label, *last_label, *section;
16455 dw_cfa_location remember;
16458 gcc_assert (fde != NULL);
16460 section = secname_for_decl (current_function_decl);
16464 memset (&next_cfa, 0, sizeof (next_cfa));
16465 next_cfa.reg = INVALID_REGNUM;
16466 remember = next_cfa;
16468 start_label = fde->dw_fde_begin;
16470 /* ??? Bald assumption that the CIE opcode list does not contain
16471 advance opcodes. */
16472 FOR_EACH_VEC_ELT (*cie_cfi_vec, ix, cfi)
16473 lookup_cfa_1 (cfi, &next_cfa, &remember);
16475 last_cfa = next_cfa;
16476 last_label = start_label;
16478 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
16480 /* If the first partition contained no CFI adjustments, the
16481 CIE opcodes apply to the whole first partition. */
16482 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16483 fde->dw_fde_begin, fde->dw_fde_end, section);
16484 list_tail =&(*list_tail)->dw_loc_next;
16485 start_label = last_label = fde->dw_fde_second_begin;
16488 FOR_EACH_VEC_SAFE_ELT (fde->dw_fde_cfi, ix, cfi)
16490 switch (cfi->dw_cfi_opc)
16492 case DW_CFA_set_loc:
16493 case DW_CFA_advance_loc1:
16494 case DW_CFA_advance_loc2:
16495 case DW_CFA_advance_loc4:
16496 if (!cfa_equal_p (&last_cfa, &next_cfa))
16498 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16499 start_label, last_label, section);
16501 list_tail = &(*list_tail)->dw_loc_next;
16502 last_cfa = next_cfa;
16503 start_label = last_label;
16505 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
16508 case DW_CFA_advance_loc:
16509 /* The encoding is complex enough that we should never emit this. */
16510 gcc_unreachable ();
16513 lookup_cfa_1 (cfi, &next_cfa, &remember);
16516 if (ix + 1 == fde->dw_fde_switch_cfi_index)
16518 if (!cfa_equal_p (&last_cfa, &next_cfa))
16520 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16521 start_label, last_label, section);
16523 list_tail = &(*list_tail)->dw_loc_next;
16524 last_cfa = next_cfa;
16525 start_label = last_label;
16527 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16528 start_label, fde->dw_fde_end, section);
16529 list_tail = &(*list_tail)->dw_loc_next;
16530 start_label = last_label = fde->dw_fde_second_begin;
16534 if (!cfa_equal_p (&last_cfa, &next_cfa))
16536 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16537 start_label, last_label, section);
16538 list_tail = &(*list_tail)->dw_loc_next;
16539 start_label = last_label;
16542 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
16544 fde->dw_fde_second_begin
16545 ? fde->dw_fde_second_end : fde->dw_fde_end,
16548 if (list && list->dw_loc_next)
16554 /* Compute a displacement from the "steady-state frame pointer" to the
16555 frame base (often the same as the CFA), and store it in
16556 frame_pointer_fb_offset. OFFSET is added to the displacement
16557 before the latter is negated. */
16560 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
16564 #ifdef FRAME_POINTER_CFA_OFFSET
16565 reg = frame_pointer_rtx;
16566 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
16568 reg = arg_pointer_rtx;
16569 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
16572 elim = (ira_use_lra_p
16573 ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
16574 : eliminate_regs (reg, VOIDmode, NULL_RTX));
16575 if (GET_CODE (elim) == PLUS)
16577 offset += INTVAL (XEXP (elim, 1));
16578 elim = XEXP (elim, 0);
16581 frame_pointer_fb_offset = -offset;
16583 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16584 in which to eliminate. This is because it's stack pointer isn't
16585 directly accessible as a register within the ISA. To work around
16586 this, assume that while we cannot provide a proper value for
16587 frame_pointer_fb_offset, we won't need one either. */
16588 frame_pointer_fb_offset_valid
16589 = ((SUPPORTS_STACK_ALIGNMENT
16590 && (elim == hard_frame_pointer_rtx
16591 || elim == stack_pointer_rtx))
16592 || elim == (frame_pointer_needed
16593 ? hard_frame_pointer_rtx
16594 : stack_pointer_rtx));
16597 /* Generate a DW_AT_name attribute given some string value to be included as
16598 the value of the attribute. */
16601 add_name_attribute (dw_die_ref die, const char *name_string)
16603 if (name_string != NULL && *name_string != 0)
16605 if (demangle_name_func)
16606 name_string = (*demangle_name_func) (name_string);
16608 add_AT_string (die, DW_AT_name, name_string);
16612 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16613 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16614 of TYPE accordingly.
16616 ??? This is a temporary measure until after we're able to generate
16617 regular DWARF for the complex Ada type system. */
16620 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
16621 dw_die_ref context_die)
16624 dw_die_ref dtype_die;
16626 if (!lang_hooks.types.descriptive_type)
16629 dtype = lang_hooks.types.descriptive_type (type);
16633 dtype_die = lookup_type_die (dtype);
16636 gen_type_die (dtype, context_die);
16637 dtype_die = lookup_type_die (dtype);
16638 gcc_assert (dtype_die);
16641 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
16644 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16646 static const char *
16647 comp_dir_string (void)
16651 static const char *cached_wd = NULL;
16653 if (cached_wd != NULL)
16656 wd = get_src_pwd ();
16660 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
16664 wdlen = strlen (wd);
16665 wd1 = ggc_vec_alloc<char> (wdlen + 2);
16667 wd1 [wdlen] = DIR_SEPARATOR;
16668 wd1 [wdlen + 1] = 0;
16672 cached_wd = remap_debug_filename (wd);
16676 /* Generate a DW_AT_comp_dir attribute for DIE. */
16679 add_comp_dir_attribute (dw_die_ref die)
16681 const char * wd = comp_dir_string ();
16683 add_AT_string (die, DW_AT_comp_dir, wd);
16686 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
16687 pointer computation, ...), output a representation for that bound according
16688 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
16689 loc_list_from_tree for the meaning of CONTEXT. */
16692 add_scalar_info (dw_die_ref die, enum dwarf_attribute attr, tree value,
16693 int forms, const struct loc_descr_context *context)
16695 dw_die_ref ctx, decl_die;
16696 dw_loc_list_ref list;
16698 bool strip_conversions = true;
16700 while (strip_conversions)
16701 switch (TREE_CODE (value))
16708 case VIEW_CONVERT_EXPR:
16709 value = TREE_OPERAND (value, 0);
16713 strip_conversions = false;
16717 /* If possible and permitted, output the attribute as a constant. */
16718 if ((forms & dw_scalar_form_constant) != 0
16719 && TREE_CODE (value) == INTEGER_CST)
16721 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (value));
16723 /* If HOST_WIDE_INT is big enough then represent the bound as
16724 a constant value. We need to choose a form based on
16725 whether the type is signed or unsigned. We cannot just
16726 call add_AT_unsigned if the value itself is positive
16727 (add_AT_unsigned might add the unsigned value encoded as
16728 DW_FORM_data[1248]). Some DWARF consumers will lookup the
16729 bounds type and then sign extend any unsigned values found
16730 for signed types. This is needed only for
16731 DW_AT_{lower,upper}_bound, since for most other attributes,
16732 consumers will treat DW_FORM_data[1248] as unsigned values,
16733 regardless of the underlying type. */
16734 if (prec <= HOST_BITS_PER_WIDE_INT
16735 || tree_fits_uhwi_p (value))
16737 if (TYPE_UNSIGNED (TREE_TYPE (value)))
16738 add_AT_unsigned (die, attr, TREE_INT_CST_LOW (value));
16740 add_AT_int (die, attr, TREE_INT_CST_LOW (value));
16743 /* Otherwise represent the bound as an unsigned value with
16744 the precision of its type. The precision and signedness
16745 of the type will be necessary to re-interpret it
16747 add_AT_wide (die, attr, value);
16751 /* Otherwise, if it's possible and permitted too, output a reference to
16753 if ((forms & dw_scalar_form_reference) != 0)
16755 tree decl = NULL_TREE;
16757 /* Some type attributes reference an outer type. For instance, the upper
16758 bound of an array may reference an embedding record (this happens in
16760 if (TREE_CODE (value) == COMPONENT_REF
16761 && TREE_CODE (TREE_OPERAND (value, 0)) == PLACEHOLDER_EXPR
16762 && TREE_CODE (TREE_OPERAND (value, 1)) == FIELD_DECL)
16763 decl = TREE_OPERAND (value, 1);
16765 else if (TREE_CODE (value) == VAR_DECL
16766 || TREE_CODE (value) == PARM_DECL
16767 || TREE_CODE (value) == RESULT_DECL)
16770 if (decl != NULL_TREE)
16772 dw_die_ref decl_die = lookup_decl_die (decl);
16774 /* ??? Can this happen, or should the variable have been bound
16775 first? Probably it can, since I imagine that we try to create
16776 the types of parameters in the order in which they exist in
16777 the list, and won't have created a forward reference to a
16778 later parameter. */
16779 if (decl_die != NULL)
16781 add_AT_die_ref (die, attr, decl_die);
16787 /* Last chance: try to create a stack operation procedure to evaluate the
16788 value. Do nothing if even that is not possible or permitted. */
16789 if ((forms & dw_scalar_form_exprloc) == 0)
16792 list = loc_list_from_tree (value, 2, context);
16793 if (list == NULL || single_element_loc_list_p (list))
16795 /* If this attribute is not a reference nor constant, it is
16796 a DWARF expression rather than location description. For that
16797 loc_list_from_tree (value, 0, &context) is needed. */
16798 dw_loc_list_ref list2 = loc_list_from_tree (value, 0, context);
16799 if (list2 && single_element_loc_list_p (list2))
16801 add_AT_loc (die, attr, list2->expr);
16806 /* If that failed to give a single element location list, fall back to
16807 outputting this as a reference... still if permitted. */
16808 if (list == NULL || (forms & dw_scalar_form_reference) == 0)
16811 if (current_function_decl == 0)
16812 ctx = comp_unit_die ();
16814 ctx = lookup_decl_die (current_function_decl);
16816 decl_die = new_die (DW_TAG_variable, ctx, value);
16817 add_AT_flag (decl_die, DW_AT_artificial, 1);
16818 add_type_attribute (decl_die, TREE_TYPE (value), TYPE_QUAL_CONST, ctx);
16819 add_AT_location_description (decl_die, DW_AT_location, list);
16820 add_AT_die_ref (die, attr, decl_die);
16823 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16827 lower_bound_default (void)
16829 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
16835 case DW_LANG_C_plus_plus:
16836 case DW_LANG_C_plus_plus_11:
16837 case DW_LANG_C_plus_plus_14:
16839 case DW_LANG_ObjC_plus_plus:
16842 case DW_LANG_Fortran77:
16843 case DW_LANG_Fortran90:
16844 case DW_LANG_Fortran95:
16845 case DW_LANG_Fortran03:
16846 case DW_LANG_Fortran08:
16850 case DW_LANG_Python:
16851 return dwarf_version >= 4 ? 0 : -1;
16852 case DW_LANG_Ada95:
16853 case DW_LANG_Ada83:
16854 case DW_LANG_Cobol74:
16855 case DW_LANG_Cobol85:
16856 case DW_LANG_Pascal83:
16857 case DW_LANG_Modula2:
16859 return dwarf_version >= 4 ? 1 : -1;
16865 /* Given a tree node describing an array bound (either lower or upper) output
16866 a representation for that bound. */
16869 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr,
16870 tree bound, const struct loc_descr_context *context)
16875 switch (TREE_CODE (bound))
16877 /* Strip all conversions. */
16879 case VIEW_CONVERT_EXPR:
16880 bound = TREE_OPERAND (bound, 0);
16883 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
16884 are even omitted when they are the default. */
16886 /* If the value for this bound is the default one, we can even omit the
16888 if (bound_attr == DW_AT_lower_bound
16889 && tree_fits_shwi_p (bound)
16890 && (dflt = lower_bound_default ()) != -1
16891 && tree_to_shwi (bound) == dflt)
16897 add_scalar_info (subrange_die, bound_attr, bound,
16898 dw_scalar_form_constant
16899 | dw_scalar_form_exprloc
16900 | dw_scalar_form_reference,
16906 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16907 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16908 Note that the block of subscript information for an array type also
16909 includes information about the element type of the given array type.
16911 This function reuses previously set type and bound information if
16915 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
16917 unsigned dimension_number;
16919 dw_die_ref child = type_die->die_child;
16921 for (dimension_number = 0;
16922 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
16923 type = TREE_TYPE (type), dimension_number++)
16925 tree domain = TYPE_DOMAIN (type);
16927 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
16930 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16931 and (in GNU C only) variable bounds. Handle all three forms
16934 /* Find and reuse a previously generated DW_TAG_subrange_type if
16937 For multi-dimensional arrays, as we iterate through the
16938 various dimensions in the enclosing for loop above, we also
16939 iterate through the DIE children and pick at each
16940 DW_TAG_subrange_type previously generated (if available).
16941 Each child DW_TAG_subrange_type DIE describes the range of
16942 the current dimension. At this point we should have as many
16943 DW_TAG_subrange_type's as we have dimensions in the
16945 dw_die_ref subrange_die = NULL;
16949 child = child->die_sib;
16950 if (child->die_tag == DW_TAG_subrange_type)
16951 subrange_die = child;
16952 if (child == type_die->die_child)
16954 /* If we wrapped around, stop looking next time. */
16958 if (child->die_tag == DW_TAG_subrange_type)
16962 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
16966 /* We have an array type with specified bounds. */
16967 lower = TYPE_MIN_VALUE (domain);
16968 upper = TYPE_MAX_VALUE (domain);
16970 /* Define the index type. */
16971 if (TREE_TYPE (domain)
16972 && !get_AT (subrange_die, DW_AT_type))
16974 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16975 TREE_TYPE field. We can't emit debug info for this
16976 because it is an unnamed integral type. */
16977 if (TREE_CODE (domain) == INTEGER_TYPE
16978 && TYPE_NAME (domain) == NULL_TREE
16979 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
16980 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
16983 add_type_attribute (subrange_die, TREE_TYPE (domain),
16984 TYPE_UNQUALIFIED, type_die);
16987 /* ??? If upper is NULL, the array has unspecified length,
16988 but it does have a lower bound. This happens with Fortran
16990 Since the debugger is definitely going to need to know N
16991 to produce useful results, go ahead and output the lower
16992 bound solo, and hope the debugger can cope. */
16994 if (!get_AT (subrange_die, DW_AT_lower_bound))
16995 add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL);
16996 if (upper && !get_AT (subrange_die, DW_AT_upper_bound))
16997 add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
17000 /* Otherwise we have an array type with an unspecified length. The
17001 DWARF-2 spec does not say how to handle this; let's just leave out the
17006 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
17009 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17011 dw_die_ref decl_die;
17012 HOST_WIDE_INT size;
17014 switch (TREE_CODE (tree_node))
17019 case ENUMERAL_TYPE:
17022 case QUAL_UNION_TYPE:
17023 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node)) == VAR_DECL
17024 && (decl_die = lookup_decl_die (TYPE_SIZE_UNIT (tree_node))))
17026 add_AT_die_ref (die, DW_AT_byte_size, decl_die);
17029 size = int_size_in_bytes (tree_node);
17032 /* For a data member of a struct or union, the DW_AT_byte_size is
17033 generally given as the number of bytes normally allocated for an
17034 object of the *declared* type of the member itself. This is true
17035 even for bit-fields. */
17036 size = int_size_in_bytes (field_type (tree_node));
17039 gcc_unreachable ();
17042 /* Note that `size' might be -1 when we get to this point. If it is, that
17043 indicates that the byte size of the entity in question is variable. We
17044 have no good way of expressing this fact in Dwarf at the present time,
17045 when location description was not used by the caller code instead. */
17047 add_AT_unsigned (die, DW_AT_byte_size, size);
17050 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17051 which specifies the distance in bits from the highest order bit of the
17052 "containing object" for the bit-field to the highest order bit of the
17055 For any given bit-field, the "containing object" is a hypothetical object
17056 (of some integral or enum type) within which the given bit-field lives. The
17057 type of this hypothetical "containing object" is always the same as the
17058 declared type of the individual bit-field itself. The determination of the
17059 exact location of the "containing object" for a bit-field is rather
17060 complicated. It's handled by the `field_byte_offset' function (above).
17062 Note that it is the size (in bytes) of the hypothetical "containing object"
17063 which will be given in the DW_AT_byte_size attribute for this bit-field.
17064 (See `byte_size_attribute' above). */
17067 add_bit_offset_attribute (dw_die_ref die, tree decl)
17069 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17070 tree type = DECL_BIT_FIELD_TYPE (decl);
17071 HOST_WIDE_INT bitpos_int;
17072 HOST_WIDE_INT highest_order_object_bit_offset;
17073 HOST_WIDE_INT highest_order_field_bit_offset;
17074 HOST_WIDE_INT bit_offset;
17076 /* Must be a field and a bit field. */
17077 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17079 /* We can't yet handle bit-fields whose offsets are variable, so if we
17080 encounter such things, just return without generating any attribute
17081 whatsoever. Likewise for variable or too large size. */
17082 if (! tree_fits_shwi_p (bit_position (decl))
17083 || ! tree_fits_uhwi_p (DECL_SIZE (decl)))
17086 bitpos_int = int_bit_position (decl);
17088 /* Note that the bit offset is always the distance (in bits) from the
17089 highest-order bit of the "containing object" to the highest-order bit of
17090 the bit-field itself. Since the "high-order end" of any object or field
17091 is different on big-endian and little-endian machines, the computation
17092 below must take account of these differences. */
17093 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17094 highest_order_field_bit_offset = bitpos_int;
17096 if (! BYTES_BIG_ENDIAN)
17098 highest_order_field_bit_offset += tree_to_shwi (DECL_SIZE (decl));
17099 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17103 = (! BYTES_BIG_ENDIAN
17104 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17105 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17107 if (bit_offset < 0)
17108 add_AT_int (die, DW_AT_bit_offset, bit_offset);
17110 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
17113 /* For a FIELD_DECL node which represents a bit field, output an attribute
17114 which specifies the length in bits of the given field. */
17117 add_bit_size_attribute (dw_die_ref die, tree decl)
17119 /* Must be a field and a bit field. */
17120 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17121 && DECL_BIT_FIELD_TYPE (decl));
17123 if (tree_fits_uhwi_p (DECL_SIZE (decl)))
17124 add_AT_unsigned (die, DW_AT_bit_size, tree_to_uhwi (DECL_SIZE (decl)));
17127 /* If the compiled language is ANSI C, then add a 'prototyped'
17128 attribute, if arg types are given for the parameters of a function. */
17131 add_prototyped_attribute (dw_die_ref die, tree func_type)
17133 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17140 if (prototype_p (func_type))
17141 add_AT_flag (die, DW_AT_prototyped, 1);
17148 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17149 by looking in either the type declaration or object declaration
17152 static inline dw_die_ref
17153 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17155 dw_die_ref origin_die = NULL;
17157 if (TREE_CODE (origin) != FUNCTION_DECL)
17159 /* We may have gotten separated from the block for the inlined
17160 function, if we're in an exception handler or some such; make
17161 sure that the abstract function has been written out.
17163 Doing this for nested functions is wrong, however; functions are
17164 distinct units, and our context might not even be inline. */
17168 fn = TYPE_STUB_DECL (fn);
17170 fn = decl_function_context (fn);
17172 dwarf2out_abstract_function (fn);
17175 if (DECL_P (origin))
17176 origin_die = lookup_decl_die (origin);
17177 else if (TYPE_P (origin))
17178 origin_die = lookup_type_die (origin);
17180 /* XXX: Functions that are never lowered don't always have correct block
17181 trees (in the case of java, they simply have no block tree, in some other
17182 languages). For these functions, there is nothing we can really do to
17183 output correct debug info for inlined functions in all cases. Rather
17184 than die, we'll just produce deficient debug info now, in that we will
17185 have variables without a proper abstract origin. In the future, when all
17186 functions are lowered, we should re-add a gcc_assert (origin_die)
17190 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17194 /* We do not currently support the pure_virtual attribute. */
17197 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17199 if (DECL_VINDEX (func_decl))
17201 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17203 if (tree_fits_shwi_p (DECL_VINDEX (func_decl)))
17204 add_AT_loc (die, DW_AT_vtable_elem_location,
17205 new_loc_descr (DW_OP_constu,
17206 tree_to_shwi (DECL_VINDEX (func_decl)),
17209 /* GNU extension: Record what type this method came from originally. */
17210 if (debug_info_level > DINFO_LEVEL_TERSE
17211 && DECL_CONTEXT (func_decl))
17212 add_AT_die_ref (die, DW_AT_containing_type,
17213 lookup_type_die (DECL_CONTEXT (func_decl)));
17217 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17218 given decl. This used to be a vendor extension until after DWARF 4
17219 standardized it. */
17222 add_linkage_attr (dw_die_ref die, tree decl)
17224 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17226 /* Mimic what assemble_name_raw does with a leading '*'. */
17227 if (name[0] == '*')
17230 if (dwarf_version >= 4)
17231 add_AT_string (die, DW_AT_linkage_name, name);
17233 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17236 /* Add source coordinate attributes for the given decl. */
17239 add_src_coords_attributes (dw_die_ref die, tree decl)
17241 expanded_location s;
17243 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl)) == UNKNOWN_LOCATION)
17245 s = expand_location (DECL_SOURCE_LOCATION (decl));
17246 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17247 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17250 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17253 add_linkage_name (dw_die_ref die, tree decl)
17255 if (debug_info_level > DINFO_LEVEL_NONE
17256 && (TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17257 && TREE_PUBLIC (decl)
17258 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17259 && die->die_tag != DW_TAG_member)
17261 /* Defer until we have an assembler name set. */
17262 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17264 limbo_die_node *asm_name;
17266 asm_name = ggc_cleared_alloc<limbo_die_node> ();
17267 asm_name->die = die;
17268 asm_name->created_for = decl;
17269 asm_name->next = deferred_asm_name;
17270 deferred_asm_name = asm_name;
17272 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17273 add_linkage_attr (die, decl);
17277 /* Add a DW_AT_name attribute and source coordinate attribute for the
17278 given decl, but only if it actually has a name. */
17281 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17285 decl_name = DECL_NAME (decl);
17286 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17288 const char *name = dwarf2_name (decl, 0);
17290 add_name_attribute (die, name);
17291 if (! DECL_ARTIFICIAL (decl))
17292 add_src_coords_attributes (die, decl);
17294 add_linkage_name (die, decl);
17297 #ifdef VMS_DEBUGGING_INFO
17298 /* Get the function's name, as described by its RTL. This may be different
17299 from the DECL_NAME name used in the source file. */
17300 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17302 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17303 XEXP (DECL_RTL (decl), 0), false);
17304 vec_safe_push (used_rtx_array, XEXP (DECL_RTL (decl), 0));
17306 #endif /* VMS_DEBUGGING_INFO */
17309 #ifdef VMS_DEBUGGING_INFO
17310 /* Output the debug main pointer die for VMS */
17313 dwarf2out_vms_debug_main_pointer (void)
17315 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17318 /* Allocate the VMS debug main subprogram die. */
17319 die = ggc_cleared_alloc<die_node> ();
17320 die->die_tag = DW_TAG_subprogram;
17321 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17322 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17323 current_function_funcdef_no);
17324 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17326 /* Make it the first child of comp_unit_die (). */
17327 die->die_parent = comp_unit_die ();
17328 if (comp_unit_die ()->die_child)
17330 die->die_sib = comp_unit_die ()->die_child->die_sib;
17331 comp_unit_die ()->die_child->die_sib = die;
17335 die->die_sib = die;
17336 comp_unit_die ()->die_child = die;
17339 #endif /* VMS_DEBUGGING_INFO */
17341 /* Push a new declaration scope. */
17344 push_decl_scope (tree scope)
17346 vec_safe_push (decl_scope_table, scope);
17349 /* Pop a declaration scope. */
17352 pop_decl_scope (void)
17354 decl_scope_table->pop ();
17357 /* walk_tree helper function for uses_local_type, below. */
17360 uses_local_type_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
17363 *walk_subtrees = 0;
17366 tree name = TYPE_NAME (*tp);
17367 if (name && DECL_P (name) && decl_function_context (name))
17373 /* If TYPE involves a function-local type (including a local typedef to a
17374 non-local type), returns that type; otherwise returns NULL_TREE. */
17377 uses_local_type (tree type)
17379 tree used = walk_tree_without_duplicates (&type, uses_local_type_r, NULL);
17383 /* Return the DIE for the scope that immediately contains this type.
17384 Non-named types that do not involve a function-local type get global
17385 scope. Named types nested in namespaces or other types get their
17386 containing scope. All other types (i.e. function-local named types) get
17387 the current active scope. */
17390 scope_die_for (tree t, dw_die_ref context_die)
17392 dw_die_ref scope_die = NULL;
17393 tree containing_scope;
17395 /* Non-types always go in the current scope. */
17396 gcc_assert (TYPE_P (t));
17398 /* Use the scope of the typedef, rather than the scope of the type
17400 if (TYPE_NAME (t) && DECL_P (TYPE_NAME (t)))
17401 containing_scope = DECL_CONTEXT (TYPE_NAME (t));
17403 containing_scope = TYPE_CONTEXT (t);
17405 /* Use the containing namespace if there is one. */
17406 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17408 if (context_die == lookup_decl_die (containing_scope))
17410 else if (debug_info_level > DINFO_LEVEL_TERSE)
17411 context_die = get_context_die (containing_scope);
17413 containing_scope = NULL_TREE;
17416 /* Ignore function type "scopes" from the C frontend. They mean that
17417 a tagged type is local to a parmlist of a function declarator, but
17418 that isn't useful to DWARF. */
17419 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
17420 containing_scope = NULL_TREE;
17422 if (SCOPE_FILE_SCOPE_P (containing_scope))
17424 /* If T uses a local type keep it local as well, to avoid references
17425 to function-local DIEs from outside the function. */
17426 if (current_function_decl && uses_local_type (t))
17427 scope_die = context_die;
17429 scope_die = comp_unit_die ();
17431 else if (TYPE_P (containing_scope))
17433 /* For types, we can just look up the appropriate DIE. */
17434 if (debug_info_level > DINFO_LEVEL_TERSE)
17435 scope_die = get_context_die (containing_scope);
17438 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
17439 if (scope_die == NULL)
17440 scope_die = comp_unit_die ();
17444 scope_die = context_die;
17449 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17452 local_scope_p (dw_die_ref context_die)
17454 for (; context_die; context_die = context_die->die_parent)
17455 if (context_die->die_tag == DW_TAG_inlined_subroutine
17456 || context_die->die_tag == DW_TAG_subprogram)
17462 /* Returns nonzero if CONTEXT_DIE is a class. */
17465 class_scope_p (dw_die_ref context_die)
17467 return (context_die
17468 && (context_die->die_tag == DW_TAG_structure_type
17469 || context_die->die_tag == DW_TAG_class_type
17470 || context_die->die_tag == DW_TAG_interface_type
17471 || context_die->die_tag == DW_TAG_union_type));
17474 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17475 whether or not to treat a DIE in this context as a declaration. */
17478 class_or_namespace_scope_p (dw_die_ref context_die)
17480 return (class_scope_p (context_die)
17481 || (context_die && context_die->die_tag == DW_TAG_namespace));
17484 /* Many forms of DIEs require a "type description" attribute. This
17485 routine locates the proper "type descriptor" die for the type given
17486 by 'type' plus any additional qualifiers given by 'cv_quals', and
17487 adds a DW_AT_type attribute below the given die. */
17490 add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
17491 dw_die_ref context_die)
17493 enum tree_code code = TREE_CODE (type);
17494 dw_die_ref type_die = NULL;
17496 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17497 or fixed-point type, use the inner type. This is because we have no
17498 support for unnamed types in base_type_die. This can happen if this is
17499 an Ada subrange type. Correct solution is emit a subrange type die. */
17500 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
17501 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
17502 type = TREE_TYPE (type), code = TREE_CODE (type);
17504 if (code == ERROR_MARK
17505 /* Handle a special case. For functions whose return type is void, we
17506 generate *no* type attribute. (Note that no object may have type
17507 `void', so this only applies to function return types). */
17508 || code == VOID_TYPE)
17511 type_die = modified_type_die (type,
17512 cv_quals | TYPE_QUALS_NO_ADDR_SPACE (type),
17515 if (type_die != NULL)
17516 add_AT_die_ref (object_die, DW_AT_type, type_die);
17519 /* Given an object die, add the calling convention attribute for the
17520 function call type. */
17522 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
17524 enum dwarf_calling_convention value = DW_CC_normal;
17526 value = ((enum dwarf_calling_convention)
17527 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
17530 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
17532 /* DWARF 2 doesn't provide a way to identify a program's source-level
17533 entry point. DW_AT_calling_convention attributes are only meant
17534 to describe functions' calling conventions. However, lacking a
17535 better way to signal the Fortran main program, we used this for
17536 a long time, following existing custom. Now, DWARF 4 has
17537 DW_AT_main_subprogram, which we add below, but some tools still
17538 rely on the old way, which we thus keep. */
17539 value = DW_CC_program;
17541 if (dwarf_version >= 4 || !dwarf_strict)
17542 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
17545 /* Only add the attribute if the backend requests it, and
17546 is not DW_CC_normal. */
17547 if (value && (value != DW_CC_normal))
17548 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
17551 /* Given a tree pointer to a struct, class, union, or enum type node, return
17552 a pointer to the (string) tag name for the given type, or zero if the type
17553 was declared without a tag. */
17555 static const char *
17556 type_tag (const_tree type)
17558 const char *name = 0;
17560 if (TYPE_NAME (type) != 0)
17564 /* Find the IDENTIFIER_NODE for the type name. */
17565 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
17566 && !TYPE_NAMELESS (type))
17567 t = TYPE_NAME (type);
17569 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17570 a TYPE_DECL node, regardless of whether or not a `typedef' was
17572 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
17573 && ! DECL_IGNORED_P (TYPE_NAME (type)))
17575 /* We want to be extra verbose. Don't call dwarf_name if
17576 DECL_NAME isn't set. The default hook for decl_printable_name
17577 doesn't like that, and in this context it's correct to return
17578 0, instead of "<anonymous>" or the like. */
17579 if (DECL_NAME (TYPE_NAME (type))
17580 && !DECL_NAMELESS (TYPE_NAME (type)))
17581 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
17584 /* Now get the name as a string, or invent one. */
17585 if (!name && t != 0)
17586 name = IDENTIFIER_POINTER (t);
17589 return (name == 0 || *name == '\0') ? 0 : name;
17592 /* Return the type associated with a data member, make a special check
17593 for bit field types. */
17596 member_declared_type (const_tree member)
17598 return (DECL_BIT_FIELD_TYPE (member)
17599 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
17602 /* Get the decl's label, as described by its RTL. This may be different
17603 from the DECL_NAME name used in the source file. */
17606 static const char *
17607 decl_start_label (tree decl)
17610 const char *fnname;
17612 x = DECL_RTL (decl);
17613 gcc_assert (MEM_P (x));
17616 gcc_assert (GET_CODE (x) == SYMBOL_REF);
17618 fnname = XSTR (x, 0);
17623 /* For variable-length arrays that have been previously generated, but
17624 may be incomplete due to missing subscript info, fill the subscript
17625 info. Return TRUE if this is one of those cases. */
17627 fill_variable_array_bounds (tree type)
17629 if (TREE_ASM_WRITTEN (type)
17630 && TREE_CODE (type) == ARRAY_TYPE
17631 && variably_modified_type_p (type, NULL))
17633 dw_die_ref array_die = lookup_type_die (type);
17636 add_subscript_info (array_die, type, !is_ada ());
17642 /* These routines generate the internal representation of the DIE's for
17643 the compilation unit. Debugging information is collected by walking
17644 the declaration trees passed in from dwarf2out_decl(). */
17647 gen_array_type_die (tree type, dw_die_ref context_die)
17649 dw_die_ref array_die;
17651 /* GNU compilers represent multidimensional array types as sequences of one
17652 dimensional array types whose element types are themselves array types.
17653 We sometimes squish that down to a single array_type DIE with multiple
17654 subscripts in the Dwarf debugging info. The draft Dwarf specification
17655 say that we are allowed to do this kind of compression in C, because
17656 there is no difference between an array of arrays and a multidimensional
17657 array. We don't do this for Ada to remain as close as possible to the
17658 actual representation, which is especially important against the language
17659 flexibilty wrt arrays of variable size. */
17661 bool collapse_nested_arrays = !is_ada ();
17663 if (fill_variable_array_bounds (type))
17666 dw_die_ref scope_die = scope_die_for (type, context_die);
17669 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17670 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17671 if (TYPE_STRING_FLAG (type)
17672 && TREE_CODE (type) == ARRAY_TYPE
17674 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
17676 HOST_WIDE_INT size;
17678 array_die = new_die (DW_TAG_string_type, scope_die, type);
17679 add_name_attribute (array_die, type_tag (type));
17680 equate_type_number_to_die (type, array_die);
17681 size = int_size_in_bytes (type);
17683 add_AT_unsigned (array_die, DW_AT_byte_size, size);
17684 else if (TYPE_DOMAIN (type) != NULL_TREE
17685 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
17686 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
17688 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
17689 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2, NULL);
17691 size = int_size_in_bytes (TREE_TYPE (szdecl));
17692 if (loc && size > 0)
17694 add_AT_location_description (array_die, DW_AT_string_length, loc);
17695 if (size != DWARF2_ADDR_SIZE)
17696 add_AT_unsigned (array_die, DW_AT_byte_size, size);
17702 array_die = new_die (DW_TAG_array_type, scope_die, type);
17703 add_name_attribute (array_die, type_tag (type));
17704 equate_type_number_to_die (type, array_die);
17706 if (TREE_CODE (type) == VECTOR_TYPE)
17707 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
17709 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17711 && TREE_CODE (type) == ARRAY_TYPE
17712 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
17713 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
17714 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
17717 /* We default the array ordering. SDB will probably do
17718 the right things even if DW_AT_ordering is not present. It's not even
17719 an issue until we start to get into multidimensional arrays anyway. If
17720 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17721 then we'll have to put the DW_AT_ordering attribute back in. (But if
17722 and when we find out that we need to put these in, we will only do so
17723 for multidimensional arrays. */
17724 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
17727 if (TREE_CODE (type) == VECTOR_TYPE)
17729 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17730 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
17731 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node, NULL);
17732 add_bound_info (subrange_die, DW_AT_upper_bound,
17733 size_int (TYPE_VECTOR_SUBPARTS (type) - 1), NULL);
17736 add_subscript_info (array_die, type, collapse_nested_arrays);
17738 /* Add representation of the type of the elements of this array type and
17739 emit the corresponding DIE if we haven't done it already. */
17740 element_type = TREE_TYPE (type);
17741 if (collapse_nested_arrays)
17742 while (TREE_CODE (element_type) == ARRAY_TYPE)
17744 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
17746 element_type = TREE_TYPE (element_type);
17749 add_type_attribute (array_die, element_type, TYPE_UNQUALIFIED, context_die);
17751 add_gnat_descriptive_type_attribute (array_die, type, context_die);
17752 if (TYPE_ARTIFICIAL (type))
17753 add_AT_flag (array_die, DW_AT_artificial, 1);
17755 if (get_AT (array_die, DW_AT_name))
17756 add_pubtype (type, array_die);
17759 /* This routine generates DIE for array with hidden descriptor, details
17760 are filled into *info by a langhook. */
17763 gen_descr_array_type_die (tree type, struct array_descr_info *info,
17764 dw_die_ref context_die)
17766 const dw_die_ref scope_die = scope_die_for (type, context_die);
17767 const dw_die_ref array_die = new_die (DW_TAG_array_type, scope_die, type);
17768 const struct loc_descr_context context = { type, info->base_decl };
17771 add_name_attribute (array_die, type_tag (type));
17772 equate_type_number_to_die (type, array_die);
17774 if (info->ndimensions > 1)
17775 switch (info->ordering)
17777 case array_descr_ordering_row_major:
17778 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
17780 case array_descr_ordering_column_major:
17781 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
17787 if (dwarf_version >= 3 || !dwarf_strict)
17789 if (info->data_location)
17790 add_scalar_info (array_die, DW_AT_data_location, info->data_location,
17791 dw_scalar_form_exprloc, &context);
17792 if (info->associated)
17793 add_scalar_info (array_die, DW_AT_associated, info->associated,
17794 dw_scalar_form_constant
17795 | dw_scalar_form_exprloc
17796 | dw_scalar_form_reference, &context);
17797 if (info->allocated)
17798 add_scalar_info (array_die, DW_AT_allocated, info->allocated,
17799 dw_scalar_form_constant
17800 | dw_scalar_form_exprloc
17801 | dw_scalar_form_reference, &context);
17804 add_gnat_descriptive_type_attribute (array_die, type, context_die);
17806 for (dim = 0; dim < info->ndimensions; dim++)
17808 dw_die_ref subrange_die
17809 = new_die (DW_TAG_subrange_type, array_die, NULL);
17811 if (info->dimen[dim].bounds_type)
17812 add_type_attribute (subrange_die,
17813 info->dimen[dim].bounds_type, 0,
17815 if (info->dimen[dim].lower_bound)
17816 add_bound_info (subrange_die, DW_AT_lower_bound,
17817 info->dimen[dim].lower_bound, &context);
17818 if (info->dimen[dim].upper_bound)
17819 add_bound_info (subrange_die, DW_AT_upper_bound,
17820 info->dimen[dim].upper_bound, &context);
17821 if ((dwarf_version >= 3 || !dwarf_strict) && info->dimen[dim].stride)
17822 add_scalar_info (subrange_die, DW_AT_byte_stride,
17823 info->dimen[dim].stride,
17824 dw_scalar_form_constant
17825 | dw_scalar_form_exprloc
17826 | dw_scalar_form_reference,
17830 gen_type_die (info->element_type, context_die);
17831 add_type_attribute (array_die, info->element_type, TYPE_UNQUALIFIED,
17834 if (get_AT (array_die, DW_AT_name))
17835 add_pubtype (type, array_die);
17840 gen_entry_point_die (tree decl, dw_die_ref context_die)
17842 tree origin = decl_ultimate_origin (decl);
17843 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
17845 if (origin != NULL)
17846 add_abstract_origin_attribute (decl_die, origin);
17849 add_name_and_src_coords_attributes (decl_die, decl);
17850 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
17851 TYPE_UNQUALIFIED, context_die);
17854 if (DECL_ABSTRACT_P (decl))
17855 equate_decl_number_to_die (decl, decl_die);
17857 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
17861 /* Walk through the list of incomplete types again, trying once more to
17862 emit full debugging info for them. */
17865 retry_incomplete_types (void)
17869 for (i = vec_safe_length (incomplete_types) - 1; i >= 0; i--)
17870 if (should_emit_struct_debug ((*incomplete_types)[i], DINFO_USAGE_DIR_USE))
17871 gen_type_die ((*incomplete_types)[i], comp_unit_die ());
17874 /* Determine what tag to use for a record type. */
17876 static enum dwarf_tag
17877 record_type_tag (tree type)
17879 if (! lang_hooks.types.classify_record)
17880 return DW_TAG_structure_type;
17882 switch (lang_hooks.types.classify_record (type))
17884 case RECORD_IS_STRUCT:
17885 return DW_TAG_structure_type;
17887 case RECORD_IS_CLASS:
17888 return DW_TAG_class_type;
17890 case RECORD_IS_INTERFACE:
17891 if (dwarf_version >= 3 || !dwarf_strict)
17892 return DW_TAG_interface_type;
17893 return DW_TAG_structure_type;
17896 gcc_unreachable ();
17900 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17901 include all of the information about the enumeration values also. Each
17902 enumerated type name/value is listed as a child of the enumerated type
17906 gen_enumeration_type_die (tree type, dw_die_ref context_die)
17908 dw_die_ref type_die = lookup_type_die (type);
17910 if (type_die == NULL)
17912 type_die = new_die (DW_TAG_enumeration_type,
17913 scope_die_for (type, context_die), type);
17914 equate_type_number_to_die (type, type_die);
17915 add_name_attribute (type_die, type_tag (type));
17916 if (dwarf_version >= 4 || !dwarf_strict)
17918 if (ENUM_IS_SCOPED (type))
17919 add_AT_flag (type_die, DW_AT_enum_class, 1);
17920 if (ENUM_IS_OPAQUE (type))
17921 add_AT_flag (type_die, DW_AT_declaration, 1);
17924 else if (! TYPE_SIZE (type))
17927 remove_AT (type_die, DW_AT_declaration);
17929 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17930 given enum type is incomplete, do not generate the DW_AT_byte_size
17931 attribute or the DW_AT_element_list attribute. */
17932 if (TYPE_SIZE (type))
17936 TREE_ASM_WRITTEN (type) = 1;
17937 add_byte_size_attribute (type_die, type);
17938 if (dwarf_version >= 3 || !dwarf_strict)
17940 tree underlying = lang_hooks.types.enum_underlying_base_type (type);
17941 add_type_attribute (type_die, underlying, TYPE_UNQUALIFIED,
17944 if (TYPE_STUB_DECL (type) != NULL_TREE)
17946 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
17947 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
17950 /* If the first reference to this type was as the return type of an
17951 inline function, then it may not have a parent. Fix this now. */
17952 if (type_die->die_parent == NULL)
17953 add_child_die (scope_die_for (type, context_die), type_die);
17955 for (link = TYPE_VALUES (type);
17956 link != NULL; link = TREE_CHAIN (link))
17958 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
17959 tree value = TREE_VALUE (link);
17961 add_name_attribute (enum_die,
17962 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
17964 if (TREE_CODE (value) == CONST_DECL)
17965 value = DECL_INITIAL (value);
17967 if (simple_type_size_in_bits (TREE_TYPE (value))
17968 <= HOST_BITS_PER_WIDE_INT || tree_fits_shwi_p (value))
17970 /* For constant forms created by add_AT_unsigned DWARF
17971 consumers (GDB, elfutils, etc.) always zero extend
17972 the value. Only when the actual value is negative
17973 do we need to use add_AT_int to generate a constant
17974 form that can represent negative values. */
17975 HOST_WIDE_INT val = TREE_INT_CST_LOW (value);
17976 if (TYPE_UNSIGNED (TREE_TYPE (value)) || val >= 0)
17977 add_AT_unsigned (enum_die, DW_AT_const_value,
17978 (unsigned HOST_WIDE_INT) val);
17980 add_AT_int (enum_die, DW_AT_const_value, val);
17983 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17984 that here. TODO: This should be re-worked to use correct
17985 signed/unsigned double tags for all cases. */
17986 add_AT_wide (enum_die, DW_AT_const_value, value);
17989 add_gnat_descriptive_type_attribute (type_die, type, context_die);
17990 if (TYPE_ARTIFICIAL (type))
17991 add_AT_flag (type_die, DW_AT_artificial, 1);
17994 add_AT_flag (type_die, DW_AT_declaration, 1);
17996 add_pubtype (type, type_die);
18001 /* Generate a DIE to represent either a real live formal parameter decl or to
18002 represent just the type of some formal parameter position in some function
18005 Note that this routine is a bit unusual because its argument may be a
18006 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18007 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18008 node. If it's the former then this function is being called to output a
18009 DIE to represent a formal parameter object (or some inlining thereof). If
18010 it's the latter, then this function is only being called to output a
18011 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18012 argument type of some subprogram type.
18013 If EMIT_NAME_P is true, name and source coordinate attributes
18017 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18018 dw_die_ref context_die)
18020 tree node_or_origin = node ? node : origin;
18021 tree ultimate_origin;
18022 dw_die_ref parm_die = NULL;
18024 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin)) == tcc_declaration)
18026 parm_die = lookup_decl_die (node);
18028 /* If the contexts differ, we may not be talking about the same
18030 if (parm_die && parm_die->die_parent != context_die)
18032 if (!DECL_ABSTRACT_P (node))
18034 /* This can happen when creating an inlined instance, in
18035 which case we need to create a new DIE that will get
18036 annotated with DW_AT_abstract_origin. */
18041 /* FIXME: Reuse DIE even with a differing context.
18043 This can happen when calling
18044 dwarf2out_abstract_function to build debug info for
18045 the abstract instance of a function for which we have
18046 already generated a DIE in
18047 dwarf2out_early_global_decl.
18049 Once we remove dwarf2out_abstract_function, we should
18050 have a call to gcc_unreachable here. */
18054 if (parm_die && parm_die->die_parent == NULL)
18056 /* Check that parm_die already has the right attributes that
18057 we would have added below. If any attributes are
18058 missing, fall through to add them. */
18059 if (! DECL_ABSTRACT_P (node_or_origin)
18060 && !get_AT (parm_die, DW_AT_location)
18061 && !get_AT (parm_die, DW_AT_const_value))
18062 /* We are missing location info, and are about to add it. */
18066 add_child_die (context_die, parm_die);
18072 /* If we have a previously generated DIE, use it, unless this is an
18073 concrete instance (origin != NULL), in which case we need a new
18074 DIE with a corresponding DW_AT_abstract_origin. */
18076 if (parm_die && origin == NULL)
18077 reusing_die = true;
18080 parm_die = new_die (DW_TAG_formal_parameter, context_die, node);
18081 reusing_die = false;
18084 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18086 case tcc_declaration:
18087 ultimate_origin = decl_ultimate_origin (node_or_origin);
18088 if (node || ultimate_origin)
18089 origin = ultimate_origin;
18094 if (origin != NULL)
18095 add_abstract_origin_attribute (parm_die, origin);
18096 else if (emit_name_p)
18097 add_name_and_src_coords_attributes (parm_die, node);
18099 || (! DECL_ABSTRACT_P (node_or_origin)
18100 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18101 decl_function_context
18102 (node_or_origin))))
18104 tree type = TREE_TYPE (node_or_origin);
18105 if (decl_by_reference_p (node_or_origin))
18106 add_type_attribute (parm_die, TREE_TYPE (type),
18107 TYPE_UNQUALIFIED, context_die);
18109 add_type_attribute (parm_die, type,
18110 decl_quals (node_or_origin),
18113 if (origin == NULL && DECL_ARTIFICIAL (node))
18114 add_AT_flag (parm_die, DW_AT_artificial, 1);
18116 if (node && node != origin)
18117 equate_decl_number_to_die (node, parm_die);
18118 if (! DECL_ABSTRACT_P (node_or_origin))
18119 add_location_or_const_value_attribute (parm_die, node_or_origin,
18120 node == NULL, DW_AT_location);
18125 /* We were called with some kind of a ..._TYPE node. */
18126 add_type_attribute (parm_die, node_or_origin, TYPE_UNQUALIFIED,
18131 gcc_unreachable ();
18137 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18138 children DW_TAG_formal_parameter DIEs representing the arguments of the
18141 PARM_PACK must be a function parameter pack.
18142 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18143 must point to the subsequent arguments of the function PACK_ARG belongs to.
18144 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18145 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18146 following the last one for which a DIE was generated. */
18149 gen_formal_parameter_pack_die (tree parm_pack,
18151 dw_die_ref subr_die,
18155 dw_die_ref parm_pack_die;
18157 gcc_assert (parm_pack
18158 && lang_hooks.function_parameter_pack_p (parm_pack)
18161 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18162 add_src_coords_attributes (parm_pack_die, parm_pack);
18164 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18166 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18169 gen_formal_parameter_die (arg, NULL,
18170 false /* Don't emit name attribute. */,
18175 return parm_pack_die;
18178 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18179 at the end of an (ANSI prototyped) formal parameters list. */
18182 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18184 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18187 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18188 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18189 parameters as specified in some function type specification (except for
18190 those which appear as part of a function *definition*). */
18193 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18196 tree formal_type = NULL;
18197 tree first_parm_type;
18200 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18202 arg = DECL_ARGUMENTS (function_or_method_type);
18203 function_or_method_type = TREE_TYPE (function_or_method_type);
18208 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18210 /* Make our first pass over the list of formal parameter types and output a
18211 DW_TAG_formal_parameter DIE for each one. */
18212 for (link = first_parm_type; link; )
18214 dw_die_ref parm_die;
18216 formal_type = TREE_VALUE (link);
18217 if (formal_type == void_type_node)
18220 /* Output a (nameless) DIE to represent the formal parameter itself. */
18221 if (!POINTER_BOUNDS_TYPE_P (formal_type))
18223 parm_die = gen_formal_parameter_die (formal_type, NULL,
18224 true /* Emit name attribute. */,
18226 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18227 && link == first_parm_type)
18229 add_AT_flag (parm_die, DW_AT_artificial, 1);
18230 if (dwarf_version >= 3 || !dwarf_strict)
18231 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18233 else if (arg && DECL_ARTIFICIAL (arg))
18234 add_AT_flag (parm_die, DW_AT_artificial, 1);
18237 link = TREE_CHAIN (link);
18239 arg = DECL_CHAIN (arg);
18242 /* If this function type has an ellipsis, add a
18243 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18244 if (formal_type != void_type_node)
18245 gen_unspecified_parameters_die (function_or_method_type, context_die);
18247 /* Make our second (and final) pass over the list of formal parameter types
18248 and output DIEs to represent those types (as necessary). */
18249 for (link = TYPE_ARG_TYPES (function_or_method_type);
18250 link && TREE_VALUE (link);
18251 link = TREE_CHAIN (link))
18252 gen_type_die (TREE_VALUE (link), context_die);
18255 /* We want to generate the DIE for TYPE so that we can generate the
18256 die for MEMBER, which has been defined; we will need to refer back
18257 to the member declaration nested within TYPE. If we're trying to
18258 generate minimal debug info for TYPE, processing TYPE won't do the
18259 trick; we need to attach the member declaration by hand. */
18262 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18264 gen_type_die (type, context_die);
18266 /* If we're trying to avoid duplicate debug info, we may not have
18267 emitted the member decl for this function. Emit it now. */
18268 if (TYPE_STUB_DECL (type)
18269 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18270 && ! lookup_decl_die (member))
18272 dw_die_ref type_die;
18273 gcc_assert (!decl_ultimate_origin (member));
18275 push_decl_scope (type);
18276 type_die = lookup_type_die_strip_naming_typedef (type);
18277 if (TREE_CODE (member) == FUNCTION_DECL)
18278 gen_subprogram_die (member, type_die);
18279 else if (TREE_CODE (member) == FIELD_DECL)
18281 /* Ignore the nameless fields that are used to skip bits but handle
18282 C++ anonymous unions and structs. */
18283 if (DECL_NAME (member) != NULL_TREE
18284 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18285 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18287 gen_type_die (member_declared_type (member), type_die);
18288 gen_field_die (member, type_die);
18292 gen_variable_die (member, NULL_TREE, type_die);
18298 /* Forward declare these functions, because they are mutually recursive
18299 with their set_block_* pairing functions. */
18300 static void set_decl_origin_self (tree);
18301 static void set_decl_abstract_flags (tree, vec<tree> &);
18303 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
18304 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
18305 that it points to the node itself, thus indicating that the node is its
18306 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
18307 the given node is NULL, recursively descend the decl/block tree which
18308 it is the root of, and for each other ..._DECL or BLOCK node contained
18309 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
18310 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
18311 values to point to themselves. */
18314 set_block_origin_self (tree stmt)
18316 if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
18318 BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
18323 for (local_decl = BLOCK_VARS (stmt);
18324 local_decl != NULL_TREE;
18325 local_decl = DECL_CHAIN (local_decl))
18326 /* Do not recurse on nested functions since the inlining status
18327 of parent and child can be different as per the DWARF spec. */
18328 if (TREE_CODE (local_decl) != FUNCTION_DECL
18329 && !DECL_EXTERNAL (local_decl))
18330 set_decl_origin_self (local_decl);
18336 for (subblock = BLOCK_SUBBLOCKS (stmt);
18337 subblock != NULL_TREE;
18338 subblock = BLOCK_CHAIN (subblock))
18339 set_block_origin_self (subblock); /* Recurse. */
18344 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
18345 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
18346 node to so that it points to the node itself, thus indicating that the
18347 node represents its own (abstract) origin. Additionally, if the
18348 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
18349 the decl/block tree of which the given node is the root of, and for
18350 each other ..._DECL or BLOCK node contained therein whose
18351 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
18352 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
18353 point to themselves. */
18356 set_decl_origin_self (tree decl)
18358 if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
18360 DECL_ABSTRACT_ORIGIN (decl) = decl;
18361 if (TREE_CODE (decl) == FUNCTION_DECL)
18365 for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
18366 DECL_ABSTRACT_ORIGIN (arg) = arg;
18367 if (DECL_INITIAL (decl) != NULL_TREE
18368 && DECL_INITIAL (decl) != error_mark_node)
18369 set_block_origin_self (DECL_INITIAL (decl));
18374 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
18375 and if it wasn't 1 before, push it to abstract_vec vector.
18376 For all local decls and all local sub-blocks (recursively) do it
18380 set_block_abstract_flags (tree stmt, vec<tree> &abstract_vec)
18386 if (!BLOCK_ABSTRACT (stmt))
18388 abstract_vec.safe_push (stmt);
18389 BLOCK_ABSTRACT (stmt) = 1;
18392 for (local_decl = BLOCK_VARS (stmt);
18393 local_decl != NULL_TREE;
18394 local_decl = DECL_CHAIN (local_decl))
18395 if (! DECL_EXTERNAL (local_decl))
18396 set_decl_abstract_flags (local_decl, abstract_vec);
18398 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
18400 local_decl = BLOCK_NONLOCALIZED_VAR (stmt, i);
18401 if ((TREE_CODE (local_decl) == VAR_DECL && !TREE_STATIC (local_decl))
18402 || TREE_CODE (local_decl) == PARM_DECL)
18403 set_decl_abstract_flags (local_decl, abstract_vec);
18406 for (subblock = BLOCK_SUBBLOCKS (stmt);
18407 subblock != NULL_TREE;
18408 subblock = BLOCK_CHAIN (subblock))
18409 set_block_abstract_flags (subblock, abstract_vec);
18412 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
18413 to 1 and if it wasn't 1 before, push to abstract_vec vector.
18414 In the case where the decl is a FUNCTION_DECL also set the abstract
18415 flags for all of the parameters, local vars, local
18416 blocks and sub-blocks (recursively). */
18419 set_decl_abstract_flags (tree decl, vec<tree> &abstract_vec)
18421 if (!DECL_ABSTRACT_P (decl))
18423 abstract_vec.safe_push (decl);
18424 DECL_ABSTRACT_P (decl) = 1;
18427 if (TREE_CODE (decl) == FUNCTION_DECL)
18431 for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
18432 if (!DECL_ABSTRACT_P (arg))
18434 abstract_vec.safe_push (arg);
18435 DECL_ABSTRACT_P (arg) = 1;
18437 if (DECL_INITIAL (decl) != NULL_TREE
18438 && DECL_INITIAL (decl) != error_mark_node)
18439 set_block_abstract_flags (DECL_INITIAL (decl), abstract_vec);
18443 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18444 may later generate inlined and/or out-of-line instances of.
18446 FIXME: In the early-dwarf world, this function, and most of the
18447 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
18448 the abstract instance. All we would need to do is annotate
18449 the early DIE with the appropriate DW_AT_inline in late
18450 dwarf (perhaps in gen_inlined_subroutine_die).
18452 However, we can't do this yet, because LTO streaming of DIEs
18453 has not been implemented yet. */
18456 dwarf2out_abstract_function (tree decl)
18458 dw_die_ref old_die;
18461 hash_table<decl_loc_hasher> *old_decl_loc_table;
18462 hash_table<dw_loc_list_hasher> *old_cached_dw_loc_list_table;
18463 int old_call_site_count, old_tail_call_site_count;
18464 struct call_arg_loc_node *old_call_arg_locations;
18466 /* Make sure we have the actual abstract inline, not a clone. */
18467 decl = DECL_ORIGIN (decl);
18469 old_die = lookup_decl_die (decl);
18470 if (old_die && get_AT (old_die, DW_AT_inline))
18471 /* We've already generated the abstract instance. */
18474 /* We can be called while recursively when seeing block defining inlined subroutine
18475 DIE. Be sure to not clobber the outer location table nor use it or we would
18476 get locations in abstract instantces. */
18477 old_decl_loc_table = decl_loc_table;
18478 decl_loc_table = NULL;
18479 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
18480 cached_dw_loc_list_table = NULL;
18481 old_call_arg_locations = call_arg_locations;
18482 call_arg_locations = NULL;
18483 old_call_site_count = call_site_count;
18484 call_site_count = -1;
18485 old_tail_call_site_count = tail_call_site_count;
18486 tail_call_site_count = -1;
18488 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18489 we don't get confused by DECL_ABSTRACT_P. */
18490 if (debug_info_level > DINFO_LEVEL_TERSE)
18492 context = decl_class_context (decl);
18494 gen_type_die_for_member
18495 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
18498 /* Pretend we've just finished compiling this function. */
18499 save_fn = current_function_decl;
18500 current_function_decl = decl;
18502 auto_vec<tree, 64> abstract_vec;
18503 set_decl_abstract_flags (decl, abstract_vec);
18504 dwarf2out_decl (decl);
18507 FOR_EACH_VEC_ELT (abstract_vec, i, t)
18508 if (TREE_CODE (t) == BLOCK)
18509 BLOCK_ABSTRACT (t) = 0;
18511 DECL_ABSTRACT_P (t) = 0;
18513 current_function_decl = save_fn;
18514 decl_loc_table = old_decl_loc_table;
18515 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
18516 call_arg_locations = old_call_arg_locations;
18517 call_site_count = old_call_site_count;
18518 tail_call_site_count = old_tail_call_site_count;
18521 /* Helper function of premark_used_types() which gets called through
18524 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18525 marked as unused by prune_unused_types. */
18528 premark_used_types_helper (tree const &type, void *)
18532 die = lookup_type_die (type);
18534 die->die_perennial_p = 1;
18538 /* Helper function of premark_types_used_by_global_vars which gets called
18539 through htab_traverse.
18541 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18542 marked as unused by prune_unused_types. The DIE of the type is marked
18543 only if the global variable using the type will actually be emitted. */
18546 premark_types_used_by_global_vars_helper (types_used_by_vars_entry **slot,
18549 struct types_used_by_vars_entry *entry;
18552 entry = (struct types_used_by_vars_entry *) *slot;
18553 gcc_assert (entry->type != NULL
18554 && entry->var_decl != NULL);
18555 die = lookup_type_die (entry->type);
18558 /* Ask cgraph if the global variable really is to be emitted.
18559 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18560 varpool_node *node = varpool_node::get (entry->var_decl);
18561 if (node && node->definition)
18563 die->die_perennial_p = 1;
18564 /* Keep the parent DIEs as well. */
18565 while ((die = die->die_parent) && die->die_perennial_p == 0)
18566 die->die_perennial_p = 1;
18572 /* Mark all members of used_types_hash as perennial. */
18575 premark_used_types (struct function *fun)
18577 if (fun && fun->used_types_hash)
18578 fun->used_types_hash->traverse<void *, premark_used_types_helper> (NULL);
18581 /* Mark all members of types_used_by_vars_entry as perennial. */
18584 premark_types_used_by_global_vars (void)
18586 if (types_used_by_vars_hash)
18587 types_used_by_vars_hash
18588 ->traverse<void *, premark_types_used_by_global_vars_helper> (NULL);
18591 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18592 for CA_LOC call arg loc node. */
18595 gen_call_site_die (tree decl, dw_die_ref subr_die,
18596 struct call_arg_loc_node *ca_loc)
18598 dw_die_ref stmt_die = NULL, die;
18599 tree block = ca_loc->block;
18602 && block != DECL_INITIAL (decl)
18603 && TREE_CODE (block) == BLOCK)
18605 stmt_die = BLOCK_DIE (block);
18608 block = BLOCK_SUPERCONTEXT (block);
18610 if (stmt_die == NULL)
18611 stmt_die = subr_die;
18612 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
18613 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
18614 if (ca_loc->tail_call_p)
18615 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
18616 if (ca_loc->symbol_ref)
18618 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
18620 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
18622 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref, false);
18627 /* Generate a DIE to represent a declared function (either file-scope or
18631 gen_subprogram_die (tree decl, dw_die_ref context_die)
18633 tree origin = decl_ultimate_origin (decl);
18634 dw_die_ref subr_die;
18635 dw_die_ref old_die = lookup_decl_die (decl);
18637 /* This function gets called multiple times for different stages of
18638 the debug process. For example, for func() in this code:
18642 void func() { ... }
18645 ...we get called 4 times. Twice in early debug and twice in
18651 1. Once while generating func() within the namespace. This is
18652 the declaration. The declaration bit below is set, as the
18653 context is the namespace.
18655 A new DIE will be generated with DW_AT_declaration set.
18657 2. Once for func() itself. This is the specification. The
18658 declaration bit below is clear as the context is the CU.
18660 We will use the cached DIE from (1) to create a new DIE with
18661 DW_AT_specification pointing to the declaration in (1).
18663 Late debug via rest_of_handle_final()
18664 -------------------------------------
18666 3. Once generating func() within the namespace. This is also the
18667 declaration, as in (1), but this time we will early exit below
18668 as we have a cached DIE and a declaration needs no additional
18669 annotations (no locations), as the source declaration line
18672 4. Once for func() itself. As in (2), this is the specification,
18673 but this time we will re-use the cached DIE, and just annotate
18674 it with the location information that should now be available.
18676 For something without namespaces, but with abstract instances, we
18677 are also called a multiple times:
18682 Base (); // constructor declaration (1)
18685 Base::Base () { } // constructor specification (2)
18690 1. Once for the Base() constructor by virtue of it being a
18691 member of the Base class. This is done via
18692 rest_of_type_compilation.
18694 This is a declaration, so a new DIE will be created with
18697 2. Once for the Base() constructor definition, but this time
18698 while generating the abstract instance of the base
18699 constructor (__base_ctor) which is being generated via early
18700 debug of reachable functions.
18702 Even though we have a cached version of the declaration (1),
18703 we will create a DW_AT_specification of the declaration DIE
18706 3. Once for the __base_ctor itself, but this time, we generate
18707 an DW_AT_abstract_origin version of the DW_AT_specification in
18710 Late debug via rest_of_handle_final
18711 -----------------------------------
18713 4. One final time for the __base_ctor (which will have a cached
18714 DIE with DW_AT_abstract_origin created in (3). This time,
18715 we will just annotate the location information now
18718 int declaration = (current_function_decl != decl
18719 || class_or_namespace_scope_p (context_die));
18721 premark_used_types (DECL_STRUCT_FUNCTION (decl));
18723 /* Now that the C++ front end lazily declares artificial member fns, we
18724 might need to retrofit the declaration into its class. */
18725 if (!declaration && !origin && !old_die
18726 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
18727 && !class_or_namespace_scope_p (context_die)
18728 && debug_info_level > DINFO_LEVEL_TERSE)
18729 old_die = force_decl_die (decl);
18731 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
18732 if (origin != NULL)
18734 gcc_assert (!declaration || local_scope_p (context_die));
18736 /* Fixup die_parent for the abstract instance of a nested
18737 inline function. */
18738 if (old_die && old_die->die_parent == NULL)
18739 add_child_die (context_die, old_die);
18741 if (old_die && get_AT_ref (old_die, DW_AT_abstract_origin))
18743 /* If we have a DW_AT_abstract_origin we have a working
18745 subr_die = old_die;
18749 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18750 add_abstract_origin_attribute (subr_die, origin);
18751 /* This is where the actual code for a cloned function is.
18752 Let's emit linkage name attribute for it. This helps
18753 debuggers to e.g, set breakpoints into
18754 constructors/destructors when the user asks "break
18756 add_linkage_name (subr_die, decl);
18759 /* A cached copy, possibly from early dwarf generation. Reuse as
18760 much as possible. */
18763 /* A declaration that has been previously dumped needs no
18764 additional information. */
18768 if (!get_AT_flag (old_die, DW_AT_declaration)
18769 /* We can have a normal definition following an inline one in the
18770 case of redefinition of GNU C extern inlines.
18771 It seems reasonable to use AT_specification in this case. */
18772 && !get_AT (old_die, DW_AT_inline))
18774 /* Detect and ignore this case, where we are trying to output
18775 something we have already output. */
18776 if (get_AT (old_die, DW_AT_low_pc)
18777 || get_AT (old_die, DW_AT_ranges))
18780 /* If we have no location information, this must be a
18781 partially generated DIE from early dwarf generation.
18782 Fall through and generate it. */
18785 /* If the definition comes from the same place as the declaration,
18786 maybe use the old DIE. We always want the DIE for this function
18787 that has the *_pc attributes to be under comp_unit_die so the
18788 debugger can find it. We also need to do this for abstract
18789 instances of inlines, since the spec requires the out-of-line copy
18790 to have the same parent. For local class methods, this doesn't
18791 apply; we just use the old DIE. */
18792 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
18793 struct dwarf_file_data * file_index = lookup_filename (s.file);
18794 if ((is_cu_die (old_die->die_parent)
18795 /* This condition fixes the inconsistency/ICE with the
18796 following Fortran test (or some derivative thereof) while
18797 building libgfortran:
18801 logical function funky (FLAG)
18806 || (old_die->die_parent
18807 && old_die->die_parent->die_tag == DW_TAG_module)
18808 || context_die == NULL)
18809 && (DECL_ARTIFICIAL (decl)
18810 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
18811 && (get_AT_unsigned (old_die, DW_AT_decl_line)
18812 == (unsigned) s.line))))
18814 subr_die = old_die;
18816 /* Clear out the declaration attribute, but leave the
18817 parameters so they can be augmented with location
18818 information later. Unless this was a declaration, in
18819 which case, wipe out the nameless parameters and recreate
18820 them further down. */
18821 if (remove_AT (subr_die, DW_AT_declaration))
18824 remove_AT (subr_die, DW_AT_object_pointer);
18825 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
18828 /* Make a specification pointing to the previously built
18832 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18833 add_AT_specification (subr_die, old_die);
18834 add_pubname (decl, subr_die);
18835 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
18836 add_AT_file (subr_die, DW_AT_decl_file, file_index);
18837 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
18838 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
18840 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18841 emit the real type on the definition die. */
18842 if (is_cxx() && debug_info_level > DINFO_LEVEL_TERSE)
18844 dw_die_ref die = get_AT_ref (old_die, DW_AT_type);
18845 if (die == auto_die || die == decltype_auto_die)
18846 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
18847 TYPE_UNQUALIFIED, context_die);
18851 /* Create a fresh DIE for anything else. */
18854 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18856 if (TREE_PUBLIC (decl))
18857 add_AT_flag (subr_die, DW_AT_external, 1);
18859 add_name_and_src_coords_attributes (subr_die, decl);
18860 add_pubname (decl, subr_die);
18861 if (debug_info_level > DINFO_LEVEL_TERSE)
18863 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
18864 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
18865 TYPE_UNQUALIFIED, context_die);
18868 add_pure_or_virtual_attribute (subr_die, decl);
18869 if (DECL_ARTIFICIAL (decl))
18870 add_AT_flag (subr_die, DW_AT_artificial, 1);
18872 if (TREE_THIS_VOLATILE (decl) && (dwarf_version >= 5 || !dwarf_strict))
18873 add_AT_flag (subr_die, DW_AT_noreturn, 1);
18875 add_accessibility_attribute (subr_die, decl);
18878 /* Unless we have an existing non-declaration DIE, equate the new
18880 if (!old_die || is_declaration_die (old_die))
18881 equate_decl_number_to_die (decl, subr_die);
18885 if (!old_die || !get_AT (old_die, DW_AT_inline))
18887 add_AT_flag (subr_die, DW_AT_declaration, 1);
18889 /* If this is an explicit function declaration then generate
18890 a DW_AT_explicit attribute. */
18891 if (lang_hooks.decls.function_decl_explicit_p (decl)
18892 && (dwarf_version >= 3 || !dwarf_strict))
18893 add_AT_flag (subr_die, DW_AT_explicit, 1);
18895 /* If this is a C++11 deleted special function member then generate
18896 a DW_AT_GNU_deleted attribute. */
18897 if (lang_hooks.decls.function_decl_deleted_p (decl)
18898 && (! dwarf_strict))
18899 add_AT_flag (subr_die, DW_AT_GNU_deleted, 1);
18902 /* Tag abstract instances with DW_AT_inline. */
18903 else if (DECL_ABSTRACT_P (decl))
18905 if (DECL_DECLARED_INLINE_P (decl))
18907 if (cgraph_function_possibly_inlined_p (decl))
18908 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
18910 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
18914 if (cgraph_function_possibly_inlined_p (decl))
18915 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
18917 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
18920 if (DECL_DECLARED_INLINE_P (decl)
18921 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
18922 add_AT_flag (subr_die, DW_AT_artificial, 1);
18924 /* For non DECL_EXTERNALs, if range information is available, fill
18925 the DIE with it. */
18926 else if (!DECL_EXTERNAL (decl) && !early_dwarf)
18928 HOST_WIDE_INT cfa_fb_offset;
18930 struct function *fun = DECL_STRUCT_FUNCTION (decl);
18932 if (!flag_reorder_blocks_and_partition)
18934 dw_fde_ref fde = fun->fde;
18935 if (fde->dw_fde_begin)
18937 /* We have already generated the labels. */
18938 add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
18939 fde->dw_fde_end, false);
18943 /* Create start/end labels and add the range. */
18944 char label_id_low[MAX_ARTIFICIAL_LABEL_BYTES];
18945 char label_id_high[MAX_ARTIFICIAL_LABEL_BYTES];
18946 ASM_GENERATE_INTERNAL_LABEL (label_id_low, FUNC_BEGIN_LABEL,
18947 current_function_funcdef_no);
18948 ASM_GENERATE_INTERNAL_LABEL (label_id_high, FUNC_END_LABEL,
18949 current_function_funcdef_no);
18950 add_AT_low_high_pc (subr_die, label_id_low, label_id_high,
18954 #if VMS_DEBUGGING_INFO
18955 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18956 Section 2.3 Prologue and Epilogue Attributes:
18957 When a breakpoint is set on entry to a function, it is generally
18958 desirable for execution to be suspended, not on the very first
18959 instruction of the function, but rather at a point after the
18960 function's frame has been set up, after any language defined local
18961 declaration processing has been completed, and before execution of
18962 the first statement of the function begins. Debuggers generally
18963 cannot properly determine where this point is. Similarly for a
18964 breakpoint set on exit from a function. The prologue and epilogue
18965 attributes allow a compiler to communicate the location(s) to use. */
18968 if (fde->dw_fde_vms_end_prologue)
18969 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
18970 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
18972 if (fde->dw_fde_vms_begin_epilogue)
18973 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
18974 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
18981 /* Generate pubnames entries for the split function code ranges. */
18982 dw_fde_ref fde = fun->fde;
18984 if (fde->dw_fde_second_begin)
18986 if (dwarf_version >= 3 || !dwarf_strict)
18988 /* We should use ranges for non-contiguous code section
18989 addresses. Use the actual code range for the initial
18990 section, since the HOT/COLD labels might precede an
18991 alignment offset. */
18992 bool range_list_added = false;
18993 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
18994 fde->dw_fde_end, &range_list_added,
18996 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
18997 fde->dw_fde_second_end,
18998 &range_list_added, false);
18999 if (range_list_added)
19004 /* There is no real support in DW2 for this .. so we make
19005 a work-around. First, emit the pub name for the segment
19006 containing the function label. Then make and emit a
19007 simplified subprogram DIE for the second segment with the
19008 name pre-fixed by __hot/cold_sect_of_. We use the same
19009 linkage name for the second die so that gdb will find both
19010 sections when given "b foo". */
19011 const char *name = NULL;
19012 tree decl_name = DECL_NAME (decl);
19013 dw_die_ref seg_die;
19015 /* Do the 'primary' section. */
19016 add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
19017 fde->dw_fde_end, false);
19019 /* Build a minimal DIE for the secondary section. */
19020 seg_die = new_die (DW_TAG_subprogram,
19021 subr_die->die_parent, decl);
19023 if (TREE_PUBLIC (decl))
19024 add_AT_flag (seg_die, DW_AT_external, 1);
19026 if (decl_name != NULL
19027 && IDENTIFIER_POINTER (decl_name) != NULL)
19029 name = dwarf2_name (decl, 1);
19030 if (! DECL_ARTIFICIAL (decl))
19031 add_src_coords_attributes (seg_die, decl);
19033 add_linkage_name (seg_die, decl);
19035 gcc_assert (name != NULL);
19036 add_pure_or_virtual_attribute (seg_die, decl);
19037 if (DECL_ARTIFICIAL (decl))
19038 add_AT_flag (seg_die, DW_AT_artificial, 1);
19040 name = concat ("__second_sect_of_", name, NULL);
19041 add_AT_low_high_pc (seg_die, fde->dw_fde_second_begin,
19042 fde->dw_fde_second_end, false);
19043 add_name_attribute (seg_die, name);
19044 if (want_pubnames ())
19045 add_pubname_string (name, seg_die);
19049 add_AT_low_high_pc (subr_die, fde->dw_fde_begin, fde->dw_fde_end,
19053 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19055 /* We define the "frame base" as the function's CFA. This is more
19056 convenient for several reasons: (1) It's stable across the prologue
19057 and epilogue, which makes it better than just a frame pointer,
19058 (2) With dwarf3, there exists a one-byte encoding that allows us
19059 to reference the .debug_frame data by proxy, but failing that,
19060 (3) We can at least reuse the code inspection and interpretation
19061 code that determines the CFA position at various points in the
19063 if (dwarf_version >= 3 && targetm.debug_unwind_info () == UI_DWARF2)
19065 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19066 add_AT_loc (subr_die, DW_AT_frame_base, op);
19070 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19071 if (list->dw_loc_next)
19072 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19074 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19077 /* Compute a displacement from the "steady-state frame pointer" to
19078 the CFA. The former is what all stack slots and argument slots
19079 will reference in the rtl; the latter is what we've told the
19080 debugger about. We'll need to adjust all frame_base references
19081 by this displacement. */
19082 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19084 if (fun->static_chain_decl)
19085 add_AT_location_description
19086 (subr_die, DW_AT_static_link,
19087 loc_list_from_tree (fun->static_chain_decl, 2, NULL));
19090 /* Generate child dies for template paramaters. */
19091 if (early_dwarf && debug_info_level > DINFO_LEVEL_TERSE)
19092 gen_generic_params_dies (decl);
19094 /* Now output descriptions of the arguments for this function. This gets
19095 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19096 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19097 `...' at the end of the formal parameter list. In order to find out if
19098 there was a trailing ellipsis or not, we must instead look at the type
19099 associated with the FUNCTION_DECL. This will be a node of type
19100 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19101 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19102 an ellipsis at the end. */
19104 /* In the case where we are describing a mere function declaration, all we
19105 need to do here (and all we *can* do here) is to describe the *types* of
19106 its formal parameters. */
19107 if (debug_info_level <= DINFO_LEVEL_TERSE)
19109 else if (declaration)
19110 gen_formal_types_die (decl, subr_die);
19113 /* Generate DIEs to represent all known formal parameters. */
19114 tree parm = DECL_ARGUMENTS (decl);
19115 tree generic_decl = early_dwarf
19116 ? lang_hooks.decls.get_generic_function_decl (decl) : NULL;
19117 tree generic_decl_parm = generic_decl
19118 ? DECL_ARGUMENTS (generic_decl)
19121 /* Now we want to walk the list of parameters of the function and
19122 emit their relevant DIEs.
19124 We consider the case of DECL being an instance of a generic function
19125 as well as it being a normal function.
19127 If DECL is an instance of a generic function we walk the
19128 parameters of the generic function declaration _and_ the parameters of
19129 DECL itself. This is useful because we want to emit specific DIEs for
19130 function parameter packs and those are declared as part of the
19131 generic function declaration. In that particular case,
19132 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19133 That DIE has children DIEs representing the set of arguments
19134 of the pack. Note that the set of pack arguments can be empty.
19135 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19138 Otherwise, we just consider the parameters of DECL. */
19139 while (generic_decl_parm || parm)
19141 if (generic_decl_parm
19142 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19143 gen_formal_parameter_pack_die (generic_decl_parm,
19146 else if (parm && !POINTER_BOUNDS_P (parm))
19148 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19150 if (parm == DECL_ARGUMENTS (decl)
19151 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19153 && (dwarf_version >= 3 || !dwarf_strict))
19154 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19156 parm = DECL_CHAIN (parm);
19159 parm = DECL_CHAIN (parm);
19161 if (generic_decl_parm)
19162 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19165 /* Decide whether we need an unspecified_parameters DIE at the end.
19166 There are 2 more cases to do this for: 1) the ansi ... declaration -
19167 this is detectable when the end of the arg list is not a
19168 void_type_node 2) an unprototyped function declaration (not a
19169 definition). This just means that we have no info about the
19170 parameters at all. */
19171 if (prototype_p (TREE_TYPE (decl)))
19173 /* This is the prototyped case, check for.... */
19174 if (stdarg_p (TREE_TYPE (decl)))
19175 gen_unspecified_parameters_die (decl, subr_die);
19177 else if (DECL_INITIAL (decl) == NULL_TREE)
19178 gen_unspecified_parameters_die (decl, subr_die);
19181 if (subr_die != old_die)
19182 /* Add the calling convention attribute if requested. */
19183 add_calling_convention_attribute (subr_die, decl);
19185 /* Output Dwarf info for all of the stuff within the body of the function
19186 (if it has one - it may be just a declaration).
19188 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19189 a function. This BLOCK actually represents the outermost binding contour
19190 for the function, i.e. the contour in which the function's formal
19191 parameters and labels get declared. Curiously, it appears that the front
19192 end doesn't actually put the PARM_DECL nodes for the current function onto
19193 the BLOCK_VARS list for this outer scope, but are strung off of the
19194 DECL_ARGUMENTS list for the function instead.
19196 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19197 the LABEL_DECL nodes for the function however, and we output DWARF info
19198 for those in decls_for_scope. Just within the `outer_scope' there will be
19199 a BLOCK node representing the function's outermost pair of curly braces,
19200 and any blocks used for the base and member initializers of a C++
19201 constructor function. */
19202 tree outer_scope = DECL_INITIAL (decl);
19203 if (! declaration && outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
19205 int call_site_note_count = 0;
19206 int tail_call_site_note_count = 0;
19208 /* Emit a DW_TAG_variable DIE for a named return value. */
19209 if (DECL_NAME (DECL_RESULT (decl)))
19210 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19212 /* The first time through decls_for_scope we will generate the
19213 DIEs for the locals. The second time, we fill in the
19215 decls_for_scope (outer_scope, subr_die);
19217 if (call_arg_locations && !dwarf_strict)
19219 struct call_arg_loc_node *ca_loc;
19220 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
19222 dw_die_ref die = NULL;
19223 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
19226 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
19227 arg; arg = next_arg)
19229 dw_loc_descr_ref reg, val;
19230 machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
19231 dw_die_ref cdie, tdie = NULL;
19233 next_arg = XEXP (arg, 1);
19234 if (REG_P (XEXP (XEXP (arg, 0), 0))
19236 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
19237 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
19238 && REGNO (XEXP (XEXP (arg, 0), 0))
19239 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
19240 next_arg = XEXP (next_arg, 1);
19241 if (mode == VOIDmode)
19243 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
19244 if (mode == VOIDmode)
19245 mode = GET_MODE (XEXP (arg, 0));
19247 if (mode == VOIDmode || mode == BLKmode)
19249 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
19251 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19252 tloc = XEXP (XEXP (arg, 0), 1);
19255 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
19256 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
19258 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19259 tlocc = XEXP (XEXP (arg, 0), 1);
19263 if (REG_P (XEXP (XEXP (arg, 0), 0)))
19264 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
19265 VAR_INIT_STATUS_INITIALIZED);
19266 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
19268 rtx mem = XEXP (XEXP (arg, 0), 0);
19269 reg = mem_loc_descriptor (XEXP (mem, 0),
19270 get_address_mode (mem),
19272 VAR_INIT_STATUS_INITIALIZED);
19274 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
19275 == DEBUG_PARAMETER_REF)
19278 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
19279 tdie = lookup_decl_die (tdecl);
19286 && GET_CODE (XEXP (XEXP (arg, 0), 0))
19287 != DEBUG_PARAMETER_REF)
19289 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
19291 VAR_INIT_STATUS_INITIALIZED);
19295 die = gen_call_site_die (decl, subr_die, ca_loc);
19296 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
19299 add_AT_loc (cdie, DW_AT_location, reg);
19300 else if (tdie != NULL)
19301 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
19302 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
19303 if (next_arg != XEXP (arg, 1))
19305 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
19306 if (mode == VOIDmode)
19307 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
19308 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
19311 VAR_INIT_STATUS_INITIALIZED);
19313 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
19317 && (ca_loc->symbol_ref || tloc))
19318 die = gen_call_site_die (decl, subr_die, ca_loc);
19319 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
19321 dw_loc_descr_ref tval = NULL;
19323 if (tloc != NULL_RTX)
19324 tval = mem_loc_descriptor (tloc,
19325 GET_MODE (tloc) == VOIDmode
19326 ? Pmode : GET_MODE (tloc),
19328 VAR_INIT_STATUS_INITIALIZED);
19330 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
19331 else if (tlocc != NULL_RTX)
19333 tval = mem_loc_descriptor (tlocc,
19334 GET_MODE (tlocc) == VOIDmode
19335 ? Pmode : GET_MODE (tlocc),
19337 VAR_INIT_STATUS_INITIALIZED);
19339 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
19345 call_site_note_count++;
19346 if (ca_loc->tail_call_p)
19347 tail_call_site_note_count++;
19351 call_arg_locations = NULL;
19352 call_arg_loc_last = NULL;
19353 if (tail_call_site_count >= 0
19354 && tail_call_site_count == tail_call_site_note_count
19357 if (call_site_count >= 0
19358 && call_site_count == call_site_note_count)
19359 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
19361 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
19363 call_site_count = -1;
19364 tail_call_site_count = -1;
19368 /* Returns a hash value for X (which really is a die_struct). */
19371 block_die_hasher::hash (die_struct *d)
19373 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19376 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19377 as decl_id and die_parent of die_struct Y. */
19380 block_die_hasher::equal (die_struct *x, die_struct *y)
19382 return x->decl_id == y->decl_id && x->die_parent == y->die_parent;
19385 /* Return TRUE if DECL, which may have been previously generated as
19386 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
19387 true if decl (or its origin) is either an extern declaration or a
19388 class/namespace scoped declaration.
19390 The declare_in_namespace support causes us to get two DIEs for one
19391 variable, both of which are declarations. We want to avoid
19392 considering one to be a specification, so we must test for
19393 DECLARATION and DW_AT_declaration. */
19395 decl_will_get_specification_p (dw_die_ref old_die, tree decl, bool declaration)
19397 return (old_die && TREE_STATIC (decl) && !declaration
19398 && get_AT_flag (old_die, DW_AT_declaration) == 1);
19401 /* Return true if DECL is a local static. */
19404 local_function_static (tree decl)
19406 gcc_assert (TREE_CODE (decl) == VAR_DECL);
19407 return TREE_STATIC (decl)
19408 && DECL_CONTEXT (decl)
19409 && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL;
19412 /* Generate a DIE to represent a declared data object.
19413 Either DECL or ORIGIN must be non-null. */
19416 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19418 HOST_WIDE_INT off = 0;
19420 tree decl_or_origin = decl ? decl : origin;
19421 tree ultimate_origin;
19422 dw_die_ref var_die;
19423 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19424 dw_die_ref origin_die = NULL;
19425 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19426 || class_or_namespace_scope_p (context_die));
19427 bool specialization_p = false;
19429 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19430 if (decl || ultimate_origin)
19431 origin = ultimate_origin;
19432 com_decl = fortran_common (decl_or_origin, &off);
19434 /* Symbol in common gets emitted as a child of the common block, in the form
19435 of a data member. */
19438 dw_die_ref com_die;
19439 dw_loc_list_ref loc;
19440 die_node com_die_arg;
19442 var_die = lookup_decl_die (decl_or_origin);
19445 if (get_AT (var_die, DW_AT_location) == NULL)
19447 loc = loc_list_from_tree (com_decl, off ? 1 : 2, NULL);
19452 /* Optimize the common case. */
19453 if (single_element_loc_list_p (loc)
19454 && loc->expr->dw_loc_opc == DW_OP_addr
19455 && loc->expr->dw_loc_next == NULL
19456 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19459 rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
19460 loc->expr->dw_loc_oprnd1.v.val_addr
19461 = plus_constant (GET_MODE (x), x , off);
19464 loc_list_plus_const (loc, off);
19466 add_AT_location_description (var_die, DW_AT_location, loc);
19467 remove_AT (var_die, DW_AT_declaration);
19473 if (common_block_die_table == NULL)
19474 common_block_die_table = hash_table<block_die_hasher>::create_ggc (10);
19476 com_die_arg.decl_id = DECL_UID (com_decl);
19477 com_die_arg.die_parent = context_die;
19478 com_die = common_block_die_table->find (&com_die_arg);
19479 loc = loc_list_from_tree (com_decl, 2, NULL);
19480 if (com_die == NULL)
19483 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19486 com_die = new_die (DW_TAG_common_block, context_die, decl);
19487 add_name_and_src_coords_attributes (com_die, com_decl);
19490 add_AT_location_description (com_die, DW_AT_location, loc);
19491 /* Avoid sharing the same loc descriptor between
19492 DW_TAG_common_block and DW_TAG_variable. */
19493 loc = loc_list_from_tree (com_decl, 2, NULL);
19495 else if (DECL_EXTERNAL (decl))
19496 add_AT_flag (com_die, DW_AT_declaration, 1);
19497 if (want_pubnames ())
19498 add_pubname_string (cnam, com_die); /* ??? needed? */
19499 com_die->decl_id = DECL_UID (com_decl);
19500 slot = common_block_die_table->find_slot (com_die, INSERT);
19503 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19505 add_AT_location_description (com_die, DW_AT_location, loc);
19506 loc = loc_list_from_tree (com_decl, 2, NULL);
19507 remove_AT (com_die, DW_AT_declaration);
19509 var_die = new_die (DW_TAG_variable, com_die, decl);
19510 add_name_and_src_coords_attributes (var_die, decl);
19511 add_type_attribute (var_die, TREE_TYPE (decl), decl_quals (decl),
19513 add_AT_flag (var_die, DW_AT_external, 1);
19518 /* Optimize the common case. */
19519 if (single_element_loc_list_p (loc)
19520 && loc->expr->dw_loc_opc == DW_OP_addr
19521 && loc->expr->dw_loc_next == NULL
19522 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19524 rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
19525 loc->expr->dw_loc_oprnd1.v.val_addr
19526 = plus_constant (GET_MODE (x), x, off);
19529 loc_list_plus_const (loc, off);
19531 add_AT_location_description (var_die, DW_AT_location, loc);
19533 else if (DECL_EXTERNAL (decl))
19534 add_AT_flag (var_die, DW_AT_declaration, 1);
19535 equate_decl_number_to_die (decl, var_die);
19543 /* A declaration that has been previously dumped, needs no
19544 further annotations, since it doesn't need location on
19545 the second pass. */
19548 else if (decl_will_get_specification_p (old_die, decl, declaration)
19549 && !get_AT (old_die, DW_AT_specification))
19551 /* Fall-thru so we can make a new variable die along with a
19552 DW_AT_specification. */
19554 else if (origin && old_die->die_parent != context_die)
19556 /* If we will be creating an inlined instance, we need a
19557 new DIE that will get annotated with
19558 DW_AT_abstract_origin. Clear things so we can get a
19560 gcc_assert (!DECL_ABSTRACT_P (decl));
19565 /* If a DIE was dumped early, it still needs location info.
19566 Skip to where we fill the location bits. */
19568 goto gen_variable_die_location;
19572 /* For static data members, the declaration in the class is supposed
19573 to have DW_TAG_member tag; the specification should still be
19574 DW_TAG_variable referencing the DW_TAG_member DIE. */
19575 if (declaration && class_scope_p (context_die))
19576 var_die = new_die (DW_TAG_member, context_die, decl);
19578 var_die = new_die (DW_TAG_variable, context_die, decl);
19580 if (origin != NULL)
19581 origin_die = add_abstract_origin_attribute (var_die, origin);
19583 /* Loop unrolling can create multiple blocks that refer to the same
19584 static variable, so we must test for the DW_AT_declaration flag.
19586 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19587 copy decls and set the DECL_ABSTRACT_P flag on them instead of
19590 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
19591 else if (decl_will_get_specification_p (old_die, decl, declaration))
19593 /* This is a definition of a C++ class level static. */
19594 add_AT_specification (var_die, old_die);
19595 specialization_p = true;
19596 if (DECL_NAME (decl))
19598 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19599 struct dwarf_file_data * file_index = lookup_filename (s.file);
19601 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19602 add_AT_file (var_die, DW_AT_decl_file, file_index);
19604 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19605 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19607 if (old_die->die_tag == DW_TAG_member)
19608 add_linkage_name (var_die, decl);
19612 add_name_and_src_coords_attributes (var_die, decl);
19614 if ((origin == NULL && !specialization_p)
19616 && !DECL_ABSTRACT_P (decl_or_origin)
19617 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19618 decl_function_context
19619 (decl_or_origin))))
19621 tree type = TREE_TYPE (decl_or_origin);
19623 if (decl_by_reference_p (decl_or_origin))
19624 add_type_attribute (var_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
19627 add_type_attribute (var_die, type, decl_quals (decl_or_origin),
19631 if (origin == NULL && !specialization_p)
19633 if (TREE_PUBLIC (decl))
19634 add_AT_flag (var_die, DW_AT_external, 1);
19636 if (DECL_ARTIFICIAL (decl))
19637 add_AT_flag (var_die, DW_AT_artificial, 1);
19639 add_accessibility_attribute (var_die, decl);
19643 add_AT_flag (var_die, DW_AT_declaration, 1);
19645 if (decl && (DECL_ABSTRACT_P (decl)
19646 || !old_die || is_declaration_die (old_die)))
19647 equate_decl_number_to_die (decl, var_die);
19649 gen_variable_die_location:
19651 && (! DECL_ABSTRACT_P (decl_or_origin)
19652 /* Local static vars are shared between all clones/inlines,
19653 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19655 || (TREE_CODE (decl_or_origin) == VAR_DECL
19656 && TREE_STATIC (decl_or_origin)
19657 && DECL_RTL_SET_P (decl_or_origin)))
19658 /* When abstract origin already has DW_AT_location attribute, no need
19659 to add it again. */
19660 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19663 add_pubname (decl_or_origin, var_die);
19665 add_location_or_const_value_attribute (var_die, decl_or_origin,
19666 decl == NULL, DW_AT_location);
19669 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19672 /* Generate a DIE to represent a named constant. */
19675 gen_const_die (tree decl, dw_die_ref context_die)
19677 dw_die_ref const_die;
19678 tree type = TREE_TYPE (decl);
19680 const_die = lookup_decl_die (decl);
19684 const_die = new_die (DW_TAG_constant, context_die, decl);
19685 equate_decl_number_to_die (decl, const_die);
19686 add_name_and_src_coords_attributes (const_die, decl);
19687 add_type_attribute (const_die, type, TYPE_QUAL_CONST, context_die);
19688 if (TREE_PUBLIC (decl))
19689 add_AT_flag (const_die, DW_AT_external, 1);
19690 if (DECL_ARTIFICIAL (decl))
19691 add_AT_flag (const_die, DW_AT_artificial, 1);
19692 tree_add_const_value_attribute_for_decl (const_die, decl);
19695 /* Generate a DIE to represent a label identifier. */
19698 gen_label_die (tree decl, dw_die_ref context_die)
19700 tree origin = decl_ultimate_origin (decl);
19701 dw_die_ref lbl_die = lookup_decl_die (decl);
19703 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19707 lbl_die = new_die (DW_TAG_label, context_die, decl);
19708 equate_decl_number_to_die (decl, lbl_die);
19710 if (origin != NULL)
19711 add_abstract_origin_attribute (lbl_die, origin);
19713 add_name_and_src_coords_attributes (lbl_die, decl);
19716 if (DECL_ABSTRACT_P (decl))
19717 equate_decl_number_to_die (decl, lbl_die);
19720 insn = DECL_RTL_IF_SET (decl);
19722 /* Deleted labels are programmer specified labels which have been
19723 eliminated because of various optimizations. We still emit them
19724 here so that it is possible to put breakpoints on them. */
19728 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19730 /* When optimization is enabled (via -O) some parts of the compiler
19731 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19732 represent source-level labels which were explicitly declared by
19733 the user. This really shouldn't be happening though, so catch
19734 it if it ever does happen. */
19735 gcc_assert (!as_a<rtx_insn *> (insn)->deleted ());
19737 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19738 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19742 && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL
19743 && CODE_LABEL_NUMBER (insn) != -1)
19745 ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn));
19746 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19751 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19752 attributes to the DIE for a block STMT, to describe where the inlined
19753 function was called from. This is similar to add_src_coords_attributes. */
19756 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19758 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19760 if (dwarf_version >= 3 || !dwarf_strict)
19762 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19763 add_AT_unsigned (die, DW_AT_call_line, s.line);
19768 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19769 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19772 add_high_low_attributes (tree stmt, dw_die_ref die)
19774 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19776 if (BLOCK_FRAGMENT_CHAIN (stmt)
19777 && (dwarf_version >= 3 || !dwarf_strict))
19779 tree chain, superblock = NULL_TREE;
19781 dw_attr_node *attr = NULL;
19783 if (inlined_function_outer_scope_p (stmt))
19785 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19786 BLOCK_NUMBER (stmt));
19787 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19790 /* Optimize duplicate .debug_ranges lists or even tails of
19791 lists. If this BLOCK has same ranges as its supercontext,
19792 lookup DW_AT_ranges attribute in the supercontext (and
19793 recursively so), verify that the ranges_table contains the
19794 right values and use it instead of adding a new .debug_range. */
19795 for (chain = stmt, pdie = die;
19796 BLOCK_SAME_RANGE (chain);
19797 chain = BLOCK_SUPERCONTEXT (chain))
19799 dw_attr_node *new_attr;
19801 pdie = pdie->die_parent;
19804 if (BLOCK_SUPERCONTEXT (chain) == NULL_TREE)
19806 new_attr = get_AT (pdie, DW_AT_ranges);
19807 if (new_attr == NULL
19808 || new_attr->dw_attr_val.val_class != dw_val_class_range_list)
19811 superblock = BLOCK_SUPERCONTEXT (chain);
19814 && (ranges_table[attr->dw_attr_val.v.val_offset
19815 / 2 / DWARF2_ADDR_SIZE].num
19816 == BLOCK_NUMBER (superblock))
19817 && BLOCK_FRAGMENT_CHAIN (superblock))
19819 unsigned long off = attr->dw_attr_val.v.val_offset
19820 / 2 / DWARF2_ADDR_SIZE;
19821 unsigned long supercnt = 0, thiscnt = 0;
19822 for (chain = BLOCK_FRAGMENT_CHAIN (superblock);
19823 chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
19826 gcc_checking_assert (ranges_table[off + supercnt].num
19827 == BLOCK_NUMBER (chain));
19829 gcc_checking_assert (ranges_table[off + supercnt + 1].num == 0);
19830 for (chain = BLOCK_FRAGMENT_CHAIN (stmt);
19831 chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
19833 gcc_assert (supercnt >= thiscnt);
19834 add_AT_range_list (die, DW_AT_ranges,
19835 ((off + supercnt - thiscnt)
19836 * 2 * DWARF2_ADDR_SIZE),
19841 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt), false);
19843 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19846 add_ranges (chain);
19847 chain = BLOCK_FRAGMENT_CHAIN (chain);
19854 char label_high[MAX_ARTIFICIAL_LABEL_BYTES];
19855 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19856 BLOCK_NUMBER (stmt));
19857 ASM_GENERATE_INTERNAL_LABEL (label_high, BLOCK_END_LABEL,
19858 BLOCK_NUMBER (stmt));
19859 add_AT_low_high_pc (die, label, label_high, false);
19863 /* Generate a DIE for a lexical block. */
19866 gen_lexical_block_die (tree stmt, dw_die_ref context_die)
19868 dw_die_ref old_die = BLOCK_DIE (stmt);
19869 dw_die_ref stmt_die = NULL;
19872 stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19873 BLOCK_DIE (stmt) = stmt_die;
19876 if (BLOCK_ABSTRACT (stmt))
19880 #ifdef ENABLE_CHECKING
19881 /* This must have been generated early and it won't even
19882 need location information since it's a DW_AT_inline
19884 for (dw_die_ref c = context_die; c; c = c->die_parent)
19885 if (c->die_tag == DW_TAG_inlined_subroutine
19886 || c->die_tag == DW_TAG_subprogram)
19888 gcc_assert (get_AT (c, DW_AT_inline));
19895 else if (BLOCK_ABSTRACT_ORIGIN (stmt))
19897 /* If this is an inlined instance, create a new lexical die for
19898 anything below to attach DW_AT_abstract_origin to. */
19901 stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19902 BLOCK_DIE (stmt) = stmt_die;
19908 stmt_die = old_die;
19910 /* A non abstract block whose blocks have already been reordered
19911 should have the instruction range for this block. If so, set the
19912 high/low attributes. */
19913 if (!early_dwarf && !BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19915 gcc_assert (stmt_die);
19916 add_high_low_attributes (stmt, stmt_die);
19919 decls_for_scope (stmt, stmt_die);
19922 /* Generate a DIE for an inlined subprogram. */
19925 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die)
19929 /* The instance of function that is effectively being inlined shall not
19931 gcc_assert (! BLOCK_ABSTRACT (stmt));
19933 decl = block_ultimate_origin (stmt);
19935 /* Make sure any inlined functions are known to be inlineable. */
19936 gcc_checking_assert (DECL_ABSTRACT_P (decl)
19937 || cgraph_function_possibly_inlined_p (decl));
19939 /* Emit info for the abstract instance first, if we haven't yet. We
19940 must emit this even if the block is abstract, otherwise when we
19941 emit the block below (or elsewhere), we may end up trying to emit
19942 a die whose origin die hasn't been emitted, and crashing. */
19943 dwarf2out_abstract_function (decl);
19945 if (! BLOCK_ABSTRACT (stmt))
19947 dw_die_ref subr_die
19948 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
19950 if (call_arg_locations)
19951 BLOCK_DIE (stmt) = subr_die;
19952 add_abstract_origin_attribute (subr_die, decl);
19953 if (TREE_ASM_WRITTEN (stmt))
19954 add_high_low_attributes (stmt, subr_die);
19955 add_call_src_coords_attributes (stmt, subr_die);
19957 decls_for_scope (stmt, subr_die);
19961 /* Generate a DIE for a field in a record, or structure. */
19964 gen_field_die (tree decl, dw_die_ref context_die)
19966 dw_die_ref decl_die;
19968 if (TREE_TYPE (decl) == error_mark_node)
19971 decl_die = new_die (DW_TAG_member, context_die, decl);
19972 add_name_and_src_coords_attributes (decl_die, decl);
19973 add_type_attribute (decl_die, member_declared_type (decl),
19974 decl_quals (decl), context_die);
19976 if (DECL_BIT_FIELD_TYPE (decl))
19978 add_byte_size_attribute (decl_die, decl);
19979 add_bit_size_attribute (decl_die, decl);
19980 add_bit_offset_attribute (decl_die, decl);
19983 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
19984 add_data_member_location_attribute (decl_die, decl);
19986 if (DECL_ARTIFICIAL (decl))
19987 add_AT_flag (decl_die, DW_AT_artificial, 1);
19989 add_accessibility_attribute (decl_die, decl);
19991 /* Equate decl number to die, so that we can look up this decl later on. */
19992 equate_decl_number_to_die (decl, decl_die);
19996 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19997 Use modified_type_die instead.
19998 We keep this code here just in case these types of DIEs may be needed to
19999 represent certain things in other languages (e.g. Pascal) someday. */
20002 gen_pointer_type_die (tree type, dw_die_ref context_die)
20005 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
20007 equate_type_number_to_die (type, ptr_die);
20008 add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
20010 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20013 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20014 Use modified_type_die instead.
20015 We keep this code here just in case these types of DIEs may be needed to
20016 represent certain things in other languages (e.g. Pascal) someday. */
20019 gen_reference_type_die (tree type, dw_die_ref context_die)
20021 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
20023 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
20024 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
20026 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
20028 equate_type_number_to_die (type, ref_die);
20029 add_type_attribute (ref_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
20031 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20035 /* Generate a DIE for a pointer to a member type. */
20038 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
20041 = new_die (DW_TAG_ptr_to_member_type,
20042 scope_die_for (type, context_die), type);
20044 equate_type_number_to_die (type, ptr_die);
20045 add_AT_die_ref (ptr_die, DW_AT_containing_type,
20046 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
20047 add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
20051 static char *producer_string;
20053 /* Return a heap allocated producer string including command line options
20054 if -grecord-gcc-switches. */
20057 gen_producer_string (void)
20060 auto_vec<const char *> switches;
20061 const char *language_string = lang_hooks.name;
20062 char *producer, *tail;
20064 size_t len = dwarf_record_gcc_switches ? 0 : 3;
20065 size_t plen = strlen (language_string) + 1 + strlen (version_string);
20067 for (j = 1; dwarf_record_gcc_switches && j < save_decoded_options_count; j++)
20068 switch (save_decoded_options[j].opt_index)
20075 case OPT_auxbase_strip:
20084 case OPT_SPECIAL_unknown:
20085 case OPT_SPECIAL_ignore:
20086 case OPT_SPECIAL_program_name:
20087 case OPT_SPECIAL_input_file:
20088 case OPT_grecord_gcc_switches:
20089 case OPT_gno_record_gcc_switches:
20090 case OPT__output_pch_:
20091 case OPT_fdiagnostics_show_location_:
20092 case OPT_fdiagnostics_show_option:
20093 case OPT_fdiagnostics_show_caret:
20094 case OPT_fdiagnostics_color_:
20095 case OPT_fverbose_asm:
20097 case OPT__sysroot_:
20099 case OPT_nostdinc__:
20100 case OPT_fpreprocessed:
20101 case OPT_fltrans_output_list_:
20102 case OPT_fresolution_:
20103 /* Ignore these. */
20106 if (cl_options[save_decoded_options[j].opt_index].flags
20107 & CL_NO_DWARF_RECORD)
20109 gcc_checking_assert (save_decoded_options[j].canonical_option[0][0]
20111 switch (save_decoded_options[j].canonical_option[0][1])
20118 if (strncmp (save_decoded_options[j].canonical_option[0] + 2,
20125 switches.safe_push (save_decoded_options[j].orig_option_with_args_text);
20126 len += strlen (save_decoded_options[j].orig_option_with_args_text) + 1;
20130 producer = XNEWVEC (char, plen + 1 + len + 1);
20132 sprintf (tail, "%s %s", language_string, version_string);
20135 FOR_EACH_VEC_ELT (switches, j, p)
20139 memcpy (tail + 1, p, len);
20147 /* Given a C and/or C++ language/version string return the "highest".
20148 C++ is assumed to be "higher" than C in this case. Used for merging
20149 LTO translation unit languages. */
20150 static const char *
20151 highest_c_language (const char *lang1, const char *lang2)
20153 if (strcmp ("GNU C++14", lang1) == 0 || strcmp ("GNU C++14", lang2) == 0)
20154 return "GNU C++14";
20155 if (strcmp ("GNU C++11", lang1) == 0 || strcmp ("GNU C++11", lang2) == 0)
20156 return "GNU C++11";
20157 if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) == 0)
20158 return "GNU C++98";
20160 if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
20162 if (strcmp ("GNU C99", lang1) == 0 || strcmp ("GNU C99", lang2) == 0)
20164 if (strcmp ("GNU C89", lang1) == 0 || strcmp ("GNU C89", lang2) == 0)
20167 gcc_unreachable ();
20171 /* Generate the DIE for the compilation unit. */
20174 gen_compile_unit_die (const char *filename)
20177 const char *language_string = lang_hooks.name;
20180 die = new_die (DW_TAG_compile_unit, NULL, NULL);
20184 add_name_attribute (die, filename);
20185 /* Don't add cwd for <built-in>. */
20186 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
20187 add_comp_dir_attribute (die);
20190 add_AT_string (die, DW_AT_producer, producer_string ? producer_string : "");
20192 /* If our producer is LTO try to figure out a common language to use
20193 from the global list of translation units. */
20194 if (strcmp (language_string, "GNU GIMPLE") == 0)
20198 const char *common_lang = NULL;
20200 FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t)
20202 if (!TRANSLATION_UNIT_LANGUAGE (t))
20205 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
20206 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
20208 else if (strncmp (common_lang, "GNU C", 5) == 0
20209 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
20210 /* Mixing C and C++ is ok, use C++ in that case. */
20211 common_lang = highest_c_language (common_lang,
20212 TRANSLATION_UNIT_LANGUAGE (t));
20215 /* Fall back to C. */
20216 common_lang = NULL;
20222 language_string = common_lang;
20225 language = DW_LANG_C;
20226 if (strncmp (language_string, "GNU C", 5) == 0
20227 && ISDIGIT (language_string[5]))
20229 language = DW_LANG_C89;
20230 if (dwarf_version >= 3 || !dwarf_strict)
20232 if (strcmp (language_string, "GNU C89") != 0)
20233 language = DW_LANG_C99;
20235 if (dwarf_version >= 5 /* || !dwarf_strict */)
20236 if (strcmp (language_string, "GNU C11") == 0)
20237 language = DW_LANG_C11;
20240 else if (strncmp (language_string, "GNU C++", 7) == 0)
20242 language = DW_LANG_C_plus_plus;
20243 if (dwarf_version >= 5 /* || !dwarf_strict */)
20245 if (strcmp (language_string, "GNU C++11") == 0)
20246 language = DW_LANG_C_plus_plus_11;
20247 else if (strcmp (language_string, "GNU C++14") == 0)
20248 language = DW_LANG_C_plus_plus_14;
20251 else if (strcmp (language_string, "GNU F77") == 0)
20252 language = DW_LANG_Fortran77;
20253 else if (strcmp (language_string, "GNU Pascal") == 0)
20254 language = DW_LANG_Pascal83;
20255 else if (dwarf_version >= 3 || !dwarf_strict)
20257 if (strcmp (language_string, "GNU Ada") == 0)
20258 language = DW_LANG_Ada95;
20259 else if (strncmp (language_string, "GNU Fortran", 11) == 0)
20261 language = DW_LANG_Fortran95;
20262 if (dwarf_version >= 5 /* || !dwarf_strict */)
20264 if (strcmp (language_string, "GNU Fortran2003") == 0)
20265 language = DW_LANG_Fortran03;
20266 else if (strcmp (language_string, "GNU Fortran2008") == 0)
20267 language = DW_LANG_Fortran08;
20270 else if (strcmp (language_string, "GNU Java") == 0)
20271 language = DW_LANG_Java;
20272 else if (strcmp (language_string, "GNU Objective-C") == 0)
20273 language = DW_LANG_ObjC;
20274 else if (strcmp (language_string, "GNU Objective-C++") == 0)
20275 language = DW_LANG_ObjC_plus_plus;
20276 else if (dwarf_version >= 5 || !dwarf_strict)
20278 if (strcmp (language_string, "GNU Go") == 0)
20279 language = DW_LANG_Go;
20282 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
20283 else if (strncmp (language_string, "GNU Fortran", 11) == 0)
20284 language = DW_LANG_Fortran90;
20286 add_AT_unsigned (die, DW_AT_language, language);
20290 case DW_LANG_Fortran77:
20291 case DW_LANG_Fortran90:
20292 case DW_LANG_Fortran95:
20293 case DW_LANG_Fortran03:
20294 case DW_LANG_Fortran08:
20295 /* Fortran has case insensitive identifiers and the front-end
20296 lowercases everything. */
20297 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
20300 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20306 /* Generate the DIE for a base class. */
20309 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
20311 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
20313 add_type_attribute (die, BINFO_TYPE (binfo), TYPE_UNQUALIFIED, context_die);
20314 add_data_member_location_attribute (die, binfo);
20316 if (BINFO_VIRTUAL_P (binfo))
20317 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
20319 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20320 children, otherwise the default is DW_ACCESS_public. In DWARF2
20321 the default has always been DW_ACCESS_private. */
20322 if (access == access_public_node)
20324 if (dwarf_version == 2
20325 || context_die->die_tag == DW_TAG_class_type)
20326 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20328 else if (access == access_protected_node)
20329 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20330 else if (dwarf_version > 2
20331 && context_die->die_tag != DW_TAG_class_type)
20332 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20335 /* Generate a DIE for a class member. */
20338 gen_member_die (tree type, dw_die_ref context_die)
20341 tree binfo = TYPE_BINFO (type);
20344 /* If this is not an incomplete type, output descriptions of each of its
20345 members. Note that as we output the DIEs necessary to represent the
20346 members of this record or union type, we will also be trying to output
20347 DIEs to represent the *types* of those members. However the `type'
20348 function (above) will specifically avoid generating type DIEs for member
20349 types *within* the list of member DIEs for this (containing) type except
20350 for those types (of members) which are explicitly marked as also being
20351 members of this (containing) type themselves. The g++ front- end can
20352 force any given type to be treated as a member of some other (containing)
20353 type by setting the TYPE_CONTEXT of the given (member) type to point to
20354 the TREE node representing the appropriate (containing) type. */
20356 /* First output info about the base classes. */
20359 vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
20363 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
20364 gen_inheritance_die (base,
20365 (accesses ? (*accesses)[i] : access_public_node),
20369 /* Now output info about the data members and type members. */
20370 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
20372 /* If we thought we were generating minimal debug info for TYPE
20373 and then changed our minds, some of the member declarations
20374 may have already been defined. Don't define them again, but
20375 do put them in the right order. */
20377 child = lookup_decl_die (member);
20379 splice_child_die (context_die, child);
20381 gen_decl_die (member, NULL, context_die);
20384 /* We do not keep type methods in type variants. */
20385 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
20386 /* Now output info about the function members (if any). */
20387 if (TYPE_METHODS (type) != error_mark_node)
20388 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
20390 /* Don't include clones in the member list. */
20391 if (DECL_ABSTRACT_ORIGIN (member))
20393 /* Nor constructors for anonymous classes. */
20394 if (DECL_ARTIFICIAL (member)
20395 && dwarf2_name (member, 0) == NULL)
20398 child = lookup_decl_die (member);
20400 splice_child_die (context_die, child);
20402 gen_decl_die (member, NULL, context_die);
20406 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20407 is set, we pretend that the type was never defined, so we only get the
20408 member DIEs needed by later specification DIEs. */
20411 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
20412 enum debug_info_usage usage)
20414 if (TREE_ASM_WRITTEN (type))
20416 /* Fill in the bound of variable-length fields in late dwarf if
20417 still incomplete. */
20418 if (!early_dwarf && variably_modified_type_p (type, NULL))
20419 for (tree member = TYPE_FIELDS (type);
20421 member = DECL_CHAIN (member))
20422 fill_variable_array_bounds (TREE_TYPE (member));
20426 dw_die_ref type_die = lookup_type_die (type);
20427 dw_die_ref scope_die = 0;
20429 int complete = (TYPE_SIZE (type)
20430 && (! TYPE_STUB_DECL (type)
20431 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20432 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20433 complete = complete && should_emit_struct_debug (type, usage);
20435 if (type_die && ! complete)
20438 if (TYPE_CONTEXT (type) != NULL_TREE
20439 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20440 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20443 scope_die = scope_die_for (type, context_die);
20445 /* Generate child dies for template paramaters. */
20446 if (!type_die && debug_info_level > DINFO_LEVEL_TERSE)
20447 schedule_generic_params_dies_gen (type);
20449 if (! type_die || (nested && is_cu_die (scope_die)))
20450 /* First occurrence of type or toplevel definition of nested class. */
20452 dw_die_ref old_die = type_die;
20454 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20455 ? record_type_tag (type) : DW_TAG_union_type,
20457 equate_type_number_to_die (type, type_die);
20459 add_AT_specification (type_die, old_die);
20461 add_name_attribute (type_die, type_tag (type));
20464 remove_AT (type_die, DW_AT_declaration);
20466 /* If this type has been completed, then give it a byte_size attribute and
20467 then give a list of members. */
20468 if (complete && !ns_decl)
20470 /* Prevent infinite recursion in cases where the type of some member of
20471 this type is expressed in terms of this type itself. */
20472 TREE_ASM_WRITTEN (type) = 1;
20473 add_byte_size_attribute (type_die, type);
20474 if (TYPE_STUB_DECL (type) != NULL_TREE)
20476 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20477 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20480 /* If the first reference to this type was as the return type of an
20481 inline function, then it may not have a parent. Fix this now. */
20482 if (type_die->die_parent == NULL)
20483 add_child_die (scope_die, type_die);
20485 push_decl_scope (type);
20486 gen_member_die (type, type_die);
20489 add_gnat_descriptive_type_attribute (type_die, type, context_die);
20490 if (TYPE_ARTIFICIAL (type))
20491 add_AT_flag (type_die, DW_AT_artificial, 1);
20493 /* GNU extension: Record what type our vtable lives in. */
20494 if (TYPE_VFIELD (type))
20496 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20498 gen_type_die (vtype, context_die);
20499 add_AT_die_ref (type_die, DW_AT_containing_type,
20500 lookup_type_die (vtype));
20505 add_AT_flag (type_die, DW_AT_declaration, 1);
20507 /* We don't need to do this for function-local types. */
20508 if (TYPE_STUB_DECL (type)
20509 && ! decl_function_context (TYPE_STUB_DECL (type)))
20510 vec_safe_push (incomplete_types, type);
20513 if (get_AT (type_die, DW_AT_name))
20514 add_pubtype (type, type_die);
20517 /* Generate a DIE for a subroutine _type_. */
20520 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20522 tree return_type = TREE_TYPE (type);
20523 dw_die_ref subr_die
20524 = new_die (DW_TAG_subroutine_type,
20525 scope_die_for (type, context_die), type);
20527 equate_type_number_to_die (type, subr_die);
20528 add_prototyped_attribute (subr_die, type);
20529 add_type_attribute (subr_die, return_type, TYPE_UNQUALIFIED, context_die);
20530 gen_formal_types_die (type, subr_die);
20532 if (get_AT (subr_die, DW_AT_name))
20533 add_pubtype (type, subr_die);
20536 /* Generate a DIE for a type definition. */
20539 gen_typedef_die (tree decl, dw_die_ref context_die)
20541 dw_die_ref type_die;
20544 if (TREE_ASM_WRITTEN (decl))
20546 if (DECL_ORIGINAL_TYPE (decl))
20547 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl));
20551 TREE_ASM_WRITTEN (decl) = 1;
20552 type_die = new_die (DW_TAG_typedef, context_die, decl);
20553 origin = decl_ultimate_origin (decl);
20554 if (origin != NULL)
20555 add_abstract_origin_attribute (type_die, origin);
20560 add_name_and_src_coords_attributes (type_die, decl);
20561 if (DECL_ORIGINAL_TYPE (decl))
20563 type = DECL_ORIGINAL_TYPE (decl);
20565 if (type == error_mark_node)
20568 gcc_assert (type != TREE_TYPE (decl));
20569 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20573 type = TREE_TYPE (decl);
20575 if (type == error_mark_node)
20578 if (is_naming_typedef_decl (TYPE_NAME (type)))
20580 /* Here, we are in the case of decl being a typedef naming
20581 an anonymous type, e.g:
20582 typedef struct {...} foo;
20583 In that case TREE_TYPE (decl) is not a typedef variant
20584 type and TYPE_NAME of the anonymous type is set to the
20585 TYPE_DECL of the typedef. This construct is emitted by
20588 TYPE is the anonymous struct named by the typedef
20589 DECL. As we need the DW_AT_type attribute of the
20590 DW_TAG_typedef to point to the DIE of TYPE, let's
20591 generate that DIE right away. add_type_attribute
20592 called below will then pick (via lookup_type_die) that
20593 anonymous struct DIE. */
20594 if (!TREE_ASM_WRITTEN (type))
20595 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20597 /* This is a GNU Extension. We are adding a
20598 DW_AT_linkage_name attribute to the DIE of the
20599 anonymous struct TYPE. The value of that attribute
20600 is the name of the typedef decl naming the anonymous
20601 struct. This greatly eases the work of consumers of
20602 this debug info. */
20603 add_linkage_attr (lookup_type_die (type), decl);
20607 add_type_attribute (type_die, type, decl_quals (decl), context_die);
20609 if (is_naming_typedef_decl (decl))
20610 /* We want that all subsequent calls to lookup_type_die with
20611 TYPE in argument yield the DW_TAG_typedef we have just
20613 equate_type_number_to_die (type, type_die);
20615 add_accessibility_attribute (type_die, decl);
20618 if (DECL_ABSTRACT_P (decl))
20619 equate_decl_number_to_die (decl, type_die);
20621 if (get_AT (type_die, DW_AT_name))
20622 add_pubtype (decl, type_die);
20625 /* Generate a DIE for a struct, class, enum or union type. */
20628 gen_tagged_type_die (tree type,
20629 dw_die_ref context_die,
20630 enum debug_info_usage usage)
20634 if (type == NULL_TREE
20635 || !is_tagged_type (type))
20638 if (TREE_ASM_WRITTEN (type))
20640 /* If this is a nested type whose containing class hasn't been written
20641 out yet, writing it out will cover this one, too. This does not apply
20642 to instantiations of member class templates; they need to be added to
20643 the containing class as they are generated. FIXME: This hurts the
20644 idea of combining type decls from multiple TUs, since we can't predict
20645 what set of template instantiations we'll get. */
20646 else if (TYPE_CONTEXT (type)
20647 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20648 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20650 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20652 if (TREE_ASM_WRITTEN (type))
20655 /* If that failed, attach ourselves to the stub. */
20656 push_decl_scope (TYPE_CONTEXT (type));
20657 context_die = lookup_type_die (TYPE_CONTEXT (type));
20660 else if (TYPE_CONTEXT (type) != NULL_TREE
20661 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20663 /* If this type is local to a function that hasn't been written
20664 out yet, use a NULL context for now; it will be fixed up in
20665 decls_for_scope. */
20666 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20667 /* A declaration DIE doesn't count; nested types need to go in the
20669 if (context_die && is_declaration_die (context_die))
20670 context_die = NULL;
20675 context_die = declare_in_namespace (type, context_die);
20679 if (TREE_CODE (type) == ENUMERAL_TYPE)
20681 /* This might have been written out by the call to
20682 declare_in_namespace. */
20683 if (!TREE_ASM_WRITTEN (type))
20684 gen_enumeration_type_die (type, context_die);
20687 gen_struct_or_union_type_die (type, context_die, usage);
20692 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20693 it up if it is ever completed. gen_*_type_die will set it for us
20694 when appropriate. */
20697 /* Generate a type description DIE. */
20700 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20701 enum debug_info_usage usage)
20703 struct array_descr_info info;
20705 if (type == NULL_TREE || type == error_mark_node)
20708 #ifdef ENABLE_CHECKING
20710 verify_type (type);
20713 if (TYPE_NAME (type) != NULL_TREE
20714 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
20715 && is_redundant_typedef (TYPE_NAME (type))
20716 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
20717 /* The DECL of this type is a typedef we don't want to emit debug
20718 info for but we want debug info for its underlying typedef.
20719 This can happen for e.g, the injected-class-name of a C++
20721 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
20723 /* If TYPE is a typedef type variant, let's generate debug info
20724 for the parent typedef which TYPE is a type of. */
20725 if (typedef_variant_p (type))
20727 if (TREE_ASM_WRITTEN (type))
20730 /* Prevent broken recursion; we can't hand off to the same type. */
20731 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20733 /* Give typedefs the right scope. */
20734 context_die = scope_die_for (type, context_die);
20736 TREE_ASM_WRITTEN (type) = 1;
20738 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20742 /* If type is an anonymous tagged type named by a typedef, let's
20743 generate debug info for the typedef. */
20744 if (is_naming_typedef_decl (TYPE_NAME (type)))
20746 /* Use the DIE of the containing namespace as the parent DIE of
20747 the type description DIE we want to generate. */
20748 if (DECL_CONTEXT (TYPE_NAME (type))
20749 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20750 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20752 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20756 /* We are going to output a DIE to represent the unqualified version
20757 of this type (i.e. without any const or volatile qualifiers) so
20758 get the main variant (i.e. the unqualified version) of this type
20759 now. (Vectors are special because the debugging info is in the
20760 cloned type itself). */
20761 if (TREE_CODE (type) != VECTOR_TYPE)
20762 type = type_main_variant (type);
20764 /* If this is an array type with hidden descriptor, handle it first. */
20765 if (!TREE_ASM_WRITTEN (type)
20766 && lang_hooks.types.get_array_descr_info)
20768 memset (&info, 0, sizeof (info));
20769 if (lang_hooks.types.get_array_descr_info (type, &info))
20771 gen_descr_array_type_die (type, &info, context_die);
20772 TREE_ASM_WRITTEN (type) = 1;
20777 if (TREE_ASM_WRITTEN (type))
20779 /* Variable-length types may be incomplete even if
20780 TREE_ASM_WRITTEN. For such types, fall through to
20781 gen_array_type_die() and possibly fill in
20782 DW_AT_{upper,lower}_bound attributes. */
20783 if ((TREE_CODE (type) != ARRAY_TYPE
20784 && TREE_CODE (type) != RECORD_TYPE
20785 && TREE_CODE (type) != UNION_TYPE
20786 && TREE_CODE (type) != QUAL_UNION_TYPE)
20787 || !variably_modified_type_p (type, NULL))
20791 switch (TREE_CODE (type))
20797 case REFERENCE_TYPE:
20798 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20799 ensures that the gen_type_die recursion will terminate even if the
20800 type is recursive. Recursive types are possible in Ada. */
20801 /* ??? We could perhaps do this for all types before the switch
20803 TREE_ASM_WRITTEN (type) = 1;
20805 /* For these types, all that is required is that we output a DIE (or a
20806 set of DIEs) to represent the "basis" type. */
20807 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20808 DINFO_USAGE_IND_USE);
20812 /* This code is used for C++ pointer-to-data-member types.
20813 Output a description of the relevant class type. */
20814 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20815 DINFO_USAGE_IND_USE);
20817 /* Output a description of the type of the object pointed to. */
20818 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20819 DINFO_USAGE_IND_USE);
20821 /* Now output a DIE to represent this pointer-to-data-member type
20823 gen_ptr_to_mbr_type_die (type, context_die);
20826 case FUNCTION_TYPE:
20827 /* Force out return type (in case it wasn't forced out already). */
20828 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20829 DINFO_USAGE_DIR_USE);
20830 gen_subroutine_type_die (type, context_die);
20834 /* Force out return type (in case it wasn't forced out already). */
20835 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20836 DINFO_USAGE_DIR_USE);
20837 gen_subroutine_type_die (type, context_die);
20842 gen_array_type_die (type, context_die);
20845 case ENUMERAL_TYPE:
20848 case QUAL_UNION_TYPE:
20849 gen_tagged_type_die (type, context_die, usage);
20855 case FIXED_POINT_TYPE:
20858 case POINTER_BOUNDS_TYPE:
20859 /* No DIEs needed for fundamental types. */
20864 /* Just use DW_TAG_unspecified_type. */
20866 dw_die_ref type_die = lookup_type_die (type);
20867 if (type_die == NULL)
20869 tree name = TYPE_IDENTIFIER (type);
20870 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (),
20872 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20873 equate_type_number_to_die (type, type_die);
20879 if (is_cxx_auto (type))
20881 tree name = TYPE_IDENTIFIER (type);
20882 dw_die_ref *die = (name == get_identifier ("auto")
20883 ? &auto_die : &decltype_auto_die);
20886 *die = new_die (DW_TAG_unspecified_type,
20887 comp_unit_die (), NULL_TREE);
20888 add_name_attribute (*die, IDENTIFIER_POINTER (name));
20890 equate_type_number_to_die (type, *die);
20893 gcc_unreachable ();
20896 TREE_ASM_WRITTEN (type) = 1;
20900 gen_type_die (tree type, dw_die_ref context_die)
20902 if (type != error_mark_node)
20904 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20905 #ifdef ENABLE_CHECKING
20906 dw_die_ref die = lookup_type_die (type);
20913 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20914 things which are local to the given block. */
20917 gen_block_die (tree stmt, dw_die_ref context_die)
20919 int must_output_die = 0;
20922 /* Ignore blocks that are NULL. */
20923 if (stmt == NULL_TREE)
20926 inlined_func = inlined_function_outer_scope_p (stmt);
20928 /* If the block is one fragment of a non-contiguous block, do not
20929 process the variables, since they will have been done by the
20930 origin block. Do process subblocks. */
20931 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20935 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20936 gen_block_die (sub, context_die);
20941 /* Determine if we need to output any Dwarf DIEs at all to represent this
20944 /* The outer scopes for inlinings *must* always be represented. We
20945 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20946 must_output_die = 1;
20949 /* Determine if this block directly contains any "significant"
20950 local declarations which we will need to output DIEs for. */
20951 if (debug_info_level > DINFO_LEVEL_TERSE)
20952 /* We are not in terse mode so *any* local declaration counts
20953 as being a "significant" one. */
20954 must_output_die = ((BLOCK_VARS (stmt) != NULL
20955 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20956 && (TREE_USED (stmt)
20957 || TREE_ASM_WRITTEN (stmt)
20958 || BLOCK_ABSTRACT (stmt)));
20959 else if ((TREE_USED (stmt)
20960 || TREE_ASM_WRITTEN (stmt)
20961 || BLOCK_ABSTRACT (stmt))
20962 && !dwarf2out_ignore_block (stmt))
20963 must_output_die = 1;
20966 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20967 DIE for any block which contains no significant local declarations at
20968 all. Rather, in such cases we just call `decls_for_scope' so that any
20969 needed Dwarf info for any sub-blocks will get properly generated. Note
20970 that in terse mode, our definition of what constitutes a "significant"
20971 local declaration gets restricted to include only inlined function
20972 instances and local (nested) function definitions. */
20973 if (must_output_die)
20977 /* If STMT block is abstract, that means we have been called
20978 indirectly from dwarf2out_abstract_function.
20979 That function rightfully marks the descendent blocks (of
20980 the abstract function it is dealing with) as being abstract,
20981 precisely to prevent us from emitting any
20982 DW_TAG_inlined_subroutine DIE as a descendent
20983 of an abstract function instance. So in that case, we should
20984 not call gen_inlined_subroutine_die.
20986 Later though, when cgraph asks dwarf2out to emit info
20987 for the concrete instance of the function decl into which
20988 the concrete instance of STMT got inlined, the later will lead
20989 to the generation of a DW_TAG_inlined_subroutine DIE. */
20990 if (! BLOCK_ABSTRACT (stmt))
20991 gen_inlined_subroutine_die (stmt, context_die);
20994 gen_lexical_block_die (stmt, context_die);
20997 decls_for_scope (stmt, context_die);
21000 /* Process variable DECL (or variable with origin ORIGIN) within
21001 block STMT and add it to CONTEXT_DIE. */
21003 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
21006 tree decl_or_origin = decl ? decl : origin;
21008 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
21009 die = lookup_decl_die (decl_or_origin);
21010 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
21011 && TYPE_DECL_IS_STUB (decl_or_origin))
21012 die = lookup_type_die (TREE_TYPE (decl_or_origin));
21016 if (die != NULL && die->die_parent == NULL)
21017 add_child_die (context_die, die);
21018 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
21021 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
21022 stmt, context_die);
21025 gen_decl_die (decl, origin, context_die);
21028 /* Generate all of the decls declared within a given scope and (recursively)
21029 all of its sub-blocks. */
21032 decls_for_scope (tree stmt, dw_die_ref context_die)
21038 /* Ignore NULL blocks. */
21039 if (stmt == NULL_TREE)
21042 /* Output the DIEs to represent all of the data objects and typedefs
21043 declared directly within this block but not within any nested
21044 sub-blocks. Also, nested function and tag DIEs have been
21045 generated with a parent of NULL; fix that up now. We don't
21046 have to do this if we're at -g1. */
21047 if (debug_info_level > DINFO_LEVEL_TERSE)
21049 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
21050 process_scope_var (stmt, decl, NULL_TREE, context_die);
21051 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
21052 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
21056 /* Even if we're at -g1, we need to process the subblocks in order to get
21057 inlined call information. */
21059 /* Output the DIEs to represent all sub-blocks (and the items declared
21060 therein) of this block. */
21061 for (subblocks = BLOCK_SUBBLOCKS (stmt);
21063 subblocks = BLOCK_CHAIN (subblocks))
21064 gen_block_die (subblocks, context_die);
21067 /* Is this a typedef we can avoid emitting? */
21070 is_redundant_typedef (const_tree decl)
21072 if (TYPE_DECL_IS_STUB (decl))
21075 if (DECL_ARTIFICIAL (decl)
21076 && DECL_CONTEXT (decl)
21077 && is_tagged_type (DECL_CONTEXT (decl))
21078 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
21079 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
21080 /* Also ignore the artificial member typedef for the class name. */
21086 /* Return TRUE if TYPE is a typedef that names a type for linkage
21087 purposes. This kind of typedefs is produced by the C++ FE for
21090 typedef struct {...} foo;
21092 In that case, there is no typedef variant type produced for foo.
21093 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
21097 is_naming_typedef_decl (const_tree decl)
21099 if (decl == NULL_TREE
21100 || TREE_CODE (decl) != TYPE_DECL
21101 || !is_tagged_type (TREE_TYPE (decl))
21102 || DECL_IS_BUILTIN (decl)
21103 || is_redundant_typedef (decl)
21104 /* It looks like Ada produces TYPE_DECLs that are very similar
21105 to C++ naming typedefs but that have different
21106 semantics. Let's be specific to c++ for now. */
21110 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
21111 && TYPE_NAME (TREE_TYPE (decl)) == decl
21112 && (TYPE_STUB_DECL (TREE_TYPE (decl))
21113 != TYPE_NAME (TREE_TYPE (decl))));
21116 /* Looks up the DIE for a context. */
21118 static inline dw_die_ref
21119 lookup_context_die (tree context)
21123 /* Find die that represents this context. */
21124 if (TYPE_P (context))
21126 context = TYPE_MAIN_VARIANT (context);
21127 dw_die_ref ctx = lookup_type_die (context);
21130 return strip_naming_typedef (context, ctx);
21133 return lookup_decl_die (context);
21135 return comp_unit_die ();
21138 /* Returns the DIE for a context. */
21140 static inline dw_die_ref
21141 get_context_die (tree context)
21145 /* Find die that represents this context. */
21146 if (TYPE_P (context))
21148 context = TYPE_MAIN_VARIANT (context);
21149 return strip_naming_typedef (context, force_type_die (context));
21152 return force_decl_die (context);
21154 return comp_unit_die ();
21157 /* Returns the DIE for decl. A DIE will always be returned. */
21160 force_decl_die (tree decl)
21162 dw_die_ref decl_die;
21163 unsigned saved_external_flag;
21164 tree save_fn = NULL_TREE;
21165 decl_die = lookup_decl_die (decl);
21168 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
21170 decl_die = lookup_decl_die (decl);
21174 switch (TREE_CODE (decl))
21176 case FUNCTION_DECL:
21177 /* Clear current_function_decl, so that gen_subprogram_die thinks
21178 that this is a declaration. At this point, we just want to force
21179 declaration die. */
21180 save_fn = current_function_decl;
21181 current_function_decl = NULL_TREE;
21182 gen_subprogram_die (decl, context_die);
21183 current_function_decl = save_fn;
21187 /* Set external flag to force declaration die. Restore it after
21188 gen_decl_die() call. */
21189 saved_external_flag = DECL_EXTERNAL (decl);
21190 DECL_EXTERNAL (decl) = 1;
21191 gen_decl_die (decl, NULL, context_die);
21192 DECL_EXTERNAL (decl) = saved_external_flag;
21195 case NAMESPACE_DECL:
21196 if (dwarf_version >= 3 || !dwarf_strict)
21197 dwarf2out_decl (decl);
21199 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21200 decl_die = comp_unit_die ();
21203 case TRANSLATION_UNIT_DECL:
21204 decl_die = comp_unit_die ();
21208 gcc_unreachable ();
21211 /* We should be able to find the DIE now. */
21213 decl_die = lookup_decl_die (decl);
21214 gcc_assert (decl_die);
21220 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21221 always returned. */
21224 force_type_die (tree type)
21226 dw_die_ref type_die;
21228 type_die = lookup_type_die (type);
21231 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
21233 type_die = modified_type_die (type, TYPE_QUALS_NO_ADDR_SPACE (type),
21235 gcc_assert (type_die);
21240 /* Force out any required namespaces to be able to output DECL,
21241 and return the new context_die for it, if it's changed. */
21244 setup_namespace_context (tree thing, dw_die_ref context_die)
21246 tree context = (DECL_P (thing)
21247 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
21248 if (context && TREE_CODE (context) == NAMESPACE_DECL)
21249 /* Force out the namespace. */
21250 context_die = force_decl_die (context);
21252 return context_die;
21255 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21256 type) within its namespace, if appropriate.
21258 For compatibility with older debuggers, namespace DIEs only contain
21259 declarations; all definitions are emitted at CU scope, with
21260 DW_AT_specification pointing to the declaration (like with class
21264 declare_in_namespace (tree thing, dw_die_ref context_die)
21266 dw_die_ref ns_context;
21268 if (debug_info_level <= DINFO_LEVEL_TERSE)
21269 return context_die;
21271 /* External declarations in the local scope only need to be emitted
21272 once, not once in the namespace and once in the scope.
21274 This avoids declaring the `extern' below in the
21275 namespace DIE as well as in the innermost scope:
21288 if (DECL_P (thing) && DECL_EXTERNAL (thing) && local_scope_p (context_die))
21289 return context_die;
21291 /* If this decl is from an inlined function, then don't try to emit it in its
21292 namespace, as we will get confused. It would have already been emitted
21293 when the abstract instance of the inline function was emitted anyways. */
21294 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
21295 return context_die;
21297 ns_context = setup_namespace_context (thing, context_die);
21299 if (ns_context != context_die)
21303 if (DECL_P (thing))
21304 gen_decl_die (thing, NULL, ns_context);
21306 gen_type_die (thing, ns_context);
21308 return context_die;
21311 /* Generate a DIE for a namespace or namespace alias. */
21314 gen_namespace_die (tree decl, dw_die_ref context_die)
21316 dw_die_ref namespace_die;
21318 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21319 they are an alias of. */
21320 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
21322 /* Output a real namespace or module. */
21323 context_die = setup_namespace_context (decl, comp_unit_die ());
21324 namespace_die = new_die (is_fortran ()
21325 ? DW_TAG_module : DW_TAG_namespace,
21326 context_die, decl);
21327 /* For Fortran modules defined in different CU don't add src coords. */
21328 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
21330 const char *name = dwarf2_name (decl, 0);
21332 add_name_attribute (namespace_die, name);
21335 add_name_and_src_coords_attributes (namespace_die, decl);
21336 if (DECL_EXTERNAL (decl))
21337 add_AT_flag (namespace_die, DW_AT_declaration, 1);
21338 equate_decl_number_to_die (decl, namespace_die);
21342 /* Output a namespace alias. */
21344 /* Force out the namespace we are an alias of, if necessary. */
21345 dw_die_ref origin_die
21346 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
21348 if (DECL_FILE_SCOPE_P (decl)
21349 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
21350 context_die = setup_namespace_context (decl, comp_unit_die ());
21351 /* Now create the namespace alias DIE. */
21352 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
21353 add_name_and_src_coords_attributes (namespace_die, decl);
21354 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
21355 equate_decl_number_to_die (decl, namespace_die);
21357 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
21358 if (want_pubnames ())
21359 add_pubname_string (lang_hooks.dwarf_name (decl, 1), namespace_die);
21362 /* Generate Dwarf debug information for a decl described by DECL.
21363 The return value is currently only meaningful for PARM_DECLs,
21364 for all other decls it returns NULL. */
21367 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
21369 tree decl_or_origin = decl ? decl : origin;
21370 tree class_origin = NULL, ultimate_origin;
21372 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
21375 /* Ignore pointer bounds decls. */
21376 if (DECL_P (decl_or_origin)
21377 && TREE_TYPE (decl_or_origin)
21378 && POINTER_BOUNDS_P (decl_or_origin))
21381 switch (TREE_CODE (decl_or_origin))
21387 if (!is_fortran () && !is_ada ())
21389 /* The individual enumerators of an enum type get output when we output
21390 the Dwarf representation of the relevant enum type itself. */
21394 /* Emit its type. */
21395 gen_type_die (TREE_TYPE (decl), context_die);
21397 /* And its containing namespace. */
21398 context_die = declare_in_namespace (decl, context_die);
21400 gen_const_die (decl, context_die);
21403 case FUNCTION_DECL:
21404 /* Don't output any DIEs to represent mere function declarations,
21405 unless they are class members or explicit block externs. */
21406 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
21407 && DECL_FILE_SCOPE_P (decl_or_origin)
21408 && (current_function_decl == NULL_TREE
21409 || DECL_ARTIFICIAL (decl_or_origin)))
21414 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21415 on local redeclarations of global functions. That seems broken. */
21416 if (current_function_decl != decl)
21417 /* This is only a declaration. */;
21420 /* If we're emitting a clone, emit info for the abstract instance. */
21421 if (origin || DECL_ORIGIN (decl) != decl)
21422 dwarf2out_abstract_function (origin
21423 ? DECL_ORIGIN (origin)
21424 : DECL_ABSTRACT_ORIGIN (decl));
21426 /* If we're emitting an out-of-line copy of an inline function,
21427 emit info for the abstract instance and set up to refer to it. */
21428 else if (cgraph_function_possibly_inlined_p (decl)
21429 && ! DECL_ABSTRACT_P (decl)
21430 && ! class_or_namespace_scope_p (context_die)
21431 /* dwarf2out_abstract_function won't emit a die if this is just
21432 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21433 that case, because that works only if we have a die. */
21434 && DECL_INITIAL (decl) != NULL_TREE)
21436 dwarf2out_abstract_function (decl);
21437 set_decl_origin_self (decl);
21440 /* Otherwise we're emitting the primary DIE for this decl. */
21441 else if (debug_info_level > DINFO_LEVEL_TERSE)
21443 /* Before we describe the FUNCTION_DECL itself, make sure that we
21444 have its containing type. */
21446 origin = decl_class_context (decl);
21447 if (origin != NULL_TREE)
21448 gen_type_die (origin, context_die);
21450 /* And its return type. */
21451 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
21453 /* And its virtual context. */
21454 if (DECL_VINDEX (decl) != NULL_TREE)
21455 gen_type_die (DECL_CONTEXT (decl), context_die);
21457 /* Make sure we have a member DIE for decl. */
21458 if (origin != NULL_TREE)
21459 gen_type_die_for_member (origin, decl, context_die);
21461 /* And its containing namespace. */
21462 context_die = declare_in_namespace (decl, context_die);
21465 /* Now output a DIE to represent the function itself. */
21467 gen_subprogram_die (decl, context_die);
21471 /* If we are in terse mode, don't generate any DIEs to represent any
21472 actual typedefs. */
21473 if (debug_info_level <= DINFO_LEVEL_TERSE)
21476 /* In the special case of a TYPE_DECL node representing the declaration
21477 of some type tag, if the given TYPE_DECL is marked as having been
21478 instantiated from some other (original) TYPE_DECL node (e.g. one which
21479 was generated within the original definition of an inline function) we
21480 used to generate a special (abbreviated) DW_TAG_structure_type,
21481 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21482 should be actually referencing those DIEs, as variable DIEs with that
21483 type would be emitted already in the abstract origin, so it was always
21484 removed during unused type prunning. Don't add anything in this
21486 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
21489 if (is_redundant_typedef (decl))
21490 gen_type_die (TREE_TYPE (decl), context_die);
21492 /* Output a DIE to represent the typedef itself. */
21493 gen_typedef_die (decl, context_die);
21497 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21498 gen_label_die (decl, context_die);
21503 /* If we are in terse mode, don't generate any DIEs to represent any
21504 variable declarations or definitions. */
21505 if (debug_info_level <= DINFO_LEVEL_TERSE)
21508 /* Output any DIEs that are needed to specify the type of this data
21510 if (decl_by_reference_p (decl_or_origin))
21511 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21513 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21515 /* And its containing type. */
21516 class_origin = decl_class_context (decl_or_origin);
21517 if (class_origin != NULL_TREE)
21518 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
21520 /* And its containing namespace. */
21521 context_die = declare_in_namespace (decl_or_origin, context_die);
21523 /* Now output the DIE to represent the data object itself. This gets
21524 complicated because of the possibility that the VAR_DECL really
21525 represents an inlined instance of a formal parameter for an inline
21527 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21528 if (ultimate_origin != NULL_TREE
21529 && TREE_CODE (ultimate_origin) == PARM_DECL)
21530 gen_formal_parameter_die (decl, origin,
21531 true /* Emit name attribute. */,
21534 gen_variable_die (decl, origin, context_die);
21538 /* Ignore the nameless fields that are used to skip bits but handle C++
21539 anonymous unions and structs. */
21540 if (DECL_NAME (decl) != NULL_TREE
21541 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
21542 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
21544 gen_type_die (member_declared_type (decl), context_die);
21545 gen_field_die (decl, context_die);
21550 if (DECL_BY_REFERENCE (decl_or_origin))
21551 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21553 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21554 return gen_formal_parameter_die (decl, origin,
21555 true /* Emit name attribute. */,
21558 case NAMESPACE_DECL:
21559 case IMPORTED_DECL:
21560 if (dwarf_version >= 3 || !dwarf_strict)
21561 gen_namespace_die (decl, context_die);
21564 case NAMELIST_DECL:
21565 gen_namelist_decl (DECL_NAME (decl), context_die,
21566 NAMELIST_DECL_ASSOCIATED_DECL (decl));
21570 /* Probably some frontend-internal decl. Assume we don't care. */
21571 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21578 /* Output initial debug information for global DECL. Called at the
21579 end of the parsing process.
21581 This is the initial debug generation process. As such, the DIEs
21582 generated may be incomplete. A later debug generation pass
21583 (dwarf2out_late_global_decl) will augment the information generated
21584 in this pass (e.g., with complete location info). */
21587 dwarf2out_early_global_decl (tree decl)
21591 /* gen_decl_die() will set DECL_ABSTRACT because
21592 cgraph_function_possibly_inlined_p() returns true. This is in
21593 turn will cause DW_AT_inline attributes to be set.
21595 This happens because at early dwarf generation, there is no
21596 cgraph information, causing cgraph_function_possibly_inlined_p()
21597 to return true. Trick cgraph_function_possibly_inlined_p()
21598 while we generate dwarf early. */
21599 bool save = symtab->global_info_ready;
21600 symtab->global_info_ready = true;
21602 /* We don't handle TYPE_DECLs. If required, they'll be reached via
21603 other DECLs and they can point to template types or other things
21604 that dwarf2out can't handle when done via dwarf2out_decl. */
21605 if (TREE_CODE (decl) != TYPE_DECL
21606 && TREE_CODE (decl) != PARM_DECL)
21608 tree save_fndecl = current_function_decl;
21609 if (TREE_CODE (decl) == FUNCTION_DECL)
21611 /* No cfun means the symbol has no body, so there's nothing
21613 if (!DECL_STRUCT_FUNCTION (decl))
21614 goto early_decl_exit;
21616 current_function_decl = decl;
21618 dwarf2out_decl (decl);
21619 if (TREE_CODE (decl) == FUNCTION_DECL)
21620 current_function_decl = save_fndecl;
21623 symtab->global_info_ready = save;
21626 /* Output debug information for global decl DECL. Called from
21627 toplev.c after compilation proper has finished. */
21630 dwarf2out_late_global_decl (tree decl)
21632 /* We have to generate early debug late for LTO. */
21634 dwarf2out_early_global_decl (decl);
21636 /* Fill-in any location information we were unable to determine
21637 on the first pass. */
21638 if (TREE_CODE (decl) == VAR_DECL
21639 && !POINTER_BOUNDS_P (decl))
21641 dw_die_ref die = lookup_decl_die (decl);
21643 add_location_or_const_value_attribute (die, decl, false,
21648 /* Output debug information for type decl DECL. Called from toplev.c
21649 and from language front ends (to record built-in types). */
21651 dwarf2out_type_decl (tree decl, int local)
21656 dwarf2out_decl (decl);
21660 /* Output debug information for imported module or decl DECL.
21661 NAME is non-NULL name in the lexical block if the decl has been renamed.
21662 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21663 that DECL belongs to.
21664 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21666 dwarf2out_imported_module_or_decl_1 (tree decl,
21668 tree lexical_block,
21669 dw_die_ref lexical_block_die)
21671 expanded_location xloc;
21672 dw_die_ref imported_die = NULL;
21673 dw_die_ref at_import_die;
21675 if (TREE_CODE (decl) == IMPORTED_DECL)
21677 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21678 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21682 xloc = expand_location (input_location);
21684 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21686 at_import_die = force_type_die (TREE_TYPE (decl));
21687 /* For namespace N { typedef void T; } using N::T; base_type_die
21688 returns NULL, but DW_TAG_imported_declaration requires
21689 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21690 if (!at_import_die)
21692 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21693 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21694 at_import_die = lookup_type_die (TREE_TYPE (decl));
21695 gcc_assert (at_import_die);
21700 at_import_die = lookup_decl_die (decl);
21701 if (!at_import_die)
21703 /* If we're trying to avoid duplicate debug info, we may not have
21704 emitted the member decl for this field. Emit it now. */
21705 if (TREE_CODE (decl) == FIELD_DECL)
21707 tree type = DECL_CONTEXT (decl);
21709 if (TYPE_CONTEXT (type)
21710 && TYPE_P (TYPE_CONTEXT (type))
21711 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21712 DINFO_USAGE_DIR_USE))
21714 gen_type_die_for_member (type, decl,
21715 get_context_die (TYPE_CONTEXT (type)));
21717 if (TREE_CODE (decl) == NAMELIST_DECL)
21718 at_import_die = gen_namelist_decl (DECL_NAME (decl),
21719 get_context_die (DECL_CONTEXT (decl)),
21722 at_import_die = force_decl_die (decl);
21726 if (TREE_CODE (decl) == NAMESPACE_DECL)
21728 if (dwarf_version >= 3 || !dwarf_strict)
21729 imported_die = new_die (DW_TAG_imported_module,
21736 imported_die = new_die (DW_TAG_imported_declaration,
21740 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21741 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21743 add_AT_string (imported_die, DW_AT_name,
21744 IDENTIFIER_POINTER (name));
21745 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21748 /* Output debug information for imported module or decl DECL.
21749 NAME is non-NULL name in context if the decl has been renamed.
21750 CHILD is true if decl is one of the renamed decls as part of
21751 importing whole module. */
21754 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21757 /* dw_die_ref at_import_die; */
21758 dw_die_ref scope_die;
21760 if (debug_info_level <= DINFO_LEVEL_TERSE)
21767 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21768 We need decl DIE for reference and scope die. First, get DIE for the decl
21771 /* Get the scope die for decl context. Use comp_unit_die for global module
21772 or decl. If die is not found for non globals, force new die. */
21774 && TYPE_P (context)
21775 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21778 if (!(dwarf_version >= 3 || !dwarf_strict))
21781 scope_die = get_context_die (context);
21785 gcc_assert (scope_die->die_child);
21786 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21787 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21788 scope_die = scope_die->die_child;
21791 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21792 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21795 /* Output debug information for namelists. */
21798 gen_namelist_decl (tree name, dw_die_ref scope_die, tree item_decls)
21800 dw_die_ref nml_die, nml_item_die, nml_item_ref_die;
21804 if (debug_info_level <= DINFO_LEVEL_TERSE)
21807 gcc_assert (scope_die != NULL);
21808 nml_die = new_die (DW_TAG_namelist, scope_die, NULL);
21809 add_AT_string (nml_die, DW_AT_name, IDENTIFIER_POINTER (name));
21811 /* If there are no item_decls, we have a nondefining namelist, e.g.
21812 with USE association; hence, set DW_AT_declaration. */
21813 if (item_decls == NULL_TREE)
21815 add_AT_flag (nml_die, DW_AT_declaration, 1);
21819 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls), i, value)
21821 nml_item_ref_die = lookup_decl_die (value);
21822 if (!nml_item_ref_die)
21823 nml_item_ref_die = force_decl_die (value);
21825 nml_item_die = new_die (DW_TAG_namelist_item, nml_die, NULL);
21826 add_AT_die_ref (nml_item_die, DW_AT_namelist_items, nml_item_ref_die);
21832 /* Write the debugging output for DECL and return the DIE. */
21835 dwarf2out_decl (tree decl)
21837 dw_die_ref context_die = comp_unit_die ();
21839 switch (TREE_CODE (decl))
21844 case FUNCTION_DECL:
21845 /* What we would really like to do here is to filter out all mere
21846 file-scope declarations of file-scope functions which are never
21847 referenced later within this translation unit (and keep all of ones
21848 that *are* referenced later on) but we aren't clairvoyant, so we have
21849 no idea which functions will be referenced in the future (i.e. later
21850 on within the current translation unit). So here we just ignore all
21851 file-scope function declarations which are not also definitions. If
21852 and when the debugger needs to know something about these functions,
21853 it will have to hunt around and find the DWARF information associated
21854 with the definition of the function.
21856 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21857 nodes represent definitions and which ones represent mere
21858 declarations. We have to check DECL_INITIAL instead. That's because
21859 the C front-end supports some weird semantics for "extern inline"
21860 function definitions. These can get inlined within the current
21861 translation unit (and thus, we need to generate Dwarf info for their
21862 abstract instances so that the Dwarf info for the concrete inlined
21863 instances can have something to refer to) but the compiler never
21864 generates any out-of-lines instances of such things (despite the fact
21865 that they *are* definitions).
21867 The important point is that the C front-end marks these "extern
21868 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21869 them anyway. Note that the C++ front-end also plays some similar games
21870 for inline function definitions appearing within include files which
21871 also contain `#pragma interface' pragmas.
21873 If we are called from dwarf2out_abstract_function output a DIE
21874 anyway. We can end up here this way with early inlining and LTO
21875 where the inlined function is output in a different LTRANS unit
21877 if (DECL_INITIAL (decl) == NULL_TREE
21878 && ! DECL_ABSTRACT_P (decl))
21881 /* If we're a nested function, initially use a parent of NULL; if we're
21882 a plain function, this will be fixed up in decls_for_scope. If
21883 we're a method, it will be ignored, since we already have a DIE. */
21884 if (decl_function_context (decl)
21885 /* But if we're in terse mode, we don't care about scope. */
21886 && debug_info_level > DINFO_LEVEL_TERSE)
21887 context_die = NULL;
21891 /* For local statics lookup proper context die. */
21892 if (local_function_static (decl))
21893 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21895 /* If we are in terse mode, don't generate any DIEs to represent any
21896 variable declarations or definitions. */
21897 if (debug_info_level <= DINFO_LEVEL_TERSE)
21902 if (debug_info_level <= DINFO_LEVEL_TERSE)
21904 if (!is_fortran () && !is_ada ())
21906 if (TREE_STATIC (decl) && decl_function_context (decl))
21907 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21910 case NAMESPACE_DECL:
21911 case IMPORTED_DECL:
21912 if (debug_info_level <= DINFO_LEVEL_TERSE)
21914 if (lookup_decl_die (decl) != NULL)
21919 /* Don't emit stubs for types unless they are needed by other DIEs. */
21920 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21923 /* Don't bother trying to generate any DIEs to represent any of the
21924 normal built-in types for the language we are compiling. */
21925 if (DECL_IS_BUILTIN (decl))
21928 /* If we are in terse mode, don't generate any DIEs for types. */
21929 if (debug_info_level <= DINFO_LEVEL_TERSE)
21932 /* If we're a function-scope tag, initially use a parent of NULL;
21933 this will be fixed up in decls_for_scope. */
21934 if (decl_function_context (decl))
21935 context_die = NULL;
21939 case NAMELIST_DECL:
21946 gen_decl_die (decl, NULL, context_die);
21948 #ifdef ENABLE_CHECKING
21949 dw_die_ref die = lookup_decl_die (decl);
21955 /* Write the debugging output for DECL. */
21958 dwarf2out_function_decl (tree decl)
21960 dwarf2out_decl (decl);
21961 call_arg_locations = NULL;
21962 call_arg_loc_last = NULL;
21963 call_site_count = -1;
21964 tail_call_site_count = -1;
21965 decl_loc_table->empty ();
21966 cached_dw_loc_list_table->empty ();
21969 /* Output a marker (i.e. a label) for the beginning of the generated code for
21970 a lexical block. */
21973 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21974 unsigned int blocknum)
21976 switch_to_section (current_function_section ());
21977 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21980 /* Output a marker (i.e. a label) for the end of the generated code for a
21984 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21986 switch_to_section (current_function_section ());
21987 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21990 /* Returns nonzero if it is appropriate not to emit any debugging
21991 information for BLOCK, because it doesn't contain any instructions.
21993 Don't allow this for blocks with nested functions or local classes
21994 as we would end up with orphans, and in the presence of scheduling
21995 we may end up calling them anyway. */
21998 dwarf2out_ignore_block (const_tree block)
22003 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
22004 if (TREE_CODE (decl) == FUNCTION_DECL
22005 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22007 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
22009 decl = BLOCK_NONLOCALIZED_VAR (block, i);
22010 if (TREE_CODE (decl) == FUNCTION_DECL
22011 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22018 /* Hash table routines for file_hash. */
22021 dwarf_file_hasher::equal (dwarf_file_data *p1, const char *p2)
22023 return filename_cmp (p1->filename, p2) == 0;
22027 dwarf_file_hasher::hash (dwarf_file_data *p)
22029 return htab_hash_string (p->filename);
22032 /* Lookup FILE_NAME (in the list of filenames that we know about here in
22033 dwarf2out.c) and return its "index". The index of each (known) filename is
22034 just a unique number which is associated with only that one filename. We
22035 need such numbers for the sake of generating labels (in the .debug_sfnames
22036 section) and references to those files numbers (in the .debug_srcinfo
22037 and.debug_macinfo sections). If the filename given as an argument is not
22038 found in our current list, add it to the list and assign it the next
22039 available unique index number. */
22041 static struct dwarf_file_data *
22042 lookup_filename (const char *file_name)
22044 struct dwarf_file_data * created;
22049 dwarf_file_data **slot
22050 = file_table->find_slot_with_hash (file_name, htab_hash_string (file_name),
22055 created = ggc_alloc<dwarf_file_data> ();
22056 created->filename = file_name;
22057 created->emitted_number = 0;
22062 /* If the assembler will construct the file table, then translate the compiler
22063 internal file table number into the assembler file table number, and emit
22064 a .file directive if we haven't already emitted one yet. The file table
22065 numbers are different because we prune debug info for unused variables and
22066 types, which may include filenames. */
22069 maybe_emit_file (struct dwarf_file_data * fd)
22071 if (! fd->emitted_number)
22073 if (last_emitted_file)
22074 fd->emitted_number = last_emitted_file->emitted_number + 1;
22076 fd->emitted_number = 1;
22077 last_emitted_file = fd;
22079 if (DWARF2_ASM_LINE_DEBUG_INFO)
22081 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
22082 output_quoted_string (asm_out_file,
22083 remap_debug_filename (fd->filename));
22084 fputc ('\n', asm_out_file);
22088 return fd->emitted_number;
22091 /* Schedule generation of a DW_AT_const_value attribute to DIE.
22092 That generation should happen after function debug info has been
22093 generated. The value of the attribute is the constant value of ARG. */
22096 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
22098 die_arg_entry entry;
22103 gcc_assert (early_dwarf);
22105 if (!tmpl_value_parm_die_table)
22106 vec_alloc (tmpl_value_parm_die_table, 32);
22110 vec_safe_push (tmpl_value_parm_die_table, entry);
22113 /* Return TRUE if T is an instance of generic type, FALSE
22117 generic_type_p (tree t)
22119 if (t == NULL_TREE || !TYPE_P (t))
22121 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
22124 /* Schedule the generation of the generic parameter dies for the
22125 instance of generic type T. The proper generation itself is later
22126 done by gen_scheduled_generic_parms_dies. */
22129 schedule_generic_params_dies_gen (tree t)
22131 if (!generic_type_p (t))
22134 gcc_assert (early_dwarf);
22136 if (!generic_type_instances)
22137 vec_alloc (generic_type_instances, 256);
22139 vec_safe_push (generic_type_instances, t);
22142 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
22143 by append_entry_to_tmpl_value_parm_die_table. This function must
22144 be called after function DIEs have been generated. */
22147 gen_remaining_tmpl_value_param_die_attribute (void)
22149 if (tmpl_value_parm_die_table)
22154 /* We do this in two phases - first get the cases we can
22155 handle during early-finish, preserving those we cannot
22156 (containing symbolic constants where we don't yet know
22157 whether we are going to output the referenced symbols).
22158 For those we try again at late-finish. */
22160 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table, i, e)
22162 if (!tree_add_const_value_attribute (e->die, e->arg))
22163 (*tmpl_value_parm_die_table)[j++] = *e;
22165 tmpl_value_parm_die_table->truncate (j);
22169 /* Generate generic parameters DIEs for instances of generic types
22170 that have been previously scheduled by
22171 schedule_generic_params_dies_gen. This function must be called
22172 after all the types of the CU have been laid out. */
22175 gen_scheduled_generic_parms_dies (void)
22180 if (!generic_type_instances)
22183 /* We end up "recursing" into schedule_generic_params_dies_gen, so
22184 pretend this generation is part of "early dwarf" as well. */
22187 FOR_EACH_VEC_ELT (*generic_type_instances, i, t)
22188 if (COMPLETE_TYPE_P (t))
22189 gen_generic_params_dies (t);
22191 generic_type_instances = NULL;
22195 /* Replace DW_AT_name for the decl with name. */
22198 dwarf2out_set_name (tree decl, tree name)
22201 dw_attr_node *attr;
22204 die = TYPE_SYMTAB_DIE (decl);
22208 dname = dwarf2_name (name, 0);
22212 attr = get_AT (die, DW_AT_name);
22215 struct indirect_string_node *node;
22217 node = find_AT_string (dname);
22218 /* replace the string. */
22219 attr->dw_attr_val.v.val_str = node;
22223 add_name_attribute (die, dname);
22226 /* True if before or during processing of the first function being emitted. */
22227 static bool in_first_function_p = true;
22228 /* True if loc_note during dwarf2out_var_location call might still be
22229 before first real instruction at address equal to .Ltext0. */
22230 static bool maybe_at_text_label_p = true;
22231 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
22232 static unsigned int first_loclabel_num_not_at_text_label;
22234 /* Called by the final INSN scan whenever we see a var location. We
22235 use it to drop labels in the right places, and throw the location in
22236 our lookup table. */
22239 dwarf2out_var_location (rtx_insn *loc_note)
22241 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
22242 struct var_loc_node *newloc;
22243 rtx_insn *next_real, *next_note;
22244 static const char *last_label;
22245 static const char *last_postcall_label;
22246 static bool last_in_cold_section_p;
22247 static rtx_insn *expected_next_loc_note;
22251 if (!NOTE_P (loc_note))
22253 if (CALL_P (loc_note))
22256 if (SIBLING_CALL_P (loc_note))
22257 tail_call_site_count++;
22262 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
22263 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
22266 /* Optimize processing a large consecutive sequence of location
22267 notes so we don't spend too much time in next_real_insn. If the
22268 next insn is another location note, remember the next_real_insn
22269 calculation for next time. */
22270 next_real = cached_next_real_insn;
22273 if (expected_next_loc_note != loc_note)
22277 next_note = NEXT_INSN (loc_note);
22279 || next_note->deleted ()
22280 || ! NOTE_P (next_note)
22281 || (NOTE_KIND (next_note) != NOTE_INSN_VAR_LOCATION
22282 && NOTE_KIND (next_note) != NOTE_INSN_CALL_ARG_LOCATION))
22286 next_real = next_real_insn (loc_note);
22290 expected_next_loc_note = next_note;
22291 cached_next_real_insn = next_real;
22294 cached_next_real_insn = NULL;
22296 /* If there are no instructions which would be affected by this note,
22297 don't do anything. */
22299 && next_real == NULL_RTX
22300 && !NOTE_DURING_CALL_P (loc_note))
22303 if (next_real == NULL_RTX)
22304 next_real = get_last_insn ();
22306 /* If there were any real insns between note we processed last time
22307 and this note (or if it is the first note), clear
22308 last_{,postcall_}label so that they are not reused this time. */
22309 if (last_var_location_insn == NULL_RTX
22310 || last_var_location_insn != next_real
22311 || last_in_cold_section_p != in_cold_section_p)
22314 last_postcall_label = NULL;
22319 decl = NOTE_VAR_LOCATION_DECL (loc_note);
22320 newloc = add_var_loc_to_decl (decl, loc_note,
22321 NOTE_DURING_CALL_P (loc_note)
22322 ? last_postcall_label : last_label);
22323 if (newloc == NULL)
22332 /* If there were no real insns between note we processed last time
22333 and this note, use the label we emitted last time. Otherwise
22334 create a new label and emit it. */
22335 if (last_label == NULL)
22337 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
22338 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
22340 last_label = ggc_strdup (loclabel);
22341 /* See if loclabel might be equal to .Ltext0. If yes,
22342 bump first_loclabel_num_not_at_text_label. */
22343 if (!have_multiple_function_sections
22344 && in_first_function_p
22345 && maybe_at_text_label_p)
22347 static rtx_insn *last_start;
22349 for (insn = loc_note; insn; insn = previous_insn (insn))
22350 if (insn == last_start)
22352 else if (!NONDEBUG_INSN_P (insn))
22356 rtx body = PATTERN (insn);
22357 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
22359 /* Inline asm could occupy zero bytes. */
22360 else if (GET_CODE (body) == ASM_INPUT
22361 || asm_noperands (body) >= 0)
22363 #ifdef HAVE_attr_length
22364 else if (get_attr_min_length (insn) == 0)
22369 /* Assume insn has non-zero length. */
22370 maybe_at_text_label_p = false;
22374 if (maybe_at_text_label_p)
22376 last_start = loc_note;
22377 first_loclabel_num_not_at_text_label = loclabel_num;
22384 struct call_arg_loc_node *ca_loc
22385 = ggc_cleared_alloc<call_arg_loc_node> ();
22386 rtx_insn *prev = prev_real_insn (loc_note);
22388 ca_loc->call_arg_loc_note = loc_note;
22389 ca_loc->next = NULL;
22390 ca_loc->label = last_label;
22393 || (NONJUMP_INSN_P (prev)
22394 && GET_CODE (PATTERN (prev)) == SEQUENCE
22395 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
22396 if (!CALL_P (prev))
22397 prev = as_a <rtx_sequence *> (PATTERN (prev))->insn (0);
22398 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
22399 x = get_call_rtx_from (PATTERN (prev));
22402 x = XEXP (XEXP (x, 0), 0);
22403 if (GET_CODE (x) == SYMBOL_REF
22404 && SYMBOL_REF_DECL (x)
22405 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
22406 ca_loc->symbol_ref = x;
22408 ca_loc->block = insn_scope (prev);
22409 if (call_arg_locations)
22410 call_arg_loc_last->next = ca_loc;
22412 call_arg_locations = ca_loc;
22413 call_arg_loc_last = ca_loc;
22415 else if (!NOTE_DURING_CALL_P (loc_note))
22416 newloc->label = last_label;
22419 if (!last_postcall_label)
22421 sprintf (loclabel, "%s-1", last_label);
22422 last_postcall_label = ggc_strdup (loclabel);
22424 newloc->label = last_postcall_label;
22427 last_var_location_insn = next_real;
22428 last_in_cold_section_p = in_cold_section_p;
22431 /* Note in one location list that text section has changed. */
22434 var_location_switch_text_section_1 (var_loc_list **slot, void *)
22436 var_loc_list *list = *slot;
22438 list->last_before_switch
22439 = list->last->next ? list->last->next : list->last;
22443 /* Note in all location lists that text section has changed. */
22446 var_location_switch_text_section (void)
22448 if (decl_loc_table == NULL)
22451 decl_loc_table->traverse<void *, var_location_switch_text_section_1> (NULL);
22454 /* Create a new line number table. */
22456 static dw_line_info_table *
22457 new_line_info_table (void)
22459 dw_line_info_table *table;
22461 table = ggc_cleared_alloc<dw_line_info_table> ();
22462 table->file_num = 1;
22463 table->line_num = 1;
22464 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
22469 /* Lookup the "current" table into which we emit line info, so
22470 that we don't have to do it for every source line. */
22473 set_cur_line_info_table (section *sec)
22475 dw_line_info_table *table;
22477 if (sec == text_section)
22478 table = text_section_line_info;
22479 else if (sec == cold_text_section)
22481 table = cold_text_section_line_info;
22484 cold_text_section_line_info = table = new_line_info_table ();
22485 table->end_label = cold_end_label;
22490 const char *end_label;
22492 if (flag_reorder_blocks_and_partition)
22494 if (in_cold_section_p)
22495 end_label = crtl->subsections.cold_section_end_label;
22497 end_label = crtl->subsections.hot_section_end_label;
22501 char label[MAX_ARTIFICIAL_LABEL_BYTES];
22502 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
22503 current_function_funcdef_no);
22504 end_label = ggc_strdup (label);
22507 table = new_line_info_table ();
22508 table->end_label = end_label;
22510 vec_safe_push (separate_line_info, table);
22513 if (DWARF2_ASM_LINE_DEBUG_INFO)
22514 table->is_stmt = (cur_line_info_table
22515 ? cur_line_info_table->is_stmt
22516 : DWARF_LINE_DEFAULT_IS_STMT_START);
22517 cur_line_info_table = table;
22521 /* We need to reset the locations at the beginning of each
22522 function. We can't do this in the end_function hook, because the
22523 declarations that use the locations won't have been output when
22524 that hook is called. Also compute have_multiple_function_sections here. */
22527 dwarf2out_begin_function (tree fun)
22529 section *sec = function_section (fun);
22531 if (sec != text_section)
22532 have_multiple_function_sections = true;
22534 if (flag_reorder_blocks_and_partition && !cold_text_section)
22536 gcc_assert (current_function_decl == fun);
22537 cold_text_section = unlikely_text_section ();
22538 switch_to_section (cold_text_section);
22539 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
22540 switch_to_section (sec);
22543 dwarf2out_note_section_used ();
22544 call_site_count = 0;
22545 tail_call_site_count = 0;
22547 set_cur_line_info_table (sec);
22550 /* Helper function of dwarf2out_end_function, called only after emitting
22551 the very first function into assembly. Check if some .debug_loc range
22552 might end with a .LVL* label that could be equal to .Ltext0.
22553 In that case we must force using absolute addresses in .debug_loc ranges,
22554 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
22555 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
22557 Set have_multiple_function_sections to true in that case and
22558 terminate htab traversal. */
22561 find_empty_loc_ranges_at_text_label (var_loc_list **slot, int)
22563 var_loc_list *entry = *slot;
22564 struct var_loc_node *node;
22566 node = entry->first;
22567 if (node && node->next && node->next->label)
22570 const char *label = node->next->label;
22571 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
22573 for (i = 0; i < first_loclabel_num_not_at_text_label; i++)
22575 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", i);
22576 if (strcmp (label, loclabel) == 0)
22578 have_multiple_function_sections = true;
22586 /* Hook called after emitting a function into assembly.
22587 This does something only for the very first function emitted. */
22590 dwarf2out_end_function (unsigned int)
22592 if (in_first_function_p
22593 && !have_multiple_function_sections
22594 && first_loclabel_num_not_at_text_label
22596 decl_loc_table->traverse<int, find_empty_loc_ranges_at_text_label> (0);
22597 in_first_function_p = false;
22598 maybe_at_text_label_p = false;
22601 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
22602 front-ends register a translation unit even before dwarf2out_init is
22604 static tree main_translation_unit = NULL_TREE;
22606 /* Hook called by front-ends after they built their main translation unit.
22607 Associate comp_unit_die to UNIT. */
22610 dwarf2out_register_main_translation_unit (tree unit)
22612 gcc_assert (TREE_CODE (unit) == TRANSLATION_UNIT_DECL
22613 && main_translation_unit == NULL_TREE);
22614 main_translation_unit = unit;
22615 /* If dwarf2out_init has not been called yet, it will perform the association
22616 itself looking at main_translation_unit. */
22617 if (decl_die_table != NULL)
22618 equate_decl_number_to_die (unit, comp_unit_die ());
22621 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22624 push_dw_line_info_entry (dw_line_info_table *table,
22625 enum dw_line_info_opcode opcode, unsigned int val)
22627 dw_line_info_entry e;
22630 vec_safe_push (table->entries, e);
22633 /* Output a label to mark the beginning of a source code line entry
22634 and record information relating to this source line, in
22635 'line_info_table' for later output of the .debug_line section. */
22636 /* ??? The discriminator parameter ought to be unsigned. */
22639 dwarf2out_source_line (unsigned int line, const char *filename,
22640 int discriminator, bool is_stmt)
22642 unsigned int file_num;
22643 dw_line_info_table *table;
22645 if (debug_info_level < DINFO_LEVEL_TERSE || line == 0)
22648 /* The discriminator column was added in dwarf4. Simplify the below
22649 by simply removing it if we're not supposed to output it. */
22650 if (dwarf_version < 4 && dwarf_strict)
22653 table = cur_line_info_table;
22654 file_num = maybe_emit_file (lookup_filename (filename));
22656 /* ??? TODO: Elide duplicate line number entries. Traditionally,
22657 the debugger has used the second (possibly duplicate) line number
22658 at the beginning of the function to mark the end of the prologue.
22659 We could eliminate any other duplicates within the function. For
22660 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
22661 that second line number entry. */
22662 /* Recall that this end-of-prologue indication is *not* the same thing
22663 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
22664 to which the hook corresponds, follows the last insn that was
22665 emitted by gen_prologue. What we need is to precede the first insn
22666 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
22667 insn that corresponds to something the user wrote. These may be
22668 very different locations once scheduling is enabled. */
22670 if (0 && file_num == table->file_num
22671 && line == table->line_num
22672 && discriminator == table->discrim_num
22673 && is_stmt == table->is_stmt)
22676 switch_to_section (current_function_section ());
22678 /* If requested, emit something human-readable. */
22679 if (flag_debug_asm)
22680 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
22682 if (DWARF2_ASM_LINE_DEBUG_INFO)
22684 /* Emit the .loc directive understood by GNU as. */
22685 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
22686 file_num, line, is_stmt, discriminator */
22687 fputs ("\t.loc ", asm_out_file);
22688 fprint_ul (asm_out_file, file_num);
22689 putc (' ', asm_out_file);
22690 fprint_ul (asm_out_file, line);
22691 putc (' ', asm_out_file);
22692 putc ('0', asm_out_file);
22694 if (is_stmt != table->is_stmt)
22696 fputs (" is_stmt ", asm_out_file);
22697 putc (is_stmt ? '1' : '0', asm_out_file);
22699 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
22701 gcc_assert (discriminator > 0);
22702 fputs (" discriminator ", asm_out_file);
22703 fprint_ul (asm_out_file, (unsigned long) discriminator);
22705 putc ('\n', asm_out_file);
22709 unsigned int label_num = ++line_info_label_num;
22711 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
22713 push_dw_line_info_entry (table, LI_set_address, label_num);
22714 if (file_num != table->file_num)
22715 push_dw_line_info_entry (table, LI_set_file, file_num);
22716 if (discriminator != table->discrim_num)
22717 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
22718 if (is_stmt != table->is_stmt)
22719 push_dw_line_info_entry (table, LI_negate_stmt, 0);
22720 push_dw_line_info_entry (table, LI_set_line, line);
22723 table->file_num = file_num;
22724 table->line_num = line;
22725 table->discrim_num = discriminator;
22726 table->is_stmt = is_stmt;
22727 table->in_use = true;
22730 /* Record the beginning of a new source file. */
22733 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
22735 if (flag_eliminate_dwarf2_dups)
22737 /* Record the beginning of the file for break_out_includes. */
22738 dw_die_ref bincl_die;
22740 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
22741 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
22744 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22747 e.code = DW_MACINFO_start_file;
22749 e.info = ggc_strdup (filename);
22750 vec_safe_push (macinfo_table, e);
22754 /* Record the end of a source file. */
22757 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
22759 if (flag_eliminate_dwarf2_dups)
22760 /* Record the end of the file for break_out_includes. */
22761 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
22763 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22766 e.code = DW_MACINFO_end_file;
22769 vec_safe_push (macinfo_table, e);
22773 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22774 the tail part of the directive line, i.e. the part which is past the
22775 initial whitespace, #, whitespace, directive-name, whitespace part. */
22778 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
22779 const char *buffer ATTRIBUTE_UNUSED)
22781 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22784 /* Insert a dummy first entry to be able to optimize the whole
22785 predefined macro block using DW_MACRO_GNU_transparent_include. */
22786 if (macinfo_table->is_empty () && lineno <= 1)
22791 vec_safe_push (macinfo_table, e);
22793 e.code = DW_MACINFO_define;
22795 e.info = ggc_strdup (buffer);
22796 vec_safe_push (macinfo_table, e);
22800 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22801 the tail part of the directive line, i.e. the part which is past the
22802 initial whitespace, #, whitespace, directive-name, whitespace part. */
22805 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
22806 const char *buffer ATTRIBUTE_UNUSED)
22808 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22811 /* Insert a dummy first entry to be able to optimize the whole
22812 predefined macro block using DW_MACRO_GNU_transparent_include. */
22813 if (macinfo_table->is_empty () && lineno <= 1)
22818 vec_safe_push (macinfo_table, e);
22820 e.code = DW_MACINFO_undef;
22822 e.info = ggc_strdup (buffer);
22823 vec_safe_push (macinfo_table, e);
22827 /* Helpers to manipulate hash table of CUs. */
22829 struct macinfo_entry_hasher : nofree_ptr_hash <macinfo_entry>
22831 static inline hashval_t hash (const macinfo_entry *);
22832 static inline bool equal (const macinfo_entry *, const macinfo_entry *);
22836 macinfo_entry_hasher::hash (const macinfo_entry *entry)
22838 return htab_hash_string (entry->info);
22842 macinfo_entry_hasher::equal (const macinfo_entry *entry1,
22843 const macinfo_entry *entry2)
22845 return !strcmp (entry1->info, entry2->info);
22848 typedef hash_table<macinfo_entry_hasher> macinfo_hash_type;
22850 /* Output a single .debug_macinfo entry. */
22853 output_macinfo_op (macinfo_entry *ref)
22857 struct indirect_string_node *node;
22858 char label[MAX_ARTIFICIAL_LABEL_BYTES];
22859 struct dwarf_file_data *fd;
22863 case DW_MACINFO_start_file:
22864 fd = lookup_filename (ref->info);
22865 file_num = maybe_emit_file (fd);
22866 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
22867 dw2_asm_output_data_uleb128 (ref->lineno,
22868 "Included from line number %lu",
22869 (unsigned long) ref->lineno);
22870 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
22872 case DW_MACINFO_end_file:
22873 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
22875 case DW_MACINFO_define:
22876 case DW_MACINFO_undef:
22877 len = strlen (ref->info) + 1;
22879 && len > DWARF_OFFSET_SIZE
22880 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22881 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
22883 ref->code = ref->code == DW_MACINFO_define
22884 ? DW_MACRO_GNU_define_indirect
22885 : DW_MACRO_GNU_undef_indirect;
22886 output_macinfo_op (ref);
22889 dw2_asm_output_data (1, ref->code,
22890 ref->code == DW_MACINFO_define
22891 ? "Define macro" : "Undefine macro");
22892 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22893 (unsigned long) ref->lineno);
22894 dw2_asm_output_nstring (ref->info, -1, "The macro");
22896 case DW_MACRO_GNU_define_indirect:
22897 case DW_MACRO_GNU_undef_indirect:
22898 node = find_AT_string (ref->info);
22900 && ((node->form == DW_FORM_strp)
22901 || (node->form == DW_FORM_GNU_str_index)));
22902 dw2_asm_output_data (1, ref->code,
22903 ref->code == DW_MACRO_GNU_define_indirect
22904 ? "Define macro indirect"
22905 : "Undefine macro indirect");
22906 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22907 (unsigned long) ref->lineno);
22908 if (node->form == DW_FORM_strp)
22909 dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
22910 debug_str_section, "The macro: \"%s\"",
22913 dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
22916 case DW_MACRO_GNU_transparent_include:
22917 dw2_asm_output_data (1, ref->code, "Transparent include");
22918 ASM_GENERATE_INTERNAL_LABEL (label,
22919 DEBUG_MACRO_SECTION_LABEL, ref->lineno);
22920 dw2_asm_output_offset (DWARF_OFFSET_SIZE, label, NULL, NULL);
22923 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
22924 ASM_COMMENT_START, (unsigned long) ref->code);
22929 /* Attempt to make a sequence of define/undef macinfo ops shareable with
22930 other compilation unit .debug_macinfo sections. IDX is the first
22931 index of a define/undef, return the number of ops that should be
22932 emitted in a comdat .debug_macinfo section and emit
22933 a DW_MACRO_GNU_transparent_include entry referencing it.
22934 If the define/undef entry should be emitted normally, return 0. */
22937 optimize_macinfo_range (unsigned int idx, vec<macinfo_entry, va_gc> *files,
22938 macinfo_hash_type **macinfo_htab)
22940 macinfo_entry *first, *second, *cur, *inc;
22941 char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
22942 unsigned char checksum[16];
22943 struct md5_ctx ctx;
22944 char *grp_name, *tail;
22946 unsigned int i, count, encoded_filename_len, linebuf_len;
22947 macinfo_entry **slot;
22949 first = &(*macinfo_table)[idx];
22950 second = &(*macinfo_table)[idx + 1];
22952 /* Optimize only if there are at least two consecutive define/undef ops,
22953 and either all of them are before first DW_MACINFO_start_file
22954 with lineno {0,1} (i.e. predefined macro block), or all of them are
22955 in some included header file. */
22956 if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
22958 if (vec_safe_is_empty (files))
22960 if (first->lineno > 1 || second->lineno > 1)
22963 else if (first->lineno == 0)
22966 /* Find the last define/undef entry that can be grouped together
22967 with first and at the same time compute md5 checksum of their
22968 codes, linenumbers and strings. */
22969 md5_init_ctx (&ctx);
22970 for (i = idx; macinfo_table->iterate (i, &cur); i++)
22971 if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
22973 else if (vec_safe_is_empty (files) && cur->lineno > 1)
22977 unsigned char code = cur->code;
22978 md5_process_bytes (&code, 1, &ctx);
22979 checksum_uleb128 (cur->lineno, &ctx);
22980 md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
22982 md5_finish_ctx (&ctx, checksum);
22985 /* From the containing include filename (if any) pick up just
22986 usable characters from its basename. */
22987 if (vec_safe_is_empty (files))
22990 base = lbasename (files->last ().info);
22991 for (encoded_filename_len = 0, i = 0; base[i]; i++)
22992 if (ISIDNUM (base[i]) || base[i] == '.')
22993 encoded_filename_len++;
22994 /* Count . at the end. */
22995 if (encoded_filename_len)
22996 encoded_filename_len++;
22998 sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
22999 linebuf_len = strlen (linebuf);
23001 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
23002 grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
23004 memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4);
23005 tail = grp_name + 4;
23006 if (encoded_filename_len)
23008 for (i = 0; base[i]; i++)
23009 if (ISIDNUM (base[i]) || base[i] == '.')
23013 memcpy (tail, linebuf, linebuf_len);
23014 tail += linebuf_len;
23016 for (i = 0; i < 16; i++)
23017 sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
23019 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
23020 in the empty vector entry before the first define/undef. */
23021 inc = &(*macinfo_table)[idx - 1];
23022 inc->code = DW_MACRO_GNU_transparent_include;
23024 inc->info = ggc_strdup (grp_name);
23025 if (!*macinfo_htab)
23026 *macinfo_htab = new macinfo_hash_type (10);
23027 /* Avoid emitting duplicates. */
23028 slot = (*macinfo_htab)->find_slot (inc, INSERT);
23033 /* If such an entry has been used before, just emit
23034 a DW_MACRO_GNU_transparent_include op. */
23036 output_macinfo_op (inc);
23037 /* And clear all macinfo_entry in the range to avoid emitting them
23038 in the second pass. */
23039 for (i = idx; macinfo_table->iterate (i, &cur) && i < idx + count; i++)
23048 inc->lineno = (*macinfo_htab)->elements ();
23049 output_macinfo_op (inc);
23054 /* Save any strings needed by the macinfo table in the debug str
23055 table. All strings must be collected into the table by the time
23056 index_string is called. */
23059 save_macinfo_strings (void)
23063 macinfo_entry *ref;
23065 for (i = 0; macinfo_table && macinfo_table->iterate (i, &ref); i++)
23069 /* Match the logic in output_macinfo_op to decide on
23070 indirect strings. */
23071 case DW_MACINFO_define:
23072 case DW_MACINFO_undef:
23073 len = strlen (ref->info) + 1;
23075 && len > DWARF_OFFSET_SIZE
23076 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
23077 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
23078 set_indirect_string (find_AT_string (ref->info));
23080 case DW_MACRO_GNU_define_indirect:
23081 case DW_MACRO_GNU_undef_indirect:
23082 set_indirect_string (find_AT_string (ref->info));
23090 /* Output macinfo section(s). */
23093 output_macinfo (void)
23096 unsigned long length = vec_safe_length (macinfo_table);
23097 macinfo_entry *ref;
23098 vec<macinfo_entry, va_gc> *files = NULL;
23099 macinfo_hash_type *macinfo_htab = NULL;
23104 /* output_macinfo* uses these interchangeably. */
23105 gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_GNU_define
23106 && (int) DW_MACINFO_undef == (int) DW_MACRO_GNU_undef
23107 && (int) DW_MACINFO_start_file == (int) DW_MACRO_GNU_start_file
23108 && (int) DW_MACINFO_end_file == (int) DW_MACRO_GNU_end_file);
23110 /* For .debug_macro emit the section header. */
23113 dw2_asm_output_data (2, 4, "DWARF macro version number");
23114 if (DWARF_OFFSET_SIZE == 8)
23115 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
23117 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
23118 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
23119 (!dwarf_split_debug_info ? debug_line_section_label
23120 : debug_skeleton_line_section_label),
23121 debug_line_section, NULL);
23124 /* In the first loop, it emits the primary .debug_macinfo section
23125 and after each emitted op the macinfo_entry is cleared.
23126 If a longer range of define/undef ops can be optimized using
23127 DW_MACRO_GNU_transparent_include, the
23128 DW_MACRO_GNU_transparent_include op is emitted and kept in
23129 the vector before the first define/undef in the range and the
23130 whole range of define/undef ops is not emitted and kept. */
23131 for (i = 0; macinfo_table->iterate (i, &ref); i++)
23135 case DW_MACINFO_start_file:
23136 vec_safe_push (files, *ref);
23138 case DW_MACINFO_end_file:
23139 if (!vec_safe_is_empty (files))
23142 case DW_MACINFO_define:
23143 case DW_MACINFO_undef:
23145 && HAVE_COMDAT_GROUP
23146 && vec_safe_length (files) != 1
23149 && (*macinfo_table)[i - 1].code == 0)
23151 unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
23160 /* A dummy entry may be inserted at the beginning to be able
23161 to optimize the whole block of predefined macros. */
23167 output_macinfo_op (ref);
23175 delete macinfo_htab;
23176 macinfo_htab = NULL;
23178 /* If any DW_MACRO_GNU_transparent_include were used, on those
23179 DW_MACRO_GNU_transparent_include entries terminate the
23180 current chain and switch to a new comdat .debug_macinfo
23181 section and emit the define/undef entries within it. */
23182 for (i = 0; macinfo_table->iterate (i, &ref); i++)
23187 case DW_MACRO_GNU_transparent_include:
23189 char label[MAX_ARTIFICIAL_LABEL_BYTES];
23190 tree comdat_key = get_identifier (ref->info);
23191 /* Terminate the previous .debug_macinfo section. */
23192 dw2_asm_output_data (1, 0, "End compilation unit");
23193 targetm.asm_out.named_section (DEBUG_MACRO_SECTION,
23195 | SECTION_LINKONCE,
23197 ASM_GENERATE_INTERNAL_LABEL (label,
23198 DEBUG_MACRO_SECTION_LABEL,
23200 ASM_OUTPUT_LABEL (asm_out_file, label);
23203 dw2_asm_output_data (2, 4, "DWARF macro version number");
23204 if (DWARF_OFFSET_SIZE == 8)
23205 dw2_asm_output_data (1, 1, "Flags: 64-bit");
23207 dw2_asm_output_data (1, 0, "Flags: 32-bit");
23210 case DW_MACINFO_define:
23211 case DW_MACINFO_undef:
23212 output_macinfo_op (ref);
23217 gcc_unreachable ();
23221 /* Set up for Dwarf output at the start of compilation. */
23224 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
23226 /* This option is currently broken, see (PR53118 and PR46102). */
23227 if (flag_eliminate_dwarf2_dups
23228 && strstr (lang_hooks.name, "C++"))
23230 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
23231 flag_eliminate_dwarf2_dups = 0;
23234 /* Allocate the file_table. */
23235 file_table = hash_table<dwarf_file_hasher>::create_ggc (50);
23237 #ifndef DWARF2_LINENO_DEBUGGING_INFO
23238 /* Allocate the decl_die_table. */
23239 decl_die_table = hash_table<decl_die_hasher>::create_ggc (10);
23241 /* Allocate the decl_loc_table. */
23242 decl_loc_table = hash_table<decl_loc_hasher>::create_ggc (10);
23244 /* Allocate the cached_dw_loc_list_table. */
23245 cached_dw_loc_list_table = hash_table<dw_loc_list_hasher>::create_ggc (10);
23247 /* Allocate the initial hunk of the decl_scope_table. */
23248 vec_alloc (decl_scope_table, 256);
23250 /* Allocate the initial hunk of the abbrev_die_table. */
23251 abbrev_die_table = ggc_cleared_vec_alloc<dw_die_ref>
23252 (ABBREV_DIE_TABLE_INCREMENT);
23253 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
23254 /* Zero-th entry is allocated, but unused. */
23255 abbrev_die_table_in_use = 1;
23257 /* Allocate the pubtypes and pubnames vectors. */
23258 vec_alloc (pubname_table, 32);
23259 vec_alloc (pubtype_table, 32);
23261 vec_alloc (incomplete_types, 64);
23263 vec_alloc (used_rtx_array, 32);
23265 if (!dwarf_split_debug_info)
23267 debug_info_section = get_section (DEBUG_INFO_SECTION,
23268 SECTION_DEBUG, NULL);
23269 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
23270 SECTION_DEBUG, NULL);
23271 debug_loc_section = get_section (DEBUG_LOC_SECTION,
23272 SECTION_DEBUG, NULL);
23276 debug_info_section = get_section (DEBUG_DWO_INFO_SECTION,
23277 SECTION_DEBUG | SECTION_EXCLUDE, NULL);
23278 debug_abbrev_section = get_section (DEBUG_DWO_ABBREV_SECTION,
23279 SECTION_DEBUG | SECTION_EXCLUDE,
23281 debug_addr_section = get_section (DEBUG_ADDR_SECTION,
23282 SECTION_DEBUG, NULL);
23283 debug_skeleton_info_section = get_section (DEBUG_INFO_SECTION,
23284 SECTION_DEBUG, NULL);
23285 debug_skeleton_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
23286 SECTION_DEBUG, NULL);
23287 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
23288 DEBUG_SKELETON_ABBREV_SECTION_LABEL, 0);
23290 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
23291 the main .o, but the skeleton_line goes into the split off dwo. */
23292 debug_skeleton_line_section
23293 = get_section (DEBUG_DWO_LINE_SECTION,
23294 SECTION_DEBUG | SECTION_EXCLUDE, NULL);
23295 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
23296 DEBUG_SKELETON_LINE_SECTION_LABEL, 0);
23297 debug_str_offsets_section = get_section (DEBUG_STR_OFFSETS_SECTION,
23298 SECTION_DEBUG | SECTION_EXCLUDE,
23300 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
23301 DEBUG_SKELETON_INFO_SECTION_LABEL, 0);
23302 debug_loc_section = get_section (DEBUG_DWO_LOC_SECTION,
23303 SECTION_DEBUG | SECTION_EXCLUDE, NULL);
23304 debug_str_dwo_section = get_section (DEBUG_STR_DWO_SECTION,
23305 DEBUG_STR_DWO_SECTION_FLAGS, NULL);
23307 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
23308 SECTION_DEBUG, NULL);
23309 debug_macinfo_section = get_section (dwarf_strict
23310 ? DEBUG_MACINFO_SECTION
23311 : DEBUG_MACRO_SECTION,
23312 DEBUG_MACRO_SECTION_FLAGS, NULL);
23313 debug_line_section = get_section (DEBUG_LINE_SECTION,
23314 SECTION_DEBUG, NULL);
23315 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
23316 SECTION_DEBUG, NULL);
23317 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
23318 SECTION_DEBUG, NULL);
23319 debug_str_section = get_section (DEBUG_STR_SECTION,
23320 DEBUG_STR_SECTION_FLAGS, NULL);
23321 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
23322 SECTION_DEBUG, NULL);
23323 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
23324 SECTION_DEBUG, NULL);
23326 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
23327 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
23328 DEBUG_ABBREV_SECTION_LABEL, 0);
23329 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
23330 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
23331 COLD_TEXT_SECTION_LABEL, 0);
23332 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
23334 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
23335 DEBUG_INFO_SECTION_LABEL, 0);
23336 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
23337 DEBUG_LINE_SECTION_LABEL, 0);
23338 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
23339 DEBUG_RANGES_SECTION_LABEL, 0);
23340 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label,
23341 DEBUG_ADDR_SECTION_LABEL, 0);
23342 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
23344 ? DEBUG_MACINFO_SECTION_LABEL
23345 : DEBUG_MACRO_SECTION_LABEL, 0);
23346 ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
23348 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23349 vec_alloc (macinfo_table, 64);
23351 switch_to_section (text_section);
23352 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
23355 /* Make sure the line number table for .text always exists. */
23356 text_section_line_info = new_line_info_table ();
23357 text_section_line_info->end_label = text_end_label;
23359 #ifdef DWARF2_LINENO_DEBUGGING_INFO
23360 cur_line_info_table = text_section_line_info;
23363 /* If front-ends already registered a main translation unit but we were not
23364 ready to perform the association, do this now. */
23365 if (main_translation_unit != NULL_TREE)
23366 equate_decl_number_to_die (main_translation_unit, comp_unit_die ());
23369 /* Called before compile () starts outputtting functions, variables
23370 and toplevel asms into assembly. */
23373 dwarf2out_assembly_start (void)
23375 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23376 && dwarf2out_do_cfi_asm ()
23377 && (!(flag_unwind_tables || flag_exceptions)
23378 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
23379 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
23382 /* A helper function for dwarf2out_finish called through
23383 htab_traverse. Assign a string its index. All strings must be
23384 collected into the table by the time index_string is called,
23385 because the indexing code relies on htab_traverse to traverse nodes
23386 in the same order for each run. */
23389 index_string (indirect_string_node **h, unsigned int *index)
23391 indirect_string_node *node = *h;
23393 find_string_form (node);
23394 if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
23396 gcc_assert (node->index == NO_INDEX_ASSIGNED);
23397 node->index = *index;
23403 /* A helper function for output_indirect_strings called through
23404 htab_traverse. Output the offset to a string and update the
23408 output_index_string_offset (indirect_string_node **h, unsigned int *offset)
23410 indirect_string_node *node = *h;
23412 if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
23414 /* Assert that this node has been assigned an index. */
23415 gcc_assert (node->index != NO_INDEX_ASSIGNED
23416 && node->index != NOT_INDEXED);
23417 dw2_asm_output_data (DWARF_OFFSET_SIZE, *offset,
23418 "indexed string 0x%x: %s", node->index, node->str);
23419 *offset += strlen (node->str) + 1;
23424 /* A helper function for dwarf2out_finish called through
23425 htab_traverse. Output the indexed string. */
23428 output_index_string (indirect_string_node **h, unsigned int *cur_idx)
23430 struct indirect_string_node *node = *h;
23432 if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
23434 /* Assert that the strings are output in the same order as their
23435 indexes were assigned. */
23436 gcc_assert (*cur_idx == node->index);
23437 assemble_string (node->str, strlen (node->str) + 1);
23443 /* A helper function for dwarf2out_finish called through
23444 htab_traverse. Emit one queued .debug_str string. */
23447 output_indirect_string (indirect_string_node **h, void *)
23449 struct indirect_string_node *node = *h;
23451 node->form = find_string_form (node);
23452 if (node->form == DW_FORM_strp && node->refcount > 0)
23454 ASM_OUTPUT_LABEL (asm_out_file, node->label);
23455 assemble_string (node->str, strlen (node->str) + 1);
23461 /* Output the indexed string table. */
23464 output_indirect_strings (void)
23466 switch_to_section (debug_str_section);
23467 if (!dwarf_split_debug_info)
23468 debug_str_hash->traverse<void *, output_indirect_string> (NULL);
23471 unsigned int offset = 0;
23472 unsigned int cur_idx = 0;
23474 skeleton_debug_str_hash->traverse<void *, output_indirect_string> (NULL);
23476 switch_to_section (debug_str_offsets_section);
23477 debug_str_hash->traverse_noresize
23478 <unsigned int *, output_index_string_offset> (&offset);
23479 switch_to_section (debug_str_dwo_section);
23480 debug_str_hash->traverse_noresize<unsigned int *, output_index_string>
23485 /* Callback for htab_traverse to assign an index to an entry in the
23486 table, and to write that entry to the .debug_addr section. */
23489 output_addr_table_entry (addr_table_entry **slot, unsigned int *cur_index)
23491 addr_table_entry *entry = *slot;
23493 if (entry->refcount == 0)
23495 gcc_assert (entry->index == NO_INDEX_ASSIGNED
23496 || entry->index == NOT_INDEXED);
23500 gcc_assert (entry->index == *cur_index);
23503 switch (entry->kind)
23506 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, entry->addr.rtl,
23507 "0x%x", entry->index);
23509 case ate_kind_rtx_dtprel:
23510 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
23511 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
23514 fputc ('\n', asm_out_file);
23516 case ate_kind_label:
23517 dw2_asm_output_addr (DWARF2_ADDR_SIZE, entry->addr.label,
23518 "0x%x", entry->index);
23521 gcc_unreachable ();
23526 /* Produce the .debug_addr section. */
23529 output_addr_table (void)
23531 unsigned int index = 0;
23532 if (addr_index_table == NULL || addr_index_table->size () == 0)
23535 switch_to_section (debug_addr_section);
23537 ->traverse_noresize<unsigned int *, output_addr_table_entry> (&index);
23540 #if ENABLE_ASSERT_CHECKING
23541 /* Verify that all marks are clear. */
23544 verify_marks_clear (dw_die_ref die)
23548 gcc_assert (! die->die_mark);
23549 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
23551 #endif /* ENABLE_ASSERT_CHECKING */
23553 /* Clear the marks for a die and its children.
23554 Be cool if the mark isn't set. */
23557 prune_unmark_dies (dw_die_ref die)
23563 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
23566 /* Given DIE that we're marking as used, find any other dies
23567 it references as attributes and mark them as used. */
23570 prune_unused_types_walk_attribs (dw_die_ref die)
23575 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
23577 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
23579 /* A reference to another DIE.
23580 Make sure that it will get emitted.
23581 If it was broken out into a comdat group, don't follow it. */
23582 if (! AT_ref (a)->comdat_type_p
23583 || a->dw_attr == DW_AT_specification)
23584 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
23586 /* Set the string's refcount to 0 so that prune_unused_types_mark
23587 accounts properly for it. */
23588 if (AT_class (a) == dw_val_class_str)
23589 a->dw_attr_val.v.val_str->refcount = 0;
23593 /* Mark the generic parameters and arguments children DIEs of DIE. */
23596 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
23600 if (die == NULL || die->die_child == NULL)
23602 c = die->die_child;
23605 if (is_template_parameter (c))
23606 prune_unused_types_mark (c, 1);
23608 } while (c && c != die->die_child);
23611 /* Mark DIE as being used. If DOKIDS is true, then walk down
23612 to DIE's children. */
23615 prune_unused_types_mark (dw_die_ref die, int dokids)
23619 if (die->die_mark == 0)
23621 /* We haven't done this node yet. Mark it as used. */
23623 /* If this is the DIE of a generic type instantiation,
23624 mark the children DIEs that describe its generic parms and
23626 prune_unused_types_mark_generic_parms_dies (die);
23628 /* We also have to mark its parents as used.
23629 (But we don't want to mark our parent's kids due to this,
23630 unless it is a class.) */
23631 if (die->die_parent)
23632 prune_unused_types_mark (die->die_parent,
23633 class_scope_p (die->die_parent));
23635 /* Mark any referenced nodes. */
23636 prune_unused_types_walk_attribs (die);
23638 /* If this node is a specification,
23639 also mark the definition, if it exists. */
23640 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
23641 prune_unused_types_mark (die->die_definition, 1);
23644 if (dokids && die->die_mark != 2)
23646 /* We need to walk the children, but haven't done so yet.
23647 Remember that we've walked the kids. */
23650 /* If this is an array type, we need to make sure our
23651 kids get marked, even if they're types. If we're
23652 breaking out types into comdat sections, do this
23653 for all type definitions. */
23654 if (die->die_tag == DW_TAG_array_type
23655 || (use_debug_types
23656 && is_type_die (die) && ! is_declaration_die (die)))
23657 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
23659 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23663 /* For local classes, look if any static member functions were emitted
23664 and if so, mark them. */
23667 prune_unused_types_walk_local_classes (dw_die_ref die)
23671 if (die->die_mark == 2)
23674 switch (die->die_tag)
23676 case DW_TAG_structure_type:
23677 case DW_TAG_union_type:
23678 case DW_TAG_class_type:
23681 case DW_TAG_subprogram:
23682 if (!get_AT_flag (die, DW_AT_declaration)
23683 || die->die_definition != NULL)
23684 prune_unused_types_mark (die, 1);
23691 /* Mark children. */
23692 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
23695 /* Walk the tree DIE and mark types that we actually use. */
23698 prune_unused_types_walk (dw_die_ref die)
23702 /* Don't do anything if this node is already marked and
23703 children have been marked as well. */
23704 if (die->die_mark == 2)
23707 switch (die->die_tag)
23709 case DW_TAG_structure_type:
23710 case DW_TAG_union_type:
23711 case DW_TAG_class_type:
23712 if (die->die_perennial_p)
23715 for (c = die->die_parent; c; c = c->die_parent)
23716 if (c->die_tag == DW_TAG_subprogram)
23719 /* Finding used static member functions inside of classes
23720 is needed just for local classes, because for other classes
23721 static member function DIEs with DW_AT_specification
23722 are emitted outside of the DW_TAG_*_type. If we ever change
23723 it, we'd need to call this even for non-local classes. */
23725 prune_unused_types_walk_local_classes (die);
23727 /* It's a type node --- don't mark it. */
23730 case DW_TAG_const_type:
23731 case DW_TAG_packed_type:
23732 case DW_TAG_pointer_type:
23733 case DW_TAG_reference_type:
23734 case DW_TAG_rvalue_reference_type:
23735 case DW_TAG_volatile_type:
23736 case DW_TAG_typedef:
23737 case DW_TAG_array_type:
23738 case DW_TAG_interface_type:
23739 case DW_TAG_friend:
23740 case DW_TAG_variant_part:
23741 case DW_TAG_enumeration_type:
23742 case DW_TAG_subroutine_type:
23743 case DW_TAG_string_type:
23744 case DW_TAG_set_type:
23745 case DW_TAG_subrange_type:
23746 case DW_TAG_ptr_to_member_type:
23747 case DW_TAG_file_type:
23748 if (die->die_perennial_p)
23751 /* It's a type node --- don't mark it. */
23755 /* Mark everything else. */
23759 if (die->die_mark == 0)
23763 /* Now, mark any dies referenced from here. */
23764 prune_unused_types_walk_attribs (die);
23769 /* Mark children. */
23770 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23773 /* Increment the string counts on strings referred to from DIE's
23777 prune_unused_types_update_strings (dw_die_ref die)
23782 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
23783 if (AT_class (a) == dw_val_class_str)
23785 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
23787 /* Avoid unnecessarily putting strings that are used less than
23788 twice in the hash table. */
23790 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
23792 indirect_string_node **slot
23793 = debug_str_hash->find_slot_with_hash (s->str,
23794 htab_hash_string (s->str),
23796 gcc_assert (*slot == NULL);
23802 /* Remove from the tree DIE any dies that aren't marked. */
23805 prune_unused_types_prune (dw_die_ref die)
23809 gcc_assert (die->die_mark);
23810 prune_unused_types_update_strings (die);
23812 if (! die->die_child)
23815 c = die->die_child;
23817 dw_die_ref prev = c;
23818 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
23819 if (c == die->die_child)
23821 /* No marked children between 'prev' and the end of the list. */
23823 /* No marked children at all. */
23824 die->die_child = NULL;
23827 prev->die_sib = c->die_sib;
23828 die->die_child = prev;
23833 if (c != prev->die_sib)
23835 prune_unused_types_prune (c);
23836 } while (c != die->die_child);
23839 /* Remove dies representing declarations that we never use. */
23842 prune_unused_types (void)
23845 limbo_die_node *node;
23846 comdat_type_node *ctnode;
23847 pubname_entry *pub;
23848 dw_die_ref base_type;
23850 #if ENABLE_ASSERT_CHECKING
23851 /* All the marks should already be clear. */
23852 verify_marks_clear (comp_unit_die ());
23853 for (node = limbo_die_list; node; node = node->next)
23854 verify_marks_clear (node->die);
23855 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23856 verify_marks_clear (ctnode->root_die);
23857 #endif /* ENABLE_ASSERT_CHECKING */
23859 /* Mark types that are used in global variables. */
23860 premark_types_used_by_global_vars ();
23862 /* Set the mark on nodes that are actually used. */
23863 prune_unused_types_walk (comp_unit_die ());
23864 for (node = limbo_die_list; node; node = node->next)
23865 prune_unused_types_walk (node->die);
23866 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23868 prune_unused_types_walk (ctnode->root_die);
23869 prune_unused_types_mark (ctnode->type_die, 1);
23872 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
23873 are unusual in that they are pubnames that are the children of pubtypes.
23874 They should only be marked via their parent DW_TAG_enumeration_type die,
23875 not as roots in themselves. */
23876 FOR_EACH_VEC_ELT (*pubname_table, i, pub)
23877 if (pub->die->die_tag != DW_TAG_enumerator)
23878 prune_unused_types_mark (pub->die, 1);
23879 for (i = 0; base_types.iterate (i, &base_type); i++)
23880 prune_unused_types_mark (base_type, 1);
23882 if (debug_str_hash)
23883 debug_str_hash->empty ();
23884 if (skeleton_debug_str_hash)
23885 skeleton_debug_str_hash->empty ();
23886 prune_unused_types_prune (comp_unit_die ());
23887 for (limbo_die_node **pnode = &limbo_die_list; *pnode; )
23890 if (!node->die->die_mark)
23891 *pnode = node->next;
23894 prune_unused_types_prune (node->die);
23895 pnode = &node->next;
23898 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23899 prune_unused_types_prune (ctnode->root_die);
23901 /* Leave the marks clear. */
23902 prune_unmark_dies (comp_unit_die ());
23903 for (node = limbo_die_list; node; node = node->next)
23904 prune_unmark_dies (node->die);
23905 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23906 prune_unmark_dies (ctnode->root_die);
23909 /* Set the parameter to true if there are any relative pathnames in
23912 file_table_relative_p (dwarf_file_data **slot, bool *p)
23914 struct dwarf_file_data *d = *slot;
23915 if (!IS_ABSOLUTE_PATH (d->filename))
23923 /* Helpers to manipulate hash table of comdat type units. */
23925 struct comdat_type_hasher : nofree_ptr_hash <comdat_type_node>
23927 static inline hashval_t hash (const comdat_type_node *);
23928 static inline bool equal (const comdat_type_node *, const comdat_type_node *);
23932 comdat_type_hasher::hash (const comdat_type_node *type_node)
23935 memcpy (&h, type_node->signature, sizeof (h));
23940 comdat_type_hasher::equal (const comdat_type_node *type_node_1,
23941 const comdat_type_node *type_node_2)
23943 return (! memcmp (type_node_1->signature, type_node_2->signature,
23944 DWARF_TYPE_SIGNATURE_SIZE));
23947 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23948 to the location it would have been added, should we know its
23949 DECL_ASSEMBLER_NAME when we added other attributes. This will
23950 probably improve compactness of debug info, removing equivalent
23951 abbrevs, and hide any differences caused by deferring the
23952 computation of the assembler name, triggered by e.g. PCH. */
23955 move_linkage_attr (dw_die_ref die)
23957 unsigned ix = vec_safe_length (die->die_attr);
23958 dw_attr_node linkage = (*die->die_attr)[ix - 1];
23960 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
23961 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
23965 dw_attr_node *prev = &(*die->die_attr)[ix - 1];
23967 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
23971 if (ix != vec_safe_length (die->die_attr) - 1)
23973 die->die_attr->pop ();
23974 die->die_attr->quick_insert (ix, linkage);
23978 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
23979 referenced from typed stack ops and count how often they are used. */
23982 mark_base_types (dw_loc_descr_ref loc)
23984 dw_die_ref base_type = NULL;
23986 for (; loc; loc = loc->dw_loc_next)
23988 switch (loc->dw_loc_opc)
23990 case DW_OP_GNU_regval_type:
23991 case DW_OP_GNU_deref_type:
23992 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
23994 case DW_OP_GNU_convert:
23995 case DW_OP_GNU_reinterpret:
23996 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
23999 case DW_OP_GNU_const_type:
24000 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
24002 case DW_OP_GNU_entry_value:
24003 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
24008 gcc_assert (base_type->die_parent == comp_unit_die ());
24009 if (base_type->die_mark)
24010 base_type->die_mark++;
24013 base_types.safe_push (base_type);
24014 base_type->die_mark = 1;
24019 /* Comparison function for sorting marked base types. */
24022 base_type_cmp (const void *x, const void *y)
24024 dw_die_ref dx = *(const dw_die_ref *) x;
24025 dw_die_ref dy = *(const dw_die_ref *) y;
24026 unsigned int byte_size1, byte_size2;
24027 unsigned int encoding1, encoding2;
24028 if (dx->die_mark > dy->die_mark)
24030 if (dx->die_mark < dy->die_mark)
24032 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
24033 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
24034 if (byte_size1 < byte_size2)
24036 if (byte_size1 > byte_size2)
24038 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
24039 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
24040 if (encoding1 < encoding2)
24042 if (encoding1 > encoding2)
24047 /* Move base types marked by mark_base_types as early as possible
24048 in the CU, sorted by decreasing usage count both to make the
24049 uleb128 references as small as possible and to make sure they
24050 will have die_offset already computed by calc_die_sizes when
24051 sizes of typed stack loc ops is computed. */
24054 move_marked_base_types (void)
24057 dw_die_ref base_type, die, c;
24059 if (base_types.is_empty ())
24062 /* Sort by decreasing usage count, they will be added again in that
24064 base_types.qsort (base_type_cmp);
24065 die = comp_unit_die ();
24066 c = die->die_child;
24069 dw_die_ref prev = c;
24071 while (c->die_mark)
24073 remove_child_with_prev (c, prev);
24074 /* As base types got marked, there must be at least
24075 one node other than DW_TAG_base_type. */
24076 gcc_assert (c != c->die_sib);
24080 while (c != die->die_child);
24081 gcc_assert (die->die_child);
24082 c = die->die_child;
24083 for (i = 0; base_types.iterate (i, &base_type); i++)
24085 base_type->die_mark = 0;
24086 base_type->die_sib = c->die_sib;
24087 c->die_sib = base_type;
24092 /* Helper function for resolve_addr, attempt to resolve
24093 one CONST_STRING, return true if successful. Similarly verify that
24094 SYMBOL_REFs refer to variables emitted in the current CU. */
24097 resolve_one_addr (rtx *addr)
24101 if (GET_CODE (rtl) == CONST_STRING)
24103 size_t len = strlen (XSTR (rtl, 0)) + 1;
24104 tree t = build_string (len, XSTR (rtl, 0));
24105 tree tlen = size_int (len - 1);
24107 = build_array_type (char_type_node, build_index_type (tlen));
24108 rtl = lookup_constant_def (t);
24109 if (!rtl || !MEM_P (rtl))
24111 rtl = XEXP (rtl, 0);
24112 if (GET_CODE (rtl) == SYMBOL_REF
24113 && SYMBOL_REF_DECL (rtl)
24114 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
24116 vec_safe_push (used_rtx_array, rtl);
24121 if (GET_CODE (rtl) == SYMBOL_REF
24122 && SYMBOL_REF_DECL (rtl))
24124 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
24126 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
24129 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
24133 if (GET_CODE (rtl) == CONST)
24135 subrtx_ptr_iterator::array_type array;
24136 FOR_EACH_SUBRTX_PTR (iter, array, &XEXP (rtl, 0), ALL)
24137 if (!resolve_one_addr (*iter))
24144 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
24145 if possible, and create DW_TAG_dwarf_procedure that can be referenced
24146 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
24149 string_cst_pool_decl (tree t)
24151 rtx rtl = output_constant_def (t, 1);
24152 unsigned char *array;
24153 dw_loc_descr_ref l;
24158 if (!rtl || !MEM_P (rtl))
24160 rtl = XEXP (rtl, 0);
24161 if (GET_CODE (rtl) != SYMBOL_REF
24162 || SYMBOL_REF_DECL (rtl) == NULL_TREE)
24165 decl = SYMBOL_REF_DECL (rtl);
24166 if (!lookup_decl_die (decl))
24168 len = TREE_STRING_LENGTH (t);
24169 vec_safe_push (used_rtx_array, rtl);
24170 ref = new_die (DW_TAG_dwarf_procedure, comp_unit_die (), decl);
24171 array = ggc_vec_alloc<unsigned char> (len);
24172 memcpy (array, TREE_STRING_POINTER (t), len);
24173 l = new_loc_descr (DW_OP_implicit_value, len, 0);
24174 l->dw_loc_oprnd2.val_class = dw_val_class_vec;
24175 l->dw_loc_oprnd2.v.val_vec.length = len;
24176 l->dw_loc_oprnd2.v.val_vec.elt_size = 1;
24177 l->dw_loc_oprnd2.v.val_vec.array = array;
24178 add_AT_loc (ref, DW_AT_location, l);
24179 equate_decl_number_to_die (decl, ref);
24184 /* Helper function of resolve_addr_in_expr. LOC is
24185 a DW_OP_addr followed by DW_OP_stack_value, either at the start
24186 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
24187 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
24188 with DW_OP_GNU_implicit_pointer if possible
24189 and return true, if unsuccessful, return false. */
24192 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc)
24194 rtx rtl = loc->dw_loc_oprnd1.v.val_addr;
24195 HOST_WIDE_INT offset = 0;
24196 dw_die_ref ref = NULL;
24199 if (GET_CODE (rtl) == CONST
24200 && GET_CODE (XEXP (rtl, 0)) == PLUS
24201 && CONST_INT_P (XEXP (XEXP (rtl, 0), 1)))
24203 offset = INTVAL (XEXP (XEXP (rtl, 0), 1));
24204 rtl = XEXP (XEXP (rtl, 0), 0);
24206 if (GET_CODE (rtl) == CONST_STRING)
24208 size_t len = strlen (XSTR (rtl, 0)) + 1;
24209 tree t = build_string (len, XSTR (rtl, 0));
24210 tree tlen = size_int (len - 1);
24213 = build_array_type (char_type_node, build_index_type (tlen));
24214 rtl = string_cst_pool_decl (t);
24218 if (GET_CODE (rtl) == SYMBOL_REF && SYMBOL_REF_DECL (rtl))
24220 decl = SYMBOL_REF_DECL (rtl);
24221 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
24223 ref = lookup_decl_die (decl);
24224 if (ref && (get_AT (ref, DW_AT_location)
24225 || get_AT (ref, DW_AT_const_value)))
24227 loc->dw_loc_opc = DW_OP_GNU_implicit_pointer;
24228 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
24229 loc->dw_loc_oprnd1.val_entry = NULL;
24230 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
24231 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
24232 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
24233 loc->dw_loc_oprnd2.v.val_int = offset;
24241 /* Helper function for resolve_addr, handle one location
24242 expression, return false if at least one CONST_STRING or SYMBOL_REF in
24243 the location list couldn't be resolved. */
24246 resolve_addr_in_expr (dw_loc_descr_ref loc)
24248 dw_loc_descr_ref keep = NULL;
24249 for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = loc->dw_loc_next)
24250 switch (loc->dw_loc_opc)
24253 if (!resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
24256 || prev->dw_loc_opc == DW_OP_piece
24257 || prev->dw_loc_opc == DW_OP_bit_piece)
24258 && loc->dw_loc_next
24259 && loc->dw_loc_next->dw_loc_opc == DW_OP_stack_value
24261 && optimize_one_addr_into_implicit_ptr (loc))
24266 case DW_OP_GNU_addr_index:
24267 case DW_OP_GNU_const_index:
24268 if (loc->dw_loc_opc == DW_OP_GNU_addr_index
24269 || (loc->dw_loc_opc == DW_OP_GNU_const_index && loc->dtprel))
24271 rtx rtl = loc->dw_loc_oprnd1.val_entry->addr.rtl;
24272 if (!resolve_one_addr (&rtl))
24274 remove_addr_table_entry (loc->dw_loc_oprnd1.val_entry);
24275 loc->dw_loc_oprnd1.val_entry =
24276 add_addr_table_entry (rtl, ate_kind_rtx);
24279 case DW_OP_const4u:
24280 case DW_OP_const8u:
24282 && !resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
24285 case DW_OP_plus_uconst:
24286 if (size_of_loc_descr (loc)
24287 > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
24289 && loc->dw_loc_oprnd1.v.val_unsigned > 0)
24291 dw_loc_descr_ref repl
24292 = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
24293 add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
24294 add_loc_descr (&repl, loc->dw_loc_next);
24298 case DW_OP_implicit_value:
24299 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
24300 && !resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr))
24303 case DW_OP_GNU_implicit_pointer:
24304 case DW_OP_GNU_parameter_ref:
24305 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
24308 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
24311 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
24312 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
24313 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
24316 case DW_OP_GNU_const_type:
24317 case DW_OP_GNU_regval_type:
24318 case DW_OP_GNU_deref_type:
24319 case DW_OP_GNU_convert:
24320 case DW_OP_GNU_reinterpret:
24321 while (loc->dw_loc_next
24322 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
24324 dw_die_ref base1, base2;
24325 unsigned enc1, enc2, size1, size2;
24326 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
24327 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
24328 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
24329 else if (loc->dw_loc_oprnd1.val_class
24330 == dw_val_class_unsigned_const)
24333 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
24334 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
24335 == dw_val_class_unsigned_const)
24337 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
24338 gcc_assert (base1->die_tag == DW_TAG_base_type
24339 && base2->die_tag == DW_TAG_base_type);
24340 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
24341 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
24342 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
24343 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
24345 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
24346 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
24350 /* Optimize away next DW_OP_GNU_convert after
24351 adjusting LOC's base type die reference. */
24352 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
24353 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
24354 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
24356 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
24357 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
24360 /* Don't change integer DW_OP_GNU_convert after e.g. floating
24361 point typed stack entry. */
24362 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
24363 keep = loc->dw_loc_next;
24373 /* Helper function of resolve_addr. DIE had DW_AT_location of
24374 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
24375 and DW_OP_addr couldn't be resolved. resolve_addr has already
24376 removed the DW_AT_location attribute. This function attempts to
24377 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
24378 to it or DW_AT_const_value attribute, if possible. */
24381 optimize_location_into_implicit_ptr (dw_die_ref die, tree decl)
24383 if (TREE_CODE (decl) != VAR_DECL
24384 || lookup_decl_die (decl) != die
24385 || DECL_EXTERNAL (decl)
24386 || !TREE_STATIC (decl)
24387 || DECL_INITIAL (decl) == NULL_TREE
24388 || DECL_P (DECL_INITIAL (decl))
24389 || get_AT (die, DW_AT_const_value))
24392 tree init = DECL_INITIAL (decl);
24393 HOST_WIDE_INT offset = 0;
24394 /* For variables that have been optimized away and thus
24395 don't have a memory location, see if we can emit
24396 DW_AT_const_value instead. */
24397 if (tree_add_const_value_attribute (die, init))
24401 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
24402 and ADDR_EXPR refers to a decl that has DW_AT_location or
24403 DW_AT_const_value (but isn't addressable, otherwise
24404 resolving the original DW_OP_addr wouldn't fail), see if
24405 we can add DW_OP_GNU_implicit_pointer. */
24407 if (TREE_CODE (init) == POINTER_PLUS_EXPR
24408 && tree_fits_shwi_p (TREE_OPERAND (init, 1)))
24410 offset = tree_to_shwi (TREE_OPERAND (init, 1));
24411 init = TREE_OPERAND (init, 0);
24414 if (TREE_CODE (init) != ADDR_EXPR)
24416 if ((TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST
24417 && !TREE_ASM_WRITTEN (TREE_OPERAND (init, 0)))
24418 || (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL
24419 && !DECL_EXTERNAL (TREE_OPERAND (init, 0))
24420 && TREE_OPERAND (init, 0) != decl))
24423 dw_loc_descr_ref l;
24425 if (TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST)
24427 rtx rtl = string_cst_pool_decl (TREE_OPERAND (init, 0));
24430 decl = SYMBOL_REF_DECL (rtl);
24433 decl = TREE_OPERAND (init, 0);
24434 ref = lookup_decl_die (decl);
24436 || (!get_AT (ref, DW_AT_location)
24437 && !get_AT (ref, DW_AT_const_value)))
24439 l = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
24440 l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
24441 l->dw_loc_oprnd1.v.val_die_ref.die = ref;
24442 l->dw_loc_oprnd1.v.val_die_ref.external = 0;
24443 add_AT_loc (die, DW_AT_location, l);
24447 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
24448 an address in .rodata section if the string literal is emitted there,
24449 or remove the containing location list or replace DW_AT_const_value
24450 with DW_AT_location and empty location expression, if it isn't found
24451 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
24452 to something that has been emitted in the current CU. */
24455 resolve_addr (dw_die_ref die)
24459 dw_loc_list_ref *curr, *start, loc;
24462 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
24463 switch (AT_class (a))
24465 case dw_val_class_loc_list:
24466 start = curr = AT_loc_list_ptr (a);
24469 /* The same list can be referenced more than once. See if we have
24470 already recorded the result from a previous pass. */
24472 *curr = loc->dw_loc_next;
24473 else if (!loc->resolved_addr)
24475 /* As things stand, we do not expect or allow one die to
24476 reference a suffix of another die's location list chain.
24477 References must be identical or completely separate.
24478 There is therefore no need to cache the result of this
24479 pass on any list other than the first; doing so
24480 would lead to unnecessary writes. */
24483 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
24484 if (!resolve_addr_in_expr ((*curr)->expr))
24486 dw_loc_list_ref next = (*curr)->dw_loc_next;
24487 dw_loc_descr_ref l = (*curr)->expr;
24489 if (next && (*curr)->ll_symbol)
24491 gcc_assert (!next->ll_symbol);
24492 next->ll_symbol = (*curr)->ll_symbol;
24494 if (dwarf_split_debug_info)
24495 remove_loc_list_addr_table_entries (l);
24500 mark_base_types ((*curr)->expr);
24501 curr = &(*curr)->dw_loc_next;
24505 loc->resolved_addr = 1;
24509 loc->dw_loc_next = *start;
24514 remove_AT (die, a->dw_attr);
24518 case dw_val_class_loc:
24520 dw_loc_descr_ref l = AT_loc (a);
24521 /* For -gdwarf-2 don't attempt to optimize
24522 DW_AT_data_member_location containing
24523 DW_OP_plus_uconst - older consumers might
24524 rely on it being that op instead of a more complex,
24525 but shorter, location description. */
24526 if ((dwarf_version > 2
24527 || a->dw_attr != DW_AT_data_member_location
24529 || l->dw_loc_opc != DW_OP_plus_uconst
24530 || l->dw_loc_next != NULL)
24531 && !resolve_addr_in_expr (l))
24533 if (dwarf_split_debug_info)
24534 remove_loc_list_addr_table_entries (l);
24536 && l->dw_loc_next == NULL
24537 && l->dw_loc_opc == DW_OP_addr
24538 && GET_CODE (l->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF
24539 && SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr)
24540 && a->dw_attr == DW_AT_location)
24542 tree decl = SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr);
24543 remove_AT (die, a->dw_attr);
24545 optimize_location_into_implicit_ptr (die, decl);
24548 remove_AT (die, a->dw_attr);
24552 mark_base_types (l);
24555 case dw_val_class_addr:
24556 if (a->dw_attr == DW_AT_const_value
24557 && !resolve_one_addr (&a->dw_attr_val.v.val_addr))
24559 if (AT_index (a) != NOT_INDEXED)
24560 remove_addr_table_entry (a->dw_attr_val.val_entry);
24561 remove_AT (die, a->dw_attr);
24564 if (die->die_tag == DW_TAG_GNU_call_site
24565 && a->dw_attr == DW_AT_abstract_origin)
24567 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
24568 dw_die_ref tdie = lookup_decl_die (tdecl);
24571 && DECL_EXTERNAL (tdecl)
24572 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE
24573 && (cdie = lookup_context_die (DECL_CONTEXT (tdecl))))
24575 /* Creating a full DIE for tdecl is overly expensive and
24576 at this point even wrong when in the LTO phase
24577 as it can end up generating new type DIEs we didn't
24578 output and thus optimize_external_refs will crash. */
24579 tdie = new_die (DW_TAG_subprogram, cdie, NULL_TREE);
24580 add_AT_flag (tdie, DW_AT_external, 1);
24581 add_AT_flag (tdie, DW_AT_declaration, 1);
24582 add_linkage_attr (tdie, tdecl);
24583 add_name_and_src_coords_attributes (tdie, tdecl);
24584 equate_decl_number_to_die (tdecl, tdie);
24588 a->dw_attr_val.val_class = dw_val_class_die_ref;
24589 a->dw_attr_val.v.val_die_ref.die = tdie;
24590 a->dw_attr_val.v.val_die_ref.external = 0;
24594 if (AT_index (a) != NOT_INDEXED)
24595 remove_addr_table_entry (a->dw_attr_val.val_entry);
24596 remove_AT (die, a->dw_attr);
24605 FOR_EACH_CHILD (die, c, resolve_addr (c));
24608 /* Helper routines for optimize_location_lists.
24609 This pass tries to share identical local lists in .debug_loc
24612 /* Iteratively hash operands of LOC opcode into HSTATE. */
24615 hash_loc_operands (dw_loc_descr_ref loc, inchash::hash &hstate)
24617 dw_val_ref val1 = &loc->dw_loc_oprnd1;
24618 dw_val_ref val2 = &loc->dw_loc_oprnd2;
24620 switch (loc->dw_loc_opc)
24622 case DW_OP_const4u:
24623 case DW_OP_const8u:
24627 case DW_OP_const1u:
24628 case DW_OP_const1s:
24629 case DW_OP_const2u:
24630 case DW_OP_const2s:
24631 case DW_OP_const4s:
24632 case DW_OP_const8s:
24636 case DW_OP_plus_uconst:
24672 case DW_OP_deref_size:
24673 case DW_OP_xderef_size:
24674 hstate.add_object (val1->v.val_int);
24681 gcc_assert (val1->val_class == dw_val_class_loc);
24682 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
24683 hstate.add_object (offset);
24686 case DW_OP_implicit_value:
24687 hstate.add_object (val1->v.val_unsigned);
24688 switch (val2->val_class)
24690 case dw_val_class_const:
24691 hstate.add_object (val2->v.val_int);
24693 case dw_val_class_vec:
24695 unsigned int elt_size = val2->v.val_vec.elt_size;
24696 unsigned int len = val2->v.val_vec.length;
24698 hstate.add_int (elt_size);
24699 hstate.add_int (len);
24700 hstate.add (val2->v.val_vec.array, len * elt_size);
24703 case dw_val_class_const_double:
24704 hstate.add_object (val2->v.val_double.low);
24705 hstate.add_object (val2->v.val_double.high);
24707 case dw_val_class_wide_int:
24708 hstate.add (val2->v.val_wide->get_val (),
24709 get_full_len (*val2->v.val_wide)
24710 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
24712 case dw_val_class_addr:
24713 inchash::add_rtx (val2->v.val_addr, hstate);
24716 gcc_unreachable ();
24720 case DW_OP_bit_piece:
24721 hstate.add_object (val1->v.val_int);
24722 hstate.add_object (val2->v.val_int);
24728 unsigned char dtprel = 0xd1;
24729 hstate.add_object (dtprel);
24731 inchash::add_rtx (val1->v.val_addr, hstate);
24733 case DW_OP_GNU_addr_index:
24734 case DW_OP_GNU_const_index:
24738 unsigned char dtprel = 0xd1;
24739 hstate.add_object (dtprel);
24741 inchash::add_rtx (val1->val_entry->addr.rtl, hstate);
24744 case DW_OP_GNU_implicit_pointer:
24745 hstate.add_int (val2->v.val_int);
24747 case DW_OP_GNU_entry_value:
24748 hstate.add_object (val1->v.val_loc);
24750 case DW_OP_GNU_regval_type:
24751 case DW_OP_GNU_deref_type:
24753 unsigned int byte_size
24754 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
24755 unsigned int encoding
24756 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
24757 hstate.add_object (val1->v.val_int);
24758 hstate.add_object (byte_size);
24759 hstate.add_object (encoding);
24762 case DW_OP_GNU_convert:
24763 case DW_OP_GNU_reinterpret:
24764 if (val1->val_class == dw_val_class_unsigned_const)
24766 hstate.add_object (val1->v.val_unsigned);
24770 case DW_OP_GNU_const_type:
24772 unsigned int byte_size
24773 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
24774 unsigned int encoding
24775 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
24776 hstate.add_object (byte_size);
24777 hstate.add_object (encoding);
24778 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
24780 hstate.add_object (val2->val_class);
24781 switch (val2->val_class)
24783 case dw_val_class_const:
24784 hstate.add_object (val2->v.val_int);
24786 case dw_val_class_vec:
24788 unsigned int elt_size = val2->v.val_vec.elt_size;
24789 unsigned int len = val2->v.val_vec.length;
24791 hstate.add_object (elt_size);
24792 hstate.add_object (len);
24793 hstate.add (val2->v.val_vec.array, len * elt_size);
24796 case dw_val_class_const_double:
24797 hstate.add_object (val2->v.val_double.low);
24798 hstate.add_object (val2->v.val_double.high);
24800 case dw_val_class_wide_int:
24801 hstate.add (val2->v.val_wide->get_val (),
24802 get_full_len (*val2->v.val_wide)
24803 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
24806 gcc_unreachable ();
24812 /* Other codes have no operands. */
24817 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
24820 hash_locs (dw_loc_descr_ref loc, inchash::hash &hstate)
24822 dw_loc_descr_ref l;
24823 bool sizes_computed = false;
24824 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24825 size_of_locs (loc);
24827 for (l = loc; l != NULL; l = l->dw_loc_next)
24829 enum dwarf_location_atom opc = l->dw_loc_opc;
24830 hstate.add_object (opc);
24831 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
24833 size_of_locs (loc);
24834 sizes_computed = true;
24836 hash_loc_operands (l, hstate);
24840 /* Compute hash of the whole location list LIST_HEAD. */
24843 hash_loc_list (dw_loc_list_ref list_head)
24845 dw_loc_list_ref curr = list_head;
24846 inchash::hash hstate;
24848 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
24850 hstate.add (curr->begin, strlen (curr->begin) + 1);
24851 hstate.add (curr->end, strlen (curr->end) + 1);
24853 hstate.add (curr->section, strlen (curr->section) + 1);
24854 hash_locs (curr->expr, hstate);
24856 list_head->hash = hstate.end ();
24859 /* Return true if X and Y opcodes have the same operands. */
24862 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
24864 dw_val_ref valx1 = &x->dw_loc_oprnd1;
24865 dw_val_ref valx2 = &x->dw_loc_oprnd2;
24866 dw_val_ref valy1 = &y->dw_loc_oprnd1;
24867 dw_val_ref valy2 = &y->dw_loc_oprnd2;
24869 switch (x->dw_loc_opc)
24871 case DW_OP_const4u:
24872 case DW_OP_const8u:
24876 case DW_OP_const1u:
24877 case DW_OP_const1s:
24878 case DW_OP_const2u:
24879 case DW_OP_const2s:
24880 case DW_OP_const4s:
24881 case DW_OP_const8s:
24885 case DW_OP_plus_uconst:
24921 case DW_OP_deref_size:
24922 case DW_OP_xderef_size:
24923 return valx1->v.val_int == valy1->v.val_int;
24926 /* If splitting debug info, the use of DW_OP_GNU_addr_index
24927 can cause irrelevant differences in dw_loc_addr. */
24928 gcc_assert (valx1->val_class == dw_val_class_loc
24929 && valy1->val_class == dw_val_class_loc
24930 && (dwarf_split_debug_info
24931 || x->dw_loc_addr == y->dw_loc_addr));
24932 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
24933 case DW_OP_implicit_value:
24934 if (valx1->v.val_unsigned != valy1->v.val_unsigned
24935 || valx2->val_class != valy2->val_class)
24937 switch (valx2->val_class)
24939 case dw_val_class_const:
24940 return valx2->v.val_int == valy2->v.val_int;
24941 case dw_val_class_vec:
24942 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24943 && valx2->v.val_vec.length == valy2->v.val_vec.length
24944 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24945 valx2->v.val_vec.elt_size
24946 * valx2->v.val_vec.length) == 0;
24947 case dw_val_class_const_double:
24948 return valx2->v.val_double.low == valy2->v.val_double.low
24949 && valx2->v.val_double.high == valy2->v.val_double.high;
24950 case dw_val_class_wide_int:
24951 return *valx2->v.val_wide == *valy2->v.val_wide;
24952 case dw_val_class_addr:
24953 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
24955 gcc_unreachable ();
24958 case DW_OP_bit_piece:
24959 return valx1->v.val_int == valy1->v.val_int
24960 && valx2->v.val_int == valy2->v.val_int;
24963 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
24964 case DW_OP_GNU_addr_index:
24965 case DW_OP_GNU_const_index:
24967 rtx ax1 = valx1->val_entry->addr.rtl;
24968 rtx ay1 = valy1->val_entry->addr.rtl;
24969 return rtx_equal_p (ax1, ay1);
24971 case DW_OP_GNU_implicit_pointer:
24972 return valx1->val_class == dw_val_class_die_ref
24973 && valx1->val_class == valy1->val_class
24974 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
24975 && valx2->v.val_int == valy2->v.val_int;
24976 case DW_OP_GNU_entry_value:
24977 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
24978 case DW_OP_GNU_const_type:
24979 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
24980 || valx2->val_class != valy2->val_class)
24982 switch (valx2->val_class)
24984 case dw_val_class_const:
24985 return valx2->v.val_int == valy2->v.val_int;
24986 case dw_val_class_vec:
24987 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24988 && valx2->v.val_vec.length == valy2->v.val_vec.length
24989 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24990 valx2->v.val_vec.elt_size
24991 * valx2->v.val_vec.length) == 0;
24992 case dw_val_class_const_double:
24993 return valx2->v.val_double.low == valy2->v.val_double.low
24994 && valx2->v.val_double.high == valy2->v.val_double.high;
24995 case dw_val_class_wide_int:
24996 return *valx2->v.val_wide == *valy2->v.val_wide;
24998 gcc_unreachable ();
25000 case DW_OP_GNU_regval_type:
25001 case DW_OP_GNU_deref_type:
25002 return valx1->v.val_int == valy1->v.val_int
25003 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
25004 case DW_OP_GNU_convert:
25005 case DW_OP_GNU_reinterpret:
25006 if (valx1->val_class != valy1->val_class)
25008 if (valx1->val_class == dw_val_class_unsigned_const)
25009 return valx1->v.val_unsigned == valy1->v.val_unsigned;
25010 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
25011 case DW_OP_GNU_parameter_ref:
25012 return valx1->val_class == dw_val_class_die_ref
25013 && valx1->val_class == valy1->val_class
25014 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
25016 /* Other codes have no operands. */
25021 /* Return true if DWARF location expressions X and Y are the same. */
25024 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
25026 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
25027 if (x->dw_loc_opc != y->dw_loc_opc
25028 || x->dtprel != y->dtprel
25029 || !compare_loc_operands (x, y))
25031 return x == NULL && y == NULL;
25034 /* Hashtable helpers. */
25036 struct loc_list_hasher : nofree_ptr_hash <dw_loc_list_struct>
25038 static inline hashval_t hash (const dw_loc_list_struct *);
25039 static inline bool equal (const dw_loc_list_struct *,
25040 const dw_loc_list_struct *);
25043 /* Return precomputed hash of location list X. */
25046 loc_list_hasher::hash (const dw_loc_list_struct *x)
25051 /* Return true if location lists A and B are the same. */
25054 loc_list_hasher::equal (const dw_loc_list_struct *a,
25055 const dw_loc_list_struct *b)
25059 if (a->hash != b->hash)
25061 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
25062 if (strcmp (a->begin, b->begin) != 0
25063 || strcmp (a->end, b->end) != 0
25064 || (a->section == NULL) != (b->section == NULL)
25065 || (a->section && strcmp (a->section, b->section) != 0)
25066 || !compare_locs (a->expr, b->expr))
25068 return a == NULL && b == NULL;
25071 typedef hash_table<loc_list_hasher> loc_list_hash_type;
25074 /* Recursively optimize location lists referenced from DIE
25075 children and share them whenever possible. */
25078 optimize_location_lists_1 (dw_die_ref die, loc_list_hash_type *htab)
25083 dw_loc_list_struct **slot;
25085 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
25086 if (AT_class (a) == dw_val_class_loc_list)
25088 dw_loc_list_ref list = AT_loc_list (a);
25089 /* TODO: perform some optimizations here, before hashing
25090 it and storing into the hash table. */
25091 hash_loc_list (list);
25092 slot = htab->find_slot_with_hash (list, list->hash, INSERT);
25096 a->dw_attr_val.v.val_loc_list = *slot;
25099 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
25103 /* Recursively assign each location list a unique index into the debug_addr
25107 index_location_lists (dw_die_ref die)
25113 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
25114 if (AT_class (a) == dw_val_class_loc_list)
25116 dw_loc_list_ref list = AT_loc_list (a);
25117 dw_loc_list_ref curr;
25118 for (curr = list; curr != NULL; curr = curr->dw_loc_next)
25120 /* Don't index an entry that has already been indexed
25121 or won't be output. */
25122 if (curr->begin_entry != NULL
25123 || (strcmp (curr->begin, curr->end) == 0 && !curr->force))
25127 = add_addr_table_entry (xstrdup (curr->begin),
25132 FOR_EACH_CHILD (die, c, index_location_lists (c));
25135 /* Optimize location lists referenced from DIE
25136 children and share them whenever possible. */
25139 optimize_location_lists (dw_die_ref die)
25141 loc_list_hash_type htab (500);
25142 optimize_location_lists_1 (die, &htab);
25145 /* Traverse the limbo die list, and add parent/child links. The only
25146 dies without parents that should be here are concrete instances of
25147 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
25148 For concrete instances, we can get the parent die from the abstract
25152 flush_limbo_die_list (void)
25154 limbo_die_node *node, *next_node;
25156 for (node = limbo_die_list; node; node = next_node)
25158 dw_die_ref die = node->die;
25159 next_node = node->next;
25161 if (die->die_parent == NULL)
25163 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
25165 if (origin && origin->die_parent)
25166 add_child_die (origin->die_parent, die);
25167 else if (is_cu_die (die))
25169 else if (seen_error ())
25170 /* It's OK to be confused by errors in the input. */
25171 add_child_die (comp_unit_die (), die);
25174 /* In certain situations, the lexical block containing a
25175 nested function can be optimized away, which results
25176 in the nested function die being orphaned. Likewise
25177 with the return type of that nested function. Force
25178 this to be a child of the containing function.
25180 It may happen that even the containing function got fully
25181 inlined and optimized out. In that case we are lost and
25182 assign the empty child. This should not be big issue as
25183 the function is likely unreachable too. */
25184 gcc_assert (node->created_for);
25186 if (DECL_P (node->created_for))
25187 origin = get_context_die (DECL_CONTEXT (node->created_for));
25188 else if (TYPE_P (node->created_for))
25189 origin = scope_die_for (node->created_for, comp_unit_die ());
25191 origin = comp_unit_die ();
25193 add_child_die (origin, die);
25198 limbo_die_list = NULL;
25201 /* Output stuff that dwarf requires at the end of every file,
25202 and generate the DWARF-2 debugging info. */
25205 dwarf2out_finish (const char *filename)
25207 comdat_type_node *ctnode;
25208 dw_die_ref main_comp_unit_die;
25210 /* Flush out any latecomers to the limbo party. */
25211 flush_limbo_die_list ();
25213 /* We shouldn't have any symbols with delayed asm names for
25214 DIEs generated after early finish. */
25215 gcc_assert (deferred_asm_name == NULL);
25217 /* PCH might result in DW_AT_producer string being restored from the
25218 header compilation, so always fill it with empty string initially
25219 and overwrite only here. */
25220 dw_attr_node *producer = get_AT (comp_unit_die (), DW_AT_producer);
25221 producer_string = gen_producer_string ();
25222 producer->dw_attr_val.v.val_str->refcount--;
25223 producer->dw_attr_val.v.val_str = find_AT_string (producer_string);
25225 gen_remaining_tmpl_value_param_die_attribute ();
25227 /* Add the name for the main input file now. We delayed this from
25228 dwarf2out_init to avoid complications with PCH.
25229 For LTO produced units use a fixed artificial name to avoid
25230 leaking tempfile names into the dwarf. */
25232 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
25234 add_name_attribute (comp_unit_die (), "<artificial>");
25235 if (!IS_ABSOLUTE_PATH (filename) || targetm.force_at_comp_dir)
25236 add_comp_dir_attribute (comp_unit_die ());
25237 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
25240 file_table->traverse<bool *, file_table_relative_p> (&p);
25242 add_comp_dir_attribute (comp_unit_die ());
25245 #if ENABLE_ASSERT_CHECKING
25247 dw_die_ref die = comp_unit_die (), c;
25248 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
25251 resolve_addr (comp_unit_die ());
25252 move_marked_base_types ();
25254 /* Walk through the list of incomplete types again, trying once more to
25255 emit full debugging info for them. */
25256 retry_incomplete_types ();
25258 if (flag_eliminate_unused_debug_types)
25259 prune_unused_types ();
25261 /* Generate separate COMDAT sections for type DIEs. */
25262 if (use_debug_types)
25264 break_out_comdat_types (comp_unit_die ());
25266 /* Each new type_unit DIE was added to the limbo die list when created.
25267 Since these have all been added to comdat_type_list, clear the
25269 limbo_die_list = NULL;
25271 /* For each new comdat type unit, copy declarations for incomplete
25272 types to make the new unit self-contained (i.e., no direct
25273 references to the main compile unit). */
25274 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25275 copy_decls_for_unworthy_types (ctnode->root_die);
25276 copy_decls_for_unworthy_types (comp_unit_die ());
25278 /* In the process of copying declarations from one unit to another,
25279 we may have left some declarations behind that are no longer
25280 referenced. Prune them. */
25281 prune_unused_types ();
25284 /* Generate separate CUs for each of the include files we've seen.
25285 They will go into limbo_die_list. */
25286 if (flag_eliminate_dwarf2_dups)
25287 break_out_includes (comp_unit_die ());
25289 /* Traverse the DIE's and add sibling attributes to those DIE's that
25291 add_sibling_attributes (comp_unit_die ());
25292 limbo_die_node *node;
25293 for (node = limbo_die_list; node; node = node->next)
25294 add_sibling_attributes (node->die);
25295 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25296 add_sibling_attributes (ctnode->root_die);
25298 /* When splitting DWARF info, we put some attributes in the
25299 skeleton compile_unit DIE that remains in the .o, while
25300 most attributes go in the DWO compile_unit_die. */
25301 if (dwarf_split_debug_info)
25302 main_comp_unit_die = gen_compile_unit_die (NULL);
25304 main_comp_unit_die = comp_unit_die ();
25306 /* Output a terminator label for the .text section. */
25307 switch_to_section (text_section);
25308 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
25309 if (cold_text_section)
25311 switch_to_section (cold_text_section);
25312 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
25315 /* We can only use the low/high_pc attributes if all of the code was
25317 if (!have_multiple_function_sections
25318 || (dwarf_version < 3 && dwarf_strict))
25320 /* Don't add if the CU has no associated code. */
25321 if (text_section_used)
25322 add_AT_low_high_pc (main_comp_unit_die, text_section_label,
25323 text_end_label, true);
25329 bool range_list_added = false;
25331 if (text_section_used)
25332 add_ranges_by_labels (main_comp_unit_die, text_section_label,
25333 text_end_label, &range_list_added, true);
25334 if (cold_text_section_used)
25335 add_ranges_by_labels (main_comp_unit_die, cold_text_section_label,
25336 cold_end_label, &range_list_added, true);
25338 FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
25340 if (DECL_IGNORED_P (fde->decl))
25342 if (!fde->in_std_section)
25343 add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_begin,
25344 fde->dw_fde_end, &range_list_added,
25346 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
25347 add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_second_begin,
25348 fde->dw_fde_second_end, &range_list_added,
25352 if (range_list_added)
25354 /* We need to give .debug_loc and .debug_ranges an appropriate
25355 "base address". Use zero so that these addresses become
25356 absolute. Historically, we've emitted the unexpected
25357 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
25358 Emit both to give time for other tools to adapt. */
25359 add_AT_addr (main_comp_unit_die, DW_AT_low_pc, const0_rtx, true);
25360 if (! dwarf_strict && dwarf_version < 4)
25361 add_AT_addr (main_comp_unit_die, DW_AT_entry_pc, const0_rtx, true);
25367 if (debug_info_level >= DINFO_LEVEL_TERSE)
25368 add_AT_lineptr (main_comp_unit_die, DW_AT_stmt_list,
25369 debug_line_section_label);
25372 add_AT_macptr (comp_unit_die (),
25373 dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros,
25374 macinfo_section_label);
25376 if (dwarf_split_debug_info)
25378 /* optimize_location_lists calculates the size of the lists,
25379 so index them first, and assign indices to the entries.
25380 Although optimize_location_lists will remove entries from
25381 the table, it only does so for duplicates, and therefore
25382 only reduces ref_counts to 1. */
25383 index_location_lists (comp_unit_die ());
25385 if (addr_index_table != NULL)
25387 unsigned int index = 0;
25389 ->traverse_noresize<unsigned int *, index_addr_table_entry>
25394 if (have_location_lists)
25395 optimize_location_lists (comp_unit_die ());
25397 save_macinfo_strings ();
25399 if (dwarf_split_debug_info)
25401 unsigned int index = 0;
25403 /* Add attributes common to skeleton compile_units and
25404 type_units. Because these attributes include strings, it
25405 must be done before freezing the string table. Top-level
25406 skeleton die attrs are added when the skeleton type unit is
25407 created, so ensure it is created by this point. */
25408 add_top_level_skeleton_die_attrs (main_comp_unit_die);
25409 debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
25412 /* Output all of the compilation units. We put the main one last so that
25413 the offsets are available to output_pubnames. */
25414 for (node = limbo_die_list; node; node = node->next)
25415 output_comp_unit (node->die, 0);
25417 hash_table<comdat_type_hasher> comdat_type_table (100);
25418 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25420 comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
25422 /* Don't output duplicate types. */
25423 if (*slot != HTAB_EMPTY_ENTRY)
25426 /* Add a pointer to the line table for the main compilation unit
25427 so that the debugger can make sense of DW_AT_decl_file
25429 if (debug_info_level >= DINFO_LEVEL_TERSE)
25430 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
25431 (!dwarf_split_debug_info
25432 ? debug_line_section_label
25433 : debug_skeleton_line_section_label));
25435 output_comdat_type_unit (ctnode);
25439 /* The AT_pubnames attribute needs to go in all skeleton dies, including
25440 both the main_cu and all skeleton TUs. Making this call unconditional
25441 would end up either adding a second copy of the AT_pubnames attribute, or
25442 requiring a special case in add_top_level_skeleton_die_attrs. */
25443 if (!dwarf_split_debug_info)
25444 add_AT_pubnames (comp_unit_die ());
25446 if (dwarf_split_debug_info)
25449 unsigned char checksum[16];
25450 struct md5_ctx ctx;
25452 /* Compute a checksum of the comp_unit to use as the dwo_id. */
25453 md5_init_ctx (&ctx);
25455 die_checksum (comp_unit_die (), &ctx, &mark);
25456 unmark_all_dies (comp_unit_die ());
25457 md5_finish_ctx (&ctx, checksum);
25459 /* Use the first 8 bytes of the checksum as the dwo_id,
25460 and add it to both comp-unit DIEs. */
25461 add_AT_data8 (main_comp_unit_die, DW_AT_GNU_dwo_id, checksum);
25462 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id, checksum);
25464 /* Add the base offset of the ranges table to the skeleton
25466 if (ranges_table_in_use)
25467 add_AT_lineptr (main_comp_unit_die, DW_AT_GNU_ranges_base,
25468 ranges_section_label);
25470 switch_to_section (debug_addr_section);
25471 ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
25472 output_addr_table ();
25475 /* Output the main compilation unit if non-empty or if .debug_macinfo
25476 or .debug_macro will be emitted. */
25477 output_comp_unit (comp_unit_die (), have_macinfo);
25479 if (dwarf_split_debug_info && info_section_emitted)
25480 output_skeleton_debug_sections (main_comp_unit_die);
25482 /* Output the abbreviation table. */
25483 if (abbrev_die_table_in_use != 1)
25485 switch_to_section (debug_abbrev_section);
25486 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
25487 output_abbrev_section ();
25490 /* Output location list section if necessary. */
25491 if (have_location_lists)
25493 /* Output the location lists info. */
25494 switch_to_section (debug_loc_section);
25495 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
25496 output_location_lists (comp_unit_die ());
25499 output_pubtables ();
25501 /* Output the address range information if a CU (.debug_info section)
25502 was emitted. We output an empty table even if we had no functions
25503 to put in it. This because the consumer has no way to tell the
25504 difference between an empty table that we omitted and failure to
25505 generate a table that would have contained data. */
25506 if (info_section_emitted)
25508 unsigned long aranges_length = size_of_aranges ();
25510 switch_to_section (debug_aranges_section);
25511 output_aranges (aranges_length);
25514 /* Output ranges section if necessary. */
25515 if (ranges_table_in_use)
25517 switch_to_section (debug_ranges_section);
25518 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
25522 /* Have to end the macro section. */
25525 switch_to_section (debug_macinfo_section);
25526 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
25528 dw2_asm_output_data (1, 0, "End compilation unit");
25531 /* Output the source line correspondence table. We must do this
25532 even if there is no line information. Otherwise, on an empty
25533 translation unit, we will generate a present, but empty,
25534 .debug_info section. IRIX 6.5 `nm' will then complain when
25535 examining the file. This is done late so that any filenames
25536 used by the debug_info section are marked as 'used'. */
25537 switch_to_section (debug_line_section);
25538 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
25539 if (! DWARF2_ASM_LINE_DEBUG_INFO)
25540 output_line_info (false);
25542 if (dwarf_split_debug_info && info_section_emitted)
25544 switch_to_section (debug_skeleton_line_section);
25545 ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_line_section_label);
25546 output_line_info (true);
25549 /* If we emitted any indirect strings, output the string table too. */
25550 if (debug_str_hash || skeleton_debug_str_hash)
25551 output_indirect_strings ();
25554 /* Perform any cleanups needed after the early debug generation pass
25558 dwarf2out_early_finish (void)
25560 limbo_die_node *node;
25562 /* Add DW_AT_linkage_name for all deferred DIEs. */
25563 for (node = deferred_asm_name; node; node = node->next)
25565 tree decl = node->created_for;
25566 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
25567 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
25568 ended up in deferred_asm_name before we knew it was
25569 constant and never written to disk. */
25570 && DECL_ASSEMBLER_NAME (decl))
25572 add_linkage_attr (node->die, decl);
25573 move_linkage_attr (node->die);
25576 deferred_asm_name = NULL;
25578 /* The point here is to flush out the limbo list so that it is empty
25579 and we don't need to stream it for LTO. */
25580 flush_limbo_die_list ();
25582 gen_scheduled_generic_parms_dies ();
25583 gen_remaining_tmpl_value_param_die_attribute ();
25586 /* Reset all state within dwarf2out.c so that we can rerun the compiler
25587 within the same process. For use by toplev::finalize. */
25590 dwarf2out_c_finalize (void)
25592 last_var_location_insn = NULL;
25593 cached_next_real_insn = NULL;
25594 used_rtx_array = NULL;
25595 incomplete_types = NULL;
25596 decl_scope_table = NULL;
25597 debug_info_section = NULL;
25598 debug_skeleton_info_section = NULL;
25599 debug_abbrev_section = NULL;
25600 debug_skeleton_abbrev_section = NULL;
25601 debug_aranges_section = NULL;
25602 debug_addr_section = NULL;
25603 debug_macinfo_section = NULL;
25604 debug_line_section = NULL;
25605 debug_skeleton_line_section = NULL;
25606 debug_loc_section = NULL;
25607 debug_pubnames_section = NULL;
25608 debug_pubtypes_section = NULL;
25609 debug_str_section = NULL;
25610 debug_str_dwo_section = NULL;
25611 debug_str_offsets_section = NULL;
25612 debug_ranges_section = NULL;
25613 debug_frame_section = NULL;
25615 debug_str_hash = NULL;
25616 skeleton_debug_str_hash = NULL;
25617 dw2_string_counter = 0;
25618 have_multiple_function_sections = false;
25619 text_section_used = false;
25620 cold_text_section_used = false;
25621 cold_text_section = NULL;
25622 current_unit_personality = NULL;
25624 next_die_offset = 0;
25625 single_comp_unit_die = NULL;
25626 comdat_type_list = NULL;
25627 limbo_die_list = NULL;
25629 decl_die_table = NULL;
25630 common_block_die_table = NULL;
25631 decl_loc_table = NULL;
25632 call_arg_locations = NULL;
25633 call_arg_loc_last = NULL;
25634 call_site_count = -1;
25635 tail_call_site_count = -1;
25636 cached_dw_loc_list_table = NULL;
25637 abbrev_die_table = NULL;
25638 abbrev_die_table_allocated = 0;
25639 abbrev_die_table_in_use = 0;
25640 line_info_label_num = 0;
25641 cur_line_info_table = NULL;
25642 text_section_line_info = NULL;
25643 cold_text_section_line_info = NULL;
25644 separate_line_info = NULL;
25645 info_section_emitted = false;
25646 pubname_table = NULL;
25647 pubtype_table = NULL;
25648 macinfo_table = NULL;
25649 ranges_table = NULL;
25650 ranges_table_allocated = 0;
25651 ranges_table_in_use = 0;
25652 ranges_by_label = 0;
25653 ranges_by_label_allocated = 0;
25654 ranges_by_label_in_use = 0;
25655 have_location_lists = false;
25658 last_emitted_file = NULL;
25660 tmpl_value_parm_die_table = NULL;
25661 generic_type_instances = NULL;
25662 frame_pointer_fb_offset = 0;
25663 frame_pointer_fb_offset_valid = false;
25664 base_types.release ();
25665 XDELETEVEC (producer_string);
25666 producer_string = NULL;
25669 #include "gt-dwarf2out.h"