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 ATTRIBUTE_UNUSED)
439 if (eh_frame_section == 0)
443 if (EH_TABLES_CAN_BE_READ_ONLY)
449 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
451 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
453 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
456 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
457 && (fde_encoding & 0x70) != DW_EH_PE_aligned
458 && (per_encoding & 0x70) != DW_EH_PE_absptr
459 && (per_encoding & 0x70) != DW_EH_PE_aligned
460 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
461 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
462 ? 0 : SECTION_WRITE);
465 flags = SECTION_WRITE;
467 #ifdef EH_FRAME_SECTION_NAME
468 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
470 eh_frame_section = ((flags == SECTION_WRITE)
471 ? data_section : readonly_data_section);
472 #endif /* EH_FRAME_SECTION_NAME */
475 switch_to_section (eh_frame_section);
477 #ifdef EH_FRAME_THROUGH_COLLECT2
478 /* We have no special eh_frame section. Emit special labels to guide
482 tree label = get_file_function_name ("F");
483 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
484 targetm.asm_out.globalize_label (asm_out_file,
485 IDENTIFIER_POINTER (label));
486 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
491 /* Switch [BACK] to the eh or debug frame table section, depending on
495 switch_to_frame_table_section (int for_eh, bool back)
498 switch_to_eh_frame_section (back);
501 if (!debug_frame_section)
502 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
503 SECTION_DEBUG, NULL);
504 switch_to_section (debug_frame_section);
508 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
510 enum dw_cfi_oprnd_type
511 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
516 case DW_CFA_GNU_window_save:
517 case DW_CFA_remember_state:
518 case DW_CFA_restore_state:
519 return dw_cfi_oprnd_unused;
522 case DW_CFA_advance_loc1:
523 case DW_CFA_advance_loc2:
524 case DW_CFA_advance_loc4:
525 case DW_CFA_MIPS_advance_loc8:
526 return dw_cfi_oprnd_addr;
529 case DW_CFA_offset_extended:
531 case DW_CFA_offset_extended_sf:
532 case DW_CFA_def_cfa_sf:
534 case DW_CFA_restore_extended:
535 case DW_CFA_undefined:
536 case DW_CFA_same_value:
537 case DW_CFA_def_cfa_register:
538 case DW_CFA_register:
539 case DW_CFA_expression:
540 return dw_cfi_oprnd_reg_num;
542 case DW_CFA_def_cfa_offset:
543 case DW_CFA_GNU_args_size:
544 case DW_CFA_def_cfa_offset_sf:
545 return dw_cfi_oprnd_offset;
547 case DW_CFA_def_cfa_expression:
548 return dw_cfi_oprnd_loc;
555 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
557 enum dw_cfi_oprnd_type
558 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
563 case DW_CFA_def_cfa_sf:
565 case DW_CFA_offset_extended_sf:
566 case DW_CFA_offset_extended:
567 return dw_cfi_oprnd_offset;
569 case DW_CFA_register:
570 return dw_cfi_oprnd_reg_num;
572 case DW_CFA_expression:
573 return dw_cfi_oprnd_loc;
576 return dw_cfi_oprnd_unused;
580 /* Output one FDE. */
583 output_fde (dw_fde_ref fde, bool for_eh, bool second,
584 char *section_start_label, int fde_encoding, char *augmentation,
585 bool any_lsda_needed, int lsda_encoding)
587 const char *begin, *end;
588 static unsigned int j;
591 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
593 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
595 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
596 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
597 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
598 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
599 " indicating 64-bit DWARF extension");
600 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
602 ASM_OUTPUT_LABEL (asm_out_file, l1);
605 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
607 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
608 debug_frame_section, "FDE CIE offset");
610 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
611 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
615 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
616 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
617 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
618 "FDE initial location");
619 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
620 end, begin, "FDE address range");
624 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
625 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
632 int size = size_of_encoded_value (lsda_encoding);
634 if (lsda_encoding == DW_EH_PE_aligned)
636 int offset = ( 4 /* Length */
638 + 2 * size_of_encoded_value (fde_encoding)
639 + 1 /* Augmentation size */ );
640 int pad = -offset & (PTR_SIZE - 1);
643 gcc_assert (size_of_uleb128 (size) == 1);
646 dw2_asm_output_data_uleb128 (size, "Augmentation size");
648 if (fde->uses_eh_lsda)
650 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
651 fde->funcdef_number);
652 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
653 gen_rtx_SYMBOL_REF (Pmode, l1),
655 "Language Specific Data Area");
659 if (lsda_encoding == DW_EH_PE_aligned)
660 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
661 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
662 "Language Specific Data Area (none)");
666 dw2_asm_output_data_uleb128 (0, "Augmentation size");
669 /* Loop through the Call Frame Instructions associated with this FDE. */
670 fde->dw_fde_current_label = begin;
672 size_t from, until, i;
675 until = vec_safe_length (fde->dw_fde_cfi);
677 if (fde->dw_fde_second_begin == NULL)
680 until = fde->dw_fde_switch_cfi_index;
682 from = fde->dw_fde_switch_cfi_index;
684 for (i = from; i < until; i++)
685 output_cfi ((*fde->dw_fde_cfi)[i], fde, for_eh);
688 /* If we are to emit a ref/link from function bodies to their frame tables,
689 do it now. This is typically performed to make sure that tables
690 associated with functions are dragged with them and not discarded in
691 garbage collecting links. We need to do this on a per function basis to
692 cope with -ffunction-sections. */
694 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
695 /* Switch to the function section, emit the ref to the tables, and
696 switch *back* into the table section. */
697 switch_to_section (function_section (fde->decl));
698 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
699 switch_to_frame_table_section (for_eh, true);
702 /* Pad the FDE out to an address sized boundary. */
703 ASM_OUTPUT_ALIGN (asm_out_file,
704 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
705 ASM_OUTPUT_LABEL (asm_out_file, l2);
710 /* Return true if frame description entry FDE is needed for EH. */
713 fde_needed_for_eh_p (dw_fde_ref fde)
715 if (flag_asynchronous_unwind_tables)
718 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
721 if (fde->uses_eh_lsda)
724 /* If exceptions are enabled, we have collected nothrow info. */
725 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
731 /* Output the call frame information used to record information
732 that relates to calculating the frame pointer, and records the
733 location of saved registers. */
736 output_call_frame_info (int for_eh)
741 char l1[20], l2[20], section_start_label[20];
742 bool any_lsda_needed = false;
743 char augmentation[6];
744 int augmentation_size;
745 int fde_encoding = DW_EH_PE_absptr;
746 int per_encoding = DW_EH_PE_absptr;
747 int lsda_encoding = DW_EH_PE_absptr;
749 rtx personality = NULL;
752 /* Don't emit a CIE if there won't be any FDEs. */
756 /* Nothing to do if the assembler's doing it all. */
757 if (dwarf2out_do_cfi_asm ())
760 /* If we don't have any functions we'll want to unwind out of, don't emit
761 any EH unwind information. If we make FDEs linkonce, we may have to
762 emit an empty label for an FDE that wouldn't otherwise be emitted. We
763 want to avoid having an FDE kept around when the function it refers to
764 is discarded. Example where this matters: a primary function template
765 in C++ requires EH information, an explicit specialization doesn't. */
768 bool any_eh_needed = false;
770 FOR_EACH_VEC_ELT (*fde_vec, i, fde)
772 if (fde->uses_eh_lsda)
773 any_eh_needed = any_lsda_needed = true;
774 else if (fde_needed_for_eh_p (fde))
775 any_eh_needed = true;
776 else if (TARGET_USES_WEAK_UNWIND_INFO)
777 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, 1, 1);
784 /* We're going to be generating comments, so turn on app. */
788 /* Switch to the proper frame section, first time. */
789 switch_to_frame_table_section (for_eh, false);
791 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
792 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
794 /* Output the CIE. */
795 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
796 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
797 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
798 dw2_asm_output_data (4, 0xffffffff,
799 "Initial length escape value indicating 64-bit DWARF extension");
800 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
801 "Length of Common Information Entry");
802 ASM_OUTPUT_LABEL (asm_out_file, l1);
804 /* Now that the CIE pointer is PC-relative for EH,
805 use 0 to identify the CIE. */
806 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
807 (for_eh ? 0 : DWARF_CIE_ID),
808 "CIE Identifier Tag");
810 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
811 use CIE version 1, unless that would produce incorrect results
812 due to overflowing the return register column. */
813 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
815 if (return_reg >= 256 || dwarf_version > 2)
817 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
820 augmentation_size = 0;
822 personality = current_unit_personality;
828 z Indicates that a uleb128 is present to size the
829 augmentation section.
830 L Indicates the encoding (and thus presence) of
831 an LSDA pointer in the FDE augmentation.
832 R Indicates a non-default pointer encoding for
834 P Indicates the presence of an encoding + language
835 personality routine in the CIE augmentation. */
837 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
838 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
839 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
841 p = augmentation + 1;
845 augmentation_size += 1 + size_of_encoded_value (per_encoding);
846 assemble_external_libcall (personality);
851 augmentation_size += 1;
853 if (fde_encoding != DW_EH_PE_absptr)
856 augmentation_size += 1;
858 if (p > augmentation + 1)
860 augmentation[0] = 'z';
864 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
865 if (personality && per_encoding == DW_EH_PE_aligned)
867 int offset = ( 4 /* Length */
869 + 1 /* CIE version */
870 + strlen (augmentation) + 1 /* Augmentation */
871 + size_of_uleb128 (1) /* Code alignment */
872 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
874 + 1 /* Augmentation size */
875 + 1 /* Personality encoding */ );
876 int pad = -offset & (PTR_SIZE - 1);
878 augmentation_size += pad;
880 /* Augmentations should be small, so there's scarce need to
881 iterate for a solution. Die if we exceed one uleb128 byte. */
882 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
886 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
887 if (dw_cie_version >= 4)
889 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
890 dw2_asm_output_data (1, 0, "CIE Segment Size");
892 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
893 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
894 "CIE Data Alignment Factor");
896 if (dw_cie_version == 1)
897 dw2_asm_output_data (1, return_reg, "CIE RA Column");
899 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
903 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
906 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
907 eh_data_format_name (per_encoding));
908 dw2_asm_output_encoded_addr_rtx (per_encoding,
914 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
915 eh_data_format_name (lsda_encoding));
917 if (fde_encoding != DW_EH_PE_absptr)
918 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
919 eh_data_format_name (fde_encoding));
922 FOR_EACH_VEC_ELT (*cie_cfi_vec, i, cfi)
923 output_cfi (cfi, NULL, for_eh);
925 /* Pad the CIE out to an address sized boundary. */
926 ASM_OUTPUT_ALIGN (asm_out_file,
927 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
928 ASM_OUTPUT_LABEL (asm_out_file, l2);
930 /* Loop through all of the FDE's. */
931 FOR_EACH_VEC_ELT (*fde_vec, i, fde)
935 /* Don't emit EH unwind info for leaf functions that don't need it. */
936 if (for_eh && !fde_needed_for_eh_p (fde))
939 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
940 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
941 augmentation, any_lsda_needed, lsda_encoding);
944 if (for_eh && targetm.terminate_dw2_eh_frame_info)
945 dw2_asm_output_data (4, 0, "End of Table");
947 /* Turn off app to make assembly quicker. */
952 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
955 dwarf2out_do_cfi_startproc (bool second)
959 rtx personality = get_personality_function (current_function_decl);
961 fprintf (asm_out_file, "\t.cfi_startproc\n");
965 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
968 /* ??? The GAS support isn't entirely consistent. We have to
969 handle indirect support ourselves, but PC-relative is done
970 in the assembler. Further, the assembler can't handle any
971 of the weirder relocation types. */
972 if (enc & DW_EH_PE_indirect)
973 ref = dw2_force_const_mem (ref, true);
975 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
976 output_addr_const (asm_out_file, ref);
977 fputc ('\n', asm_out_file);
980 if (crtl->uses_eh_lsda)
984 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
985 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
986 current_function_funcdef_no);
987 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
988 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
990 if (enc & DW_EH_PE_indirect)
991 ref = dw2_force_const_mem (ref, true);
993 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
994 output_addr_const (asm_out_file, ref);
995 fputc ('\n', asm_out_file);
999 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1000 this allocation may be done before pass_final. */
1003 dwarf2out_alloc_current_fde (void)
1007 fde = ggc_cleared_alloc<dw_fde_node> ();
1008 fde->decl = current_function_decl;
1009 fde->funcdef_number = current_function_funcdef_no;
1010 fde->fde_index = vec_safe_length (fde_vec);
1011 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
1012 fde->uses_eh_lsda = crtl->uses_eh_lsda;
1013 fde->nothrow = crtl->nothrow;
1014 fde->drap_reg = INVALID_REGNUM;
1015 fde->vdrap_reg = INVALID_REGNUM;
1017 /* Record the FDE associated with this function. */
1019 vec_safe_push (fde_vec, fde);
1024 /* Output a marker (i.e. a label) for the beginning of a function, before
1028 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
1029 const char *file ATTRIBUTE_UNUSED)
1031 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1037 current_function_func_begin_label = NULL;
1039 do_frame = dwarf2out_do_frame ();
1041 /* ??? current_function_func_begin_label is also used by except.c for
1042 call-site information. We must emit this label if it might be used. */
1044 && (!flag_exceptions
1045 || targetm_common.except_unwind_info (&global_options) == UI_SJLJ))
1048 fnsec = function_section (current_function_decl);
1049 switch_to_section (fnsec);
1050 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1051 current_function_funcdef_no);
1052 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1053 current_function_funcdef_no);
1054 dup_label = xstrdup (label);
1055 current_function_func_begin_label = dup_label;
1057 /* We can elide the fde allocation if we're not emitting debug info. */
1061 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1062 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1063 would include pass_dwarf2_frame. If we've not created the FDE yet,
1067 fde = dwarf2out_alloc_current_fde ();
1069 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1070 fde->dw_fde_begin = dup_label;
1071 fde->dw_fde_current_label = dup_label;
1072 fde->in_std_section = (fnsec == text_section
1073 || (cold_text_section && fnsec == cold_text_section));
1075 /* We only want to output line number information for the genuine dwarf2
1076 prologue case, not the eh frame case. */
1077 #ifdef DWARF2_DEBUGGING_INFO
1079 dwarf2out_source_line (line, file, 0, true);
1082 if (dwarf2out_do_cfi_asm ())
1083 dwarf2out_do_cfi_startproc (false);
1086 rtx personality = get_personality_function (current_function_decl);
1087 if (!current_unit_personality)
1088 current_unit_personality = personality;
1090 /* We cannot keep a current personality per function as without CFI
1091 asm, at the point where we emit the CFI data, there is no current
1092 function anymore. */
1093 if (personality && current_unit_personality != personality)
1094 sorry ("multiple EH personalities are supported only with assemblers "
1095 "supporting .cfi_personality directive");
1099 /* Output a marker (i.e. a label) for the end of the generated code
1100 for a function prologue. This gets called *after* the prologue code has
1104 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
1105 const char *file ATTRIBUTE_UNUSED)
1107 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1109 /* Output a label to mark the endpoint of the code generated for this
1111 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
1112 current_function_funcdef_no);
1113 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
1114 current_function_funcdef_no);
1115 cfun->fde->dw_fde_vms_end_prologue = xstrdup (label);
1118 /* Output a marker (i.e. a label) for the beginning of the generated code
1119 for a function epilogue. This gets called *before* the prologue code has
1123 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1124 const char *file ATTRIBUTE_UNUSED)
1126 dw_fde_ref fde = cfun->fde;
1127 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1129 if (fde->dw_fde_vms_begin_epilogue)
1132 /* Output a label to mark the endpoint of the code generated for this
1134 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
1135 current_function_funcdef_no);
1136 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
1137 current_function_funcdef_no);
1138 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
1141 /* Output a marker (i.e. a label) for the absolute end of the generated code
1142 for a function definition. This gets called *after* the epilogue code has
1146 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1147 const char *file ATTRIBUTE_UNUSED)
1150 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1152 last_var_location_insn = NULL;
1153 cached_next_real_insn = NULL;
1155 if (dwarf2out_do_cfi_asm ())
1156 fprintf (asm_out_file, "\t.cfi_endproc\n");
1158 /* Output a label to mark the endpoint of the code generated for this
1160 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1161 current_function_funcdef_no);
1162 ASM_OUTPUT_LABEL (asm_out_file, label);
1164 gcc_assert (fde != NULL);
1165 if (fde->dw_fde_second_begin == NULL)
1166 fde->dw_fde_end = xstrdup (label);
1170 dwarf2out_frame_finish (void)
1172 /* Output call frame information. */
1173 if (targetm.debug_unwind_info () == UI_DWARF2)
1174 output_call_frame_info (0);
1176 /* Output another copy for the unwinder. */
1177 if ((flag_unwind_tables || flag_exceptions)
1178 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
1179 output_call_frame_info (1);
1182 /* Note that the current function section is being used for code. */
1185 dwarf2out_note_section_used (void)
1187 section *sec = current_function_section ();
1188 if (sec == text_section)
1189 text_section_used = true;
1190 else if (sec == cold_text_section)
1191 cold_text_section_used = true;
1194 static void var_location_switch_text_section (void);
1195 static void set_cur_line_info_table (section *);
1198 dwarf2out_switch_text_section (void)
1201 dw_fde_ref fde = cfun->fde;
1203 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1205 if (!in_cold_section_p)
1207 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
1208 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
1209 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
1213 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1214 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
1215 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1217 have_multiple_function_sections = true;
1219 /* There is no need to mark used sections when not debugging. */
1220 if (cold_text_section != NULL)
1221 dwarf2out_note_section_used ();
1223 if (dwarf2out_do_cfi_asm ())
1224 fprintf (asm_out_file, "\t.cfi_endproc\n");
1226 /* Now do the real section switch. */
1227 sect = current_function_section ();
1228 switch_to_section (sect);
1230 fde->second_in_std_section
1231 = (sect == text_section
1232 || (cold_text_section && sect == cold_text_section));
1234 if (dwarf2out_do_cfi_asm ())
1235 dwarf2out_do_cfi_startproc (true);
1237 var_location_switch_text_section ();
1239 if (cold_text_section != NULL)
1240 set_cur_line_info_table (sect);
1243 /* And now, the subset of the debugging information support code necessary
1244 for emitting location expressions. */
1246 /* Data about a single source file. */
1247 struct GTY((for_user)) dwarf_file_data {
1248 const char * filename;
1252 /* Describe an entry into the .debug_addr section. */
1256 ate_kind_rtx_dtprel,
1260 struct GTY((for_user)) addr_table_entry {
1262 unsigned int refcount;
1264 union addr_table_entry_struct_union
1266 rtx GTY ((tag ("0"))) rtl;
1267 char * GTY ((tag ("1"))) label;
1269 GTY ((desc ("%1.kind"))) addr;
1272 /* Location lists are ranges + location descriptions for that range,
1273 so you can track variables that are in different places over
1274 their entire life. */
1275 typedef struct GTY(()) dw_loc_list_struct {
1276 dw_loc_list_ref dw_loc_next;
1277 const char *begin; /* Label and addr_entry for start of range */
1278 addr_table_entry *begin_entry;
1279 const char *end; /* Label for end of range */
1280 char *ll_symbol; /* Label for beginning of location list.
1281 Only on head of list */
1282 const char *section; /* Section this loclist is relative to */
1283 dw_loc_descr_ref expr;
1285 /* True if all addresses in this and subsequent lists are known to be
1288 /* True if this list has been replaced by dw_loc_next. */
1291 /* True if the range should be emitted even if begin and end
1296 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
1298 /* Convert a DWARF stack opcode into its string name. */
1301 dwarf_stack_op_name (unsigned int op)
1303 const char *name = get_DW_OP_name (op);
1308 return "OP_<unknown>";
1311 /* Return a pointer to a newly allocated location description. Location
1312 descriptions are simple expression terms that can be strung
1313 together to form more complicated location (address) descriptions. */
1315 static inline dw_loc_descr_ref
1316 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
1317 unsigned HOST_WIDE_INT oprnd2)
1319 dw_loc_descr_ref descr = ggc_cleared_alloc<dw_loc_descr_node> ();
1321 descr->dw_loc_opc = op;
1322 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
1323 descr->dw_loc_oprnd1.val_entry = NULL;
1324 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
1325 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
1326 descr->dw_loc_oprnd2.val_entry = NULL;
1327 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
1332 /* Return a pointer to a newly allocated location description for
1335 static inline dw_loc_descr_ref
1336 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
1339 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
1342 return new_loc_descr (DW_OP_bregx, reg, offset);
1345 /* Add a location description term to a location description expression. */
1348 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
1350 dw_loc_descr_ref *d;
1352 /* Find the end of the chain. */
1353 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
1359 /* Compare two location operands for exact equality. */
1362 dw_val_equal_p (dw_val_node *a, dw_val_node *b)
1364 if (a->val_class != b->val_class)
1366 switch (a->val_class)
1368 case dw_val_class_none:
1370 case dw_val_class_addr:
1371 return rtx_equal_p (a->v.val_addr, b->v.val_addr);
1373 case dw_val_class_offset:
1374 case dw_val_class_unsigned_const:
1375 case dw_val_class_const:
1376 case dw_val_class_range_list:
1377 case dw_val_class_lineptr:
1378 case dw_val_class_macptr:
1379 /* These are all HOST_WIDE_INT, signed or unsigned. */
1380 return a->v.val_unsigned == b->v.val_unsigned;
1382 case dw_val_class_loc:
1383 return a->v.val_loc == b->v.val_loc;
1384 case dw_val_class_loc_list:
1385 return a->v.val_loc_list == b->v.val_loc_list;
1386 case dw_val_class_die_ref:
1387 return a->v.val_die_ref.die == b->v.val_die_ref.die;
1388 case dw_val_class_fde_ref:
1389 return a->v.val_fde_index == b->v.val_fde_index;
1390 case dw_val_class_lbl_id:
1391 case dw_val_class_high_pc:
1392 return strcmp (a->v.val_lbl_id, b->v.val_lbl_id) == 0;
1393 case dw_val_class_str:
1394 return a->v.val_str == b->v.val_str;
1395 case dw_val_class_flag:
1396 return a->v.val_flag == b->v.val_flag;
1397 case dw_val_class_file:
1398 return a->v.val_file == b->v.val_file;
1399 case dw_val_class_decl_ref:
1400 return a->v.val_decl_ref == b->v.val_decl_ref;
1402 case dw_val_class_const_double:
1403 return (a->v.val_double.high == b->v.val_double.high
1404 && a->v.val_double.low == b->v.val_double.low);
1406 case dw_val_class_wide_int:
1407 return *a->v.val_wide == *b->v.val_wide;
1409 case dw_val_class_vec:
1411 size_t a_len = a->v.val_vec.elt_size * a->v.val_vec.length;
1412 size_t b_len = b->v.val_vec.elt_size * b->v.val_vec.length;
1414 return (a_len == b_len
1415 && !memcmp (a->v.val_vec.array, b->v.val_vec.array, a_len));
1418 case dw_val_class_data8:
1419 return memcmp (a->v.val_data8, b->v.val_data8, 8) == 0;
1421 case dw_val_class_vms_delta:
1422 return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)
1423 && !strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1));
1428 /* Compare two location atoms for exact equality. */
1431 loc_descr_equal_p_1 (dw_loc_descr_ref a, dw_loc_descr_ref b)
1433 if (a->dw_loc_opc != b->dw_loc_opc)
1436 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1437 address size, but since we always allocate cleared storage it
1438 should be zero for other types of locations. */
1439 if (a->dtprel != b->dtprel)
1442 return (dw_val_equal_p (&a->dw_loc_oprnd1, &b->dw_loc_oprnd1)
1443 && dw_val_equal_p (&a->dw_loc_oprnd2, &b->dw_loc_oprnd2));
1446 /* Compare two complete location expressions for exact equality. */
1449 loc_descr_equal_p (dw_loc_descr_ref a, dw_loc_descr_ref b)
1455 if (a == NULL || b == NULL)
1457 if (!loc_descr_equal_p_1 (a, b))
1466 /* Add a constant OFFSET to a location expression. */
1469 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
1471 dw_loc_descr_ref loc;
1474 gcc_assert (*list_head != NULL);
1479 /* Find the end of the chain. */
1480 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
1484 if (loc->dw_loc_opc == DW_OP_fbreg
1485 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
1486 p = &loc->dw_loc_oprnd1.v.val_int;
1487 else if (loc->dw_loc_opc == DW_OP_bregx)
1488 p = &loc->dw_loc_oprnd2.v.val_int;
1490 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1491 offset. Don't optimize if an signed integer overflow would happen. */
1493 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
1494 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
1497 else if (offset > 0)
1498 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
1502 loc->dw_loc_next = int_loc_descriptor (-offset);
1503 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
1507 /* Add a constant OFFSET to a location list. */
1510 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
1513 for (d = list_head; d != NULL; d = d->dw_loc_next)
1514 loc_descr_plus_const (&d->expr, offset);
1517 #define DWARF_REF_SIZE \
1518 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1520 static unsigned long int get_base_type_offset (dw_die_ref);
1522 /* Return the size of a location descriptor. */
1524 static unsigned long
1525 size_of_loc_descr (dw_loc_descr_ref loc)
1527 unsigned long size = 1;
1529 switch (loc->dw_loc_opc)
1532 size += DWARF2_ADDR_SIZE;
1534 case DW_OP_GNU_addr_index:
1535 case DW_OP_GNU_const_index:
1536 gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
1537 size += size_of_uleb128 (loc->dw_loc_oprnd1.val_entry->index);
1556 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1559 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1564 case DW_OP_plus_uconst:
1565 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1603 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1606 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1609 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1612 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1613 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1616 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1618 case DW_OP_bit_piece:
1619 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1620 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
1622 case DW_OP_deref_size:
1623 case DW_OP_xderef_size:
1632 case DW_OP_call_ref:
1633 size += DWARF_REF_SIZE;
1635 case DW_OP_implicit_value:
1636 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1637 + loc->dw_loc_oprnd1.v.val_unsigned;
1639 case DW_OP_GNU_implicit_pointer:
1640 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1642 case DW_OP_GNU_entry_value:
1644 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
1645 size += size_of_uleb128 (op_size) + op_size;
1648 case DW_OP_GNU_const_type:
1651 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1652 size += size_of_uleb128 (o) + 1;
1653 switch (loc->dw_loc_oprnd2.val_class)
1655 case dw_val_class_vec:
1656 size += loc->dw_loc_oprnd2.v.val_vec.length
1657 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
1659 case dw_val_class_const:
1660 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1662 case dw_val_class_const_double:
1663 size += HOST_BITS_PER_DOUBLE_INT / BITS_PER_UNIT;
1665 case dw_val_class_wide_int:
1666 size += (get_full_len (*loc->dw_loc_oprnd2.v.val_wide)
1667 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
1674 case DW_OP_GNU_regval_type:
1677 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1678 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1679 + size_of_uleb128 (o);
1682 case DW_OP_GNU_deref_type:
1685 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1686 size += 1 + size_of_uleb128 (o);
1689 case DW_OP_GNU_convert:
1690 case DW_OP_GNU_reinterpret:
1691 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
1692 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1696 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1697 size += size_of_uleb128 (o);
1700 case DW_OP_GNU_parameter_ref:
1710 /* Return the size of a series of location descriptors. */
1713 size_of_locs (dw_loc_descr_ref loc)
1718 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1719 field, to avoid writing to a PCH file. */
1720 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1722 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
1724 size += size_of_loc_descr (l);
1729 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1731 l->dw_loc_addr = size;
1732 size += size_of_loc_descr (l);
1738 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
1739 static void get_ref_die_offset_label (char *, dw_die_ref);
1740 static unsigned long int get_ref_die_offset (dw_die_ref);
1742 /* Output location description stack opcode's operands (if any).
1743 The for_eh_or_skip parameter controls whether register numbers are
1744 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1745 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1746 info). This should be suppressed for the cases that have not been converted
1747 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1750 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
1752 dw_val_ref val1 = &loc->dw_loc_oprnd1;
1753 dw_val_ref val2 = &loc->dw_loc_oprnd2;
1755 switch (loc->dw_loc_opc)
1757 #ifdef DWARF2_DEBUGGING_INFO
1760 dw2_asm_output_data (2, val1->v.val_int, NULL);
1765 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
1766 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
1768 fputc ('\n', asm_out_file);
1773 dw2_asm_output_data (4, val1->v.val_int, NULL);
1778 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
1779 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
1781 fputc ('\n', asm_out_file);
1786 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
1787 dw2_asm_output_data (8, val1->v.val_int, NULL);
1794 gcc_assert (val1->val_class == dw_val_class_loc);
1795 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
1797 dw2_asm_output_data (2, offset, NULL);
1800 case DW_OP_implicit_value:
1801 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1802 switch (val2->val_class)
1804 case dw_val_class_const:
1805 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
1807 case dw_val_class_vec:
1809 unsigned int elt_size = val2->v.val_vec.elt_size;
1810 unsigned int len = val2->v.val_vec.length;
1814 if (elt_size > sizeof (HOST_WIDE_INT))
1819 for (i = 0, p = val2->v.val_vec.array;
1822 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
1823 "fp or vector constant word %u", i);
1826 case dw_val_class_const_double:
1828 unsigned HOST_WIDE_INT first, second;
1830 if (WORDS_BIG_ENDIAN)
1832 first = val2->v.val_double.high;
1833 second = val2->v.val_double.low;
1837 first = val2->v.val_double.low;
1838 second = val2->v.val_double.high;
1840 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1842 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1846 case dw_val_class_wide_int:
1849 int len = get_full_len (*val2->v.val_wide);
1850 if (WORDS_BIG_ENDIAN)
1851 for (i = len - 1; i >= 0; --i)
1852 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1853 val2->v.val_wide->elt (i), NULL);
1855 for (i = 0; i < len; ++i)
1856 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
1857 val2->v.val_wide->elt (i), NULL);
1860 case dw_val_class_addr:
1861 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
1862 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
1877 case DW_OP_implicit_value:
1878 /* We currently don't make any attempt to make sure these are
1879 aligned properly like we do for the main unwind info, so
1880 don't support emitting things larger than a byte if we're
1881 only doing unwinding. */
1886 dw2_asm_output_data (1, val1->v.val_int, NULL);
1889 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1892 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
1895 dw2_asm_output_data (1, val1->v.val_int, NULL);
1897 case DW_OP_plus_uconst:
1898 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1932 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
1936 unsigned r = val1->v.val_unsigned;
1937 if (for_eh_or_skip >= 0)
1938 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
1939 gcc_assert (size_of_uleb128 (r)
1940 == size_of_uleb128 (val1->v.val_unsigned));
1941 dw2_asm_output_data_uleb128 (r, NULL);
1945 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
1949 unsigned r = val1->v.val_unsigned;
1950 if (for_eh_or_skip >= 0)
1951 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
1952 gcc_assert (size_of_uleb128 (r)
1953 == size_of_uleb128 (val1->v.val_unsigned));
1954 dw2_asm_output_data_uleb128 (r, NULL);
1955 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
1959 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1961 case DW_OP_bit_piece:
1962 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1963 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
1965 case DW_OP_deref_size:
1966 case DW_OP_xderef_size:
1967 dw2_asm_output_data (1, val1->v.val_int, NULL);
1973 if (targetm.asm_out.output_dwarf_dtprel)
1975 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
1978 fputc ('\n', asm_out_file);
1985 #ifdef DWARF2_DEBUGGING_INFO
1986 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
1993 case DW_OP_GNU_addr_index:
1994 case DW_OP_GNU_const_index:
1995 gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
1996 dw2_asm_output_data_uleb128 (loc->dw_loc_oprnd1.val_entry->index,
1997 "(index into .debug_addr)");
2000 case DW_OP_GNU_implicit_pointer:
2002 char label[MAX_ARTIFICIAL_LABEL_BYTES
2003 + HOST_BITS_PER_WIDE_INT / 2 + 2];
2004 gcc_assert (val1->val_class == dw_val_class_die_ref);
2005 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2006 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2007 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2011 case DW_OP_GNU_entry_value:
2012 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2013 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2016 case DW_OP_GNU_const_type:
2018 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2020 dw2_asm_output_data_uleb128 (o, NULL);
2021 switch (val2->val_class)
2023 case dw_val_class_const:
2024 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2025 dw2_asm_output_data (1, l, NULL);
2026 dw2_asm_output_data (l, val2->v.val_int, NULL);
2028 case dw_val_class_vec:
2030 unsigned int elt_size = val2->v.val_vec.elt_size;
2031 unsigned int len = val2->v.val_vec.length;
2036 dw2_asm_output_data (1, l, NULL);
2037 if (elt_size > sizeof (HOST_WIDE_INT))
2042 for (i = 0, p = val2->v.val_vec.array;
2045 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2046 "fp or vector constant word %u", i);
2049 case dw_val_class_const_double:
2051 unsigned HOST_WIDE_INT first, second;
2052 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2054 dw2_asm_output_data (1, 2 * l, NULL);
2055 if (WORDS_BIG_ENDIAN)
2057 first = val2->v.val_double.high;
2058 second = val2->v.val_double.low;
2062 first = val2->v.val_double.low;
2063 second = val2->v.val_double.high;
2065 dw2_asm_output_data (l, first, NULL);
2066 dw2_asm_output_data (l, second, NULL);
2069 case dw_val_class_wide_int:
2072 int len = get_full_len (*val2->v.val_wide);
2073 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2075 dw2_asm_output_data (1, len * l, NULL);
2076 if (WORDS_BIG_ENDIAN)
2077 for (i = len - 1; i >= 0; --i)
2078 dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
2080 for (i = 0; i < len; ++i)
2081 dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
2089 case DW_OP_GNU_regval_type:
2091 unsigned r = val1->v.val_unsigned;
2092 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2094 if (for_eh_or_skip >= 0)
2096 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2097 gcc_assert (size_of_uleb128 (r)
2098 == size_of_uleb128 (val1->v.val_unsigned));
2100 dw2_asm_output_data_uleb128 (r, NULL);
2101 dw2_asm_output_data_uleb128 (o, NULL);
2104 case DW_OP_GNU_deref_type:
2106 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2108 dw2_asm_output_data (1, val1->v.val_int, NULL);
2109 dw2_asm_output_data_uleb128 (o, NULL);
2112 case DW_OP_GNU_convert:
2113 case DW_OP_GNU_reinterpret:
2114 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2115 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2118 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2120 dw2_asm_output_data_uleb128 (o, NULL);
2124 case DW_OP_GNU_parameter_ref:
2127 gcc_assert (val1->val_class == dw_val_class_die_ref);
2128 o = get_ref_die_offset (val1->v.val_die_ref.die);
2129 dw2_asm_output_data (4, o, NULL);
2134 /* Other codes have no operands. */
2139 /* Output a sequence of location operations.
2140 The for_eh_or_skip parameter controls whether register numbers are
2141 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2142 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2143 info). This should be suppressed for the cases that have not been converted
2144 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2147 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2149 for (; loc != NULL; loc = loc->dw_loc_next)
2151 enum dwarf_location_atom opc = loc->dw_loc_opc;
2152 /* Output the opcode. */
2153 if (for_eh_or_skip >= 0
2154 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2156 unsigned r = (opc - DW_OP_breg0);
2157 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2158 gcc_assert (r <= 31);
2159 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2161 else if (for_eh_or_skip >= 0
2162 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2164 unsigned r = (opc - DW_OP_reg0);
2165 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2166 gcc_assert (r <= 31);
2167 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2170 dw2_asm_output_data (1, opc,
2171 "%s", dwarf_stack_op_name (opc));
2173 /* Output the operand(s) (if any). */
2174 output_loc_operands (loc, for_eh_or_skip);
2178 /* Output location description stack opcode's operands (if any).
2179 The output is single bytes on a line, suitable for .cfi_escape. */
2182 output_loc_operands_raw (dw_loc_descr_ref loc)
2184 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2185 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2187 switch (loc->dw_loc_opc)
2190 case DW_OP_GNU_addr_index:
2191 case DW_OP_GNU_const_index:
2192 case DW_OP_implicit_value:
2193 /* We cannot output addresses in .cfi_escape, only bytes. */
2199 case DW_OP_deref_size:
2200 case DW_OP_xderef_size:
2201 fputc (',', asm_out_file);
2202 dw2_asm_output_data_raw (1, val1->v.val_int);
2207 fputc (',', asm_out_file);
2208 dw2_asm_output_data_raw (2, val1->v.val_int);
2213 fputc (',', asm_out_file);
2214 dw2_asm_output_data_raw (4, val1->v.val_int);
2219 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2220 fputc (',', asm_out_file);
2221 dw2_asm_output_data_raw (8, val1->v.val_int);
2229 gcc_assert (val1->val_class == dw_val_class_loc);
2230 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2232 fputc (',', asm_out_file);
2233 dw2_asm_output_data_raw (2, offset);
2239 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2240 gcc_assert (size_of_uleb128 (r)
2241 == size_of_uleb128 (val1->v.val_unsigned));
2242 fputc (',', asm_out_file);
2243 dw2_asm_output_data_uleb128_raw (r);
2248 case DW_OP_plus_uconst:
2250 fputc (',', asm_out_file);
2251 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2254 case DW_OP_bit_piece:
2255 fputc (',', asm_out_file);
2256 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2257 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
2294 fputc (',', asm_out_file);
2295 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
2300 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2301 gcc_assert (size_of_uleb128 (r)
2302 == size_of_uleb128 (val1->v.val_unsigned));
2303 fputc (',', asm_out_file);
2304 dw2_asm_output_data_uleb128_raw (r);
2305 fputc (',', asm_out_file);
2306 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
2310 case DW_OP_GNU_implicit_pointer:
2311 case DW_OP_GNU_entry_value:
2312 case DW_OP_GNU_const_type:
2313 case DW_OP_GNU_regval_type:
2314 case DW_OP_GNU_deref_type:
2315 case DW_OP_GNU_convert:
2316 case DW_OP_GNU_reinterpret:
2317 case DW_OP_GNU_parameter_ref:
2322 /* Other codes have no operands. */
2328 output_loc_sequence_raw (dw_loc_descr_ref loc)
2332 enum dwarf_location_atom opc = loc->dw_loc_opc;
2333 /* Output the opcode. */
2334 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2336 unsigned r = (opc - DW_OP_breg0);
2337 r = DWARF2_FRAME_REG_OUT (r, 1);
2338 gcc_assert (r <= 31);
2339 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2341 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2343 unsigned r = (opc - DW_OP_reg0);
2344 r = DWARF2_FRAME_REG_OUT (r, 1);
2345 gcc_assert (r <= 31);
2346 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2348 /* Output the opcode. */
2349 fprintf (asm_out_file, "%#x", opc);
2350 output_loc_operands_raw (loc);
2352 if (!loc->dw_loc_next)
2354 loc = loc->dw_loc_next;
2356 fputc (',', asm_out_file);
2360 /* This function builds a dwarf location descriptor sequence from a
2361 dw_cfa_location, adding the given OFFSET to the result of the
2364 struct dw_loc_descr_node *
2365 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
2367 struct dw_loc_descr_node *head, *tmp;
2369 offset += cfa->offset;
2373 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
2374 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2375 head->dw_loc_oprnd1.val_entry = NULL;
2376 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2377 add_loc_descr (&head, tmp);
2380 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
2381 add_loc_descr (&head, tmp);
2385 head = new_reg_loc_descr (cfa->reg, offset);
2390 /* This function builds a dwarf location descriptor sequence for
2391 the address at OFFSET from the CFA when stack is aligned to
2394 struct dw_loc_descr_node *
2395 build_cfa_aligned_loc (dw_cfa_location *cfa,
2396 HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
2398 struct dw_loc_descr_node *head;
2399 unsigned int dwarf_fp
2400 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
2402 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2403 if (cfa->reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
2405 head = new_reg_loc_descr (dwarf_fp, 0);
2406 add_loc_descr (&head, int_loc_descriptor (alignment));
2407 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
2408 loc_descr_plus_const (&head, offset);
2411 head = new_reg_loc_descr (dwarf_fp, offset);
2415 /* And now, the support for symbolic debugging information. */
2417 /* .debug_str support. */
2419 static void dwarf2out_init (const char *);
2420 static void dwarf2out_finish (const char *);
2421 static void dwarf2out_early_finish (void);
2422 static void dwarf2out_assembly_start (void);
2423 static void dwarf2out_define (unsigned int, const char *);
2424 static void dwarf2out_undef (unsigned int, const char *);
2425 static void dwarf2out_start_source_file (unsigned, const char *);
2426 static void dwarf2out_end_source_file (unsigned);
2427 static void dwarf2out_function_decl (tree);
2428 static void dwarf2out_begin_block (unsigned, unsigned);
2429 static void dwarf2out_end_block (unsigned, unsigned);
2430 static bool dwarf2out_ignore_block (const_tree);
2431 static void dwarf2out_early_global_decl (tree);
2432 static void dwarf2out_late_global_decl (tree);
2433 static void dwarf2out_type_decl (tree, int);
2434 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
2435 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
2437 static void dwarf2out_abstract_function (tree);
2438 static void dwarf2out_var_location (rtx_insn *);
2439 static void dwarf2out_begin_function (tree);
2440 static void dwarf2out_end_function (unsigned int);
2441 static void dwarf2out_register_main_translation_unit (tree unit);
2442 static void dwarf2out_set_name (tree, tree);
2444 /* The debug hooks structure. */
2446 const struct gcc_debug_hooks dwarf2_debug_hooks =
2450 dwarf2out_early_finish,
2451 dwarf2out_assembly_start,
2454 dwarf2out_start_source_file,
2455 dwarf2out_end_source_file,
2456 dwarf2out_begin_block,
2457 dwarf2out_end_block,
2458 dwarf2out_ignore_block,
2459 dwarf2out_source_line,
2460 dwarf2out_begin_prologue,
2461 #if VMS_DEBUGGING_INFO
2462 dwarf2out_vms_end_prologue,
2463 dwarf2out_vms_begin_epilogue,
2465 debug_nothing_int_charstar,
2466 debug_nothing_int_charstar,
2468 dwarf2out_end_epilogue,
2469 dwarf2out_begin_function,
2470 dwarf2out_end_function, /* end_function */
2471 dwarf2out_register_main_translation_unit,
2472 dwarf2out_function_decl, /* function_decl */
2473 dwarf2out_early_global_decl,
2474 dwarf2out_late_global_decl,
2475 dwarf2out_type_decl, /* type_decl */
2476 dwarf2out_imported_module_or_decl,
2477 debug_nothing_tree, /* deferred_inline_function */
2478 /* The DWARF 2 backend tries to reduce debugging bloat by not
2479 emitting the abstract description of inline functions until
2480 something tries to reference them. */
2481 dwarf2out_abstract_function, /* outlining_inline_function */
2482 debug_nothing_rtx_code_label, /* label */
2483 debug_nothing_int, /* handle_pch */
2484 dwarf2out_var_location,
2485 dwarf2out_switch_text_section,
2487 1, /* start_end_main_source_file */
2488 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
2491 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks =
2494 debug_nothing_charstar,
2497 debug_nothing_int_charstar,
2498 debug_nothing_int_charstar,
2499 debug_nothing_int_charstar,
2501 debug_nothing_int_int, /* begin_block */
2502 debug_nothing_int_int, /* end_block */
2503 debug_true_const_tree, /* ignore_block */
2504 dwarf2out_source_line, /* source_line */
2505 debug_nothing_int_charstar, /* begin_prologue */
2506 debug_nothing_int_charstar, /* end_prologue */
2507 debug_nothing_int_charstar, /* begin_epilogue */
2508 debug_nothing_int_charstar, /* end_epilogue */
2509 debug_nothing_tree, /* begin_function */
2510 debug_nothing_int, /* end_function */
2511 debug_nothing_tree, /* register_main_translation_unit */
2512 debug_nothing_tree, /* function_decl */
2513 debug_nothing_tree, /* early_global_decl */
2514 debug_nothing_tree, /* late_global_decl */
2515 debug_nothing_tree_int, /* type_decl */
2516 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
2517 debug_nothing_tree, /* deferred_inline_function */
2518 debug_nothing_tree, /* outlining_inline_function */
2519 debug_nothing_rtx_code_label, /* label */
2520 debug_nothing_int, /* handle_pch */
2521 debug_nothing_rtx_insn, /* var_location */
2522 debug_nothing_void, /* switch_text_section */
2523 debug_nothing_tree_tree, /* set_name */
2524 0, /* start_end_main_source_file */
2525 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
2528 /* NOTE: In the comments in this file, many references are made to
2529 "Debugging Information Entries". This term is abbreviated as `DIE'
2530 throughout the remainder of this file. */
2532 /* An internal representation of the DWARF output is built, and then
2533 walked to generate the DWARF debugging info. The walk of the internal
2534 representation is done after the entire program has been compiled.
2535 The types below are used to describe the internal representation. */
2537 /* Whether to put type DIEs into their own section .debug_types instead
2538 of making them part of the .debug_info section. Only supported for
2539 Dwarf V4 or higher and the user didn't disable them through
2540 -fno-debug-types-section. It is more efficient to put them in a
2541 separate comdat sections since the linker will then be able to
2542 remove duplicates. But not all tools support .debug_types sections
2545 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2547 /* Various DIE's use offsets relative to the beginning of the
2548 .debug_info section to refer to each other. */
2550 typedef long int dw_offset;
2552 struct comdat_type_node;
2554 /* The entries in the line_info table more-or-less mirror the opcodes
2555 that are used in the real dwarf line table. Arrays of these entries
2556 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2559 enum dw_line_info_opcode {
2560 /* Emit DW_LNE_set_address; the operand is the label index. */
2563 /* Emit a row to the matrix with the given line. This may be done
2564 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2568 /* Emit a DW_LNS_set_file. */
2571 /* Emit a DW_LNS_set_column. */
2574 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2577 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2578 LI_set_prologue_end,
2579 LI_set_epilogue_begin,
2581 /* Emit a DW_LNE_set_discriminator. */
2582 LI_set_discriminator
2585 typedef struct GTY(()) dw_line_info_struct {
2586 enum dw_line_info_opcode opcode;
2588 } dw_line_info_entry;
2591 struct GTY(()) dw_line_info_table {
2592 /* The label that marks the end of this section. */
2593 const char *end_label;
2595 /* The values for the last row of the matrix, as collected in the table.
2596 These are used to minimize the changes to the next row. */
2597 unsigned int file_num;
2598 unsigned int line_num;
2599 unsigned int column_num;
2604 vec<dw_line_info_entry, va_gc> *entries;
2608 /* Each DIE attribute has a field specifying the attribute kind,
2609 a link to the next attribute in the chain, and an attribute value.
2610 Attributes are typically linked below the DIE they modify. */
2612 typedef struct GTY(()) dw_attr_struct {
2613 enum dwarf_attribute dw_attr;
2614 dw_val_node dw_attr_val;
2619 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2620 The children of each node form a circular list linked by
2621 die_sib. die_child points to the node *before* the "first" child node. */
2623 typedef struct GTY((chain_circular ("%h.die_sib"), for_user)) die_struct {
2624 union die_symbol_or_type_node
2626 const char * GTY ((tag ("0"))) die_symbol;
2627 comdat_type_node *GTY ((tag ("1"))) die_type_node;
2629 GTY ((desc ("%0.comdat_type_p"))) die_id;
2630 vec<dw_attr_node, va_gc> *die_attr;
2631 dw_die_ref die_parent;
2632 dw_die_ref die_child;
2634 dw_die_ref die_definition; /* ref from a specification to its definition */
2635 dw_offset die_offset;
2636 unsigned long die_abbrev;
2638 unsigned int decl_id;
2639 enum dwarf_tag die_tag;
2640 /* Die is used and must not be pruned as unused. */
2641 BOOL_BITFIELD die_perennial_p : 1;
2642 BOOL_BITFIELD comdat_type_p : 1; /* DIE has a type signature */
2643 /* Lots of spare bits. */
2647 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2648 static bool early_dwarf;
2649 struct set_early_dwarf {
2651 set_early_dwarf () : saved(early_dwarf) { early_dwarf = true; }
2652 ~set_early_dwarf () { early_dwarf = saved; }
2655 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2656 #define FOR_EACH_CHILD(die, c, expr) do { \
2657 c = die->die_child; \
2661 } while (c != die->die_child); \
2664 /* The pubname structure */
2666 typedef struct GTY(()) pubname_struct {
2673 struct GTY(()) dw_ranges {
2674 /* If this is positive, it's a block number, otherwise it's a
2675 bitwise-negated index into dw_ranges_by_label. */
2679 /* A structure to hold a macinfo entry. */
2681 typedef struct GTY(()) macinfo_struct {
2683 unsigned HOST_WIDE_INT lineno;
2689 struct GTY(()) dw_ranges_by_label {
2694 /* The comdat type node structure. */
2695 struct GTY(()) comdat_type_node
2697 dw_die_ref root_die;
2698 dw_die_ref type_die;
2699 dw_die_ref skeleton_die;
2700 char signature[DWARF_TYPE_SIGNATURE_SIZE];
2701 comdat_type_node *next;
2704 /* A list of DIEs for which we can't determine ancestry (parent_die
2705 field) just yet. Later in dwarf2out_finish we will fill in the
2707 typedef struct GTY(()) limbo_die_struct {
2709 /* The tree for which this DIE was created. We use this to
2710 determine ancestry later. */
2712 struct limbo_die_struct *next;
2716 typedef struct skeleton_chain_struct
2720 struct skeleton_chain_struct *parent;
2722 skeleton_chain_node;
2724 /* Define a macro which returns nonzero for a TYPE_DECL which was
2725 implicitly generated for a type.
2727 Note that, unlike the C front-end (which generates a NULL named
2728 TYPE_DECL node for each complete tagged type, each array type,
2729 and each function type node created) the C++ front-end generates
2730 a _named_ TYPE_DECL node for each tagged type node created.
2731 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2732 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2733 front-end, but for each type, tagged or not. */
2735 #define TYPE_DECL_IS_STUB(decl) \
2736 (DECL_NAME (decl) == NULL_TREE \
2737 || (DECL_ARTIFICIAL (decl) \
2738 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2739 /* This is necessary for stub decls that \
2740 appear in nested inline functions. */ \
2741 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2742 && (decl_ultimate_origin (decl) \
2743 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2745 /* Information concerning the compilation unit's programming
2746 language, and compiler version. */
2748 /* Fixed size portion of the DWARF compilation unit header. */
2749 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2750 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2752 /* Fixed size portion of the DWARF comdat type unit header. */
2753 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2754 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2755 + DWARF_OFFSET_SIZE)
2757 /* Fixed size portion of public names info. */
2758 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2760 /* Fixed size portion of the address range info. */
2761 #define DWARF_ARANGES_HEADER_SIZE \
2762 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2763 DWARF2_ADDR_SIZE * 2) \
2764 - DWARF_INITIAL_LENGTH_SIZE)
2766 /* Size of padding portion in the address range info. It must be
2767 aligned to twice the pointer size. */
2768 #define DWARF_ARANGES_PAD_SIZE \
2769 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2770 DWARF2_ADDR_SIZE * 2) \
2771 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2773 /* Use assembler line directives if available. */
2774 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2775 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2776 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2778 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2782 /* Minimum line offset in a special line info. opcode.
2783 This value was chosen to give a reasonable range of values. */
2784 #define DWARF_LINE_BASE -10
2786 /* First special line opcode - leave room for the standard opcodes. */
2787 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2789 /* Range of line offsets in a special line info. opcode. */
2790 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2792 /* Flag that indicates the initial value of the is_stmt_start flag.
2793 In the present implementation, we do not mark any lines as
2794 the beginning of a source statement, because that information
2795 is not made available by the GCC front-end. */
2796 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2798 /* Maximum number of operations per instruction bundle. */
2799 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2800 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2803 /* This location is used by calc_die_sizes() to keep track
2804 the offset of each DIE within the .debug_info section. */
2805 static unsigned long next_die_offset;
2807 /* Record the root of the DIE's built for the current compilation unit. */
2808 static GTY(()) dw_die_ref single_comp_unit_die;
2810 /* A list of type DIEs that have been separated into comdat sections. */
2811 static GTY(()) comdat_type_node *comdat_type_list;
2813 /* A list of DIEs with a NULL parent waiting to be relocated. */
2814 static GTY(()) limbo_die_node *limbo_die_list;
2816 /* A list of DIEs for which we may have to generate
2817 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2818 static GTY(()) limbo_die_node *deferred_asm_name;
2820 struct dwarf_file_hasher : ggc_ptr_hash<dwarf_file_data>
2822 typedef const char *compare_type;
2824 static hashval_t hash (dwarf_file_data *);
2825 static bool equal (dwarf_file_data *, const char *);
2828 /* Filenames referenced by this compilation unit. */
2829 static GTY(()) hash_table<dwarf_file_hasher> *file_table;
2831 struct decl_die_hasher : ggc_ptr_hash<die_node>
2833 typedef tree compare_type;
2835 static hashval_t hash (die_node *);
2836 static bool equal (die_node *, tree);
2838 /* A hash table of references to DIE's that describe declarations.
2839 The key is a DECL_UID() which is a unique number identifying each decl. */
2840 static GTY (()) hash_table<decl_die_hasher> *decl_die_table;
2842 struct block_die_hasher : ggc_ptr_hash<die_struct>
2844 static hashval_t hash (die_struct *);
2845 static bool equal (die_struct *, die_struct *);
2848 /* A hash table of references to DIE's that describe COMMON blocks.
2849 The key is DECL_UID() ^ die_parent. */
2850 static GTY (()) hash_table<block_die_hasher> *common_block_die_table;
2852 typedef struct GTY(()) die_arg_entry_struct {
2858 /* Node of the variable location list. */
2859 struct GTY ((chain_next ("%h.next"))) var_loc_node {
2860 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2861 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2862 in mode of the EXPR_LIST node and first EXPR_LIST operand
2863 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2864 location or NULL for padding. For larger bitsizes,
2865 mode is 0 and first operand is a CONCAT with bitsize
2866 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2867 NULL as second operand. */
2869 const char * GTY (()) label;
2870 struct var_loc_node * GTY (()) next;
2873 /* Variable location list. */
2874 struct GTY ((for_user)) var_loc_list_def {
2875 struct var_loc_node * GTY (()) first;
2877 /* Pointer to the last but one or last element of the
2878 chained list. If the list is empty, both first and
2879 last are NULL, if the list contains just one node
2880 or the last node certainly is not redundant, it points
2881 to the last node, otherwise points to the last but one.
2882 Do not mark it for GC because it is marked through the chain. */
2883 struct var_loc_node * GTY ((skip ("%h"))) last;
2885 /* Pointer to the last element before section switch,
2886 if NULL, either sections weren't switched or first
2887 is after section switch. */
2888 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
2890 /* DECL_UID of the variable decl. */
2891 unsigned int decl_id;
2893 typedef struct var_loc_list_def var_loc_list;
2895 /* Call argument location list. */
2896 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
2897 rtx GTY (()) call_arg_loc_note;
2898 const char * GTY (()) label;
2899 tree GTY (()) block;
2901 rtx GTY (()) symbol_ref;
2902 struct call_arg_loc_node * GTY (()) next;
2906 struct decl_loc_hasher : ggc_ptr_hash<var_loc_list>
2908 typedef const_tree compare_type;
2910 static hashval_t hash (var_loc_list *);
2911 static bool equal (var_loc_list *, const_tree);
2914 /* Table of decl location linked lists. */
2915 static GTY (()) hash_table<decl_loc_hasher> *decl_loc_table;
2917 /* Head and tail of call_arg_loc chain. */
2918 static GTY (()) struct call_arg_loc_node *call_arg_locations;
2919 static struct call_arg_loc_node *call_arg_loc_last;
2921 /* Number of call sites in the current function. */
2922 static int call_site_count = -1;
2923 /* Number of tail call sites in the current function. */
2924 static int tail_call_site_count = -1;
2926 /* A cached location list. */
2927 struct GTY ((for_user)) cached_dw_loc_list_def {
2928 /* The DECL_UID of the decl that this entry describes. */
2929 unsigned int decl_id;
2931 /* The cached location list. */
2932 dw_loc_list_ref loc_list;
2934 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
2936 struct dw_loc_list_hasher : ggc_ptr_hash<cached_dw_loc_list>
2939 typedef const_tree compare_type;
2941 static hashval_t hash (cached_dw_loc_list *);
2942 static bool equal (cached_dw_loc_list *, const_tree);
2945 /* Table of cached location lists. */
2946 static GTY (()) hash_table<dw_loc_list_hasher> *cached_dw_loc_list_table;
2948 /* A pointer to the base of a list of references to DIE's that
2949 are uniquely identified by their tag, presence/absence of
2950 children DIE's, and list of attribute/value pairs. */
2951 static GTY((length ("abbrev_die_table_allocated")))
2952 dw_die_ref *abbrev_die_table;
2954 /* Number of elements currently allocated for abbrev_die_table. */
2955 static GTY(()) unsigned abbrev_die_table_allocated;
2957 /* Number of elements in abbrev_die_table currently in use. */
2958 static GTY(()) unsigned abbrev_die_table_in_use;
2960 /* Size (in elements) of increments by which we may expand the
2961 abbrev_die_table. */
2962 #define ABBREV_DIE_TABLE_INCREMENT 256
2964 /* A global counter for generating labels for line number data. */
2965 static unsigned int line_info_label_num;
2967 /* The current table to which we should emit line number information
2968 for the current function. This will be set up at the beginning of
2969 assembly for the function. */
2970 static dw_line_info_table *cur_line_info_table;
2972 /* The two default tables of line number info. */
2973 static GTY(()) dw_line_info_table *text_section_line_info;
2974 static GTY(()) dw_line_info_table *cold_text_section_line_info;
2976 /* The set of all non-default tables of line number info. */
2977 static GTY(()) vec<dw_line_info_table *, va_gc> *separate_line_info;
2979 /* A flag to tell pubnames/types export if there is an info section to
2981 static bool info_section_emitted;
2983 /* A pointer to the base of a table that contains a list of publicly
2984 accessible names. */
2985 static GTY (()) vec<pubname_entry, va_gc> *pubname_table;
2987 /* A pointer to the base of a table that contains a list of publicly
2988 accessible types. */
2989 static GTY (()) vec<pubname_entry, va_gc> *pubtype_table;
2991 /* A pointer to the base of a table that contains a list of macro
2992 defines/undefines (and file start/end markers). */
2993 static GTY (()) vec<macinfo_entry, va_gc> *macinfo_table;
2995 /* True if .debug_macinfo or .debug_macros section is going to be
2997 #define have_macinfo \
2998 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2999 && !macinfo_table->is_empty ())
3001 /* Array of dies for which we should generate .debug_ranges info. */
3002 static GTY ((length ("ranges_table_allocated"))) dw_ranges *ranges_table;
3004 /* Number of elements currently allocated for ranges_table. */
3005 static GTY(()) unsigned ranges_table_allocated;
3007 /* Number of elements in ranges_table currently in use. */
3008 static GTY(()) unsigned ranges_table_in_use;
3010 /* Array of pairs of labels referenced in ranges_table. */
3011 static GTY ((length ("ranges_by_label_allocated")))
3012 dw_ranges_by_label *ranges_by_label;
3014 /* Number of elements currently allocated for ranges_by_label. */
3015 static GTY(()) unsigned ranges_by_label_allocated;
3017 /* Number of elements in ranges_by_label currently in use. */
3018 static GTY(()) unsigned ranges_by_label_in_use;
3020 /* Size (in elements) of increments by which we may expand the
3022 #define RANGES_TABLE_INCREMENT 64
3024 /* Whether we have location lists that need outputting */
3025 static GTY(()) bool have_location_lists;
3027 /* Unique label counter. */
3028 static GTY(()) unsigned int loclabel_num;
3030 /* Unique label counter for point-of-call tables. */
3031 static GTY(()) unsigned int poc_label_num;
3033 /* The last file entry emitted by maybe_emit_file(). */
3034 static GTY(()) struct dwarf_file_data * last_emitted_file;
3036 /* Number of internal labels generated by gen_internal_sym(). */
3037 static GTY(()) int label_num;
3039 static GTY(()) vec<die_arg_entry, va_gc> *tmpl_value_parm_die_table;
3041 /* Instances of generic types for which we need to generate debug
3042 info that describe their generic parameters and arguments. That
3043 generation needs to happen once all types are properly laid out so
3044 we do it at the end of compilation. */
3045 static GTY(()) vec<tree, va_gc> *generic_type_instances;
3047 /* Offset from the "steady-state frame pointer" to the frame base,
3048 within the current function. */
3049 static HOST_WIDE_INT frame_pointer_fb_offset;
3050 static bool frame_pointer_fb_offset_valid;
3052 static vec<dw_die_ref> base_types;
3054 /* Flags to represent a set of attribute classes for attributes that represent
3055 a scalar value (bounds, pointers, ...). */
3058 dw_scalar_form_constant = 0x01,
3059 dw_scalar_form_exprloc = 0x02,
3060 dw_scalar_form_reference = 0x04
3063 /* Forward declarations for functions defined in this file. */
3065 static int is_pseudo_reg (const_rtx);
3066 static tree type_main_variant (tree);
3067 static int is_tagged_type (const_tree);
3068 static const char *dwarf_tag_name (unsigned);
3069 static const char *dwarf_attr_name (unsigned);
3070 static const char *dwarf_form_name (unsigned);
3071 static tree decl_ultimate_origin (const_tree);
3072 static tree decl_class_context (tree);
3073 static void add_dwarf_attr (dw_die_ref, dw_attr_node *);
3074 static inline enum dw_val_class AT_class (dw_attr_node *);
3075 static inline unsigned int AT_index (dw_attr_node *);
3076 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3077 static inline unsigned AT_flag (dw_attr_node *);
3078 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3079 static inline HOST_WIDE_INT AT_int (dw_attr_node *);
3080 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3081 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_node *);
3082 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3083 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3084 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3085 unsigned int, unsigned char *);
3086 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3087 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3088 static inline const char *AT_string (dw_attr_node *);
3089 static enum dwarf_form AT_string_form (dw_attr_node *);
3090 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3091 static void add_AT_specification (dw_die_ref, dw_die_ref);
3092 static inline dw_die_ref AT_ref (dw_attr_node *);
3093 static inline int AT_ref_external (dw_attr_node *);
3094 static inline void set_AT_ref_external (dw_attr_node *, int);
3095 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3096 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3097 static inline dw_loc_descr_ref AT_loc (dw_attr_node *);
3098 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3100 static inline dw_loc_list_ref AT_loc_list (dw_attr_node *);
3101 static addr_table_entry *add_addr_table_entry (void *, enum ate_kind);
3102 static void remove_addr_table_entry (addr_table_entry *);
3103 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx, bool);
3104 static inline rtx AT_addr (dw_attr_node *);
3105 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3106 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3107 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3108 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3109 unsigned HOST_WIDE_INT);
3110 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3111 unsigned long, bool);
3112 static inline const char *AT_lbl (dw_attr_node *);
3113 static dw_attr_node *get_AT (dw_die_ref, enum dwarf_attribute);
3114 static const char *get_AT_low_pc (dw_die_ref);
3115 static const char *get_AT_hi_pc (dw_die_ref);
3116 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3117 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3118 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3119 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3120 static bool is_cxx (void);
3121 static bool is_fortran (void);
3122 static bool is_ada (void);
3123 static bool remove_AT (dw_die_ref, enum dwarf_attribute);
3124 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3125 static void add_child_die (dw_die_ref, dw_die_ref);
3126 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3127 static dw_die_ref lookup_type_die (tree);
3128 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3129 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3130 static void equate_type_number_to_die (tree, dw_die_ref);
3131 static dw_die_ref lookup_decl_die (tree);
3132 static var_loc_list *lookup_decl_loc (const_tree);
3133 static void equate_decl_number_to_die (tree, dw_die_ref);
3134 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
3135 static void print_spaces (FILE *);
3136 static void print_die (dw_die_ref, FILE *);
3137 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3138 static dw_die_ref pop_compile_unit (dw_die_ref);
3139 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3140 static void attr_checksum (dw_attr_node *, struct md5_ctx *, int *);
3141 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3142 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3143 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3144 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3145 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_node *,
3146 struct md5_ctx *, int *);
3147 struct checksum_attributes;
3148 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3149 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3150 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3151 static void generate_type_signature (dw_die_ref, comdat_type_node *);
3152 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3153 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3154 static int same_attr_p (dw_attr_node *, dw_attr_node *, int *);
3155 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3156 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3157 static void compute_section_prefix (dw_die_ref);
3158 static int is_type_die (dw_die_ref);
3159 static int is_comdat_die (dw_die_ref);
3160 static int is_symbol_die (dw_die_ref);
3161 static inline bool is_template_instantiation (dw_die_ref);
3162 static void assign_symbol_names (dw_die_ref);
3163 static void break_out_includes (dw_die_ref);
3164 static int is_declaration_die (dw_die_ref);
3165 static int should_move_die_to_comdat (dw_die_ref);
3166 static dw_die_ref clone_as_declaration (dw_die_ref);
3167 static dw_die_ref clone_die (dw_die_ref);
3168 static dw_die_ref clone_tree (dw_die_ref);
3169 static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref);
3170 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3171 static void generate_skeleton_bottom_up (skeleton_chain_node *);
3172 static dw_die_ref generate_skeleton (dw_die_ref);
3173 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3176 static void break_out_comdat_types (dw_die_ref);
3177 static void copy_decls_for_unworthy_types (dw_die_ref);
3179 static void add_sibling_attributes (dw_die_ref);
3180 static void output_location_lists (dw_die_ref);
3181 static int constant_size (unsigned HOST_WIDE_INT);
3182 static unsigned long size_of_die (dw_die_ref);
3183 static void calc_die_sizes (dw_die_ref);
3184 static void calc_base_type_die_sizes (void);
3185 static void mark_dies (dw_die_ref);
3186 static void unmark_dies (dw_die_ref);
3187 static void unmark_all_dies (dw_die_ref);
3188 static unsigned long size_of_pubnames (vec<pubname_entry, va_gc> *);
3189 static unsigned long size_of_aranges (void);
3190 static enum dwarf_form value_format (dw_attr_node *);
3191 static void output_value_format (dw_attr_node *);
3192 static void output_abbrev_section (void);
3193 static void output_die_abbrevs (unsigned long, dw_die_ref);
3194 static void output_die_symbol (dw_die_ref);
3195 static void output_die (dw_die_ref);
3196 static void output_compilation_unit_header (void);
3197 static void output_comp_unit (dw_die_ref, int);
3198 static void output_comdat_type_unit (comdat_type_node *);
3199 static const char *dwarf2_name (tree, int);
3200 static void add_pubname (tree, dw_die_ref);
3201 static void add_enumerator_pubname (const char *, dw_die_ref);
3202 static void add_pubname_string (const char *, dw_die_ref);
3203 static void add_pubtype (tree, dw_die_ref);
3204 static void output_pubnames (vec<pubname_entry, va_gc> *);
3205 static void output_aranges (unsigned long);
3206 static unsigned int add_ranges_num (int);
3207 static unsigned int add_ranges (const_tree);
3208 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3210 static void output_ranges (void);
3211 static dw_line_info_table *new_line_info_table (void);
3212 static void output_line_info (bool);
3213 static void output_file_names (void);
3214 static dw_die_ref base_type_die (tree);
3215 static int is_base_type (tree);
3216 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
3217 static int decl_quals (const_tree);
3218 static dw_die_ref modified_type_die (tree, int, dw_die_ref);
3219 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3220 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3221 static int type_is_enum (const_tree);
3222 static unsigned int dbx_reg_number (const_rtx);
3223 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3224 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3225 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3226 enum var_init_status);
3227 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3228 enum var_init_status);
3229 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
3230 enum var_init_status);
3231 static int is_based_loc (const_rtx);
3232 static bool resolve_one_addr (rtx *);
3233 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3234 enum var_init_status);
3235 static dw_loc_descr_ref loc_descriptor (rtx, machine_mode mode,
3236 enum var_init_status);
3237 struct loc_descr_context;
3238 static dw_loc_list_ref loc_list_from_tree (tree, int,
3239 const struct loc_descr_context *);
3240 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int,
3241 const struct loc_descr_context *);
3242 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3243 static tree field_type (const_tree);
3244 static unsigned int simple_type_align_in_bits (const_tree);
3245 static unsigned int simple_decl_align_in_bits (const_tree);
3246 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3247 static HOST_WIDE_INT field_byte_offset (const_tree);
3248 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3250 static void add_data_member_location_attribute (dw_die_ref, tree);
3251 static bool add_const_value_attribute (dw_die_ref, rtx);
3252 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3253 static void insert_wide_int (const wide_int &, unsigned char *, int);
3254 static void insert_float (const_rtx, unsigned char *);
3255 static rtx rtl_for_decl_location (tree);
3256 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
3257 enum dwarf_attribute);
3258 static bool tree_add_const_value_attribute (dw_die_ref, tree);
3259 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3260 static void add_name_attribute (dw_die_ref, const char *);
3261 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3262 static void add_comp_dir_attribute (dw_die_ref);
3263 static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
3264 const struct loc_descr_context *);
3265 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree,
3266 const struct loc_descr_context *);
3267 static void add_subscript_info (dw_die_ref, tree, bool);
3268 static void add_byte_size_attribute (dw_die_ref, tree);
3269 static void add_bit_offset_attribute (dw_die_ref, tree);
3270 static void add_bit_size_attribute (dw_die_ref, tree);
3271 static void add_prototyped_attribute (dw_die_ref, tree);
3272 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
3273 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3274 static void add_src_coords_attributes (dw_die_ref, tree);
3275 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3276 static void push_decl_scope (tree);
3277 static void pop_decl_scope (void);
3278 static dw_die_ref scope_die_for (tree, dw_die_ref);
3279 static inline int local_scope_p (dw_die_ref);
3280 static inline int class_scope_p (dw_die_ref);
3281 static inline int class_or_namespace_scope_p (dw_die_ref);
3282 static void add_type_attribute (dw_die_ref, tree, int, dw_die_ref);
3283 static void add_calling_convention_attribute (dw_die_ref, tree);
3284 static const char *type_tag (const_tree);
3285 static tree member_declared_type (const_tree);
3287 static const char *decl_start_label (tree);
3289 static void gen_array_type_die (tree, dw_die_ref);
3290 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
3292 static void gen_entry_point_die (tree, dw_die_ref);
3294 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3295 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
3296 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
3297 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3298 static void gen_formal_types_die (tree, dw_die_ref);
3299 static void gen_subprogram_die (tree, dw_die_ref);
3300 static void gen_variable_die (tree, tree, dw_die_ref);
3301 static void gen_const_die (tree, dw_die_ref);
3302 static void gen_label_die (tree, dw_die_ref);
3303 static void gen_lexical_block_die (tree, dw_die_ref);
3304 static void gen_inlined_subroutine_die (tree, dw_die_ref);
3305 static void gen_field_die (tree, dw_die_ref);
3306 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3307 static dw_die_ref gen_compile_unit_die (const char *);
3308 static void gen_inheritance_die (tree, tree, dw_die_ref);
3309 static void gen_member_die (tree, dw_die_ref);
3310 static void gen_struct_or_union_type_die (tree, dw_die_ref,
3311 enum debug_info_usage);
3312 static void gen_subroutine_type_die (tree, dw_die_ref);
3313 static void gen_typedef_die (tree, dw_die_ref);
3314 static void gen_type_die (tree, dw_die_ref);
3315 static void gen_block_die (tree, dw_die_ref);
3316 static void decls_for_scope (tree, dw_die_ref);
3317 static inline int is_redundant_typedef (const_tree);
3318 static bool is_naming_typedef_decl (const_tree);
3319 static inline dw_die_ref get_context_die (tree);
3320 static void gen_namespace_die (tree, dw_die_ref);
3321 static dw_die_ref gen_namelist_decl (tree, dw_die_ref, tree);
3322 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
3323 static dw_die_ref force_decl_die (tree);
3324 static dw_die_ref force_type_die (tree);
3325 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3326 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
3327 static struct dwarf_file_data * lookup_filename (const char *);
3328 static void retry_incomplete_types (void);
3329 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3330 static void gen_generic_params_dies (tree);
3331 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
3332 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
3333 static void splice_child_die (dw_die_ref, dw_die_ref);
3334 static int file_info_cmp (const void *, const void *);
3335 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3336 const char *, const char *);
3337 static void output_loc_list (dw_loc_list_ref);
3338 static char *gen_internal_sym (const char *);
3339 static bool want_pubnames (void);
3341 static void prune_unmark_dies (dw_die_ref);
3342 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
3343 static void prune_unused_types_mark (dw_die_ref, int);
3344 static void prune_unused_types_walk (dw_die_ref);
3345 static void prune_unused_types_walk_attribs (dw_die_ref);
3346 static void prune_unused_types_prune (dw_die_ref);
3347 static void prune_unused_types (void);
3348 static int maybe_emit_file (struct dwarf_file_data *fd);
3349 static inline const char *AT_vms_delta1 (dw_attr_node *);
3350 static inline const char *AT_vms_delta2 (dw_attr_node *);
3351 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
3352 const char *, const char *);
3353 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
3354 static void gen_remaining_tmpl_value_param_die_attribute (void);
3355 static bool generic_type_p (tree);
3356 static void schedule_generic_params_dies_gen (tree t);
3357 static void gen_scheduled_generic_parms_dies (void);
3359 static const char *comp_dir_string (void);
3361 static void hash_loc_operands (dw_loc_descr_ref, inchash::hash &);
3363 /* enum for tracking thread-local variables whose address is really an offset
3364 relative to the TLS pointer, which will need link-time relocation, but will
3365 not need relocation by the DWARF consumer. */
3373 /* Return the operator to use for an address of a variable. For dtprel_true, we
3374 use DW_OP_const*. For regular variables, which need both link-time
3375 relocation and consumer-level relocation (e.g., to account for shared objects
3376 loaded at a random address), we use DW_OP_addr*. */
3378 static inline enum dwarf_location_atom
3379 dw_addr_op (enum dtprel_bool dtprel)
3381 if (dtprel == dtprel_true)
3382 return (dwarf_split_debug_info ? DW_OP_GNU_const_index
3383 : (DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u));
3385 return dwarf_split_debug_info ? DW_OP_GNU_addr_index : DW_OP_addr;
3388 /* Return a pointer to a newly allocated address location description. If
3389 dwarf_split_debug_info is true, then record the address with the appropriate
3391 static inline dw_loc_descr_ref
3392 new_addr_loc_descr (rtx addr, enum dtprel_bool dtprel)
3394 dw_loc_descr_ref ref = new_loc_descr (dw_addr_op (dtprel), 0, 0);
3396 ref->dw_loc_oprnd1.val_class = dw_val_class_addr;
3397 ref->dw_loc_oprnd1.v.val_addr = addr;
3398 ref->dtprel = dtprel;
3399 if (dwarf_split_debug_info)
3400 ref->dw_loc_oprnd1.val_entry
3401 = add_addr_table_entry (addr,
3402 dtprel ? ate_kind_rtx_dtprel : ate_kind_rtx);
3404 ref->dw_loc_oprnd1.val_entry = NULL;
3409 /* Section names used to hold DWARF debugging information. */
3411 #ifndef DEBUG_INFO_SECTION
3412 #define DEBUG_INFO_SECTION ".debug_info"
3414 #ifndef DEBUG_DWO_INFO_SECTION
3415 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3417 #ifndef DEBUG_ABBREV_SECTION
3418 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3420 #ifndef DEBUG_DWO_ABBREV_SECTION
3421 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3423 #ifndef DEBUG_ARANGES_SECTION
3424 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3426 #ifndef DEBUG_ADDR_SECTION
3427 #define DEBUG_ADDR_SECTION ".debug_addr"
3429 #ifndef DEBUG_NORM_MACINFO_SECTION
3430 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3432 #ifndef DEBUG_DWO_MACINFO_SECTION
3433 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3435 #ifndef DEBUG_MACINFO_SECTION
3436 #define DEBUG_MACINFO_SECTION \
3437 (!dwarf_split_debug_info \
3438 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3440 #ifndef DEBUG_NORM_MACRO_SECTION
3441 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3443 #ifndef DEBUG_DWO_MACRO_SECTION
3444 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3446 #ifndef DEBUG_MACRO_SECTION
3447 #define DEBUG_MACRO_SECTION \
3448 (!dwarf_split_debug_info \
3449 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3451 #ifndef DEBUG_LINE_SECTION
3452 #define DEBUG_LINE_SECTION ".debug_line"
3454 #ifndef DEBUG_DWO_LINE_SECTION
3455 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3457 #ifndef DEBUG_LOC_SECTION
3458 #define DEBUG_LOC_SECTION ".debug_loc"
3460 #ifndef DEBUG_DWO_LOC_SECTION
3461 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3463 #ifndef DEBUG_PUBNAMES_SECTION
3464 #define DEBUG_PUBNAMES_SECTION \
3465 ((debug_generate_pub_sections == 2) \
3466 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3468 #ifndef DEBUG_PUBTYPES_SECTION
3469 #define DEBUG_PUBTYPES_SECTION \
3470 ((debug_generate_pub_sections == 2) \
3471 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3473 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3474 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3475 #ifndef DEBUG_STR_OFFSETS_SECTION
3476 #define DEBUG_STR_OFFSETS_SECTION \
3477 (!dwarf_split_debug_info \
3478 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3480 #ifndef DEBUG_STR_DWO_SECTION
3481 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3483 #ifndef DEBUG_STR_SECTION
3484 #define DEBUG_STR_SECTION ".debug_str"
3486 #ifndef DEBUG_RANGES_SECTION
3487 #define DEBUG_RANGES_SECTION ".debug_ranges"
3490 /* Standard ELF section names for compiled code and data. */
3491 #ifndef TEXT_SECTION_NAME
3492 #define TEXT_SECTION_NAME ".text"
3495 /* Section flags for .debug_macinfo/.debug_macro section. */
3496 #define DEBUG_MACRO_SECTION_FLAGS \
3497 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3499 /* Section flags for .debug_str section. */
3500 #define DEBUG_STR_SECTION_FLAGS \
3501 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3502 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3505 /* Section flags for .debug_str.dwo section. */
3506 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3508 /* Labels we insert at beginning sections we can reference instead of
3509 the section names themselves. */
3511 #ifndef TEXT_SECTION_LABEL
3512 #define TEXT_SECTION_LABEL "Ltext"
3514 #ifndef COLD_TEXT_SECTION_LABEL
3515 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3517 #ifndef DEBUG_LINE_SECTION_LABEL
3518 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3520 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3521 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3523 #ifndef DEBUG_INFO_SECTION_LABEL
3524 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3526 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3527 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3529 #ifndef DEBUG_ABBREV_SECTION_LABEL
3530 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3532 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3533 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3535 #ifndef DEBUG_ADDR_SECTION_LABEL
3536 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3538 #ifndef DEBUG_LOC_SECTION_LABEL
3539 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3541 #ifndef DEBUG_RANGES_SECTION_LABEL
3542 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3544 #ifndef DEBUG_MACINFO_SECTION_LABEL
3545 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3547 #ifndef DEBUG_MACRO_SECTION_LABEL
3548 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3550 #define SKELETON_COMP_DIE_ABBREV 1
3551 #define SKELETON_TYPE_DIE_ABBREV 2
3553 /* Definitions of defaults for formats and names of various special
3554 (artificial) labels which may be generated within this file (when the -g
3555 options is used and DWARF2_DEBUGGING_INFO is in effect.
3556 If necessary, these may be overridden from within the tm.h file, but
3557 typically, overriding these defaults is unnecessary. */
3559 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3560 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3561 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3562 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3563 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3564 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3565 static char debug_skeleton_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3566 static char debug_skeleton_abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3567 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3568 static char debug_addr_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3569 static char debug_skeleton_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3570 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3571 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3572 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3574 #ifndef TEXT_END_LABEL
3575 #define TEXT_END_LABEL "Letext"
3577 #ifndef COLD_END_LABEL
3578 #define COLD_END_LABEL "Letext_cold"
3580 #ifndef BLOCK_BEGIN_LABEL
3581 #define BLOCK_BEGIN_LABEL "LBB"
3583 #ifndef BLOCK_END_LABEL
3584 #define BLOCK_END_LABEL "LBE"
3586 #ifndef LINE_CODE_LABEL
3587 #define LINE_CODE_LABEL "LM"
3591 /* Return the root of the DIE's built for the current compilation unit. */
3593 comp_unit_die (void)
3595 if (!single_comp_unit_die)
3596 single_comp_unit_die = gen_compile_unit_die (NULL);
3597 return single_comp_unit_die;
3600 /* We allow a language front-end to designate a function that is to be
3601 called to "demangle" any name before it is put into a DIE. */
3603 static const char *(*demangle_name_func) (const char *);
3606 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3608 demangle_name_func = func;
3611 /* Test if rtl node points to a pseudo register. */
3614 is_pseudo_reg (const_rtx rtl)
3616 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3617 || (GET_CODE (rtl) == SUBREG
3618 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3621 /* Return a reference to a type, with its const and volatile qualifiers
3625 type_main_variant (tree type)
3627 type = TYPE_MAIN_VARIANT (type);
3629 /* ??? There really should be only one main variant among any group of
3630 variants of a given type (and all of the MAIN_VARIANT values for all
3631 members of the group should point to that one type) but sometimes the C
3632 front-end messes this up for array types, so we work around that bug
3634 if (TREE_CODE (type) == ARRAY_TYPE)
3635 while (type != TYPE_MAIN_VARIANT (type))
3636 type = TYPE_MAIN_VARIANT (type);
3641 /* Return nonzero if the given type node represents a tagged type. */
3644 is_tagged_type (const_tree type)
3646 enum tree_code code = TREE_CODE (type);
3648 return (code == RECORD_TYPE || code == UNION_TYPE
3649 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3652 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3655 get_ref_die_offset_label (char *label, dw_die_ref ref)
3657 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
3660 /* Return die_offset of a DIE reference to a base type. */
3662 static unsigned long int
3663 get_base_type_offset (dw_die_ref ref)
3665 if (ref->die_offset)
3666 return ref->die_offset;
3667 if (comp_unit_die ()->die_abbrev)
3669 calc_base_type_die_sizes ();
3670 gcc_assert (ref->die_offset);
3672 return ref->die_offset;
3675 /* Return die_offset of a DIE reference other than base type. */
3677 static unsigned long int
3678 get_ref_die_offset (dw_die_ref ref)
3680 gcc_assert (ref->die_offset);
3681 return ref->die_offset;
3684 /* Convert a DIE tag into its string name. */
3687 dwarf_tag_name (unsigned int tag)
3689 const char *name = get_DW_TAG_name (tag);
3694 return "DW_TAG_<unknown>";
3697 /* Convert a DWARF attribute code into its string name. */
3700 dwarf_attr_name (unsigned int attr)
3706 #if VMS_DEBUGGING_INFO
3707 case DW_AT_HP_prologue:
3708 return "DW_AT_HP_prologue";
3710 case DW_AT_MIPS_loop_unroll_factor:
3711 return "DW_AT_MIPS_loop_unroll_factor";
3714 #if VMS_DEBUGGING_INFO
3715 case DW_AT_HP_epilogue:
3716 return "DW_AT_HP_epilogue";
3718 case DW_AT_MIPS_stride:
3719 return "DW_AT_MIPS_stride";
3723 name = get_DW_AT_name (attr);
3728 return "DW_AT_<unknown>";
3731 /* Convert a DWARF value form code into its string name. */
3734 dwarf_form_name (unsigned int form)
3736 const char *name = get_DW_FORM_name (form);
3741 return "DW_FORM_<unknown>";
3744 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3745 instance of an inlined instance of a decl which is local to an inline
3746 function, so we have to trace all of the way back through the origin chain
3747 to find out what sort of node actually served as the original seed for the
3751 decl_ultimate_origin (const_tree decl)
3753 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
3756 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3757 we're trying to output the abstract instance of this function. */
3758 if (DECL_ABSTRACT_P (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3761 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3762 most distant ancestor, this should never happen. */
3763 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
3765 return DECL_ABSTRACT_ORIGIN (decl);
3768 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3769 of a virtual function may refer to a base class, so we check the 'this'
3773 decl_class_context (tree decl)
3775 tree context = NULL_TREE;
3777 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3778 context = DECL_CONTEXT (decl);
3780 context = TYPE_MAIN_VARIANT
3781 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3783 if (context && !TYPE_P (context))
3784 context = NULL_TREE;
3789 /* Add an attribute/value pair to a DIE. */
3792 add_dwarf_attr (dw_die_ref die, dw_attr_node *attr)
3794 /* Maybe this should be an assert? */
3798 vec_safe_reserve (die->die_attr, 1);
3799 vec_safe_push (die->die_attr, *attr);
3802 static inline enum dw_val_class
3803 AT_class (dw_attr_node *a)
3805 return a->dw_attr_val.val_class;
3808 /* Return the index for any attribute that will be referenced with a
3809 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3810 are stored in dw_attr_val.v.val_str for reference counting
3813 static inline unsigned int
3814 AT_index (dw_attr_node *a)
3816 if (AT_class (a) == dw_val_class_str)
3817 return a->dw_attr_val.v.val_str->index;
3818 else if (a->dw_attr_val.val_entry != NULL)
3819 return a->dw_attr_val.val_entry->index;
3823 /* Add a flag value attribute to a DIE. */
3826 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
3830 attr.dw_attr = attr_kind;
3831 attr.dw_attr_val.val_class = dw_val_class_flag;
3832 attr.dw_attr_val.val_entry = NULL;
3833 attr.dw_attr_val.v.val_flag = flag;
3834 add_dwarf_attr (die, &attr);
3837 static inline unsigned
3838 AT_flag (dw_attr_node *a)
3840 gcc_assert (a && AT_class (a) == dw_val_class_flag);
3841 return a->dw_attr_val.v.val_flag;
3844 /* Add a signed integer attribute value to a DIE. */
3847 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
3851 attr.dw_attr = attr_kind;
3852 attr.dw_attr_val.val_class = dw_val_class_const;
3853 attr.dw_attr_val.val_entry = NULL;
3854 attr.dw_attr_val.v.val_int = int_val;
3855 add_dwarf_attr (die, &attr);
3858 static inline HOST_WIDE_INT
3859 AT_int (dw_attr_node *a)
3861 gcc_assert (a && AT_class (a) == dw_val_class_const);
3862 return a->dw_attr_val.v.val_int;
3865 /* Add an unsigned integer attribute value to a DIE. */
3868 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
3869 unsigned HOST_WIDE_INT unsigned_val)
3873 attr.dw_attr = attr_kind;
3874 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
3875 attr.dw_attr_val.val_entry = NULL;
3876 attr.dw_attr_val.v.val_unsigned = unsigned_val;
3877 add_dwarf_attr (die, &attr);
3880 static inline unsigned HOST_WIDE_INT
3881 AT_unsigned (dw_attr_node *a)
3883 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
3884 return a->dw_attr_val.v.val_unsigned;
3887 /* Add an unsigned wide integer attribute value to a DIE. */
3890 add_AT_wide (dw_die_ref die, enum dwarf_attribute attr_kind,
3895 attr.dw_attr = attr_kind;
3896 attr.dw_attr_val.val_class = dw_val_class_wide_int;
3897 attr.dw_attr_val.val_entry = NULL;
3898 attr.dw_attr_val.v.val_wide = ggc_alloc<wide_int> ();
3899 *attr.dw_attr_val.v.val_wide = w;
3900 add_dwarf_attr (die, &attr);
3903 /* Add an unsigned double integer attribute value to a DIE. */
3906 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
3907 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
3911 attr.dw_attr = attr_kind;
3912 attr.dw_attr_val.val_class = dw_val_class_const_double;
3913 attr.dw_attr_val.val_entry = NULL;
3914 attr.dw_attr_val.v.val_double.high = high;
3915 attr.dw_attr_val.v.val_double.low = low;
3916 add_dwarf_attr (die, &attr);
3919 /* Add a floating point attribute value to a DIE and return it. */
3922 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
3923 unsigned int length, unsigned int elt_size, unsigned char *array)
3927 attr.dw_attr = attr_kind;
3928 attr.dw_attr_val.val_class = dw_val_class_vec;
3929 attr.dw_attr_val.val_entry = NULL;
3930 attr.dw_attr_val.v.val_vec.length = length;
3931 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
3932 attr.dw_attr_val.v.val_vec.array = array;
3933 add_dwarf_attr (die, &attr);
3936 /* Add an 8-byte data attribute value to a DIE. */
3939 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
3940 unsigned char data8[8])
3944 attr.dw_attr = attr_kind;
3945 attr.dw_attr_val.val_class = dw_val_class_data8;
3946 attr.dw_attr_val.val_entry = NULL;
3947 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
3948 add_dwarf_attr (die, &attr);
3951 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3952 dwarf_split_debug_info, address attributes in dies destined for the
3953 final executable have force_direct set to avoid using indexed
3957 add_AT_low_high_pc (dw_die_ref die, const char *lbl_low, const char *lbl_high,
3963 lbl_id = xstrdup (lbl_low);
3964 attr.dw_attr = DW_AT_low_pc;
3965 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
3966 attr.dw_attr_val.v.val_lbl_id = lbl_id;
3967 if (dwarf_split_debug_info && !force_direct)
3968 attr.dw_attr_val.val_entry
3969 = add_addr_table_entry (lbl_id, ate_kind_label);
3971 attr.dw_attr_val.val_entry = NULL;
3972 add_dwarf_attr (die, &attr);
3974 attr.dw_attr = DW_AT_high_pc;
3975 if (dwarf_version < 4)
3976 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
3978 attr.dw_attr_val.val_class = dw_val_class_high_pc;
3979 lbl_id = xstrdup (lbl_high);
3980 attr.dw_attr_val.v.val_lbl_id = lbl_id;
3981 if (attr.dw_attr_val.val_class == dw_val_class_lbl_id
3982 && dwarf_split_debug_info && !force_direct)
3983 attr.dw_attr_val.val_entry
3984 = add_addr_table_entry (lbl_id, ate_kind_label);
3986 attr.dw_attr_val.val_entry = NULL;
3987 add_dwarf_attr (die, &attr);
3990 /* Hash and equality functions for debug_str_hash. */
3993 indirect_string_hasher::hash (indirect_string_node *x)
3995 return htab_hash_string (x->str);
3999 indirect_string_hasher::equal (indirect_string_node *x1, const char *x2)
4001 return strcmp (x1->str, x2) == 0;
4004 /* Add STR to the given string hash table. */
4006 static struct indirect_string_node *
4007 find_AT_string_in_table (const char *str,
4008 hash_table<indirect_string_hasher> *table)
4010 struct indirect_string_node *node;
4012 indirect_string_node **slot
4013 = table->find_slot_with_hash (str, htab_hash_string (str), INSERT);
4016 node = ggc_cleared_alloc<indirect_string_node> ();
4017 node->str = ggc_strdup (str);
4027 /* Add STR to the indirect string hash table. */
4029 static struct indirect_string_node *
4030 find_AT_string (const char *str)
4032 if (! debug_str_hash)
4033 debug_str_hash = hash_table<indirect_string_hasher>::create_ggc (10);
4035 return find_AT_string_in_table (str, debug_str_hash);
4038 /* Add a string attribute value to a DIE. */
4041 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4044 struct indirect_string_node *node;
4046 node = find_AT_string (str);
4048 attr.dw_attr = attr_kind;
4049 attr.dw_attr_val.val_class = dw_val_class_str;
4050 attr.dw_attr_val.val_entry = NULL;
4051 attr.dw_attr_val.v.val_str = node;
4052 add_dwarf_attr (die, &attr);
4055 static inline const char *
4056 AT_string (dw_attr_node *a)
4058 gcc_assert (a && AT_class (a) == dw_val_class_str);
4059 return a->dw_attr_val.v.val_str->str;
4062 /* Call this function directly to bypass AT_string_form's logic to put
4063 the string inline in the die. */
4066 set_indirect_string (struct indirect_string_node *node)
4069 /* Already indirect is a no op. */
4070 if (node->form == DW_FORM_strp || node->form == DW_FORM_GNU_str_index)
4072 gcc_assert (node->label);
4075 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4076 ++dw2_string_counter;
4077 node->label = xstrdup (label);
4079 if (!dwarf_split_debug_info)
4081 node->form = DW_FORM_strp;
4082 node->index = NOT_INDEXED;
4086 node->form = DW_FORM_GNU_str_index;
4087 node->index = NO_INDEX_ASSIGNED;
4091 /* Find out whether a string should be output inline in DIE
4092 or out-of-line in .debug_str section. */
4094 static enum dwarf_form
4095 find_string_form (struct indirect_string_node *node)
4102 len = strlen (node->str) + 1;
4104 /* If the string is shorter or equal to the size of the reference, it is
4105 always better to put it inline. */
4106 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4107 return node->form = DW_FORM_string;
4109 /* If we cannot expect the linker to merge strings in .debug_str
4110 section, only put it into .debug_str if it is worth even in this
4112 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4113 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
4114 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
4115 return node->form = DW_FORM_string;
4117 set_indirect_string (node);
4122 /* Find out whether the string referenced from the attribute should be
4123 output inline in DIE or out-of-line in .debug_str section. */
4125 static enum dwarf_form
4126 AT_string_form (dw_attr_node *a)
4128 gcc_assert (a && AT_class (a) == dw_val_class_str);
4129 return find_string_form (a->dw_attr_val.v.val_str);
4132 /* Add a DIE reference attribute value to a DIE. */
4135 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4139 #ifdef ENABLE_CHECKING
4140 gcc_assert (targ_die != NULL);
4142 /* With LTO we can end up trying to reference something we didn't create
4143 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4144 if (targ_die == NULL)
4148 attr.dw_attr = attr_kind;
4149 attr.dw_attr_val.val_class = dw_val_class_die_ref;
4150 attr.dw_attr_val.val_entry = NULL;
4151 attr.dw_attr_val.v.val_die_ref.die = targ_die;
4152 attr.dw_attr_val.v.val_die_ref.external = 0;
4153 add_dwarf_attr (die, &attr);
4156 /* Change DIE reference REF to point to NEW_DIE instead. */
4159 change_AT_die_ref (dw_attr_node *ref, dw_die_ref new_die)
4161 gcc_assert (ref->dw_attr_val.val_class == dw_val_class_die_ref);
4162 ref->dw_attr_val.v.val_die_ref.die = new_die;
4163 ref->dw_attr_val.v.val_die_ref.external = 0;
4166 /* Add an AT_specification attribute to a DIE, and also make the back
4167 pointer from the specification to the definition. */
4170 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4172 add_AT_die_ref (die, DW_AT_specification, targ_die);
4173 gcc_assert (!targ_die->die_definition);
4174 targ_die->die_definition = die;
4177 static inline dw_die_ref
4178 AT_ref (dw_attr_node *a)
4180 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4181 return a->dw_attr_val.v.val_die_ref.die;
4185 AT_ref_external (dw_attr_node *a)
4187 if (a && AT_class (a) == dw_val_class_die_ref)
4188 return a->dw_attr_val.v.val_die_ref.external;
4194 set_AT_ref_external (dw_attr_node *a, int i)
4196 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4197 a->dw_attr_val.v.val_die_ref.external = i;
4200 /* Add an FDE reference attribute value to a DIE. */
4203 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4207 attr.dw_attr = attr_kind;
4208 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
4209 attr.dw_attr_val.val_entry = NULL;
4210 attr.dw_attr_val.v.val_fde_index = targ_fde;
4211 add_dwarf_attr (die, &attr);
4214 /* Add a location description attribute value to a DIE. */
4217 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4221 attr.dw_attr = attr_kind;
4222 attr.dw_attr_val.val_class = dw_val_class_loc;
4223 attr.dw_attr_val.val_entry = NULL;
4224 attr.dw_attr_val.v.val_loc = loc;
4225 add_dwarf_attr (die, &attr);
4228 static inline dw_loc_descr_ref
4229 AT_loc (dw_attr_node *a)
4231 gcc_assert (a && AT_class (a) == dw_val_class_loc);
4232 return a->dw_attr_val.v.val_loc;
4236 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4240 attr.dw_attr = attr_kind;
4241 attr.dw_attr_val.val_class = dw_val_class_loc_list;
4242 attr.dw_attr_val.val_entry = NULL;
4243 attr.dw_attr_val.v.val_loc_list = loc_list;
4244 add_dwarf_attr (die, &attr);
4245 have_location_lists = true;
4248 static inline dw_loc_list_ref
4249 AT_loc_list (dw_attr_node *a)
4251 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4252 return a->dw_attr_val.v.val_loc_list;
4255 static inline dw_loc_list_ref *
4256 AT_loc_list_ptr (dw_attr_node *a)
4258 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4259 return &a->dw_attr_val.v.val_loc_list;
4262 struct addr_hasher : ggc_ptr_hash<addr_table_entry>
4264 static hashval_t hash (addr_table_entry *);
4265 static bool equal (addr_table_entry *, addr_table_entry *);
4268 /* Table of entries into the .debug_addr section. */
4270 static GTY (()) hash_table<addr_hasher> *addr_index_table;
4272 /* Hash an address_table_entry. */
4275 addr_hasher::hash (addr_table_entry *a)
4277 inchash::hash hstate;
4283 case ate_kind_rtx_dtprel:
4286 case ate_kind_label:
4287 return htab_hash_string (a->addr.label);
4291 inchash::add_rtx (a->addr.rtl, hstate);
4292 return hstate.end ();
4295 /* Determine equality for two address_table_entries. */
4298 addr_hasher::equal (addr_table_entry *a1, addr_table_entry *a2)
4300 if (a1->kind != a2->kind)
4305 case ate_kind_rtx_dtprel:
4306 return rtx_equal_p (a1->addr.rtl, a2->addr.rtl);
4307 case ate_kind_label:
4308 return strcmp (a1->addr.label, a2->addr.label) == 0;
4314 /* Initialize an addr_table_entry. */
4317 init_addr_table_entry (addr_table_entry *e, enum ate_kind kind, void *addr)
4323 case ate_kind_rtx_dtprel:
4324 e->addr.rtl = (rtx) addr;
4326 case ate_kind_label:
4327 e->addr.label = (char *) addr;
4331 e->index = NO_INDEX_ASSIGNED;
4334 /* Add attr to the address table entry to the table. Defer setting an
4335 index until output time. */
4337 static addr_table_entry *
4338 add_addr_table_entry (void *addr, enum ate_kind kind)
4340 addr_table_entry *node;
4341 addr_table_entry finder;
4343 gcc_assert (dwarf_split_debug_info);
4344 if (! addr_index_table)
4345 addr_index_table = hash_table<addr_hasher>::create_ggc (10);
4346 init_addr_table_entry (&finder, kind, addr);
4347 addr_table_entry **slot = addr_index_table->find_slot (&finder, INSERT);
4349 if (*slot == HTAB_EMPTY_ENTRY)
4351 node = ggc_cleared_alloc<addr_table_entry> ();
4352 init_addr_table_entry (node, kind, addr);
4362 /* Remove an entry from the addr table by decrementing its refcount.
4363 Strictly, decrementing the refcount would be enough, but the
4364 assertion that the entry is actually in the table has found
4368 remove_addr_table_entry (addr_table_entry *entry)
4370 gcc_assert (dwarf_split_debug_info && addr_index_table);
4371 /* After an index is assigned, the table is frozen. */
4372 gcc_assert (entry->refcount > 0 && entry->index == NO_INDEX_ASSIGNED);
4376 /* Given a location list, remove all addresses it refers to from the
4380 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr)
4382 for (; descr; descr = descr->dw_loc_next)
4383 if (descr->dw_loc_oprnd1.val_entry != NULL)
4385 gcc_assert (descr->dw_loc_oprnd1.val_entry->index == NO_INDEX_ASSIGNED);
4386 remove_addr_table_entry (descr->dw_loc_oprnd1.val_entry);
4390 /* A helper function for dwarf2out_finish called through
4391 htab_traverse. Assign an addr_table_entry its index. All entries
4392 must be collected into the table when this function is called,
4393 because the indexing code relies on htab_traverse to traverse nodes
4394 in the same order for each run. */
4397 index_addr_table_entry (addr_table_entry **h, unsigned int *index)
4399 addr_table_entry *node = *h;
4401 /* Don't index unreferenced nodes. */
4402 if (node->refcount == 0)
4405 gcc_assert (node->index == NO_INDEX_ASSIGNED);
4406 node->index = *index;
4412 /* Add an address constant attribute value to a DIE. When using
4413 dwarf_split_debug_info, address attributes in dies destined for the
4414 final executable should be direct references--setting the parameter
4415 force_direct ensures this behavior. */
4418 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr,
4423 attr.dw_attr = attr_kind;
4424 attr.dw_attr_val.val_class = dw_val_class_addr;
4425 attr.dw_attr_val.v.val_addr = addr;
4426 if (dwarf_split_debug_info && !force_direct)
4427 attr.dw_attr_val.val_entry = add_addr_table_entry (addr, ate_kind_rtx);
4429 attr.dw_attr_val.val_entry = NULL;
4430 add_dwarf_attr (die, &attr);
4433 /* Get the RTX from to an address DIE attribute. */
4436 AT_addr (dw_attr_node *a)
4438 gcc_assert (a && AT_class (a) == dw_val_class_addr);
4439 return a->dw_attr_val.v.val_addr;
4442 /* Add a file attribute value to a DIE. */
4445 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
4446 struct dwarf_file_data *fd)
4450 attr.dw_attr = attr_kind;
4451 attr.dw_attr_val.val_class = dw_val_class_file;
4452 attr.dw_attr_val.val_entry = NULL;
4453 attr.dw_attr_val.v.val_file = fd;
4454 add_dwarf_attr (die, &attr);
4457 /* Get the dwarf_file_data from a file DIE attribute. */
4459 static inline struct dwarf_file_data *
4460 AT_file (dw_attr_node *a)
4462 gcc_assert (a && AT_class (a) == dw_val_class_file);
4463 return a->dw_attr_val.v.val_file;
4466 /* Add a vms delta attribute value to a DIE. */
4469 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
4470 const char *lbl1, const char *lbl2)
4474 attr.dw_attr = attr_kind;
4475 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
4476 attr.dw_attr_val.val_entry = NULL;
4477 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
4478 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
4479 add_dwarf_attr (die, &attr);
4482 /* Add a label identifier attribute value to a DIE. */
4485 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind,
4490 attr.dw_attr = attr_kind;
4491 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4492 attr.dw_attr_val.val_entry = NULL;
4493 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4494 if (dwarf_split_debug_info)
4495 attr.dw_attr_val.val_entry
4496 = add_addr_table_entry (attr.dw_attr_val.v.val_lbl_id,
4498 add_dwarf_attr (die, &attr);
4501 /* Add a section offset attribute value to a DIE, an offset into the
4502 debug_line section. */
4505 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4510 attr.dw_attr = attr_kind;
4511 attr.dw_attr_val.val_class = dw_val_class_lineptr;
4512 attr.dw_attr_val.val_entry = NULL;
4513 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4514 add_dwarf_attr (die, &attr);
4517 /* Add a section offset attribute value to a DIE, an offset into the
4518 debug_macinfo section. */
4521 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4526 attr.dw_attr = attr_kind;
4527 attr.dw_attr_val.val_class = dw_val_class_macptr;
4528 attr.dw_attr_val.val_entry = NULL;
4529 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4530 add_dwarf_attr (die, &attr);
4533 /* Add an offset attribute value to a DIE. */
4536 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
4537 unsigned HOST_WIDE_INT offset)
4541 attr.dw_attr = attr_kind;
4542 attr.dw_attr_val.val_class = dw_val_class_offset;
4543 attr.dw_attr_val.val_entry = NULL;
4544 attr.dw_attr_val.v.val_offset = offset;
4545 add_dwarf_attr (die, &attr);
4548 /* Add a range_list attribute value to a DIE. When using
4549 dwarf_split_debug_info, address attributes in dies destined for the
4550 final executable should be direct references--setting the parameter
4551 force_direct ensures this behavior. */
4553 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4554 #define RELOCATED_OFFSET (NULL)
4557 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4558 long unsigned int offset, bool force_direct)
4562 attr.dw_attr = attr_kind;
4563 attr.dw_attr_val.val_class = dw_val_class_range_list;
4564 /* For the range_list attribute, use val_entry to store whether the
4565 offset should follow split-debug-info or normal semantics. This
4566 value is read in output_range_list_offset. */
4567 if (dwarf_split_debug_info && !force_direct)
4568 attr.dw_attr_val.val_entry = UNRELOCATED_OFFSET;
4570 attr.dw_attr_val.val_entry = RELOCATED_OFFSET;
4571 attr.dw_attr_val.v.val_offset = offset;
4572 add_dwarf_attr (die, &attr);
4575 /* Return the start label of a delta attribute. */
4577 static inline const char *
4578 AT_vms_delta1 (dw_attr_node *a)
4580 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4581 return a->dw_attr_val.v.val_vms_delta.lbl1;
4584 /* Return the end label of a delta attribute. */
4586 static inline const char *
4587 AT_vms_delta2 (dw_attr_node *a)
4589 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4590 return a->dw_attr_val.v.val_vms_delta.lbl2;
4593 static inline const char *
4594 AT_lbl (dw_attr_node *a)
4596 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
4597 || AT_class (a) == dw_val_class_lineptr
4598 || AT_class (a) == dw_val_class_macptr
4599 || AT_class (a) == dw_val_class_high_pc));
4600 return a->dw_attr_val.v.val_lbl_id;
4603 /* Get the attribute of type attr_kind. */
4605 static dw_attr_node *
4606 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4610 dw_die_ref spec = NULL;
4615 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
4616 if (a->dw_attr == attr_kind)
4618 else if (a->dw_attr == DW_AT_specification
4619 || a->dw_attr == DW_AT_abstract_origin)
4623 return get_AT (spec, attr_kind);
4628 /* Returns the parent of the declaration of DIE. */
4631 get_die_parent (dw_die_ref die)
4638 if ((t = get_AT_ref (die, DW_AT_abstract_origin))
4639 || (t = get_AT_ref (die, DW_AT_specification)))
4642 return die->die_parent;
4645 /* Return the "low pc" attribute value, typically associated with a subprogram
4646 DIE. Return null if the "low pc" attribute is either not present, or if it
4647 cannot be represented as an assembler label identifier. */
4649 static inline const char *
4650 get_AT_low_pc (dw_die_ref die)
4652 dw_attr_node *a = get_AT (die, DW_AT_low_pc);
4654 return a ? AT_lbl (a) : NULL;
4657 /* Return the "high pc" attribute value, typically associated with a subprogram
4658 DIE. Return null if the "high pc" attribute is either not present, or if it
4659 cannot be represented as an assembler label identifier. */
4661 static inline const char *
4662 get_AT_hi_pc (dw_die_ref die)
4664 dw_attr_node *a = get_AT (die, DW_AT_high_pc);
4666 return a ? AT_lbl (a) : NULL;
4669 /* Return the value of the string attribute designated by ATTR_KIND, or
4670 NULL if it is not present. */
4672 static inline const char *
4673 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4675 dw_attr_node *a = get_AT (die, attr_kind);
4677 return a ? AT_string (a) : NULL;
4680 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4681 if it is not present. */
4684 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4686 dw_attr_node *a = get_AT (die, attr_kind);
4688 return a ? AT_flag (a) : 0;
4691 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4692 if it is not present. */
4694 static inline unsigned
4695 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4697 dw_attr_node *a = get_AT (die, attr_kind);
4699 return a ? AT_unsigned (a) : 0;
4702 static inline dw_die_ref
4703 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4705 dw_attr_node *a = get_AT (die, attr_kind);
4707 return a ? AT_ref (a) : NULL;
4710 static inline struct dwarf_file_data *
4711 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
4713 dw_attr_node *a = get_AT (die, attr_kind);
4715 return a ? AT_file (a) : NULL;
4718 /* Return TRUE if the language is C++. */
4723 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4725 return (lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus
4726 || lang == DW_LANG_C_plus_plus_11 || lang == DW_LANG_C_plus_plus_14);
4729 /* Return TRUE if the language is Java. */
4734 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4736 return lang == DW_LANG_Java;
4739 /* Return TRUE if the language is Fortran. */
4744 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4746 return (lang == DW_LANG_Fortran77
4747 || lang == DW_LANG_Fortran90
4748 || lang == DW_LANG_Fortran95
4749 || lang == DW_LANG_Fortran03
4750 || lang == DW_LANG_Fortran08);
4753 /* Return TRUE if the language is Ada. */
4758 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4760 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4763 /* Remove the specified attribute if present. Return TRUE if removal
4767 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4775 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
4776 if (a->dw_attr == attr_kind)
4778 if (AT_class (a) == dw_val_class_str)
4779 if (a->dw_attr_val.v.val_str->refcount)
4780 a->dw_attr_val.v.val_str->refcount--;
4782 /* vec::ordered_remove should help reduce the number of abbrevs
4784 die->die_attr->ordered_remove (ix);
4790 /* Remove CHILD from its parent. PREV must have the property that
4791 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4794 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
4796 gcc_assert (child->die_parent == prev->die_parent);
4797 gcc_assert (prev->die_sib == child);
4800 gcc_assert (child->die_parent->die_child == child);
4804 prev->die_sib = child->die_sib;
4805 if (child->die_parent->die_child == child)
4806 child->die_parent->die_child = prev;
4809 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4810 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4813 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
4815 dw_die_ref parent = old_child->die_parent;
4817 gcc_assert (parent == prev->die_parent);
4818 gcc_assert (prev->die_sib == old_child);
4820 new_child->die_parent = parent;
4821 if (prev == old_child)
4823 gcc_assert (parent->die_child == old_child);
4824 new_child->die_sib = new_child;
4828 prev->die_sib = new_child;
4829 new_child->die_sib = old_child->die_sib;
4831 if (old_child->die_parent->die_child == old_child)
4832 old_child->die_parent->die_child = new_child;
4835 /* Move all children from OLD_PARENT to NEW_PARENT. */
4838 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
4841 new_parent->die_child = old_parent->die_child;
4842 old_parent->die_child = NULL;
4843 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
4846 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4850 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
4856 dw_die_ref prev = c;
4858 while (c->die_tag == tag)
4860 remove_child_with_prev (c, prev);
4861 c->die_parent = NULL;
4862 /* Might have removed every child. */
4863 if (c == c->die_sib)
4867 } while (c != die->die_child);
4870 /* Add a CHILD_DIE as the last child of DIE. */
4873 add_child_die (dw_die_ref die, dw_die_ref child_die)
4875 /* FIXME this should probably be an assert. */
4876 if (! die || ! child_die)
4878 gcc_assert (die != child_die);
4880 child_die->die_parent = die;
4883 child_die->die_sib = die->die_child->die_sib;
4884 die->die_child->die_sib = child_die;
4887 child_die->die_sib = child_die;
4888 die->die_child = child_die;
4891 /* Unassociate CHILD from its parent, and make its parent be
4895 reparent_child (dw_die_ref child, dw_die_ref new_parent)
4897 for (dw_die_ref p = child->die_parent->die_child; ; p = p->die_sib)
4898 if (p->die_sib == child)
4900 remove_child_with_prev (child, p);
4903 add_child_die (new_parent, child);
4906 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4907 is the specification, to the end of PARENT's list of children.
4908 This is done by removing and re-adding it. */
4911 splice_child_die (dw_die_ref parent, dw_die_ref child)
4913 /* We want the declaration DIE from inside the class, not the
4914 specification DIE at toplevel. */
4915 if (child->die_parent != parent)
4917 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4923 gcc_assert (child->die_parent == parent
4924 || (child->die_parent
4925 == get_AT_ref (parent, DW_AT_specification)));
4927 reparent_child (child, parent);
4930 /* Create and return a new die with a parent of PARENT_DIE. If
4931 PARENT_DIE is NULL, the new DIE is placed in limbo and an
4932 associated tree T must be supplied to determine parenthood
4935 static inline dw_die_ref
4936 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
4938 dw_die_ref die = ggc_cleared_alloc<die_node> ();
4940 die->die_tag = tag_value;
4942 if (parent_die != NULL)
4943 add_child_die (parent_die, die);
4946 limbo_die_node *limbo_node;
4948 /* No DIEs created after early dwarf should end up in limbo,
4949 because the limbo list should not persist past LTO
4951 if (tag_value != DW_TAG_compile_unit
4952 /* These are allowed because they're generated while
4953 breaking out COMDAT units late. */
4954 && tag_value != DW_TAG_type_unit
4956 /* Allow nested functions to live in limbo because they will
4957 only temporarily live there, as decls_for_scope will fix
4959 && (TREE_CODE (t) != FUNCTION_DECL
4960 || !decl_function_context (t))
4961 /* Same as nested functions above but for types. Types that
4962 are local to a function will be fixed in
4964 && (!RECORD_OR_UNION_TYPE_P (t)
4965 || !TYPE_CONTEXT (t)
4966 || TREE_CODE (TYPE_CONTEXT (t)) != FUNCTION_DECL)
4967 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
4968 especially in the ltrans stage, but once we implement LTO
4969 dwarf streaming, we should remove this exception. */
4972 fprintf (stderr, "symbol ended up in limbo too late:");
4973 debug_generic_stmt (t);
4977 limbo_node = ggc_cleared_alloc<limbo_die_node> ();
4978 limbo_node->die = die;
4979 limbo_node->created_for = t;
4980 limbo_node->next = limbo_die_list;
4981 limbo_die_list = limbo_node;
4987 /* Return the DIE associated with the given type specifier. */
4989 static inline dw_die_ref
4990 lookup_type_die (tree type)
4992 return TYPE_SYMTAB_DIE (type);
4995 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4996 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4997 anonymous type instead the one of the naming typedef. */
4999 static inline dw_die_ref
5000 strip_naming_typedef (tree type, dw_die_ref type_die)
5003 && TREE_CODE (type) == RECORD_TYPE
5005 && type_die->die_tag == DW_TAG_typedef
5006 && is_naming_typedef_decl (TYPE_NAME (type)))
5007 type_die = get_AT_ref (type_die, DW_AT_type);
5011 /* Like lookup_type_die, but if type is an anonymous type named by a
5012 typedef[1], return the DIE of the anonymous type instead the one of
5013 the naming typedef. This is because in gen_typedef_die, we did
5014 equate the anonymous struct named by the typedef with the DIE of
5015 the naming typedef. So by default, lookup_type_die on an anonymous
5016 struct yields the DIE of the naming typedef.
5018 [1]: Read the comment of is_naming_typedef_decl to learn about what
5019 a naming typedef is. */
5021 static inline dw_die_ref
5022 lookup_type_die_strip_naming_typedef (tree type)
5024 dw_die_ref die = lookup_type_die (type);
5025 return strip_naming_typedef (type, die);
5028 /* Equate a DIE to a given type specifier. */
5031 equate_type_number_to_die (tree type, dw_die_ref type_die)
5033 TYPE_SYMTAB_DIE (type) = type_die;
5036 /* Returns a hash value for X (which really is a die_struct). */
5039 decl_die_hasher::hash (die_node *x)
5041 return (hashval_t) x->decl_id;
5044 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5047 decl_die_hasher::equal (die_node *x, tree y)
5049 return (x->decl_id == DECL_UID (y));
5052 /* Return the DIE associated with a given declaration. */
5054 static inline dw_die_ref
5055 lookup_decl_die (tree decl)
5057 return decl_die_table->find_with_hash (decl, DECL_UID (decl));
5060 /* Returns a hash value for X (which really is a var_loc_list). */
5063 decl_loc_hasher::hash (var_loc_list *x)
5065 return (hashval_t) x->decl_id;
5068 /* Return nonzero if decl_id of var_loc_list X is the same as
5072 decl_loc_hasher::equal (var_loc_list *x, const_tree y)
5074 return (x->decl_id == DECL_UID (y));
5077 /* Return the var_loc list associated with a given declaration. */
5079 static inline var_loc_list *
5080 lookup_decl_loc (const_tree decl)
5082 if (!decl_loc_table)
5084 return decl_loc_table->find_with_hash (decl, DECL_UID (decl));
5087 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5090 dw_loc_list_hasher::hash (cached_dw_loc_list *x)
5092 return (hashval_t) x->decl_id;
5095 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5099 dw_loc_list_hasher::equal (cached_dw_loc_list *x, const_tree y)
5101 return (x->decl_id == DECL_UID (y));
5104 /* Equate a DIE to a particular declaration. */
5107 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5109 unsigned int decl_id = DECL_UID (decl);
5111 *decl_die_table->find_slot_with_hash (decl, decl_id, INSERT) = decl_die;
5112 decl_die->decl_id = decl_id;
5115 /* Return how many bits covers PIECE EXPR_LIST. */
5117 static HOST_WIDE_INT
5118 decl_piece_bitsize (rtx piece)
5120 int ret = (int) GET_MODE (piece);
5123 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
5124 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
5125 return INTVAL (XEXP (XEXP (piece, 0), 0));
5128 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5131 decl_piece_varloc_ptr (rtx piece)
5133 if ((int) GET_MODE (piece))
5134 return &XEXP (piece, 0);
5136 return &XEXP (XEXP (piece, 0), 1);
5139 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5140 Next is the chain of following piece nodes. */
5142 static rtx_expr_list *
5143 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
5145 if (bitsize > 0 && bitsize <= (int) MAX_MACHINE_MODE)
5146 return alloc_EXPR_LIST (bitsize, loc_note, next);
5148 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
5153 /* Return rtx that should be stored into loc field for
5154 LOC_NOTE and BITPOS/BITSIZE. */
5157 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
5158 HOST_WIDE_INT bitsize)
5162 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
5164 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
5169 /* This function either modifies location piece list *DEST in
5170 place (if SRC and INNER is NULL), or copies location piece list
5171 *SRC to *DEST while modifying it. Location BITPOS is modified
5172 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5173 not copied and if needed some padding around it is added.
5174 When modifying in place, DEST should point to EXPR_LIST where
5175 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5176 to the start of the whole list and INNER points to the EXPR_LIST
5177 where earlier pieces cover PIECE_BITPOS bits. */
5180 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
5181 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
5182 HOST_WIDE_INT bitsize, rtx loc_note)
5185 bool copy = inner != NULL;
5189 /* First copy all nodes preceding the current bitpos. */
5190 while (src != inner)
5192 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5193 decl_piece_bitsize (*src), NULL_RTX);
5194 dest = &XEXP (*dest, 1);
5195 src = &XEXP (*src, 1);
5198 /* Add padding if needed. */
5199 if (bitpos != piece_bitpos)
5201 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
5202 copy ? NULL_RTX : *dest);
5203 dest = &XEXP (*dest, 1);
5205 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
5208 /* A piece with correct bitpos and bitsize already exist,
5209 just update the location for it and return. */
5210 *decl_piece_varloc_ptr (*dest) = loc_note;
5213 /* Add the piece that changed. */
5214 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
5215 dest = &XEXP (*dest, 1);
5216 /* Skip over pieces that overlap it. */
5217 diff = bitpos - piece_bitpos + bitsize;
5220 while (diff > 0 && *src)
5223 diff -= decl_piece_bitsize (piece);
5225 src = &XEXP (piece, 1);
5228 *src = XEXP (piece, 1);
5229 free_EXPR_LIST_node (piece);
5232 /* Add padding if needed. */
5233 if (diff < 0 && *src)
5237 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
5238 dest = &XEXP (*dest, 1);
5242 /* Finally copy all nodes following it. */
5245 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5246 decl_piece_bitsize (*src), NULL_RTX);
5247 dest = &XEXP (*dest, 1);
5248 src = &XEXP (*src, 1);
5252 /* Add a variable location node to the linked list for DECL. */
5254 static struct var_loc_node *
5255 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
5257 unsigned int decl_id;
5259 struct var_loc_node *loc = NULL;
5260 HOST_WIDE_INT bitsize = -1, bitpos = -1;
5262 if (TREE_CODE (decl) == VAR_DECL
5263 && DECL_HAS_DEBUG_EXPR_P (decl))
5265 tree realdecl = DECL_DEBUG_EXPR (decl);
5266 if (handled_component_p (realdecl)
5267 || (TREE_CODE (realdecl) == MEM_REF
5268 && TREE_CODE (TREE_OPERAND (realdecl, 0)) == ADDR_EXPR))
5270 HOST_WIDE_INT maxsize;
5273 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
5274 if (!DECL_P (innerdecl)
5275 || DECL_IGNORED_P (innerdecl)
5276 || TREE_STATIC (innerdecl)
5278 || bitpos + bitsize > 256
5279 || bitsize != maxsize)
5285 decl_id = DECL_UID (decl);
5287 = decl_loc_table->find_slot_with_hash (decl, decl_id, INSERT);
5290 temp = ggc_cleared_alloc<var_loc_list> ();
5291 temp->decl_id = decl_id;
5297 /* For PARM_DECLs try to keep around the original incoming value,
5298 even if that means we'll emit a zero-range .debug_loc entry. */
5300 && temp->first == temp->last
5301 && TREE_CODE (decl) == PARM_DECL
5302 && NOTE_P (temp->first->loc)
5303 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
5304 && DECL_INCOMING_RTL (decl)
5305 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
5306 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
5307 == GET_CODE (DECL_INCOMING_RTL (decl))
5308 && prev_real_insn (temp->first->loc) == NULL_RTX
5310 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
5311 NOTE_VAR_LOCATION_LOC (loc_note))
5312 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
5313 != NOTE_VAR_LOCATION_STATUS (loc_note))))
5315 loc = ggc_cleared_alloc<var_loc_node> ();
5316 temp->first->next = loc;
5318 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5320 else if (temp->last)
5322 struct var_loc_node *last = temp->last, *unused = NULL;
5323 rtx *piece_loc = NULL, last_loc_note;
5324 HOST_WIDE_INT piece_bitpos = 0;
5328 gcc_assert (last->next == NULL);
5330 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
5332 piece_loc = &last->loc;
5335 HOST_WIDE_INT cur_bitsize = decl_piece_bitsize (*piece_loc);
5336 if (piece_bitpos + cur_bitsize > bitpos)
5338 piece_bitpos += cur_bitsize;
5339 piece_loc = &XEXP (*piece_loc, 1);
5343 /* TEMP->LAST here is either pointer to the last but one or
5344 last element in the chained list, LAST is pointer to the
5346 if (label && strcmp (last->label, label) == 0)
5348 /* For SRA optimized variables if there weren't any real
5349 insns since last note, just modify the last node. */
5350 if (piece_loc != NULL)
5352 adjust_piece_list (piece_loc, NULL, NULL,
5353 bitpos, piece_bitpos, bitsize, loc_note);
5356 /* If the last note doesn't cover any instructions, remove it. */
5357 if (temp->last != last)
5359 temp->last->next = NULL;
5362 gcc_assert (strcmp (last->label, label) != 0);
5366 gcc_assert (temp->first == temp->last
5367 || (temp->first->next == temp->last
5368 && TREE_CODE (decl) == PARM_DECL));
5369 memset (temp->last, '\0', sizeof (*temp->last));
5370 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
5374 if (bitsize == -1 && NOTE_P (last->loc))
5375 last_loc_note = last->loc;
5376 else if (piece_loc != NULL
5377 && *piece_loc != NULL_RTX
5378 && piece_bitpos == bitpos
5379 && decl_piece_bitsize (*piece_loc) == bitsize)
5380 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
5382 last_loc_note = NULL_RTX;
5383 /* If the current location is the same as the end of the list,
5384 and either both or neither of the locations is uninitialized,
5385 we have nothing to do. */
5386 if (last_loc_note == NULL_RTX
5387 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
5388 NOTE_VAR_LOCATION_LOC (loc_note)))
5389 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5390 != NOTE_VAR_LOCATION_STATUS (loc_note))
5391 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5392 == VAR_INIT_STATUS_UNINITIALIZED)
5393 || (NOTE_VAR_LOCATION_STATUS (loc_note)
5394 == VAR_INIT_STATUS_UNINITIALIZED))))
5396 /* Add LOC to the end of list and update LAST. If the last
5397 element of the list has been removed above, reuse its
5398 memory for the new node, otherwise allocate a new one. */
5402 memset (loc, '\0', sizeof (*loc));
5405 loc = ggc_cleared_alloc<var_loc_node> ();
5406 if (bitsize == -1 || piece_loc == NULL)
5407 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5409 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
5410 bitpos, piece_bitpos, bitsize, loc_note);
5412 /* Ensure TEMP->LAST will point either to the new last but one
5413 element of the chain, or to the last element in it. */
5414 if (last != temp->last)
5422 loc = ggc_cleared_alloc<var_loc_node> ();
5425 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5430 /* Keep track of the number of spaces used to indent the
5431 output of the debugging routines that print the structure of
5432 the DIE internal representation. */
5433 static int print_indent;
5435 /* Indent the line the number of spaces given by print_indent. */
5438 print_spaces (FILE *outfile)
5440 fprintf (outfile, "%*s", print_indent, "");
5443 /* Print a type signature in hex. */
5446 print_signature (FILE *outfile, char *sig)
5450 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
5451 fprintf (outfile, "%02x", sig[i] & 0xff);
5454 static void print_loc_descr (dw_loc_descr_ref, FILE *);
5456 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5457 RECURSE, output location descriptor operations. */
5460 print_dw_val (dw_val_node *val, bool recurse, FILE *outfile)
5462 switch (val->val_class)
5464 case dw_val_class_addr:
5465 fprintf (outfile, "address");
5467 case dw_val_class_offset:
5468 fprintf (outfile, "offset");
5470 case dw_val_class_loc:
5471 fprintf (outfile, "location descriptor");
5472 if (val->v.val_loc == NULL)
5473 fprintf (outfile, " -> <null>\n");
5476 fprintf (outfile, ":\n");
5478 print_loc_descr (val->v.val_loc, outfile);
5482 fprintf (outfile, " (%p)\n", (void *) val->v.val_loc);
5484 case dw_val_class_loc_list:
5485 fprintf (outfile, "location list -> label:%s",
5486 val->v.val_loc_list->ll_symbol);
5488 case dw_val_class_range_list:
5489 fprintf (outfile, "range list");
5491 case dw_val_class_const:
5492 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, val->v.val_int);
5494 case dw_val_class_unsigned_const:
5495 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, val->v.val_unsigned);
5497 case dw_val_class_const_double:
5498 fprintf (outfile, "constant (" HOST_WIDE_INT_PRINT_DEC","\
5499 HOST_WIDE_INT_PRINT_UNSIGNED")",
5500 val->v.val_double.high,
5501 val->v.val_double.low);
5503 case dw_val_class_wide_int:
5505 int i = val->v.val_wide->get_len ();
5506 fprintf (outfile, "constant (");
5508 if (val->v.val_wide->elt (i - 1) == 0)
5509 fprintf (outfile, "0x");
5510 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX,
5511 val->v.val_wide->elt (--i));
5513 fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX,
5514 val->v.val_wide->elt (i));
5515 fprintf (outfile, ")");
5518 case dw_val_class_vec:
5519 fprintf (outfile, "floating-point or vector constant");
5521 case dw_val_class_flag:
5522 fprintf (outfile, "%u", val->v.val_flag);
5524 case dw_val_class_die_ref:
5525 if (val->v.val_die_ref.die != NULL)
5527 dw_die_ref die = val->v.val_die_ref.die;
5529 if (die->comdat_type_p)
5531 fprintf (outfile, "die -> signature: ");
5532 print_signature (outfile,
5533 die->die_id.die_type_node->signature);
5535 else if (die->die_id.die_symbol)
5536 fprintf (outfile, "die -> label: %s", die->die_id.die_symbol);
5538 fprintf (outfile, "die -> %ld", die->die_offset);
5539 fprintf (outfile, " (%p)", (void *) die);
5542 fprintf (outfile, "die -> <null>");
5544 case dw_val_class_vms_delta:
5545 fprintf (outfile, "delta: @slotcount(%s-%s)",
5546 val->v.val_vms_delta.lbl2, val->v.val_vms_delta.lbl1);
5548 case dw_val_class_lbl_id:
5549 case dw_val_class_lineptr:
5550 case dw_val_class_macptr:
5551 case dw_val_class_high_pc:
5552 fprintf (outfile, "label: %s", val->v.val_lbl_id);
5554 case dw_val_class_str:
5555 if (val->v.val_str->str != NULL)
5556 fprintf (outfile, "\"%s\"", val->v.val_str->str);
5558 fprintf (outfile, "<null>");
5560 case dw_val_class_file:
5561 fprintf (outfile, "\"%s\" (%d)", val->v.val_file->filename,
5562 val->v.val_file->emitted_number);
5564 case dw_val_class_data8:
5568 for (i = 0; i < 8; i++)
5569 fprintf (outfile, "%02x", val->v.val_data8[i]);
5577 /* Likewise, for a DIE attribute. */
5580 print_attribute (dw_attr_node *a, bool recurse, FILE *outfile)
5582 print_dw_val (&a->dw_attr_val, recurse, outfile);
5586 /* Print the list of operands in the LOC location description to OUTFILE. This
5587 routine is a debugging aid only. */
5590 print_loc_descr (dw_loc_descr_ref loc, FILE *outfile)
5592 dw_loc_descr_ref l = loc;
5596 print_spaces (outfile);
5597 fprintf (outfile, "<null>\n");
5601 for (l = loc; l != NULL; l = l->dw_loc_next)
5603 print_spaces (outfile);
5604 fprintf (outfile, "(%p) %s",
5606 dwarf_stack_op_name (l->dw_loc_opc));
5607 if (l->dw_loc_oprnd1.val_class != dw_val_class_none)
5609 fprintf (outfile, " ");
5610 print_dw_val (&l->dw_loc_oprnd1, false, outfile);
5612 if (l->dw_loc_oprnd2.val_class != dw_val_class_none)
5614 fprintf (outfile, ", ");
5615 print_dw_val (&l->dw_loc_oprnd2, false, outfile);
5617 fprintf (outfile, "\n");
5621 /* Print the information associated with a given DIE, and its children.
5622 This routine is a debugging aid only. */
5625 print_die (dw_die_ref die, FILE *outfile)
5631 print_spaces (outfile);
5632 fprintf (outfile, "DIE %4ld: %s (%p)\n",
5633 die->die_offset, dwarf_tag_name (die->die_tag),
5635 print_spaces (outfile);
5636 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5637 fprintf (outfile, " offset: %ld", die->die_offset);
5638 fprintf (outfile, " mark: %d\n", die->die_mark);
5640 if (die->comdat_type_p)
5642 print_spaces (outfile);
5643 fprintf (outfile, " signature: ");
5644 print_signature (outfile, die->die_id.die_type_node->signature);
5645 fprintf (outfile, "\n");
5648 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5650 print_spaces (outfile);
5651 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5653 print_attribute (a, true, outfile);
5654 fprintf (outfile, "\n");
5657 if (die->die_child != NULL)
5660 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5663 if (print_indent == 0)
5664 fprintf (outfile, "\n");
5667 /* Print the list of operations in the LOC location description. */
5670 debug_dwarf_loc_descr (dw_loc_descr_ref loc)
5672 print_loc_descr (loc, stderr);
5675 /* Print the information collected for a given DIE. */
5678 debug_dwarf_die (dw_die_ref die)
5680 print_die (die, stderr);
5684 debug (die_struct &ref)
5686 print_die (&ref, stderr);
5690 debug (die_struct *ptr)
5695 fprintf (stderr, "<nil>\n");
5699 /* Print all DWARF information collected for the compilation unit.
5700 This routine is a debugging aid only. */
5706 print_die (comp_unit_die (), stderr);
5709 #ifdef ENABLE_CHECKING
5710 /* Sanity checks on DIEs. */
5713 check_die (dw_die_ref die)
5717 bool inline_found = false;
5718 int n_location = 0, n_low_pc = 0, n_high_pc = 0, n_artificial = 0;
5719 int n_decl_line = 0, n_decl_file = 0;
5720 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5725 if (a->dw_attr_val.v.val_unsigned)
5726 inline_found = true;
5728 case DW_AT_location:
5737 case DW_AT_artificial:
5740 case DW_AT_decl_line:
5743 case DW_AT_decl_file:
5750 if (n_location > 1 || n_low_pc > 1 || n_high_pc > 1 || n_artificial > 1
5751 || n_decl_line > 1 || n_decl_file > 1)
5753 fprintf (stderr, "Duplicate attributes in DIE:\n");
5754 debug_dwarf_die (die);
5759 /* A debugging information entry that is a member of an abstract
5760 instance tree [that has DW_AT_inline] should not contain any
5761 attributes which describe aspects of the subroutine which vary
5762 between distinct inlined expansions or distinct out-of-line
5764 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5765 gcc_assert (a->dw_attr != DW_AT_low_pc
5766 && a->dw_attr != DW_AT_high_pc
5767 && a->dw_attr != DW_AT_location
5768 && a->dw_attr != DW_AT_frame_base
5769 && a->dw_attr != DW_AT_GNU_all_call_sites);
5774 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5775 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5776 DIE that marks the start of the DIEs for this include file. */
5779 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5781 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5782 dw_die_ref new_unit = gen_compile_unit_die (filename);
5784 new_unit->die_sib = old_unit;
5788 /* Close an include-file CU and reopen the enclosing one. */
5791 pop_compile_unit (dw_die_ref old_unit)
5793 dw_die_ref new_unit = old_unit->die_sib;
5795 old_unit->die_sib = NULL;
5799 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5800 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5801 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5803 /* Calculate the checksum of a location expression. */
5806 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5809 inchash::hash hstate;
5812 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
5814 hash_loc_operands (loc, hstate);
5815 hash = hstate.end();
5819 /* Calculate the checksum of an attribute. */
5822 attr_checksum (dw_attr_node *at, struct md5_ctx *ctx, int *mark)
5824 dw_loc_descr_ref loc;
5827 CHECKSUM (at->dw_attr);
5829 /* We don't care that this was compiled with a different compiler
5830 snapshot; if the output is the same, that's what matters. */
5831 if (at->dw_attr == DW_AT_producer)
5834 switch (AT_class (at))
5836 case dw_val_class_const:
5837 CHECKSUM (at->dw_attr_val.v.val_int);
5839 case dw_val_class_unsigned_const:
5840 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5842 case dw_val_class_const_double:
5843 CHECKSUM (at->dw_attr_val.v.val_double);
5845 case dw_val_class_wide_int:
5846 CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
5847 get_full_len (*at->dw_attr_val.v.val_wide)
5848 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
5850 case dw_val_class_vec:
5851 CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
5852 (at->dw_attr_val.v.val_vec.length
5853 * at->dw_attr_val.v.val_vec.elt_size));
5855 case dw_val_class_flag:
5856 CHECKSUM (at->dw_attr_val.v.val_flag);
5858 case dw_val_class_str:
5859 CHECKSUM_STRING (AT_string (at));
5862 case dw_val_class_addr:
5864 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5865 CHECKSUM_STRING (XSTR (r, 0));
5868 case dw_val_class_offset:
5869 CHECKSUM (at->dw_attr_val.v.val_offset);
5872 case dw_val_class_loc:
5873 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5874 loc_checksum (loc, ctx);
5877 case dw_val_class_die_ref:
5878 die_checksum (AT_ref (at), ctx, mark);
5881 case dw_val_class_fde_ref:
5882 case dw_val_class_vms_delta:
5883 case dw_val_class_lbl_id:
5884 case dw_val_class_lineptr:
5885 case dw_val_class_macptr:
5886 case dw_val_class_high_pc:
5889 case dw_val_class_file:
5890 CHECKSUM_STRING (AT_file (at)->filename);
5893 case dw_val_class_data8:
5894 CHECKSUM (at->dw_attr_val.v.val_data8);
5902 /* Calculate the checksum of a DIE. */
5905 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5911 /* To avoid infinite recursion. */
5914 CHECKSUM (die->die_mark);
5917 die->die_mark = ++(*mark);
5919 CHECKSUM (die->die_tag);
5921 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5922 attr_checksum (a, ctx, mark);
5924 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
5928 #undef CHECKSUM_BLOCK
5929 #undef CHECKSUM_STRING
5931 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5932 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5933 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5934 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5935 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5936 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5937 #define CHECKSUM_ATTR(FOO) \
5938 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5940 /* Calculate the checksum of a number in signed LEB128 format. */
5943 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
5950 byte = (value & 0x7f);
5952 more = !((value == 0 && (byte & 0x40) == 0)
5953 || (value == -1 && (byte & 0x40) != 0));
5962 /* Calculate the checksum of a number in unsigned LEB128 format. */
5965 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
5969 unsigned char byte = (value & 0x7f);
5972 /* More bytes to follow. */
5980 /* Checksum the context of the DIE. This adds the names of any
5981 surrounding namespaces or structures to the checksum. */
5984 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
5988 int tag = die->die_tag;
5990 if (tag != DW_TAG_namespace
5991 && tag != DW_TAG_structure_type
5992 && tag != DW_TAG_class_type)
5995 name = get_AT_string (die, DW_AT_name);
5997 spec = get_AT_ref (die, DW_AT_specification);
6001 if (die->die_parent != NULL)
6002 checksum_die_context (die->die_parent, ctx);
6004 CHECKSUM_ULEB128 ('C');
6005 CHECKSUM_ULEB128 (tag);
6007 CHECKSUM_STRING (name);
6010 /* Calculate the checksum of a location expression. */
6013 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6015 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6016 were emitted as a DW_FORM_sdata instead of a location expression. */
6017 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
6019 CHECKSUM_ULEB128 (DW_FORM_sdata);
6020 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
6024 /* Otherwise, just checksum the raw location expression. */
6027 inchash::hash hstate;
6030 CHECKSUM_ULEB128 (loc->dtprel);
6031 CHECKSUM_ULEB128 (loc->dw_loc_opc);
6032 hash_loc_operands (loc, hstate);
6033 hash = hstate.end ();
6035 loc = loc->dw_loc_next;
6039 /* Calculate the checksum of an attribute. */
6042 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_node *at,
6043 struct md5_ctx *ctx, int *mark)
6045 dw_loc_descr_ref loc;
6048 if (AT_class (at) == dw_val_class_die_ref)
6050 dw_die_ref target_die = AT_ref (at);
6052 /* For pointer and reference types, we checksum only the (qualified)
6053 name of the target type (if there is a name). For friend entries,
6054 we checksum only the (qualified) name of the target type or function.
6055 This allows the checksum to remain the same whether the target type
6056 is complete or not. */
6057 if ((at->dw_attr == DW_AT_type
6058 && (tag == DW_TAG_pointer_type
6059 || tag == DW_TAG_reference_type
6060 || tag == DW_TAG_rvalue_reference_type
6061 || tag == DW_TAG_ptr_to_member_type))
6062 || (at->dw_attr == DW_AT_friend
6063 && tag == DW_TAG_friend))
6065 dw_attr_node *name_attr = get_AT (target_die, DW_AT_name);
6067 if (name_attr != NULL)
6069 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
6073 CHECKSUM_ULEB128 ('N');
6074 CHECKSUM_ULEB128 (at->dw_attr);
6075 if (decl->die_parent != NULL)
6076 checksum_die_context (decl->die_parent, ctx);
6077 CHECKSUM_ULEB128 ('E');
6078 CHECKSUM_STRING (AT_string (name_attr));
6083 /* For all other references to another DIE, we check to see if the
6084 target DIE has already been visited. If it has, we emit a
6085 backward reference; if not, we descend recursively. */
6086 if (target_die->die_mark > 0)
6088 CHECKSUM_ULEB128 ('R');
6089 CHECKSUM_ULEB128 (at->dw_attr);
6090 CHECKSUM_ULEB128 (target_die->die_mark);
6094 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
6098 target_die->die_mark = ++(*mark);
6099 CHECKSUM_ULEB128 ('T');
6100 CHECKSUM_ULEB128 (at->dw_attr);
6101 if (decl->die_parent != NULL)
6102 checksum_die_context (decl->die_parent, ctx);
6103 die_checksum_ordered (target_die, ctx, mark);
6108 CHECKSUM_ULEB128 ('A');
6109 CHECKSUM_ULEB128 (at->dw_attr);
6111 switch (AT_class (at))
6113 case dw_val_class_const:
6114 CHECKSUM_ULEB128 (DW_FORM_sdata);
6115 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
6118 case dw_val_class_unsigned_const:
6119 CHECKSUM_ULEB128 (DW_FORM_sdata);
6120 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
6123 case dw_val_class_const_double:
6124 CHECKSUM_ULEB128 (DW_FORM_block);
6125 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
6126 CHECKSUM (at->dw_attr_val.v.val_double);
6129 case dw_val_class_wide_int:
6130 CHECKSUM_ULEB128 (DW_FORM_block);
6131 CHECKSUM_ULEB128 (get_full_len (*at->dw_attr_val.v.val_wide)
6132 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
6133 CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
6134 get_full_len (*at->dw_attr_val.v.val_wide)
6135 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
6138 case dw_val_class_vec:
6139 CHECKSUM_ULEB128 (DW_FORM_block);
6140 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_vec.length
6141 * at->dw_attr_val.v.val_vec.elt_size);
6142 CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
6143 (at->dw_attr_val.v.val_vec.length
6144 * at->dw_attr_val.v.val_vec.elt_size));
6147 case dw_val_class_flag:
6148 CHECKSUM_ULEB128 (DW_FORM_flag);
6149 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
6152 case dw_val_class_str:
6153 CHECKSUM_ULEB128 (DW_FORM_string);
6154 CHECKSUM_STRING (AT_string (at));
6157 case dw_val_class_addr:
6159 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6160 CHECKSUM_ULEB128 (DW_FORM_string);
6161 CHECKSUM_STRING (XSTR (r, 0));
6164 case dw_val_class_offset:
6165 CHECKSUM_ULEB128 (DW_FORM_sdata);
6166 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
6169 case dw_val_class_loc:
6170 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6171 loc_checksum_ordered (loc, ctx);
6174 case dw_val_class_fde_ref:
6175 case dw_val_class_lbl_id:
6176 case dw_val_class_lineptr:
6177 case dw_val_class_macptr:
6178 case dw_val_class_high_pc:
6181 case dw_val_class_file:
6182 CHECKSUM_ULEB128 (DW_FORM_string);
6183 CHECKSUM_STRING (AT_file (at)->filename);
6186 case dw_val_class_data8:
6187 CHECKSUM (at->dw_attr_val.v.val_data8);
6195 struct checksum_attributes
6197 dw_attr_node *at_name;
6198 dw_attr_node *at_type;
6199 dw_attr_node *at_friend;
6200 dw_attr_node *at_accessibility;
6201 dw_attr_node *at_address_class;
6202 dw_attr_node *at_allocated;
6203 dw_attr_node *at_artificial;
6204 dw_attr_node *at_associated;
6205 dw_attr_node *at_binary_scale;
6206 dw_attr_node *at_bit_offset;
6207 dw_attr_node *at_bit_size;
6208 dw_attr_node *at_bit_stride;
6209 dw_attr_node *at_byte_size;
6210 dw_attr_node *at_byte_stride;
6211 dw_attr_node *at_const_value;
6212 dw_attr_node *at_containing_type;
6213 dw_attr_node *at_count;
6214 dw_attr_node *at_data_location;
6215 dw_attr_node *at_data_member_location;
6216 dw_attr_node *at_decimal_scale;
6217 dw_attr_node *at_decimal_sign;
6218 dw_attr_node *at_default_value;
6219 dw_attr_node *at_digit_count;
6220 dw_attr_node *at_discr;
6221 dw_attr_node *at_discr_list;
6222 dw_attr_node *at_discr_value;
6223 dw_attr_node *at_encoding;
6224 dw_attr_node *at_endianity;
6225 dw_attr_node *at_explicit;
6226 dw_attr_node *at_is_optional;
6227 dw_attr_node *at_location;
6228 dw_attr_node *at_lower_bound;
6229 dw_attr_node *at_mutable;
6230 dw_attr_node *at_ordering;
6231 dw_attr_node *at_picture_string;
6232 dw_attr_node *at_prototyped;
6233 dw_attr_node *at_small;
6234 dw_attr_node *at_segment;
6235 dw_attr_node *at_string_length;
6236 dw_attr_node *at_threads_scaled;
6237 dw_attr_node *at_upper_bound;
6238 dw_attr_node *at_use_location;
6239 dw_attr_node *at_use_UTF8;
6240 dw_attr_node *at_variable_parameter;
6241 dw_attr_node *at_virtuality;
6242 dw_attr_node *at_visibility;
6243 dw_attr_node *at_vtable_elem_location;
6246 /* Collect the attributes that we will want to use for the checksum. */
6249 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
6254 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
6265 attrs->at_friend = a;
6267 case DW_AT_accessibility:
6268 attrs->at_accessibility = a;
6270 case DW_AT_address_class:
6271 attrs->at_address_class = a;
6273 case DW_AT_allocated:
6274 attrs->at_allocated = a;
6276 case DW_AT_artificial:
6277 attrs->at_artificial = a;
6279 case DW_AT_associated:
6280 attrs->at_associated = a;
6282 case DW_AT_binary_scale:
6283 attrs->at_binary_scale = a;
6285 case DW_AT_bit_offset:
6286 attrs->at_bit_offset = a;
6288 case DW_AT_bit_size:
6289 attrs->at_bit_size = a;
6291 case DW_AT_bit_stride:
6292 attrs->at_bit_stride = a;
6294 case DW_AT_byte_size:
6295 attrs->at_byte_size = a;
6297 case DW_AT_byte_stride:
6298 attrs->at_byte_stride = a;
6300 case DW_AT_const_value:
6301 attrs->at_const_value = a;
6303 case DW_AT_containing_type:
6304 attrs->at_containing_type = a;
6307 attrs->at_count = a;
6309 case DW_AT_data_location:
6310 attrs->at_data_location = a;
6312 case DW_AT_data_member_location:
6313 attrs->at_data_member_location = a;
6315 case DW_AT_decimal_scale:
6316 attrs->at_decimal_scale = a;
6318 case DW_AT_decimal_sign:
6319 attrs->at_decimal_sign = a;
6321 case DW_AT_default_value:
6322 attrs->at_default_value = a;
6324 case DW_AT_digit_count:
6325 attrs->at_digit_count = a;
6328 attrs->at_discr = a;
6330 case DW_AT_discr_list:
6331 attrs->at_discr_list = a;
6333 case DW_AT_discr_value:
6334 attrs->at_discr_value = a;
6336 case DW_AT_encoding:
6337 attrs->at_encoding = a;
6339 case DW_AT_endianity:
6340 attrs->at_endianity = a;
6342 case DW_AT_explicit:
6343 attrs->at_explicit = a;
6345 case DW_AT_is_optional:
6346 attrs->at_is_optional = a;
6348 case DW_AT_location:
6349 attrs->at_location = a;
6351 case DW_AT_lower_bound:
6352 attrs->at_lower_bound = a;
6355 attrs->at_mutable = a;
6357 case DW_AT_ordering:
6358 attrs->at_ordering = a;
6360 case DW_AT_picture_string:
6361 attrs->at_picture_string = a;
6363 case DW_AT_prototyped:
6364 attrs->at_prototyped = a;
6367 attrs->at_small = a;
6370 attrs->at_segment = a;
6372 case DW_AT_string_length:
6373 attrs->at_string_length = a;
6375 case DW_AT_threads_scaled:
6376 attrs->at_threads_scaled = a;
6378 case DW_AT_upper_bound:
6379 attrs->at_upper_bound = a;
6381 case DW_AT_use_location:
6382 attrs->at_use_location = a;
6384 case DW_AT_use_UTF8:
6385 attrs->at_use_UTF8 = a;
6387 case DW_AT_variable_parameter:
6388 attrs->at_variable_parameter = a;
6390 case DW_AT_virtuality:
6391 attrs->at_virtuality = a;
6393 case DW_AT_visibility:
6394 attrs->at_visibility = a;
6396 case DW_AT_vtable_elem_location:
6397 attrs->at_vtable_elem_location = a;
6405 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6408 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6412 struct checksum_attributes attrs;
6414 CHECKSUM_ULEB128 ('D');
6415 CHECKSUM_ULEB128 (die->die_tag);
6417 memset (&attrs, 0, sizeof (attrs));
6419 decl = get_AT_ref (die, DW_AT_specification);
6421 collect_checksum_attributes (&attrs, decl);
6422 collect_checksum_attributes (&attrs, die);
6424 CHECKSUM_ATTR (attrs.at_name);
6425 CHECKSUM_ATTR (attrs.at_accessibility);
6426 CHECKSUM_ATTR (attrs.at_address_class);
6427 CHECKSUM_ATTR (attrs.at_allocated);
6428 CHECKSUM_ATTR (attrs.at_artificial);
6429 CHECKSUM_ATTR (attrs.at_associated);
6430 CHECKSUM_ATTR (attrs.at_binary_scale);
6431 CHECKSUM_ATTR (attrs.at_bit_offset);
6432 CHECKSUM_ATTR (attrs.at_bit_size);
6433 CHECKSUM_ATTR (attrs.at_bit_stride);
6434 CHECKSUM_ATTR (attrs.at_byte_size);
6435 CHECKSUM_ATTR (attrs.at_byte_stride);
6436 CHECKSUM_ATTR (attrs.at_const_value);
6437 CHECKSUM_ATTR (attrs.at_containing_type);
6438 CHECKSUM_ATTR (attrs.at_count);
6439 CHECKSUM_ATTR (attrs.at_data_location);
6440 CHECKSUM_ATTR (attrs.at_data_member_location);
6441 CHECKSUM_ATTR (attrs.at_decimal_scale);
6442 CHECKSUM_ATTR (attrs.at_decimal_sign);
6443 CHECKSUM_ATTR (attrs.at_default_value);
6444 CHECKSUM_ATTR (attrs.at_digit_count);
6445 CHECKSUM_ATTR (attrs.at_discr);
6446 CHECKSUM_ATTR (attrs.at_discr_list);
6447 CHECKSUM_ATTR (attrs.at_discr_value);
6448 CHECKSUM_ATTR (attrs.at_encoding);
6449 CHECKSUM_ATTR (attrs.at_endianity);
6450 CHECKSUM_ATTR (attrs.at_explicit);
6451 CHECKSUM_ATTR (attrs.at_is_optional);
6452 CHECKSUM_ATTR (attrs.at_location);
6453 CHECKSUM_ATTR (attrs.at_lower_bound);
6454 CHECKSUM_ATTR (attrs.at_mutable);
6455 CHECKSUM_ATTR (attrs.at_ordering);
6456 CHECKSUM_ATTR (attrs.at_picture_string);
6457 CHECKSUM_ATTR (attrs.at_prototyped);
6458 CHECKSUM_ATTR (attrs.at_small);
6459 CHECKSUM_ATTR (attrs.at_segment);
6460 CHECKSUM_ATTR (attrs.at_string_length);
6461 CHECKSUM_ATTR (attrs.at_threads_scaled);
6462 CHECKSUM_ATTR (attrs.at_upper_bound);
6463 CHECKSUM_ATTR (attrs.at_use_location);
6464 CHECKSUM_ATTR (attrs.at_use_UTF8);
6465 CHECKSUM_ATTR (attrs.at_variable_parameter);
6466 CHECKSUM_ATTR (attrs.at_virtuality);
6467 CHECKSUM_ATTR (attrs.at_visibility);
6468 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
6469 CHECKSUM_ATTR (attrs.at_type);
6470 CHECKSUM_ATTR (attrs.at_friend);
6472 /* Checksum the child DIEs. */
6475 dw_attr_node *name_attr;
6478 name_attr = get_AT (c, DW_AT_name);
6479 if (is_template_instantiation (c))
6481 /* Ignore instantiations of member type and function templates. */
6483 else if (name_attr != NULL
6484 && (is_type_die (c) || c->die_tag == DW_TAG_subprogram))
6486 /* Use a shallow checksum for named nested types and member
6488 CHECKSUM_ULEB128 ('S');
6489 CHECKSUM_ULEB128 (c->die_tag);
6490 CHECKSUM_STRING (AT_string (name_attr));
6494 /* Use a deep checksum for other children. */
6495 /* Mark this DIE so it gets processed when unmarking. */
6496 if (c->die_mark == 0)
6498 die_checksum_ordered (c, ctx, mark);
6500 } while (c != die->die_child);
6502 CHECKSUM_ULEB128 (0);
6505 /* Add a type name and tag to a hash. */
6507 die_odr_checksum (int tag, const char *name, md5_ctx *ctx)
6509 CHECKSUM_ULEB128 (tag);
6510 CHECKSUM_STRING (name);
6514 #undef CHECKSUM_STRING
6515 #undef CHECKSUM_ATTR
6516 #undef CHECKSUM_LEB128
6517 #undef CHECKSUM_ULEB128
6519 /* Generate the type signature for DIE. This is computed by generating an
6520 MD5 checksum over the DIE's tag, its relevant attributes, and its
6521 children. Attributes that are references to other DIEs are processed
6522 by recursion, using the MARK field to prevent infinite recursion.
6523 If the DIE is nested inside a namespace or another type, we also
6524 need to include that context in the signature. The lower 64 bits
6525 of the resulting MD5 checksum comprise the signature. */
6528 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
6532 unsigned char checksum[16];
6537 name = get_AT_string (die, DW_AT_name);
6538 decl = get_AT_ref (die, DW_AT_specification);
6539 parent = get_die_parent (die);
6541 /* First, compute a signature for just the type name (and its surrounding
6542 context, if any. This is stored in the type unit DIE for link-time
6543 ODR (one-definition rule) checking. */
6545 if (is_cxx () && name != NULL)
6547 md5_init_ctx (&ctx);
6549 /* Checksum the names of surrounding namespaces and structures. */
6551 checksum_die_context (parent, &ctx);
6553 /* Checksum the current DIE. */
6554 die_odr_checksum (die->die_tag, name, &ctx);
6555 md5_finish_ctx (&ctx, checksum);
6557 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
6560 /* Next, compute the complete type signature. */
6562 md5_init_ctx (&ctx);
6564 die->die_mark = mark;
6566 /* Checksum the names of surrounding namespaces and structures. */
6568 checksum_die_context (parent, &ctx);
6570 /* Checksum the DIE and its children. */
6571 die_checksum_ordered (die, &ctx, &mark);
6572 unmark_all_dies (die);
6573 md5_finish_ctx (&ctx, checksum);
6575 /* Store the signature in the type node and link the type DIE and the
6576 type node together. */
6577 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
6578 DWARF_TYPE_SIGNATURE_SIZE);
6579 die->comdat_type_p = true;
6580 die->die_id.die_type_node = type_node;
6581 type_node->type_die = die;
6583 /* If the DIE is a specification, link its declaration to the type node
6587 decl->comdat_type_p = true;
6588 decl->die_id.die_type_node = type_node;
6592 /* Do the location expressions look same? */
6594 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6596 return loc1->dw_loc_opc == loc2->dw_loc_opc
6597 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6598 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6601 /* Do the values look the same? */
6603 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6605 dw_loc_descr_ref loc1, loc2;
6608 if (v1->val_class != v2->val_class)
6611 switch (v1->val_class)
6613 case dw_val_class_const:
6614 return v1->v.val_int == v2->v.val_int;
6615 case dw_val_class_unsigned_const:
6616 return v1->v.val_unsigned == v2->v.val_unsigned;
6617 case dw_val_class_const_double:
6618 return v1->v.val_double.high == v2->v.val_double.high
6619 && v1->v.val_double.low == v2->v.val_double.low;
6620 case dw_val_class_wide_int:
6621 return *v1->v.val_wide == *v2->v.val_wide;
6622 case dw_val_class_vec:
6623 if (v1->v.val_vec.length != v2->v.val_vec.length
6624 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6626 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6627 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6630 case dw_val_class_flag:
6631 return v1->v.val_flag == v2->v.val_flag;
6632 case dw_val_class_str:
6633 return !strcmp (v1->v.val_str->str, v2->v.val_str->str);
6635 case dw_val_class_addr:
6636 r1 = v1->v.val_addr;
6637 r2 = v2->v.val_addr;
6638 if (GET_CODE (r1) != GET_CODE (r2))
6640 return !rtx_equal_p (r1, r2);
6642 case dw_val_class_offset:
6643 return v1->v.val_offset == v2->v.val_offset;
6645 case dw_val_class_loc:
6646 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6648 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6649 if (!same_loc_p (loc1, loc2, mark))
6651 return !loc1 && !loc2;
6653 case dw_val_class_die_ref:
6654 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6656 case dw_val_class_fde_ref:
6657 case dw_val_class_vms_delta:
6658 case dw_val_class_lbl_id:
6659 case dw_val_class_lineptr:
6660 case dw_val_class_macptr:
6661 case dw_val_class_high_pc:
6664 case dw_val_class_file:
6665 return v1->v.val_file == v2->v.val_file;
6667 case dw_val_class_data8:
6668 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
6675 /* Do the attributes look the same? */
6678 same_attr_p (dw_attr_node *at1, dw_attr_node *at2, int *mark)
6680 if (at1->dw_attr != at2->dw_attr)
6683 /* We don't care that this was compiled with a different compiler
6684 snapshot; if the output is the same, that's what matters. */
6685 if (at1->dw_attr == DW_AT_producer)
6688 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6691 /* Do the dies look the same? */
6694 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6700 /* To avoid infinite recursion. */
6702 return die1->die_mark == die2->die_mark;
6703 die1->die_mark = die2->die_mark = ++(*mark);
6705 if (die1->die_tag != die2->die_tag)
6708 if (vec_safe_length (die1->die_attr) != vec_safe_length (die2->die_attr))
6711 FOR_EACH_VEC_SAFE_ELT (die1->die_attr, ix, a1)
6712 if (!same_attr_p (a1, &(*die2->die_attr)[ix], mark))
6715 c1 = die1->die_child;
6716 c2 = die2->die_child;
6725 if (!same_die_p (c1, c2, mark))
6729 if (c1 == die1->die_child)
6731 if (c2 == die2->die_child)
6741 /* Do the dies look the same? Wrapper around same_die_p. */
6744 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6747 int ret = same_die_p (die1, die2, &mark);
6749 unmark_all_dies (die1);
6750 unmark_all_dies (die2);
6755 /* The prefix to attach to symbols on DIEs in the current comdat debug
6757 static const char *comdat_symbol_id;
6759 /* The index of the current symbol within the current comdat CU. */
6760 static unsigned int comdat_symbol_number;
6762 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6763 children, and set comdat_symbol_id accordingly. */
6766 compute_section_prefix (dw_die_ref unit_die)
6768 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6769 const char *base = die_name ? lbasename (die_name) : "anonymous";
6770 char *name = XALLOCAVEC (char, strlen (base) + 64);
6773 unsigned char checksum[16];
6776 /* Compute the checksum of the DIE, then append part of it as hex digits to
6777 the name filename of the unit. */
6779 md5_init_ctx (&ctx);
6781 die_checksum (unit_die, &ctx, &mark);
6782 unmark_all_dies (unit_die);
6783 md5_finish_ctx (&ctx, checksum);
6785 sprintf (name, "%s.", base);
6786 clean_symbol_name (name);
6788 p = name + strlen (name);
6789 for (i = 0; i < 4; i++)
6791 sprintf (p, "%.2x", checksum[i]);
6795 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
6796 comdat_symbol_number = 0;
6799 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6802 is_type_die (dw_die_ref die)
6804 switch (die->die_tag)
6806 case DW_TAG_array_type:
6807 case DW_TAG_class_type:
6808 case DW_TAG_interface_type:
6809 case DW_TAG_enumeration_type:
6810 case DW_TAG_pointer_type:
6811 case DW_TAG_reference_type:
6812 case DW_TAG_rvalue_reference_type:
6813 case DW_TAG_string_type:
6814 case DW_TAG_structure_type:
6815 case DW_TAG_subroutine_type:
6816 case DW_TAG_union_type:
6817 case DW_TAG_ptr_to_member_type:
6818 case DW_TAG_set_type:
6819 case DW_TAG_subrange_type:
6820 case DW_TAG_base_type:
6821 case DW_TAG_const_type:
6822 case DW_TAG_file_type:
6823 case DW_TAG_packed_type:
6824 case DW_TAG_volatile_type:
6825 case DW_TAG_typedef:
6832 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6833 Basically, we want to choose the bits that are likely to be shared between
6834 compilations (types) and leave out the bits that are specific to individual
6835 compilations (functions). */
6838 is_comdat_die (dw_die_ref c)
6840 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6841 we do for stabs. The advantage is a greater likelihood of sharing between
6842 objects that don't include headers in the same order (and therefore would
6843 put the base types in a different comdat). jason 8/28/00 */
6845 if (c->die_tag == DW_TAG_base_type)
6848 if (c->die_tag == DW_TAG_pointer_type
6849 || c->die_tag == DW_TAG_reference_type
6850 || c->die_tag == DW_TAG_rvalue_reference_type
6851 || c->die_tag == DW_TAG_const_type
6852 || c->die_tag == DW_TAG_volatile_type)
6854 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6856 return t ? is_comdat_die (t) : 0;
6859 return is_type_die (c);
6862 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6863 compilation unit. */
6866 is_symbol_die (dw_die_ref c)
6868 return (is_type_die (c)
6869 || is_declaration_die (c)
6870 || c->die_tag == DW_TAG_namespace
6871 || c->die_tag == DW_TAG_module);
6874 /* Returns true iff C is a compile-unit DIE. */
6877 is_cu_die (dw_die_ref c)
6879 return c && c->die_tag == DW_TAG_compile_unit;
6882 /* Returns true iff C is a unit DIE of some sort. */
6885 is_unit_die (dw_die_ref c)
6887 return c && (c->die_tag == DW_TAG_compile_unit
6888 || c->die_tag == DW_TAG_partial_unit
6889 || c->die_tag == DW_TAG_type_unit);
6892 /* Returns true iff C is a namespace DIE. */
6895 is_namespace_die (dw_die_ref c)
6897 return c && c->die_tag == DW_TAG_namespace;
6900 /* Returns true iff C is a class or structure DIE. */
6903 is_class_die (dw_die_ref c)
6905 return c && (c->die_tag == DW_TAG_class_type
6906 || c->die_tag == DW_TAG_structure_type);
6909 /* Return non-zero if this DIE is a template parameter. */
6912 is_template_parameter (dw_die_ref die)
6914 switch (die->die_tag)
6916 case DW_TAG_template_type_param:
6917 case DW_TAG_template_value_param:
6918 case DW_TAG_GNU_template_template_param:
6919 case DW_TAG_GNU_template_parameter_pack:
6926 /* Return non-zero if this DIE represents a template instantiation. */
6929 is_template_instantiation (dw_die_ref die)
6933 if (!is_type_die (die) && die->die_tag != DW_TAG_subprogram)
6935 FOR_EACH_CHILD (die, c, if (is_template_parameter (c)) return true);
6940 gen_internal_sym (const char *prefix)
6944 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6945 return xstrdup (buf);
6948 /* Assign symbols to all worthy DIEs under DIE. */
6951 assign_symbol_names (dw_die_ref die)
6955 if (is_symbol_die (die) && !die->comdat_type_p)
6957 if (comdat_symbol_id)
6959 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
6961 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6962 comdat_symbol_id, comdat_symbol_number++);
6963 die->die_id.die_symbol = xstrdup (p);
6966 die->die_id.die_symbol = gen_internal_sym ("LDIE");
6969 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6972 struct cu_hash_table_entry
6975 unsigned min_comdat_num, max_comdat_num;
6976 struct cu_hash_table_entry *next;
6979 /* Helpers to manipulate hash table of CUs. */
6981 struct cu_hash_table_entry_hasher : pointer_hash <cu_hash_table_entry>
6983 typedef die_struct *compare_type;
6984 static inline hashval_t hash (const cu_hash_table_entry *);
6985 static inline bool equal (const cu_hash_table_entry *, const die_struct *);
6986 static inline void remove (cu_hash_table_entry *);
6990 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry *entry)
6992 return htab_hash_string (entry->cu->die_id.die_symbol);
6996 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry *entry1,
6997 const die_struct *entry2)
6999 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
7003 cu_hash_table_entry_hasher::remove (cu_hash_table_entry *entry)
7005 struct cu_hash_table_entry *next;
7015 typedef hash_table<cu_hash_table_entry_hasher> cu_hash_type;
7017 /* Check whether we have already seen this CU and set up SYM_NUM
7020 check_duplicate_cu (dw_die_ref cu, cu_hash_type *htable, unsigned int *sym_num)
7022 struct cu_hash_table_entry dummy;
7023 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7025 dummy.max_comdat_num = 0;
7027 slot = htable->find_slot_with_hash (cu,
7028 htab_hash_string (cu->die_id.die_symbol),
7032 for (; entry; last = entry, entry = entry->next)
7034 if (same_die_p_wrap (cu, entry->cu))
7040 *sym_num = entry->min_comdat_num;
7044 entry = XCNEW (struct cu_hash_table_entry);
7046 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7047 entry->next = *slot;
7053 /* Record SYM_NUM to record of CU in HTABLE. */
7055 record_comdat_symbol_number (dw_die_ref cu, cu_hash_type *htable,
7056 unsigned int sym_num)
7058 struct cu_hash_table_entry **slot, *entry;
7060 slot = htable->find_slot_with_hash (cu,
7061 htab_hash_string (cu->die_id.die_symbol),
7065 entry->max_comdat_num = sym_num;
7068 /* Traverse the DIE (which is always comp_unit_die), and set up
7069 additional compilation units for each of the include files we see
7070 bracketed by BINCL/EINCL. */
7073 break_out_includes (dw_die_ref die)
7076 dw_die_ref unit = NULL;
7077 limbo_die_node *node, **pnode;
7081 dw_die_ref prev = c;
7083 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7084 || (unit && is_comdat_die (c)))
7086 dw_die_ref next = c->die_sib;
7088 /* This DIE is for a secondary CU; remove it from the main one. */
7089 remove_child_with_prev (c, prev);
7091 if (c->die_tag == DW_TAG_GNU_BINCL)
7092 unit = push_new_compile_unit (unit, c);
7093 else if (c->die_tag == DW_TAG_GNU_EINCL)
7094 unit = pop_compile_unit (unit);
7096 add_child_die (unit, c);
7098 if (c == die->die_child)
7101 } while (c != die->die_child);
7104 /* We can only use this in debugging, since the frontend doesn't check
7105 to make sure that we leave every include file we enter. */
7109 assign_symbol_names (die);
7110 cu_hash_type cu_hash_table (10);
7111 for (node = limbo_die_list, pnode = &limbo_die_list;
7117 compute_section_prefix (node->die);
7118 is_dupl = check_duplicate_cu (node->die, &cu_hash_table,
7119 &comdat_symbol_number);
7120 assign_symbol_names (node->die);
7122 *pnode = node->next;
7125 pnode = &node->next;
7126 record_comdat_symbol_number (node->die, &cu_hash_table,
7127 comdat_symbol_number);
7132 /* Return non-zero if this DIE is a declaration. */
7135 is_declaration_die (dw_die_ref die)
7140 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7141 if (a->dw_attr == DW_AT_declaration)
7147 /* Return non-zero if this DIE is nested inside a subprogram. */
7150 is_nested_in_subprogram (dw_die_ref die)
7152 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
7156 return local_scope_p (decl);
7159 /* Return non-zero if this DIE contains a defining declaration of a
7163 contains_subprogram_definition (dw_die_ref die)
7167 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
7169 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition (c)) return 1);
7173 /* Return non-zero if this is a type DIE that should be moved to a
7174 COMDAT .debug_types section. */
7177 should_move_die_to_comdat (dw_die_ref die)
7179 switch (die->die_tag)
7181 case DW_TAG_class_type:
7182 case DW_TAG_structure_type:
7183 case DW_TAG_enumeration_type:
7184 case DW_TAG_union_type:
7185 /* Don't move declarations, inlined instances, types nested in a
7186 subprogram, or types that contain subprogram definitions. */
7187 if (is_declaration_die (die)
7188 || get_AT (die, DW_AT_abstract_origin)
7189 || is_nested_in_subprogram (die)
7190 || contains_subprogram_definition (die))
7193 case DW_TAG_array_type:
7194 case DW_TAG_interface_type:
7195 case DW_TAG_pointer_type:
7196 case DW_TAG_reference_type:
7197 case DW_TAG_rvalue_reference_type:
7198 case DW_TAG_string_type:
7199 case DW_TAG_subroutine_type:
7200 case DW_TAG_ptr_to_member_type:
7201 case DW_TAG_set_type:
7202 case DW_TAG_subrange_type:
7203 case DW_TAG_base_type:
7204 case DW_TAG_const_type:
7205 case DW_TAG_file_type:
7206 case DW_TAG_packed_type:
7207 case DW_TAG_volatile_type:
7208 case DW_TAG_typedef:
7214 /* Make a clone of DIE. */
7217 clone_die (dw_die_ref die)
7223 clone = ggc_cleared_alloc<die_node> ();
7224 clone->die_tag = die->die_tag;
7226 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7227 add_dwarf_attr (clone, a);
7232 /* Make a clone of the tree rooted at DIE. */
7235 clone_tree (dw_die_ref die)
7238 dw_die_ref clone = clone_die (die);
7240 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree (c)));
7245 /* Make a clone of DIE as a declaration. */
7248 clone_as_declaration (dw_die_ref die)
7255 /* If the DIE is already a declaration, just clone it. */
7256 if (is_declaration_die (die))
7257 return clone_die (die);
7259 /* If the DIE is a specification, just clone its declaration DIE. */
7260 decl = get_AT_ref (die, DW_AT_specification);
7263 clone = clone_die (decl);
7264 if (die->comdat_type_p)
7265 add_AT_die_ref (clone, DW_AT_signature, die);
7269 clone = ggc_cleared_alloc<die_node> ();
7270 clone->die_tag = die->die_tag;
7272 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7274 /* We don't want to copy over all attributes.
7275 For example we don't want DW_AT_byte_size because otherwise we will no
7276 longer have a declaration and GDB will treat it as a definition. */
7280 case DW_AT_abstract_origin:
7281 case DW_AT_artificial:
7282 case DW_AT_containing_type:
7283 case DW_AT_external:
7286 case DW_AT_virtuality:
7287 case DW_AT_linkage_name:
7288 case DW_AT_MIPS_linkage_name:
7289 add_dwarf_attr (clone, a);
7291 case DW_AT_byte_size:
7297 if (die->comdat_type_p)
7298 add_AT_die_ref (clone, DW_AT_signature, die);
7300 add_AT_flag (clone, DW_AT_declaration, 1);
7305 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7307 struct decl_table_entry
7313 /* Helpers to manipulate hash table of copied declarations. */
7315 /* Hashtable helpers. */
7317 struct decl_table_entry_hasher : free_ptr_hash <decl_table_entry>
7319 typedef die_struct *compare_type;
7320 static inline hashval_t hash (const decl_table_entry *);
7321 static inline bool equal (const decl_table_entry *, const die_struct *);
7325 decl_table_entry_hasher::hash (const decl_table_entry *entry)
7327 return htab_hash_pointer (entry->orig);
7331 decl_table_entry_hasher::equal (const decl_table_entry *entry1,
7332 const die_struct *entry2)
7334 return entry1->orig == entry2;
7337 typedef hash_table<decl_table_entry_hasher> decl_hash_type;
7339 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7340 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7341 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7342 to check if the ancestor has already been copied into UNIT. */
7345 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die,
7346 decl_hash_type *decl_table)
7348 dw_die_ref parent = die->die_parent;
7349 dw_die_ref new_parent = unit;
7351 decl_table_entry **slot = NULL;
7352 struct decl_table_entry *entry = NULL;
7356 /* Check if the entry has already been copied to UNIT. */
7357 slot = decl_table->find_slot_with_hash (die, htab_hash_pointer (die),
7359 if (*slot != HTAB_EMPTY_ENTRY)
7365 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7366 entry = XCNEW (struct decl_table_entry);
7374 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
7377 if (!is_unit_die (parent))
7378 new_parent = copy_ancestor_tree (unit, parent, decl_table);
7381 copy = clone_as_declaration (die);
7382 add_child_die (new_parent, copy);
7386 /* Record the pointer to the copy. */
7392 /* Copy the declaration context to the new type unit DIE. This includes
7393 any surrounding namespace or type declarations. If the DIE has an
7394 AT_specification attribute, it also includes attributes and children
7395 attached to the specification, and returns a pointer to the original
7396 parent of the declaration DIE. Returns NULL otherwise. */
7399 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
7402 dw_die_ref new_decl;
7403 dw_die_ref orig_parent = NULL;
7405 decl = get_AT_ref (die, DW_AT_specification);
7414 /* The original DIE will be changed to a declaration, and must
7415 be moved to be a child of the original declaration DIE. */
7416 orig_parent = decl->die_parent;
7418 /* Copy the type node pointer from the new DIE to the original
7419 declaration DIE so we can forward references later. */
7420 decl->comdat_type_p = true;
7421 decl->die_id.die_type_node = die->die_id.die_type_node;
7423 remove_AT (die, DW_AT_specification);
7425 FOR_EACH_VEC_SAFE_ELT (decl->die_attr, ix, a)
7427 if (a->dw_attr != DW_AT_name
7428 && a->dw_attr != DW_AT_declaration
7429 && a->dw_attr != DW_AT_external)
7430 add_dwarf_attr (die, a);
7433 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree (c)));
7436 if (decl->die_parent != NULL
7437 && !is_unit_die (decl->die_parent))
7439 new_decl = copy_ancestor_tree (unit, decl, NULL);
7440 if (new_decl != NULL)
7442 remove_AT (new_decl, DW_AT_signature);
7443 add_AT_specification (die, new_decl);
7450 /* Generate the skeleton ancestor tree for the given NODE, then clone
7451 the DIE and add the clone into the tree. */
7454 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
7456 if (node->new_die != NULL)
7459 node->new_die = clone_as_declaration (node->old_die);
7461 if (node->parent != NULL)
7463 generate_skeleton_ancestor_tree (node->parent);
7464 add_child_die (node->parent->new_die, node->new_die);
7468 /* Generate a skeleton tree of DIEs containing any declarations that are
7469 found in the original tree. We traverse the tree looking for declaration
7470 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7473 generate_skeleton_bottom_up (skeleton_chain_node *parent)
7475 skeleton_chain_node node;
7478 dw_die_ref prev = NULL;
7479 dw_die_ref next = NULL;
7481 node.parent = parent;
7483 first = c = parent->old_die->die_child;
7487 if (prev == NULL || prev->die_sib == c)
7490 next = (c == first ? NULL : c->die_sib);
7492 node.new_die = NULL;
7493 if (is_declaration_die (c))
7495 if (is_template_instantiation (c))
7497 /* Instantiated templates do not need to be cloned into the
7498 type unit. Just move the DIE and its children back to
7499 the skeleton tree (in the main CU). */
7500 remove_child_with_prev (c, prev);
7501 add_child_die (parent->new_die, c);
7506 /* Clone the existing DIE, move the original to the skeleton
7507 tree (which is in the main CU), and put the clone, with
7508 all the original's children, where the original came from
7509 (which is about to be moved to the type unit). */
7510 dw_die_ref clone = clone_die (c);
7511 move_all_children (c, clone);
7513 /* If the original has a DW_AT_object_pointer attribute,
7514 it would now point to a child DIE just moved to the
7515 cloned tree, so we need to remove that attribute from
7517 remove_AT (c, DW_AT_object_pointer);
7519 replace_child (c, clone, prev);
7520 generate_skeleton_ancestor_tree (parent);
7521 add_child_die (parent->new_die, c);
7526 generate_skeleton_bottom_up (&node);
7527 } while (next != NULL);
7530 /* Wrapper function for generate_skeleton_bottom_up. */
7533 generate_skeleton (dw_die_ref die)
7535 skeleton_chain_node node;
7538 node.new_die = NULL;
7541 /* If this type definition is nested inside another type,
7542 and is not an instantiation of a template, always leave
7543 at least a declaration in its place. */
7544 if (die->die_parent != NULL
7545 && is_type_die (die->die_parent)
7546 && !is_template_instantiation (die))
7547 node.new_die = clone_as_declaration (die);
7549 generate_skeleton_bottom_up (&node);
7550 return node.new_die;
7553 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7554 declaration. The original DIE is moved to a new compile unit so that
7555 existing references to it follow it to the new location. If any of the
7556 original DIE's descendants is a declaration, we need to replace the
7557 original DIE with a skeleton tree and move the declarations back into the
7561 remove_child_or_replace_with_skeleton (dw_die_ref unit, dw_die_ref child,
7564 dw_die_ref skeleton, orig_parent;
7566 /* Copy the declaration context to the type unit DIE. If the returned
7567 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7569 orig_parent = copy_declaration_context (unit, child);
7571 skeleton = generate_skeleton (child);
7572 if (skeleton == NULL)
7573 remove_child_with_prev (child, prev);
7576 skeleton->comdat_type_p = true;
7577 skeleton->die_id.die_type_node = child->die_id.die_type_node;
7579 /* If the original DIE was a specification, we need to put
7580 the skeleton under the parent DIE of the declaration.
7581 This leaves the original declaration in the tree, but
7582 it will be pruned later since there are no longer any
7583 references to it. */
7584 if (orig_parent != NULL)
7586 remove_child_with_prev (child, prev);
7587 add_child_die (orig_parent, skeleton);
7590 replace_child (child, skeleton, prev);
7596 /* Traverse the DIE and set up additional .debug_types sections for each
7597 type worthy of being placed in a COMDAT section. */
7600 break_out_comdat_types (dw_die_ref die)
7604 dw_die_ref prev = NULL;
7605 dw_die_ref next = NULL;
7606 dw_die_ref unit = NULL;
7608 first = c = die->die_child;
7612 if (prev == NULL || prev->die_sib == c)
7615 next = (c == first ? NULL : c->die_sib);
7616 if (should_move_die_to_comdat (c))
7618 dw_die_ref replacement;
7619 comdat_type_node *type_node;
7621 /* Break out nested types into their own type units. */
7622 break_out_comdat_types (c);
7624 /* Create a new type unit DIE as the root for the new tree, and
7625 add it to the list of comdat types. */
7626 unit = new_die (DW_TAG_type_unit, NULL, NULL);
7627 add_AT_unsigned (unit, DW_AT_language,
7628 get_AT_unsigned (comp_unit_die (), DW_AT_language));
7629 type_node = ggc_cleared_alloc<comdat_type_node> ();
7630 type_node->root_die = unit;
7631 type_node->next = comdat_type_list;
7632 comdat_type_list = type_node;
7634 /* Generate the type signature. */
7635 generate_type_signature (c, type_node);
7637 /* Copy the declaration context, attributes, and children of the
7638 declaration into the new type unit DIE, then remove this DIE
7639 from the main CU (or replace it with a skeleton if necessary). */
7640 replacement = remove_child_or_replace_with_skeleton (unit, c, prev);
7641 type_node->skeleton_die = replacement;
7643 /* Add the DIE to the new compunit. */
7644 add_child_die (unit, c);
7646 if (replacement != NULL)
7649 else if (c->die_tag == DW_TAG_namespace
7650 || c->die_tag == DW_TAG_class_type
7651 || c->die_tag == DW_TAG_structure_type
7652 || c->die_tag == DW_TAG_union_type)
7654 /* Look for nested types that can be broken out. */
7655 break_out_comdat_types (c);
7657 } while (next != NULL);
7660 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7661 Enter all the cloned children into the hash table decl_table. */
7664 clone_tree_partial (dw_die_ref die, decl_hash_type *decl_table)
7668 struct decl_table_entry *entry;
7669 decl_table_entry **slot;
7671 if (die->die_tag == DW_TAG_subprogram)
7672 clone = clone_as_declaration (die);
7674 clone = clone_die (die);
7676 slot = decl_table->find_slot_with_hash (die,
7677 htab_hash_pointer (die), INSERT);
7679 /* Assert that DIE isn't in the hash table yet. If it would be there
7680 before, the ancestors would be necessarily there as well, therefore
7681 clone_tree_partial wouldn't be called. */
7682 gcc_assert (*slot == HTAB_EMPTY_ENTRY);
7684 entry = XCNEW (struct decl_table_entry);
7686 entry->copy = clone;
7689 if (die->die_tag != DW_TAG_subprogram)
7690 FOR_EACH_CHILD (die, c,
7691 add_child_die (clone, clone_tree_partial (c, decl_table)));
7696 /* Walk the DIE and its children, looking for references to incomplete
7697 or trivial types that are unmarked (i.e., that are not in the current
7701 copy_decls_walk (dw_die_ref unit, dw_die_ref die, decl_hash_type *decl_table)
7707 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7709 if (AT_class (a) == dw_val_class_die_ref)
7711 dw_die_ref targ = AT_ref (a);
7712 decl_table_entry **slot;
7713 struct decl_table_entry *entry;
7715 if (targ->die_mark != 0 || targ->comdat_type_p)
7718 slot = decl_table->find_slot_with_hash (targ,
7719 htab_hash_pointer (targ),
7722 if (*slot != HTAB_EMPTY_ENTRY)
7724 /* TARG has already been copied, so we just need to
7725 modify the reference to point to the copy. */
7727 a->dw_attr_val.v.val_die_ref.die = entry->copy;
7731 dw_die_ref parent = unit;
7732 dw_die_ref copy = clone_die (targ);
7734 /* Record in DECL_TABLE that TARG has been copied.
7735 Need to do this now, before the recursive call,
7736 because DECL_TABLE may be expanded and SLOT
7737 would no longer be a valid pointer. */
7738 entry = XCNEW (struct decl_table_entry);
7743 /* If TARG is not a declaration DIE, we need to copy its
7745 if (!is_declaration_die (targ))
7749 add_child_die (copy,
7750 clone_tree_partial (c, decl_table)));
7753 /* Make sure the cloned tree is marked as part of the
7757 /* If TARG has surrounding context, copy its ancestor tree
7758 into the new type unit. */
7759 if (targ->die_parent != NULL
7760 && !is_unit_die (targ->die_parent))
7761 parent = copy_ancestor_tree (unit, targ->die_parent,
7764 add_child_die (parent, copy);
7765 a->dw_attr_val.v.val_die_ref.die = copy;
7767 /* Make sure the newly-copied DIE is walked. If it was
7768 installed in a previously-added context, it won't
7769 get visited otherwise. */
7772 /* Find the highest point of the newly-added tree,
7773 mark each node along the way, and walk from there. */
7774 parent->die_mark = 1;
7775 while (parent->die_parent
7776 && parent->die_parent->die_mark == 0)
7778 parent = parent->die_parent;
7779 parent->die_mark = 1;
7781 copy_decls_walk (unit, parent, decl_table);
7787 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
7790 /* Copy declarations for "unworthy" types into the new comdat section.
7791 Incomplete types, modified types, and certain other types aren't broken
7792 out into comdat sections of their own, so they don't have a signature,
7793 and we need to copy the declaration into the same section so that we
7794 don't have an external reference. */
7797 copy_decls_for_unworthy_types (dw_die_ref unit)
7800 decl_hash_type decl_table (10);
7801 copy_decls_walk (unit, unit, &decl_table);
7805 /* Traverse the DIE and add a sibling attribute if it may have the
7806 effect of speeding up access to siblings. To save some space,
7807 avoid generating sibling attributes for DIE's without children. */
7810 add_sibling_attributes (dw_die_ref die)
7814 if (! die->die_child)
7817 if (die->die_parent && die != die->die_parent->die_child)
7818 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7820 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7823 /* Output all location lists for the DIE and its children. */
7826 output_location_lists (dw_die_ref die)
7832 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7833 if (AT_class (a) == dw_val_class_loc_list)
7834 output_loc_list (AT_loc_list (a));
7836 FOR_EACH_CHILD (die, c, output_location_lists (c));
7839 /* We want to limit the number of external references, because they are
7840 larger than local references: a relocation takes multiple words, and
7841 even a sig8 reference is always eight bytes, whereas a local reference
7842 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7843 So if we encounter multiple external references to the same type DIE, we
7844 make a local typedef stub for it and redirect all references there.
7846 This is the element of the hash table for keeping track of these
7856 /* Hashtable helpers. */
7858 struct external_ref_hasher : free_ptr_hash <external_ref>
7860 static inline hashval_t hash (const external_ref *);
7861 static inline bool equal (const external_ref *, const external_ref *);
7865 external_ref_hasher::hash (const external_ref *r)
7867 dw_die_ref die = r->type;
7870 /* We can't use the address of the DIE for hashing, because
7871 that will make the order of the stub DIEs non-deterministic. */
7872 if (! die->comdat_type_p)
7873 /* We have a symbol; use it to compute a hash. */
7874 h = htab_hash_string (die->die_id.die_symbol);
7877 /* We have a type signature; use a subset of the bits as the hash.
7878 The 8-byte signature is at least as large as hashval_t. */
7879 comdat_type_node *type_node = die->die_id.die_type_node;
7880 memcpy (&h, type_node->signature, sizeof (h));
7886 external_ref_hasher::equal (const external_ref *r1, const external_ref *r2)
7888 return r1->type == r2->type;
7891 typedef hash_table<external_ref_hasher> external_ref_hash_type;
7893 /* Return a pointer to the external_ref for references to DIE. */
7895 static struct external_ref *
7896 lookup_external_ref (external_ref_hash_type *map, dw_die_ref die)
7898 struct external_ref ref, *ref_p;
7899 external_ref **slot;
7902 slot = map->find_slot (&ref, INSERT);
7903 if (*slot != HTAB_EMPTY_ENTRY)
7906 ref_p = XCNEW (struct external_ref);
7912 /* Subroutine of optimize_external_refs, below.
7914 If we see a type skeleton, record it as our stub. If we see external
7915 references, remember how many we've seen. */
7918 optimize_external_refs_1 (dw_die_ref die, external_ref_hash_type *map)
7923 struct external_ref *ref_p;
7925 if (is_type_die (die)
7926 && (c = get_AT_ref (die, DW_AT_signature)))
7928 /* This is a local skeleton; use it for local references. */
7929 ref_p = lookup_external_ref (map, c);
7933 /* Scan the DIE references, and remember any that refer to DIEs from
7934 other CUs (i.e. those which are not marked). */
7935 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7936 if (AT_class (a) == dw_val_class_die_ref
7937 && (c = AT_ref (a))->die_mark == 0
7940 ref_p = lookup_external_ref (map, c);
7944 FOR_EACH_CHILD (die, c, optimize_external_refs_1 (c, map));
7947 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7948 points to an external_ref, DATA is the CU we're processing. If we don't
7949 already have a local stub, and we have multiple refs, build a stub. */
7952 dwarf2_build_local_stub (external_ref **slot, dw_die_ref data)
7954 struct external_ref *ref_p = *slot;
7956 if (ref_p->stub == NULL && ref_p->n_refs > 1 && !dwarf_strict)
7958 /* We have multiple references to this type, so build a small stub.
7959 Both of these forms are a bit dodgy from the perspective of the
7960 DWARF standard, since technically they should have names. */
7961 dw_die_ref cu = data;
7962 dw_die_ref type = ref_p->type;
7963 dw_die_ref stub = NULL;
7965 if (type->comdat_type_p)
7967 /* If we refer to this type via sig8, use AT_signature. */
7968 stub = new_die (type->die_tag, cu, NULL_TREE);
7969 add_AT_die_ref (stub, DW_AT_signature, type);
7973 /* Otherwise, use a typedef with no name. */
7974 stub = new_die (DW_TAG_typedef, cu, NULL_TREE);
7975 add_AT_die_ref (stub, DW_AT_type, type);
7984 /* DIE is a unit; look through all the DIE references to see if there are
7985 any external references to types, and if so, create local stubs for
7986 them which will be applied in build_abbrev_table. This is useful because
7987 references to local DIEs are smaller. */
7989 static external_ref_hash_type *
7990 optimize_external_refs (dw_die_ref die)
7992 external_ref_hash_type *map = new external_ref_hash_type (10);
7993 optimize_external_refs_1 (die, map);
7994 map->traverse <dw_die_ref, dwarf2_build_local_stub> (die);
7998 /* The format of each DIE (and its attribute value pairs) is encoded in an
7999 abbreviation table. This routine builds the abbreviation table and assigns
8000 a unique abbreviation id for each abbreviation entry. The children of each
8001 die are visited recursively. */
8004 build_abbrev_table (dw_die_ref die, external_ref_hash_type *extern_map)
8006 unsigned long abbrev_id;
8007 unsigned int n_alloc;
8012 /* Scan the DIE references, and replace any that refer to
8013 DIEs from other CUs (i.e. those which are not marked) with
8014 the local stubs we built in optimize_external_refs. */
8015 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8016 if (AT_class (a) == dw_val_class_die_ref
8017 && (c = AT_ref (a))->die_mark == 0)
8019 struct external_ref *ref_p;
8020 gcc_assert (AT_ref (a)->comdat_type_p || AT_ref (a)->die_id.die_symbol);
8022 ref_p = lookup_external_ref (extern_map, c);
8023 if (ref_p->stub && ref_p->stub != die)
8024 change_AT_die_ref (a, ref_p->stub);
8026 /* We aren't changing this reference, so mark it external. */
8027 set_AT_ref_external (a, 1);
8030 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8032 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8033 dw_attr_node *die_a, *abbrev_a;
8037 if (abbrev->die_tag != die->die_tag)
8039 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
8042 if (vec_safe_length (abbrev->die_attr) != vec_safe_length (die->die_attr))
8045 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, die_a)
8047 abbrev_a = &(*abbrev->die_attr)[ix];
8048 if ((abbrev_a->dw_attr != die_a->dw_attr)
8049 || (value_format (abbrev_a) != value_format (die_a)))
8059 if (abbrev_id >= abbrev_die_table_in_use)
8061 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
8063 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
8064 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8067 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8068 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8069 abbrev_die_table_allocated = n_alloc;
8072 ++abbrev_die_table_in_use;
8073 abbrev_die_table[abbrev_id] = die;
8076 die->die_abbrev = abbrev_id;
8077 FOR_EACH_CHILD (die, c, build_abbrev_table (c, extern_map));
8080 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8083 constant_size (unsigned HOST_WIDE_INT value)
8090 log = floor_log2 (value);
8093 log = 1 << (floor_log2 (log) + 1);
8098 /* Return the size of a DIE as it is represented in the
8099 .debug_info section. */
8101 static unsigned long
8102 size_of_die (dw_die_ref die)
8104 unsigned long size = 0;
8107 enum dwarf_form form;
8109 size += size_of_uleb128 (die->die_abbrev);
8110 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8112 switch (AT_class (a))
8114 case dw_val_class_addr:
8115 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8117 gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
8118 size += size_of_uleb128 (AT_index (a));
8121 size += DWARF2_ADDR_SIZE;
8123 case dw_val_class_offset:
8124 size += DWARF_OFFSET_SIZE;
8126 case dw_val_class_loc:
8128 unsigned long lsize = size_of_locs (AT_loc (a));
8131 if (dwarf_version >= 4)
8132 size += size_of_uleb128 (lsize);
8134 size += constant_size (lsize);
8138 case dw_val_class_loc_list:
8139 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8141 gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
8142 size += size_of_uleb128 (AT_index (a));
8145 size += DWARF_OFFSET_SIZE;
8147 case dw_val_class_range_list:
8148 size += DWARF_OFFSET_SIZE;
8150 case dw_val_class_const:
8151 size += size_of_sleb128 (AT_int (a));
8153 case dw_val_class_unsigned_const:
8155 int csize = constant_size (AT_unsigned (a));
8156 if (dwarf_version == 3
8157 && a->dw_attr == DW_AT_data_member_location
8159 size += size_of_uleb128 (AT_unsigned (a));
8164 case dw_val_class_const_double:
8165 size += HOST_BITS_PER_DOUBLE_INT / HOST_BITS_PER_CHAR;
8166 if (HOST_BITS_PER_WIDE_INT >= 64)
8169 case dw_val_class_wide_int:
8170 size += (get_full_len (*a->dw_attr_val.v.val_wide)
8171 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
8172 if (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT
8176 case dw_val_class_vec:
8177 size += constant_size (a->dw_attr_val.v.val_vec.length
8178 * a->dw_attr_val.v.val_vec.elt_size)
8179 + a->dw_attr_val.v.val_vec.length
8180 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8182 case dw_val_class_flag:
8183 if (dwarf_version >= 4)
8184 /* Currently all add_AT_flag calls pass in 1 as last argument,
8185 so DW_FORM_flag_present can be used. If that ever changes,
8186 we'll need to use DW_FORM_flag and have some optimization
8187 in build_abbrev_table that will change those to
8188 DW_FORM_flag_present if it is set to 1 in all DIEs using
8189 the same abbrev entry. */
8190 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8194 case dw_val_class_die_ref:
8195 if (AT_ref_external (a))
8197 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8198 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8199 is sized by target address length, whereas in DWARF3
8200 it's always sized as an offset. */
8201 if (use_debug_types)
8202 size += DWARF_TYPE_SIGNATURE_SIZE;
8203 else if (dwarf_version == 2)
8204 size += DWARF2_ADDR_SIZE;
8206 size += DWARF_OFFSET_SIZE;
8209 size += DWARF_OFFSET_SIZE;
8211 case dw_val_class_fde_ref:
8212 size += DWARF_OFFSET_SIZE;
8214 case dw_val_class_lbl_id:
8215 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8217 gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
8218 size += size_of_uleb128 (AT_index (a));
8221 size += DWARF2_ADDR_SIZE;
8223 case dw_val_class_lineptr:
8224 case dw_val_class_macptr:
8225 size += DWARF_OFFSET_SIZE;
8227 case dw_val_class_str:
8228 form = AT_string_form (a);
8229 if (form == DW_FORM_strp)
8230 size += DWARF_OFFSET_SIZE;
8231 else if (form == DW_FORM_GNU_str_index)
8232 size += size_of_uleb128 (AT_index (a));
8234 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8236 case dw_val_class_file:
8237 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8239 case dw_val_class_data8:
8242 case dw_val_class_vms_delta:
8243 size += DWARF_OFFSET_SIZE;
8245 case dw_val_class_high_pc:
8246 size += DWARF2_ADDR_SIZE;
8256 /* Size the debugging information associated with a given DIE. Visits the
8257 DIE's children recursively. Updates the global variable next_die_offset, on
8258 each time through. Uses the current value of next_die_offset to update the
8259 die_offset field in each DIE. */
8262 calc_die_sizes (dw_die_ref die)
8266 gcc_assert (die->die_offset == 0
8267 || (unsigned long int) die->die_offset == next_die_offset);
8268 die->die_offset = next_die_offset;
8269 next_die_offset += size_of_die (die);
8271 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8273 if (die->die_child != NULL)
8274 /* Count the null byte used to terminate sibling lists. */
8275 next_die_offset += 1;
8278 /* Size just the base type children at the start of the CU.
8279 This is needed because build_abbrev needs to size locs
8280 and sizing of type based stack ops needs to know die_offset
8281 values for the base types. */
8284 calc_base_type_die_sizes (void)
8286 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8288 dw_die_ref base_type;
8289 #if ENABLE_ASSERT_CHECKING
8290 dw_die_ref prev = comp_unit_die ()->die_child;
8293 die_offset += size_of_die (comp_unit_die ());
8294 for (i = 0; base_types.iterate (i, &base_type); i++)
8296 #if ENABLE_ASSERT_CHECKING
8297 gcc_assert (base_type->die_offset == 0
8298 && prev->die_sib == base_type
8299 && base_type->die_child == NULL
8300 && base_type->die_abbrev);
8303 base_type->die_offset = die_offset;
8304 die_offset += size_of_die (base_type);
8308 /* Set the marks for a die and its children. We do this so
8309 that we know whether or not a reference needs to use FORM_ref_addr; only
8310 DIEs in the same CU will be marked. We used to clear out the offset
8311 and use that as the flag, but ran into ordering problems. */
8314 mark_dies (dw_die_ref die)
8318 gcc_assert (!die->die_mark);
8321 FOR_EACH_CHILD (die, c, mark_dies (c));
8324 /* Clear the marks for a die and its children. */
8327 unmark_dies (dw_die_ref die)
8331 if (! use_debug_types)
8332 gcc_assert (die->die_mark);
8335 FOR_EACH_CHILD (die, c, unmark_dies (c));
8338 /* Clear the marks for a die, its children and referred dies. */
8341 unmark_all_dies (dw_die_ref die)
8351 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8353 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8354 if (AT_class (a) == dw_val_class_die_ref)
8355 unmark_all_dies (AT_ref (a));
8358 /* Calculate if the entry should appear in the final output file. It may be
8359 from a pruned a type. */
8362 include_pubname_in_output (vec<pubname_entry, va_gc> *table, pubname_entry *p)
8364 /* By limiting gnu pubnames to definitions only, gold can generate a
8365 gdb index without entries for declarations, which don't include
8366 enough information to be useful. */
8367 if (debug_generate_pub_sections == 2 && is_declaration_die (p->die))
8370 if (table == pubname_table)
8372 /* Enumerator names are part of the pubname table, but the
8373 parent DW_TAG_enumeration_type die may have been pruned.
8374 Don't output them if that is the case. */
8375 if (p->die->die_tag == DW_TAG_enumerator &&
8376 (p->die->die_parent == NULL
8377 || !p->die->die_parent->die_perennial_p))
8380 /* Everything else in the pubname table is included. */
8384 /* The pubtypes table shouldn't include types that have been
8386 return (p->die->die_offset != 0
8387 || !flag_eliminate_unused_debug_types);
8390 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8391 generated for the compilation unit. */
8393 static unsigned long
8394 size_of_pubnames (vec<pubname_entry, va_gc> *names)
8399 int space_for_flags = (debug_generate_pub_sections == 2) ? 1 : 0;
8401 size = DWARF_PUBNAMES_HEADER_SIZE;
8402 FOR_EACH_VEC_ELT (*names, i, p)
8403 if (include_pubname_in_output (names, p))
8404 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1 + space_for_flags;
8406 size += DWARF_OFFSET_SIZE;
8410 /* Return the size of the information in the .debug_aranges section. */
8412 static unsigned long
8413 size_of_aranges (void)
8417 size = DWARF_ARANGES_HEADER_SIZE;
8419 /* Count the address/length pair for this compilation unit. */
8420 if (text_section_used)
8421 size += 2 * DWARF2_ADDR_SIZE;
8422 if (cold_text_section_used)
8423 size += 2 * DWARF2_ADDR_SIZE;
8424 if (have_multiple_function_sections)
8429 FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
8431 if (DECL_IGNORED_P (fde->decl))
8433 if (!fde->in_std_section)
8434 size += 2 * DWARF2_ADDR_SIZE;
8435 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
8436 size += 2 * DWARF2_ADDR_SIZE;
8440 /* Count the two zero words used to terminated the address range table. */
8441 size += 2 * DWARF2_ADDR_SIZE;
8445 /* Select the encoding of an attribute value. */
8447 static enum dwarf_form
8448 value_format (dw_attr_node *a)
8450 switch (AT_class (a))
8452 case dw_val_class_addr:
8453 /* Only very few attributes allow DW_FORM_addr. */
8458 case DW_AT_entry_pc:
8459 case DW_AT_trampoline:
8460 return (AT_index (a) == NOT_INDEXED
8461 ? DW_FORM_addr : DW_FORM_GNU_addr_index);
8465 switch (DWARF2_ADDR_SIZE)
8468 return DW_FORM_data1;
8470 return DW_FORM_data2;
8472 return DW_FORM_data4;
8474 return DW_FORM_data8;
8478 case dw_val_class_range_list:
8479 case dw_val_class_loc_list:
8480 if (dwarf_version >= 4)
8481 return DW_FORM_sec_offset;
8483 case dw_val_class_vms_delta:
8484 case dw_val_class_offset:
8485 switch (DWARF_OFFSET_SIZE)
8488 return DW_FORM_data4;
8490 return DW_FORM_data8;
8494 case dw_val_class_loc:
8495 if (dwarf_version >= 4)
8496 return DW_FORM_exprloc;
8497 switch (constant_size (size_of_locs (AT_loc (a))))
8500 return DW_FORM_block1;
8502 return DW_FORM_block2;
8504 return DW_FORM_block4;
8508 case dw_val_class_const:
8509 return DW_FORM_sdata;
8510 case dw_val_class_unsigned_const:
8511 switch (constant_size (AT_unsigned (a)))
8514 return DW_FORM_data1;
8516 return DW_FORM_data2;
8518 /* In DWARF3 DW_AT_data_member_location with
8519 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8520 constant, so we need to use DW_FORM_udata if we need
8521 a large constant. */
8522 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
8523 return DW_FORM_udata;
8524 return DW_FORM_data4;
8526 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
8527 return DW_FORM_udata;
8528 return DW_FORM_data8;
8532 case dw_val_class_const_double:
8533 switch (HOST_BITS_PER_WIDE_INT)
8536 return DW_FORM_data2;
8538 return DW_FORM_data4;
8540 return DW_FORM_data8;
8543 return DW_FORM_block1;
8545 case dw_val_class_wide_int:
8546 switch (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT)
8549 return DW_FORM_data1;
8551 return DW_FORM_data2;
8553 return DW_FORM_data4;
8555 return DW_FORM_data8;
8557 return DW_FORM_block1;
8559 case dw_val_class_vec:
8560 switch (constant_size (a->dw_attr_val.v.val_vec.length
8561 * a->dw_attr_val.v.val_vec.elt_size))
8564 return DW_FORM_block1;
8566 return DW_FORM_block2;
8568 return DW_FORM_block4;
8572 case dw_val_class_flag:
8573 if (dwarf_version >= 4)
8575 /* Currently all add_AT_flag calls pass in 1 as last argument,
8576 so DW_FORM_flag_present can be used. If that ever changes,
8577 we'll need to use DW_FORM_flag and have some optimization
8578 in build_abbrev_table that will change those to
8579 DW_FORM_flag_present if it is set to 1 in all DIEs using
8580 the same abbrev entry. */
8581 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8582 return DW_FORM_flag_present;
8584 return DW_FORM_flag;
8585 case dw_val_class_die_ref:
8586 if (AT_ref_external (a))
8587 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
8590 case dw_val_class_fde_ref:
8591 return DW_FORM_data;
8592 case dw_val_class_lbl_id:
8593 return (AT_index (a) == NOT_INDEXED
8594 ? DW_FORM_addr : DW_FORM_GNU_addr_index);
8595 case dw_val_class_lineptr:
8596 case dw_val_class_macptr:
8597 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
8598 case dw_val_class_str:
8599 return AT_string_form (a);
8600 case dw_val_class_file:
8601 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8604 return DW_FORM_data1;
8606 return DW_FORM_data2;
8608 return DW_FORM_data4;
8613 case dw_val_class_data8:
8614 return DW_FORM_data8;
8616 case dw_val_class_high_pc:
8617 switch (DWARF2_ADDR_SIZE)
8620 return DW_FORM_data1;
8622 return DW_FORM_data2;
8624 return DW_FORM_data4;
8626 return DW_FORM_data8;
8636 /* Output the encoding of an attribute value. */
8639 output_value_format (dw_attr_node *a)
8641 enum dwarf_form form = value_format (a);
8643 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8646 /* Given a die and id, produce the appropriate abbreviations. */
8649 output_die_abbrevs (unsigned long abbrev_id, dw_die_ref abbrev)
8652 dw_attr_node *a_attr;
8654 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8655 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8656 dwarf_tag_name (abbrev->die_tag));
8658 if (abbrev->die_child != NULL)
8659 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8661 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8663 for (ix = 0; vec_safe_iterate (abbrev->die_attr, ix, &a_attr); ix++)
8665 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8666 dwarf_attr_name (a_attr->dw_attr));
8667 output_value_format (a_attr);
8670 dw2_asm_output_data (1, 0, NULL);
8671 dw2_asm_output_data (1, 0, NULL);
8675 /* Output the .debug_abbrev section which defines the DIE abbreviation
8679 output_abbrev_section (void)
8681 unsigned long abbrev_id;
8683 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8684 output_die_abbrevs (abbrev_id, abbrev_die_table[abbrev_id]);
8686 /* Terminate the table. */
8687 dw2_asm_output_data (1, 0, NULL);
8690 /* Output a symbol we can use to refer to this DIE from another CU. */
8693 output_die_symbol (dw_die_ref die)
8695 const char *sym = die->die_id.die_symbol;
8697 gcc_assert (!die->comdat_type_p);
8702 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8703 /* We make these global, not weak; if the target doesn't support
8704 .linkonce, it doesn't support combining the sections, so debugging
8706 targetm.asm_out.globalize_label (asm_out_file, sym);
8708 ASM_OUTPUT_LABEL (asm_out_file, sym);
8711 /* Return a new location list, given the begin and end range, and the
8714 static inline dw_loc_list_ref
8715 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8716 const char *section)
8718 dw_loc_list_ref retlist = ggc_cleared_alloc<dw_loc_list_node> ();
8720 retlist->begin = begin;
8721 retlist->begin_entry = NULL;
8723 retlist->expr = expr;
8724 retlist->section = section;
8729 /* Generate a new internal symbol for this location list node, if it
8730 hasn't got one yet. */
8733 gen_llsym (dw_loc_list_ref list)
8735 gcc_assert (!list->ll_symbol);
8736 list->ll_symbol = gen_internal_sym ("LLST");
8739 /* Output the location list given to us. */
8742 output_loc_list (dw_loc_list_ref list_head)
8744 dw_loc_list_ref curr = list_head;
8746 if (list_head->emitted)
8748 list_head->emitted = true;
8750 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8752 /* Walk the location list, and output each range + expression. */
8753 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8756 /* Don't output an entry that starts and ends at the same address. */
8757 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
8759 size = size_of_locs (curr->expr);
8760 /* If the expression is too large, drop it on the floor. We could
8761 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8762 in the expression, but >= 64KB expressions for a single value
8763 in a single range are unlikely very useful. */
8766 if (dwarf_split_debug_info)
8768 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry,
8769 "Location list start/length entry (%s)",
8770 list_head->ll_symbol);
8771 dw2_asm_output_data_uleb128 (curr->begin_entry->index,
8772 "Location list range start index (%s)",
8774 /* The length field is 4 bytes. If we ever need to support
8775 an 8-byte length, we can add a new DW_LLE code or fall back
8776 to DW_LLE_GNU_start_end_entry. */
8777 dw2_asm_output_delta (4, curr->end, curr->begin,
8778 "Location list range length (%s)",
8779 list_head->ll_symbol);
8781 else if (!have_multiple_function_sections)
8783 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8784 "Location list begin address (%s)",
8785 list_head->ll_symbol);
8786 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8787 "Location list end address (%s)",
8788 list_head->ll_symbol);
8792 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8793 "Location list begin address (%s)",
8794 list_head->ll_symbol);
8795 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8796 "Location list end address (%s)",
8797 list_head->ll_symbol);
8800 /* Output the block length for this list of location operations. */
8801 gcc_assert (size <= 0xffff);
8802 dw2_asm_output_data (2, size, "%s", "Location expression size");
8804 output_loc_sequence (curr->expr, -1);
8807 if (dwarf_split_debug_info)
8808 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry,
8809 "Location list terminator (%s)",
8810 list_head->ll_symbol);
8813 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8814 "Location list terminator begin (%s)",
8815 list_head->ll_symbol);
8816 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8817 "Location list terminator end (%s)",
8818 list_head->ll_symbol);
8822 /* Output a range_list offset into the debug_range section. Emit a
8823 relocated reference if val_entry is NULL, otherwise, emit an
8824 indirect reference. */
8827 output_range_list_offset (dw_attr_node *a)
8829 const char *name = dwarf_attr_name (a->dw_attr);
8831 if (a->dw_attr_val.val_entry == RELOCATED_OFFSET)
8833 char *p = strchr (ranges_section_label, '\0');
8834 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX, a->dw_attr_val.v.val_offset);
8835 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8836 debug_ranges_section, "%s", name);
8840 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8841 "%s (offset from %s)", name, ranges_section_label);
8844 /* Output the offset into the debug_loc section. */
8847 output_loc_list_offset (dw_attr_node *a)
8849 char *sym = AT_loc_list (a)->ll_symbol;
8852 if (dwarf_split_debug_info)
8853 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label,
8854 "%s", dwarf_attr_name (a->dw_attr));
8856 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8857 "%s", dwarf_attr_name (a->dw_attr));
8860 /* Output an attribute's index or value appropriately. */
8863 output_attr_index_or_value (dw_attr_node *a)
8865 const char *name = dwarf_attr_name (a->dw_attr);
8867 if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
8869 dw2_asm_output_data_uleb128 (AT_index (a), "%s", name);
8872 switch (AT_class (a))
8874 case dw_val_class_addr:
8875 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8877 case dw_val_class_high_pc:
8878 case dw_val_class_lbl_id:
8879 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8881 case dw_val_class_loc_list:
8882 output_loc_list_offset (a);
8889 /* Output a type signature. */
8892 output_signature (const char *sig, const char *name)
8896 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8897 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
8900 /* Output the DIE and its attributes. Called recursively to generate
8901 the definitions of each child DIE. */
8904 output_die (dw_die_ref die)
8911 /* If someone in another CU might refer to us, set up a symbol for
8912 them to point to. */
8913 if (! die->comdat_type_p && die->die_id.die_symbol)
8914 output_die_symbol (die);
8916 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
8917 (unsigned long)die->die_offset,
8918 dwarf_tag_name (die->die_tag));
8920 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8922 const char *name = dwarf_attr_name (a->dw_attr);
8924 switch (AT_class (a))
8926 case dw_val_class_addr:
8927 output_attr_index_or_value (a);
8930 case dw_val_class_offset:
8931 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8935 case dw_val_class_range_list:
8936 output_range_list_offset (a);
8939 case dw_val_class_loc:
8940 size = size_of_locs (AT_loc (a));
8942 /* Output the block length for this list of location operations. */
8943 if (dwarf_version >= 4)
8944 dw2_asm_output_data_uleb128 (size, "%s", name);
8946 dw2_asm_output_data (constant_size (size), size, "%s", name);
8948 output_loc_sequence (AT_loc (a), -1);
8951 case dw_val_class_const:
8952 /* ??? It would be slightly more efficient to use a scheme like is
8953 used for unsigned constants below, but gdb 4.x does not sign
8954 extend. Gdb 5.x does sign extend. */
8955 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8958 case dw_val_class_unsigned_const:
8960 int csize = constant_size (AT_unsigned (a));
8961 if (dwarf_version == 3
8962 && a->dw_attr == DW_AT_data_member_location
8964 dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name);
8966 dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
8970 case dw_val_class_const_double:
8972 unsigned HOST_WIDE_INT first, second;
8974 if (HOST_BITS_PER_WIDE_INT >= 64)
8975 dw2_asm_output_data (1,
8976 HOST_BITS_PER_DOUBLE_INT
8977 / HOST_BITS_PER_CHAR,
8980 if (WORDS_BIG_ENDIAN)
8982 first = a->dw_attr_val.v.val_double.high;
8983 second = a->dw_attr_val.v.val_double.low;
8987 first = a->dw_attr_val.v.val_double.low;
8988 second = a->dw_attr_val.v.val_double.high;
8991 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8993 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8998 case dw_val_class_wide_int:
9001 int len = get_full_len (*a->dw_attr_val.v.val_wide);
9002 int l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
9003 if (len * HOST_BITS_PER_WIDE_INT > 64)
9004 dw2_asm_output_data (1, get_full_len (*a->dw_attr_val.v.val_wide) * l,
9007 if (WORDS_BIG_ENDIAN)
9008 for (i = len - 1; i >= 0; --i)
9010 dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
9015 for (i = 0; i < len; ++i)
9017 dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
9024 case dw_val_class_vec:
9026 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
9027 unsigned int len = a->dw_attr_val.v.val_vec.length;
9031 dw2_asm_output_data (constant_size (len * elt_size),
9032 len * elt_size, "%s", name);
9033 if (elt_size > sizeof (HOST_WIDE_INT))
9038 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
9041 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
9042 "fp or vector constant word %u", i);
9046 case dw_val_class_flag:
9047 if (dwarf_version >= 4)
9049 /* Currently all add_AT_flag calls pass in 1 as last argument,
9050 so DW_FORM_flag_present can be used. If that ever changes,
9051 we'll need to use DW_FORM_flag and have some optimization
9052 in build_abbrev_table that will change those to
9053 DW_FORM_flag_present if it is set to 1 in all DIEs using
9054 the same abbrev entry. */
9055 gcc_assert (AT_flag (a) == 1);
9057 fprintf (asm_out_file, "\t\t\t%s %s\n",
9058 ASM_COMMENT_START, name);
9061 dw2_asm_output_data (1, AT_flag (a), "%s", name);
9064 case dw_val_class_loc_list:
9065 output_attr_index_or_value (a);
9068 case dw_val_class_die_ref:
9069 if (AT_ref_external (a))
9071 if (AT_ref (a)->comdat_type_p)
9073 comdat_type_node *type_node =
9074 AT_ref (a)->die_id.die_type_node;
9076 gcc_assert (type_node);
9077 output_signature (type_node->signature, name);
9081 const char *sym = AT_ref (a)->die_id.die_symbol;
9085 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9086 length, whereas in DWARF3 it's always sized as an
9088 if (dwarf_version == 2)
9089 size = DWARF2_ADDR_SIZE;
9091 size = DWARF_OFFSET_SIZE;
9092 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
9098 gcc_assert (AT_ref (a)->die_offset);
9099 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
9104 case dw_val_class_fde_ref:
9108 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
9109 a->dw_attr_val.v.val_fde_index * 2);
9110 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
9115 case dw_val_class_vms_delta:
9116 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9117 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
9118 AT_vms_delta2 (a), AT_vms_delta1 (a),
9121 dw2_asm_output_delta (DWARF_OFFSET_SIZE,
9122 AT_vms_delta2 (a), AT_vms_delta1 (a),
9127 case dw_val_class_lbl_id:
9128 output_attr_index_or_value (a);
9131 case dw_val_class_lineptr:
9132 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9133 debug_line_section, "%s", name);
9136 case dw_val_class_macptr:
9137 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9138 debug_macinfo_section, "%s", name);
9141 case dw_val_class_str:
9142 if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
9143 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
9144 a->dw_attr_val.v.val_str->label,
9146 "%s: \"%s\"", name, AT_string (a));
9147 else if (a->dw_attr_val.v.val_str->form == DW_FORM_GNU_str_index)
9148 dw2_asm_output_data_uleb128 (AT_index (a),
9149 "%s: \"%s\"", name, AT_string (a));
9151 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
9154 case dw_val_class_file:
9156 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
9158 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
9159 a->dw_attr_val.v.val_file->filename);
9163 case dw_val_class_data8:
9167 for (i = 0; i < 8; i++)
9168 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
9169 i == 0 ? "%s" : NULL, name);
9173 case dw_val_class_high_pc:
9174 dw2_asm_output_delta (DWARF2_ADDR_SIZE, AT_lbl (a),
9175 get_AT_low_pc (die), "DW_AT_high_pc");
9183 FOR_EACH_CHILD (die, c, output_die (c));
9185 /* Add null byte to terminate sibling list. */
9186 if (die->die_child != NULL)
9187 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9188 (unsigned long) die->die_offset);
9191 /* Output the compilation unit that appears at the beginning of the
9192 .debug_info section, and precedes the DIE descriptions. */
9195 output_compilation_unit_header (void)
9197 /* We don't support actual DWARFv5 units yet, we just use some
9198 DWARFv5 draft DIE tags in DWARFv4 format. */
9199 int ver = dwarf_version < 5 ? dwarf_version : 4;
9201 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9202 dw2_asm_output_data (4, 0xffffffff,
9203 "Initial length escape value indicating 64-bit DWARF extension");
9204 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9205 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
9206 "Length of Compilation Unit Info");
9207 dw2_asm_output_data (2, ver, "DWARF version number");
9208 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
9209 debug_abbrev_section,
9210 "Offset Into Abbrev. Section");
9211 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9214 /* Output the compilation unit DIE and its children. */
9217 output_comp_unit (dw_die_ref die, int output_if_empty)
9219 const char *secname, *oldsym;
9222 /* Unless we are outputting main CU, we may throw away empty ones. */
9223 if (!output_if_empty && die->die_child == NULL)
9226 /* Even if there are no children of this DIE, we must output the information
9227 about the compilation unit. Otherwise, on an empty translation unit, we
9228 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9229 will then complain when examining the file. First mark all the DIEs in
9230 this CU so we know which get local refs. */
9233 external_ref_hash_type *extern_map = optimize_external_refs (die);
9235 build_abbrev_table (die, extern_map);
9239 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9240 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9241 calc_die_sizes (die);
9243 oldsym = die->die_id.die_symbol;
9246 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
9248 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
9250 die->die_id.die_symbol = NULL;
9251 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9255 switch_to_section (debug_info_section);
9256 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9257 info_section_emitted = true;
9260 /* Output debugging information. */
9261 output_compilation_unit_header ();
9264 /* Leave the marks on the main CU, so we can check them in
9269 die->die_id.die_symbol = oldsym;
9273 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9274 and .debug_pubtypes. This is configured per-target, but can be
9275 overridden by the -gpubnames or -gno-pubnames options. */
9278 want_pubnames (void)
9280 if (debug_info_level <= DINFO_LEVEL_TERSE)
9282 if (debug_generate_pub_sections != -1)
9283 return debug_generate_pub_sections;
9284 return targetm.want_debug_pub_sections;
9287 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9290 add_AT_pubnames (dw_die_ref die)
9292 if (want_pubnames ())
9293 add_AT_flag (die, DW_AT_GNU_pubnames, 1);
9296 /* Add a string attribute value to a skeleton DIE. */
9299 add_skeleton_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
9303 struct indirect_string_node *node;
9305 if (! skeleton_debug_str_hash)
9306 skeleton_debug_str_hash
9307 = hash_table<indirect_string_hasher>::create_ggc (10);
9309 node = find_AT_string_in_table (str, skeleton_debug_str_hash);
9310 find_string_form (node);
9311 if (node->form == DW_FORM_GNU_str_index)
9312 node->form = DW_FORM_strp;
9314 attr.dw_attr = attr_kind;
9315 attr.dw_attr_val.val_class = dw_val_class_str;
9316 attr.dw_attr_val.val_entry = NULL;
9317 attr.dw_attr_val.v.val_str = node;
9318 add_dwarf_attr (die, &attr);
9321 /* Helper function to generate top-level dies for skeleton debug_info and
9325 add_top_level_skeleton_die_attrs (dw_die_ref die)
9327 const char *dwo_file_name = concat (aux_base_name, ".dwo", NULL);
9328 const char *comp_dir = comp_dir_string ();
9330 add_skeleton_AT_string (die, DW_AT_GNU_dwo_name, dwo_file_name);
9331 if (comp_dir != NULL)
9332 add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir);
9333 add_AT_pubnames (die);
9334 add_AT_lineptr (die, DW_AT_GNU_addr_base, debug_addr_section_label);
9337 /* Output skeleton debug sections that point to the dwo file. */
9340 output_skeleton_debug_sections (dw_die_ref comp_unit)
9342 /* We don't support actual DWARFv5 units yet, we just use some
9343 DWARFv5 draft DIE tags in DWARFv4 format. */
9344 int ver = dwarf_version < 5 ? dwarf_version : 4;
9346 /* These attributes will be found in the full debug_info section. */
9347 remove_AT (comp_unit, DW_AT_producer);
9348 remove_AT (comp_unit, DW_AT_language);
9350 switch_to_section (debug_skeleton_info_section);
9351 ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_info_section_label);
9353 /* Produce the skeleton compilation-unit header. This one differs enough from
9354 a normal CU header that it's better not to call output_compilation_unit
9356 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9357 dw2_asm_output_data (4, 0xffffffff,
9358 "Initial length escape value indicating 64-bit DWARF extension");
9360 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9361 DWARF_COMPILE_UNIT_HEADER_SIZE
9362 - DWARF_INITIAL_LENGTH_SIZE
9363 + size_of_die (comp_unit),
9364 "Length of Compilation Unit Info");
9365 dw2_asm_output_data (2, ver, "DWARF version number");
9366 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_abbrev_section_label,
9367 debug_abbrev_section,
9368 "Offset Into Abbrev. Section");
9369 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9371 comp_unit->die_abbrev = SKELETON_COMP_DIE_ABBREV;
9372 output_die (comp_unit);
9374 /* Build the skeleton debug_abbrev section. */
9375 switch_to_section (debug_skeleton_abbrev_section);
9376 ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_abbrev_section_label);
9378 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV, comp_unit);
9380 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9383 /* Output a comdat type unit DIE and its children. */
9386 output_comdat_type_unit (comdat_type_node *node)
9388 const char *secname;
9391 #if defined (OBJECT_FORMAT_ELF)
9395 /* First mark all the DIEs in this CU so we know which get local refs. */
9396 mark_dies (node->root_die);
9398 external_ref_hash_type *extern_map = optimize_external_refs (node->root_die);
9400 build_abbrev_table (node->root_die, extern_map);
9405 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9406 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
9407 calc_die_sizes (node->root_die);
9409 #if defined (OBJECT_FORMAT_ELF)
9410 if (!dwarf_split_debug_info)
9411 secname = ".debug_types";
9413 secname = ".debug_types.dwo";
9415 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
9416 sprintf (tmp, "wt.");
9417 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9418 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
9419 comdat_key = get_identifier (tmp);
9420 targetm.asm_out.named_section (secname,
9421 SECTION_DEBUG | SECTION_LINKONCE,
9424 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
9425 sprintf (tmp, ".gnu.linkonce.wt.");
9426 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9427 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
9429 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9432 /* Output debugging information. */
9433 output_compilation_unit_header ();
9434 output_signature (node->signature, "Type Signature");
9435 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
9436 "Offset to Type DIE");
9437 output_die (node->root_die);
9439 unmark_dies (node->root_die);
9442 /* Return the DWARF2/3 pubname associated with a decl. */
9445 dwarf2_name (tree decl, int scope)
9447 if (DECL_NAMELESS (decl))
9449 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
9452 /* Add a new entry to .debug_pubnames if appropriate. */
9455 add_pubname_string (const char *str, dw_die_ref die)
9460 e.name = xstrdup (str);
9461 vec_safe_push (pubname_table, e);
9465 add_pubname (tree decl, dw_die_ref die)
9467 if (!want_pubnames ())
9470 /* Don't add items to the table when we expect that the consumer will have
9471 just read the enclosing die. For example, if the consumer is looking at a
9472 class_member, it will either be inside the class already, or will have just
9473 looked up the class to find the member. Either way, searching the class is
9474 faster than searching the index. */
9475 if ((TREE_PUBLIC (decl) && !class_scope_p (die->die_parent))
9476 || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
9478 const char *name = dwarf2_name (decl, 1);
9481 add_pubname_string (name, die);
9485 /* Add an enumerator to the pubnames section. */
9488 add_enumerator_pubname (const char *scope_name, dw_die_ref die)
9492 gcc_assert (scope_name);
9493 e.name = concat (scope_name, get_AT_string (die, DW_AT_name), NULL);
9495 vec_safe_push (pubname_table, e);
9498 /* Add a new entry to .debug_pubtypes if appropriate. */
9501 add_pubtype (tree decl, dw_die_ref die)
9505 if (!want_pubnames ())
9508 if ((TREE_PUBLIC (decl)
9509 || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
9510 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
9513 const char *scope_name = "";
9514 const char *sep = is_cxx () ? "::" : ".";
9517 scope = TYPE_P (decl) ? TYPE_CONTEXT (decl) : NULL;
9518 if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
9520 scope_name = lang_hooks.dwarf_name (scope, 1);
9521 if (scope_name != NULL && scope_name[0] != '\0')
9522 scope_name = concat (scope_name, sep, NULL);
9528 name = type_tag (decl);
9530 name = lang_hooks.dwarf_name (decl, 1);
9532 /* If we don't have a name for the type, there's no point in adding
9534 if (name != NULL && name[0] != '\0')
9537 e.name = concat (scope_name, name, NULL);
9538 vec_safe_push (pubtype_table, e);
9541 /* Although it might be more consistent to add the pubinfo for the
9542 enumerators as their dies are created, they should only be added if the
9543 enum type meets the criteria above. So rather than re-check the parent
9544 enum type whenever an enumerator die is created, just output them all
9545 here. This isn't protected by the name conditional because anonymous
9546 enums don't have names. */
9547 if (die->die_tag == DW_TAG_enumeration_type)
9551 FOR_EACH_CHILD (die, c, add_enumerator_pubname (scope_name, c));
9556 /* Output a single entry in the pubnames table. */
9559 output_pubname (dw_offset die_offset, pubname_entry *entry)
9561 dw_die_ref die = entry->die;
9562 int is_static = get_AT_flag (die, DW_AT_external) ? 0 : 1;
9564 dw2_asm_output_data (DWARF_OFFSET_SIZE, die_offset, "DIE offset");
9566 if (debug_generate_pub_sections == 2)
9568 /* This logic follows gdb's method for determining the value of the flag
9570 uint32_t flags = GDB_INDEX_SYMBOL_KIND_NONE;
9571 switch (die->die_tag)
9573 case DW_TAG_typedef:
9574 case DW_TAG_base_type:
9575 case DW_TAG_subrange_type:
9576 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
9577 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
9579 case DW_TAG_enumerator:
9580 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9581 GDB_INDEX_SYMBOL_KIND_VARIABLE);
9582 if (!is_cxx () && !is_java ())
9583 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
9585 case DW_TAG_subprogram:
9586 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9587 GDB_INDEX_SYMBOL_KIND_FUNCTION);
9589 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
9591 case DW_TAG_constant:
9592 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9593 GDB_INDEX_SYMBOL_KIND_VARIABLE);
9594 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
9596 case DW_TAG_variable:
9597 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
9598 GDB_INDEX_SYMBOL_KIND_VARIABLE);
9599 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
9601 case DW_TAG_namespace:
9602 case DW_TAG_imported_declaration:
9603 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
9605 case DW_TAG_class_type:
9606 case DW_TAG_interface_type:
9607 case DW_TAG_structure_type:
9608 case DW_TAG_union_type:
9609 case DW_TAG_enumeration_type:
9610 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
9611 if (!is_cxx () && !is_java ())
9612 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
9615 /* An unusual tag. Leave the flag-byte empty. */
9618 dw2_asm_output_data (1, flags >> GDB_INDEX_CU_BITSIZE,
9622 dw2_asm_output_nstring (entry->name, -1, "external name");
9626 /* Output the public names table used to speed up access to externally
9627 visible names; or the public types table used to find type definitions. */
9630 output_pubnames (vec<pubname_entry, va_gc> *names)
9633 unsigned long pubnames_length = size_of_pubnames (names);
9636 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9637 dw2_asm_output_data (4, 0xffffffff,
9638 "Initial length escape value indicating 64-bit DWARF extension");
9639 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, "Pub Info Length");
9641 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9642 dw2_asm_output_data (2, 2, "DWARF Version");
9644 if (dwarf_split_debug_info)
9645 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
9646 debug_skeleton_info_section,
9647 "Offset of Compilation Unit Info");
9649 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9651 "Offset of Compilation Unit Info");
9652 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
9653 "Compilation Unit Length");
9655 FOR_EACH_VEC_ELT (*names, i, pub)
9657 if (include_pubname_in_output (names, pub))
9659 dw_offset die_offset = pub->die->die_offset;
9661 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9662 if (names == pubname_table && pub->die->die_tag != DW_TAG_enumerator)
9663 gcc_assert (pub->die->die_mark);
9665 /* If we're putting types in their own .debug_types sections,
9666 the .debug_pubtypes table will still point to the compile
9667 unit (not the type unit), so we want to use the offset of
9668 the skeleton DIE (if there is one). */
9669 if (pub->die->comdat_type_p && names == pubtype_table)
9671 comdat_type_node *type_node = pub->die->die_id.die_type_node;
9673 if (type_node != NULL)
9674 die_offset = (type_node->skeleton_die != NULL
9675 ? type_node->skeleton_die->die_offset
9676 : comp_unit_die ()->die_offset);
9679 output_pubname (die_offset, pub);
9683 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
9686 /* Output public names and types tables if necessary. */
9689 output_pubtables (void)
9691 if (!want_pubnames () || !info_section_emitted)
9694 switch_to_section (debug_pubnames_section);
9695 output_pubnames (pubname_table);
9696 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9697 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9698 simply won't look for the section. */
9699 switch_to_section (debug_pubtypes_section);
9700 output_pubnames (pubtype_table);
9704 /* Output the information that goes into the .debug_aranges table.
9705 Namely, define the beginning and ending address range of the
9706 text section generated for this compilation unit. */
9709 output_aranges (unsigned long aranges_length)
9713 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9714 dw2_asm_output_data (4, 0xffffffff,
9715 "Initial length escape value indicating 64-bit DWARF extension");
9716 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
9717 "Length of Address Ranges Info");
9718 /* Version number for aranges is still 2, even up to DWARF5. */
9719 dw2_asm_output_data (2, 2, "DWARF Version");
9720 if (dwarf_split_debug_info)
9721 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
9722 debug_skeleton_info_section,
9723 "Offset of Compilation Unit Info");
9725 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9727 "Offset of Compilation Unit Info");
9728 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
9729 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9731 /* We need to align to twice the pointer size here. */
9732 if (DWARF_ARANGES_PAD_SIZE)
9734 /* Pad using a 2 byte words so that padding is correct for any
9736 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9737 2 * DWARF2_ADDR_SIZE);
9738 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
9739 dw2_asm_output_data (2, 0, NULL);
9742 /* It is necessary not to output these entries if the sections were
9743 not used; if the sections were not used, the length will be 0 and
9744 the address may end up as 0 if the section is discarded by ld
9745 --gc-sections, leaving an invalid (0, 0) entry that can be
9746 confused with the terminator. */
9747 if (text_section_used)
9749 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
9750 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
9751 text_section_label, "Length");
9753 if (cold_text_section_used)
9755 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
9757 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
9758 cold_text_section_label, "Length");
9761 if (have_multiple_function_sections)
9766 FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
9768 if (DECL_IGNORED_P (fde->decl))
9770 if (!fde->in_std_section)
9772 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
9774 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
9775 fde->dw_fde_begin, "Length");
9777 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
9779 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
9781 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
9782 fde->dw_fde_second_begin, "Length");
9787 /* Output the terminator words. */
9788 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9789 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9792 /* Add a new entry to .debug_ranges. Return the offset at which it
9796 add_ranges_num (int num)
9798 unsigned int in_use = ranges_table_in_use;
9800 if (in_use == ranges_table_allocated)
9802 ranges_table_allocated += RANGES_TABLE_INCREMENT;
9803 ranges_table = GGC_RESIZEVEC (dw_ranges, ranges_table,
9804 ranges_table_allocated);
9805 memset (ranges_table + ranges_table_in_use, 0,
9806 RANGES_TABLE_INCREMENT * sizeof (dw_ranges));
9809 ranges_table[in_use].num = num;
9810 ranges_table_in_use = in_use + 1;
9812 return in_use * 2 * DWARF2_ADDR_SIZE;
9815 /* Add a new entry to .debug_ranges corresponding to a block, or a
9816 range terminator if BLOCK is NULL. */
9819 add_ranges (const_tree block)
9821 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
9824 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9825 When using dwarf_split_debug_info, address attributes in dies destined
9826 for the final executable should be direct references--setting the
9827 parameter force_direct ensures this behavior. */
9830 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
9831 bool *added, bool force_direct)
9833 unsigned int in_use = ranges_by_label_in_use;
9834 unsigned int offset;
9836 if (in_use == ranges_by_label_allocated)
9838 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
9839 ranges_by_label = GGC_RESIZEVEC (dw_ranges_by_label, ranges_by_label,
9840 ranges_by_label_allocated);
9841 memset (ranges_by_label + ranges_by_label_in_use, 0,
9842 RANGES_TABLE_INCREMENT * sizeof (dw_ranges_by_label));
9845 ranges_by_label[in_use].begin = begin;
9846 ranges_by_label[in_use].end = end;
9847 ranges_by_label_in_use = in_use + 1;
9849 offset = add_ranges_num (-(int)in_use - 1);
9852 add_AT_range_list (die, DW_AT_ranges, offset, force_direct);
9858 output_ranges (void)
9861 static const char *const start_fmt = "Offset %#x";
9862 const char *fmt = start_fmt;
9864 for (i = 0; i < ranges_table_in_use; i++)
9866 int block_num = ranges_table[i].num;
9870 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9871 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9873 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9874 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9876 /* If all code is in the text section, then the compilation
9877 unit base address defaults to DW_AT_low_pc, which is the
9878 base of the text section. */
9879 if (!have_multiple_function_sections)
9881 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9883 fmt, i * 2 * DWARF2_ADDR_SIZE);
9884 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9885 text_section_label, NULL);
9888 /* Otherwise, the compilation unit base address is zero,
9889 which allows us to use absolute addresses, and not worry
9890 about whether the target supports cross-section
9894 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9895 fmt, i * 2 * DWARF2_ADDR_SIZE);
9896 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9902 /* Negative block_num stands for an index into ranges_by_label. */
9903 else if (block_num < 0)
9905 int lab_idx = - block_num - 1;
9907 if (!have_multiple_function_sections)
9911 /* If we ever use add_ranges_by_labels () for a single
9912 function section, all we have to do is to take out
9914 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9915 ranges_by_label[lab_idx].begin,
9917 fmt, i * 2 * DWARF2_ADDR_SIZE);
9918 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9919 ranges_by_label[lab_idx].end,
9920 text_section_label, NULL);
9925 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9926 ranges_by_label[lab_idx].begin,
9927 fmt, i * 2 * DWARF2_ADDR_SIZE);
9928 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9929 ranges_by_label[lab_idx].end,
9935 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9936 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9942 /* Data structure containing information about input files. */
9945 const char *path; /* Complete file name. */
9946 const char *fname; /* File name part. */
9947 int length; /* Length of entire string. */
9948 struct dwarf_file_data * file_idx; /* Index in input file table. */
9949 int dir_idx; /* Index in directory table. */
9952 /* Data structure containing information about directories with source
9956 const char *path; /* Path including directory name. */
9957 int length; /* Path length. */
9958 int prefix; /* Index of directory entry which is a prefix. */
9959 int count; /* Number of files in this directory. */
9960 int dir_idx; /* Index of directory used as base. */
9963 /* Callback function for file_info comparison. We sort by looking at
9964 the directories in the path. */
9967 file_info_cmp (const void *p1, const void *p2)
9969 const struct file_info *const s1 = (const struct file_info *) p1;
9970 const struct file_info *const s2 = (const struct file_info *) p2;
9971 const unsigned char *cp1;
9972 const unsigned char *cp2;
9974 /* Take care of file names without directories. We need to make sure that
9975 we return consistent values to qsort since some will get confused if
9976 we return the same value when identical operands are passed in opposite
9977 orders. So if neither has a directory, return 0 and otherwise return
9978 1 or -1 depending on which one has the directory. */
9979 if ((s1->path == s1->fname || s2->path == s2->fname))
9980 return (s2->path == s2->fname) - (s1->path == s1->fname);
9982 cp1 = (const unsigned char *) s1->path;
9983 cp2 = (const unsigned char *) s2->path;
9989 /* Reached the end of the first path? If so, handle like above. */
9990 if ((cp1 == (const unsigned char *) s1->fname)
9991 || (cp2 == (const unsigned char *) s2->fname))
9992 return ((cp2 == (const unsigned char *) s2->fname)
9993 - (cp1 == (const unsigned char *) s1->fname));
9995 /* Character of current path component the same? */
9996 else if (*cp1 != *cp2)
10001 struct file_name_acquire_data
10003 struct file_info *files;
10008 /* Traversal function for the hash table. */
10011 file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
10013 struct dwarf_file_data *d = *slot;
10014 struct file_info *fi;
10017 gcc_assert (fnad->max_files >= d->emitted_number);
10019 if (! d->emitted_number)
10022 gcc_assert (fnad->max_files != fnad->used_files);
10024 fi = fnad->files + fnad->used_files++;
10026 /* Skip all leading "./". */
10028 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
10031 /* Create a new array entry. */
10033 fi->length = strlen (f);
10036 /* Search for the file name part. */
10037 f = strrchr (f, DIR_SEPARATOR);
10038 #if defined (DIR_SEPARATOR_2)
10040 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
10044 if (f == NULL || f < g)
10050 fi->fname = f == NULL ? fi->path : f + 1;
10054 /* Output the directory table and the file name table. We try to minimize
10055 the total amount of memory needed. A heuristic is used to avoid large
10056 slowdowns with many input files. */
10059 output_file_names (void)
10061 struct file_name_acquire_data fnad;
10063 struct file_info *files;
10064 struct dir_info *dirs;
10072 if (!last_emitted_file)
10074 dw2_asm_output_data (1, 0, "End directory table");
10075 dw2_asm_output_data (1, 0, "End file name table");
10079 numfiles = last_emitted_file->emitted_number;
10081 /* Allocate the various arrays we need. */
10082 files = XALLOCAVEC (struct file_info, numfiles);
10083 dirs = XALLOCAVEC (struct dir_info, numfiles);
10085 fnad.files = files;
10086 fnad.used_files = 0;
10087 fnad.max_files = numfiles;
10088 file_table->traverse<file_name_acquire_data *, file_name_acquire> (&fnad);
10089 gcc_assert (fnad.used_files == fnad.max_files);
10091 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
10093 /* Find all the different directories used. */
10094 dirs[0].path = files[0].path;
10095 dirs[0].length = files[0].fname - files[0].path;
10096 dirs[0].prefix = -1;
10098 dirs[0].dir_idx = 0;
10099 files[0].dir_idx = 0;
10102 for (i = 1; i < numfiles; i++)
10103 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
10104 && memcmp (dirs[ndirs - 1].path, files[i].path,
10105 dirs[ndirs - 1].length) == 0)
10107 /* Same directory as last entry. */
10108 files[i].dir_idx = ndirs - 1;
10109 ++dirs[ndirs - 1].count;
10115 /* This is a new directory. */
10116 dirs[ndirs].path = files[i].path;
10117 dirs[ndirs].length = files[i].fname - files[i].path;
10118 dirs[ndirs].count = 1;
10119 dirs[ndirs].dir_idx = ndirs;
10120 files[i].dir_idx = ndirs;
10122 /* Search for a prefix. */
10123 dirs[ndirs].prefix = -1;
10124 for (j = 0; j < ndirs; j++)
10125 if (dirs[j].length < dirs[ndirs].length
10126 && dirs[j].length > 1
10127 && (dirs[ndirs].prefix == -1
10128 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
10129 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
10130 dirs[ndirs].prefix = j;
10135 /* Now to the actual work. We have to find a subset of the directories which
10136 allow expressing the file name using references to the directory table
10137 with the least amount of characters. We do not do an exhaustive search
10138 where we would have to check out every combination of every single
10139 possible prefix. Instead we use a heuristic which provides nearly optimal
10140 results in most cases and never is much off. */
10141 saved = XALLOCAVEC (int, ndirs);
10142 savehere = XALLOCAVEC (int, ndirs);
10144 memset (saved, '\0', ndirs * sizeof (saved[0]));
10145 for (i = 0; i < ndirs; i++)
10150 /* We can always save some space for the current directory. But this
10151 does not mean it will be enough to justify adding the directory. */
10152 savehere[i] = dirs[i].length;
10153 total = (savehere[i] - saved[i]) * dirs[i].count;
10155 for (j = i + 1; j < ndirs; j++)
10158 if (saved[j] < dirs[i].length)
10160 /* Determine whether the dirs[i] path is a prefix of the
10164 k = dirs[j].prefix;
10165 while (k != -1 && k != (int) i)
10166 k = dirs[k].prefix;
10170 /* Yes it is. We can possibly save some memory by
10171 writing the filenames in dirs[j] relative to
10173 savehere[j] = dirs[i].length;
10174 total += (savehere[j] - saved[j]) * dirs[j].count;
10179 /* Check whether we can save enough to justify adding the dirs[i]
10181 if (total > dirs[i].length + 1)
10183 /* It's worthwhile adding. */
10184 for (j = i; j < ndirs; j++)
10185 if (savehere[j] > 0)
10187 /* Remember how much we saved for this directory so far. */
10188 saved[j] = savehere[j];
10190 /* Remember the prefix directory. */
10191 dirs[j].dir_idx = i;
10196 /* Emit the directory name table. */
10197 idx_offset = dirs[0].length > 0 ? 1 : 0;
10198 for (i = 1 - idx_offset; i < ndirs; i++)
10199 dw2_asm_output_nstring (dirs[i].path,
10201 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
10202 "Directory Entry: %#x", i + idx_offset);
10204 dw2_asm_output_data (1, 0, "End directory table");
10206 /* We have to emit them in the order of emitted_number since that's
10207 used in the debug info generation. To do this efficiently we
10208 generate a back-mapping of the indices first. */
10209 backmap = XALLOCAVEC (int, numfiles);
10210 for (i = 0; i < numfiles; i++)
10211 backmap[files[i].file_idx->emitted_number - 1] = i;
10213 /* Now write all the file names. */
10214 for (i = 0; i < numfiles; i++)
10216 int file_idx = backmap[i];
10217 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
10219 #ifdef VMS_DEBUGGING_INFO
10220 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10222 /* Setting these fields can lead to debugger miscomparisons,
10223 but VMS Debug requires them to be set correctly. */
10228 int maxfilelen = strlen (files[file_idx].path)
10229 + dirs[dir_idx].length
10230 + MAX_VMS_VERSION_LEN + 1;
10231 char *filebuf = XALLOCAVEC (char, maxfilelen);
10233 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
10234 snprintf (filebuf, maxfilelen, "%s;%d",
10235 files[file_idx].path + dirs[dir_idx].length, ver);
10237 dw2_asm_output_nstring
10238 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
10240 /* Include directory index. */
10241 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
10243 /* Modification time. */
10244 dw2_asm_output_data_uleb128
10245 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
10249 /* File length in bytes. */
10250 dw2_asm_output_data_uleb128
10251 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
10255 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
10256 "File Entry: %#x", (unsigned) i + 1);
10258 /* Include directory index. */
10259 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
10261 /* Modification time. */
10262 dw2_asm_output_data_uleb128 (0, NULL);
10264 /* File length in bytes. */
10265 dw2_asm_output_data_uleb128 (0, NULL);
10266 #endif /* VMS_DEBUGGING_INFO */
10269 dw2_asm_output_data (1, 0, "End file name table");
10273 /* Output one line number table into the .debug_line section. */
10276 output_one_line_info_table (dw_line_info_table *table)
10278 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
10279 unsigned int current_line = 1;
10280 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
10281 dw_line_info_entry *ent;
10284 FOR_EACH_VEC_SAFE_ELT (table->entries, i, ent)
10286 switch (ent->opcode)
10288 case LI_set_address:
10289 /* ??? Unfortunately, we have little choice here currently, and
10290 must always use the most general form. GCC does not know the
10291 address delta itself, so we can't use DW_LNS_advance_pc. Many
10292 ports do have length attributes which will give an upper bound
10293 on the address range. We could perhaps use length attributes
10294 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10295 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
10297 /* This can handle any delta. This takes
10298 4+DWARF2_ADDR_SIZE bytes. */
10299 dw2_asm_output_data (1, 0, "set address %s", line_label);
10300 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10301 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10302 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10306 if (ent->val == current_line)
10308 /* We still need to start a new row, so output a copy insn. */
10309 dw2_asm_output_data (1, DW_LNS_copy,
10310 "copy line %u", current_line);
10314 int line_offset = ent->val - current_line;
10315 int line_delta = line_offset - DWARF_LINE_BASE;
10317 current_line = ent->val;
10318 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10320 /* This can handle deltas from -10 to 234, using the current
10321 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10322 This takes 1 byte. */
10323 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10324 "line %u", current_line);
10328 /* This can handle any delta. This takes at least 4 bytes,
10329 depending on the value being encoded. */
10330 dw2_asm_output_data (1, DW_LNS_advance_line,
10331 "advance to line %u", current_line);
10332 dw2_asm_output_data_sleb128 (line_offset, NULL);
10333 dw2_asm_output_data (1, DW_LNS_copy, NULL);
10339 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
10340 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
10343 case LI_set_column:
10344 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
10345 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
10348 case LI_negate_stmt:
10349 current_is_stmt = !current_is_stmt;
10350 dw2_asm_output_data (1, DW_LNS_negate_stmt,
10351 "is_stmt %d", current_is_stmt);
10354 case LI_set_prologue_end:
10355 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
10356 "set prologue end");
10359 case LI_set_epilogue_begin:
10360 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
10361 "set epilogue begin");
10364 case LI_set_discriminator:
10365 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
10366 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
10367 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
10368 dw2_asm_output_data_uleb128 (ent->val, NULL);
10373 /* Emit debug info for the address of the end of the table. */
10374 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
10375 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10376 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10377 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
10379 dw2_asm_output_data (1, 0, "end sequence");
10380 dw2_asm_output_data_uleb128 (1, NULL);
10381 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10384 /* Output the source line number correspondence information. This
10385 information goes into the .debug_line section. */
10388 output_line_info (bool prologue_only)
10390 char l1[20], l2[20], p1[20], p2[20];
10391 /* We don't support DWARFv5 line tables yet. */
10392 int ver = dwarf_version < 5 ? dwarf_version : 4;
10393 bool saw_one = false;
10396 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
10397 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
10398 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
10399 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
10401 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
10402 dw2_asm_output_data (4, 0xffffffff,
10403 "Initial length escape value indicating 64-bit DWARF extension");
10404 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
10405 "Length of Source Line Info");
10406 ASM_OUTPUT_LABEL (asm_out_file, l1);
10408 dw2_asm_output_data (2, ver, "DWARF Version");
10409 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
10410 ASM_OUTPUT_LABEL (asm_out_file, p1);
10412 /* Define the architecture-dependent minimum instruction length (in bytes).
10413 In this implementation of DWARF, this field is used for information
10414 purposes only. Since GCC generates assembly language, we have no
10415 a priori knowledge of how many instruction bytes are generated for each
10416 source line, and therefore can use only the DW_LNE_set_address and
10417 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10418 this as '1', which is "correct enough" for all architectures,
10419 and don't let the target override. */
10420 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10423 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
10424 "Maximum Operations Per Instruction");
10425 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
10426 "Default is_stmt_start flag");
10427 dw2_asm_output_data (1, DWARF_LINE_BASE,
10428 "Line Base Value (Special Opcodes)");
10429 dw2_asm_output_data (1, DWARF_LINE_RANGE,
10430 "Line Range Value (Special Opcodes)");
10431 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
10432 "Special Opcode Base");
10434 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
10439 case DW_LNS_advance_pc:
10440 case DW_LNS_advance_line:
10441 case DW_LNS_set_file:
10442 case DW_LNS_set_column:
10443 case DW_LNS_fixed_advance_pc:
10444 case DW_LNS_set_isa:
10452 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
10456 /* Write out the information about the files we use. */
10457 output_file_names ();
10458 ASM_OUTPUT_LABEL (asm_out_file, p2);
10461 /* Output the marker for the end of the line number info. */
10462 ASM_OUTPUT_LABEL (asm_out_file, l2);
10466 if (separate_line_info)
10468 dw_line_info_table *table;
10471 FOR_EACH_VEC_ELT (*separate_line_info, i, table)
10474 output_one_line_info_table (table);
10478 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
10480 output_one_line_info_table (cold_text_section_line_info);
10484 /* ??? Some Darwin linkers crash on a .debug_line section with no
10485 sequences. Further, merely a DW_LNE_end_sequence entry is not
10486 sufficient -- the address column must also be initialized.
10487 Make sure to output at least one set_address/end_sequence pair,
10488 choosing .text since that section is always present. */
10489 if (text_section_line_info->in_use || !saw_one)
10490 output_one_line_info_table (text_section_line_info);
10492 /* Output the marker for the end of the line number info. */
10493 ASM_OUTPUT_LABEL (asm_out_file, l2);
10496 /* Given a pointer to a tree node for some base type, return a pointer to
10497 a DIE that describes the given type.
10499 This routine must only be called for GCC type nodes that correspond to
10500 Dwarf base (fundamental) types. */
10503 base_type_die (tree type)
10505 dw_die_ref base_type_result;
10506 enum dwarf_type encoding;
10508 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
10511 /* If this is a subtype that should not be emitted as a subrange type,
10512 use the base type. See subrange_type_for_debug_p. */
10513 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
10514 type = TREE_TYPE (type);
10516 switch (TREE_CODE (type))
10519 if ((dwarf_version >= 4 || !dwarf_strict)
10520 && TYPE_NAME (type)
10521 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10522 && DECL_IS_BUILTIN (TYPE_NAME (type))
10523 && DECL_NAME (TYPE_NAME (type)))
10525 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
10526 if (strcmp (name, "char16_t") == 0
10527 || strcmp (name, "char32_t") == 0)
10529 encoding = DW_ATE_UTF;
10533 if (TYPE_STRING_FLAG (type))
10535 if (TYPE_UNSIGNED (type))
10536 encoding = DW_ATE_unsigned_char;
10538 encoding = DW_ATE_signed_char;
10540 else if (TYPE_UNSIGNED (type))
10541 encoding = DW_ATE_unsigned;
10543 encoding = DW_ATE_signed;
10547 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
10549 if (dwarf_version >= 3 || !dwarf_strict)
10550 encoding = DW_ATE_decimal_float;
10552 encoding = DW_ATE_lo_user;
10555 encoding = DW_ATE_float;
10558 case FIXED_POINT_TYPE:
10559 if (!(dwarf_version >= 3 || !dwarf_strict))
10560 encoding = DW_ATE_lo_user;
10561 else if (TYPE_UNSIGNED (type))
10562 encoding = DW_ATE_unsigned_fixed;
10564 encoding = DW_ATE_signed_fixed;
10567 /* Dwarf2 doesn't know anything about complex ints, so use
10568 a user defined type for it. */
10570 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
10571 encoding = DW_ATE_complex_float;
10573 encoding = DW_ATE_lo_user;
10577 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10578 encoding = DW_ATE_boolean;
10582 /* No other TREE_CODEs are Dwarf fundamental types. */
10583 gcc_unreachable ();
10586 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
10588 add_AT_unsigned (base_type_result, DW_AT_byte_size,
10589 int_size_in_bytes (type));
10590 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
10591 add_pubtype (type, base_type_result);
10593 return base_type_result;
10596 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10597 named 'auto' in its type: return true for it, false otherwise. */
10600 is_cxx_auto (tree type)
10604 tree name = TYPE_IDENTIFIER (type);
10605 if (name == get_identifier ("auto")
10606 || name == get_identifier ("decltype(auto)"))
10612 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10613 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10616 is_base_type (tree type)
10618 switch (TREE_CODE (type))
10624 case FIXED_POINT_TYPE:
10627 case POINTER_BOUNDS_TYPE:
10633 case QUAL_UNION_TYPE:
10634 case ENUMERAL_TYPE:
10635 case FUNCTION_TYPE:
10638 case REFERENCE_TYPE:
10646 if (is_cxx_auto (type))
10648 gcc_unreachable ();
10654 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10655 node, return the size in bits for the type if it is a constant, or else
10656 return the alignment for the type if the type's size is not constant, or
10657 else return BITS_PER_WORD if the type actually turns out to be an
10658 ERROR_MARK node. */
10660 static inline unsigned HOST_WIDE_INT
10661 simple_type_size_in_bits (const_tree type)
10663 if (TREE_CODE (type) == ERROR_MARK)
10664 return BITS_PER_WORD;
10665 else if (TYPE_SIZE (type) == NULL_TREE)
10667 else if (tree_fits_uhwi_p (TYPE_SIZE (type)))
10668 return tree_to_uhwi (TYPE_SIZE (type));
10670 return TYPE_ALIGN (type);
10673 /* Similarly, but return an offset_int instead of UHWI. */
10675 static inline offset_int
10676 offset_int_type_size_in_bits (const_tree type)
10678 if (TREE_CODE (type) == ERROR_MARK)
10679 return BITS_PER_WORD;
10680 else if (TYPE_SIZE (type) == NULL_TREE)
10682 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
10683 return wi::to_offset (TYPE_SIZE (type));
10685 return TYPE_ALIGN (type);
10688 /* Given a pointer to a tree node for a subrange type, return a pointer
10689 to a DIE that describes the given type. */
10692 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
10694 dw_die_ref subrange_die;
10695 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
10697 if (context_die == NULL)
10698 context_die = comp_unit_die ();
10700 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
10702 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
10704 /* The size of the subrange type and its base type do not match,
10705 so we need to generate a size attribute for the subrange type. */
10706 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
10710 add_bound_info (subrange_die, DW_AT_lower_bound, low, NULL);
10712 add_bound_info (subrange_die, DW_AT_upper_bound, high, NULL);
10714 return subrange_die;
10717 /* Returns the (const and/or volatile) cv_qualifiers associated with
10718 the decl node. This will normally be augmented with the
10719 cv_qualifiers of the underlying type in add_type_attribute. */
10722 decl_quals (const_tree decl)
10724 return ((TREE_READONLY (decl)
10725 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
10726 | (TREE_THIS_VOLATILE (decl)
10727 ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED));
10730 /* Determine the TYPE whose qualifiers match the largest strict subset
10731 of the given TYPE_QUALS, and return its qualifiers. Ignore all
10732 qualifiers outside QUAL_MASK. */
10735 get_nearest_type_subqualifiers (tree type, int type_quals, int qual_mask)
10738 int best_rank = 0, best_qual = 0, max_rank;
10740 type_quals &= qual_mask;
10741 max_rank = popcount_hwi (type_quals) - 1;
10743 for (t = TYPE_MAIN_VARIANT (type); t && best_rank < max_rank;
10744 t = TYPE_NEXT_VARIANT (t))
10746 int q = TYPE_QUALS (t) & qual_mask;
10748 if ((q & type_quals) == q && q != type_quals
10749 && check_base_type (t, type))
10751 int rank = popcount_hwi (q);
10753 if (rank > best_rank)
10764 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10765 entry that chains various modifiers in front of the given type. */
10768 modified_type_die (tree type, int cv_quals, dw_die_ref context_die)
10770 enum tree_code code = TREE_CODE (type);
10771 dw_die_ref mod_type_die;
10772 dw_die_ref sub_die = NULL;
10773 tree item_type = NULL;
10774 tree qualified_type;
10775 tree name, low, high;
10776 dw_die_ref mod_scope;
10777 /* Only these cv-qualifiers are currently handled. */
10778 const int cv_qual_mask = (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE
10779 | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC);
10781 if (code == ERROR_MARK)
10784 cv_quals &= cv_qual_mask;
10786 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
10787 tag modifier (and not an attribute) old consumers won't be able
10789 if (dwarf_version < 3)
10790 cv_quals &= ~TYPE_QUAL_RESTRICT;
10792 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
10793 if (dwarf_version < 5)
10794 cv_quals &= ~TYPE_QUAL_ATOMIC;
10796 /* See if we already have the appropriately qualified variant of
10798 qualified_type = get_qualified_type (type, cv_quals);
10800 if (qualified_type == sizetype
10801 && TYPE_NAME (qualified_type)
10802 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
10804 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
10806 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
10807 && TYPE_PRECISION (t)
10808 == TYPE_PRECISION (qualified_type)
10809 && TYPE_UNSIGNED (t)
10810 == TYPE_UNSIGNED (qualified_type));
10811 qualified_type = t;
10814 /* If we do, then we can just use its DIE, if it exists. */
10815 if (qualified_type)
10817 mod_type_die = lookup_type_die (qualified_type);
10819 return mod_type_die;
10822 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
10824 /* Handle C typedef types. */
10825 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
10826 && !DECL_ARTIFICIAL (name))
10828 tree dtype = TREE_TYPE (name);
10830 if (qualified_type == dtype)
10832 /* For a named type, use the typedef. */
10833 gen_type_die (qualified_type, context_die);
10834 return lookup_type_die (qualified_type);
10838 int dquals = TYPE_QUALS_NO_ADDR_SPACE (dtype);
10839 dquals &= cv_qual_mask;
10840 if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
10841 || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
10842 /* cv-unqualified version of named type. Just use
10843 the unnamed type to which it refers. */
10844 return modified_type_die (DECL_ORIGINAL_TYPE (name),
10845 cv_quals, context_die);
10846 /* Else cv-qualified version of named type; fall through. */
10850 mod_scope = scope_die_for (type, context_die);
10854 struct qual_info { int q; enum dwarf_tag t; };
10855 static const struct qual_info qual_info[] =
10857 { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type },
10858 { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
10859 { TYPE_QUAL_VOLATILE, DW_TAG_volatile_type },
10860 { TYPE_QUAL_CONST, DW_TAG_const_type },
10865 /* Determine a lesser qualified type that most closely matches
10866 this one. Then generate DW_TAG_* entries for the remaining
10868 sub_quals = get_nearest_type_subqualifiers (type, cv_quals,
10870 mod_type_die = modified_type_die (type, sub_quals, context_die);
10872 for (i = 0; i < sizeof (qual_info) / sizeof (qual_info[0]); i++)
10873 if (qual_info[i].q & cv_quals & ~sub_quals)
10875 dw_die_ref d = new_die (qual_info[i].t, mod_scope, type);
10877 add_AT_die_ref (d, DW_AT_type, mod_type_die);
10881 else if (code == POINTER_TYPE)
10883 mod_type_die = new_die (DW_TAG_pointer_type, mod_scope, type);
10884 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10885 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10886 item_type = TREE_TYPE (type);
10887 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
10888 add_AT_unsigned (mod_type_die, DW_AT_address_class,
10889 TYPE_ADDR_SPACE (item_type));
10891 else if (code == REFERENCE_TYPE)
10893 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
10894 mod_type_die = new_die (DW_TAG_rvalue_reference_type, mod_scope,
10897 mod_type_die = new_die (DW_TAG_reference_type, mod_scope, type);
10898 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10899 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10900 item_type = TREE_TYPE (type);
10901 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
10902 add_AT_unsigned (mod_type_die, DW_AT_address_class,
10903 TYPE_ADDR_SPACE (item_type));
10905 else if (code == INTEGER_TYPE
10906 && TREE_TYPE (type) != NULL_TREE
10907 && subrange_type_for_debug_p (type, &low, &high))
10909 mod_type_die = subrange_type_die (type, low, high, context_die);
10910 item_type = TREE_TYPE (type);
10912 else if (is_base_type (type))
10913 mod_type_die = base_type_die (type);
10916 gen_type_die (type, context_die);
10918 /* We have to get the type_main_variant here (and pass that to the
10919 `lookup_type_die' routine) because the ..._TYPE node we have
10920 might simply be a *copy* of some original type node (where the
10921 copy was created to help us keep track of typedef names) and
10922 that copy might have a different TYPE_UID from the original
10924 if (TREE_CODE (type) != VECTOR_TYPE)
10925 return lookup_type_die (type_main_variant (type));
10927 /* Vectors have the debugging information in the type,
10928 not the main variant. */
10929 return lookup_type_die (type);
10932 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10933 don't output a DW_TAG_typedef, since there isn't one in the
10934 user's program; just attach a DW_AT_name to the type.
10935 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10936 if the base type already has the same name. */
10938 && ((TREE_CODE (name) != TYPE_DECL
10939 && (qualified_type == TYPE_MAIN_VARIANT (type)
10940 || (cv_quals == TYPE_UNQUALIFIED)))
10941 || (TREE_CODE (name) == TYPE_DECL
10942 && TREE_TYPE (name) == qualified_type
10943 && DECL_NAME (name))))
10945 if (TREE_CODE (name) == TYPE_DECL)
10946 /* Could just call add_name_and_src_coords_attributes here,
10947 but since this is a builtin type it doesn't have any
10948 useful source coordinates anyway. */
10949 name = DECL_NAME (name);
10950 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
10952 /* This probably indicates a bug. */
10953 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
10955 name = TYPE_IDENTIFIER (type);
10956 add_name_attribute (mod_type_die,
10957 name ? IDENTIFIER_POINTER (name) : "__unknown__");
10960 if (qualified_type)
10961 equate_type_number_to_die (qualified_type, mod_type_die);
10964 /* We must do this after the equate_type_number_to_die call, in case
10965 this is a recursive type. This ensures that the modified_type_die
10966 recursion will terminate even if the type is recursive. Recursive
10967 types are possible in Ada. */
10968 sub_die = modified_type_die (item_type,
10969 TYPE_QUALS_NO_ADDR_SPACE (item_type),
10972 if (sub_die != NULL)
10973 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10975 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
10976 if (TYPE_ARTIFICIAL (type))
10977 add_AT_flag (mod_type_die, DW_AT_artificial, 1);
10979 return mod_type_die;
10982 /* Generate DIEs for the generic parameters of T.
10983 T must be either a generic type or a generic function.
10984 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10987 gen_generic_params_dies (tree t)
10991 dw_die_ref die = NULL;
10994 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
10998 die = lookup_type_die (t);
10999 else if (DECL_P (t))
11000 die = lookup_decl_die (t);
11004 parms = lang_hooks.get_innermost_generic_parms (t);
11006 /* T has no generic parameter. It means T is neither a generic type
11007 or function. End of story. */
11010 parms_num = TREE_VEC_LENGTH (parms);
11011 args = lang_hooks.get_innermost_generic_args (t);
11012 if (TREE_CHAIN (args) && TREE_CODE (TREE_CHAIN (args)) == INTEGER_CST)
11013 non_default = int_cst_value (TREE_CHAIN (args));
11015 non_default = TREE_VEC_LENGTH (args);
11016 for (i = 0; i < parms_num; i++)
11018 tree parm, arg, arg_pack_elems;
11019 dw_die_ref parm_die;
11021 parm = TREE_VEC_ELT (parms, i);
11022 arg = TREE_VEC_ELT (args, i);
11023 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
11024 gcc_assert (parm && TREE_VALUE (parm) && arg);
11026 if (parm && TREE_VALUE (parm) && arg)
11028 /* If PARM represents a template parameter pack,
11029 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11030 by DW_TAG_template_*_parameter DIEs for the argument
11031 pack elements of ARG. Note that ARG would then be
11032 an argument pack. */
11033 if (arg_pack_elems)
11034 parm_die = template_parameter_pack_die (TREE_VALUE (parm),
11038 parm_die = generic_parameter_die (TREE_VALUE (parm), arg,
11039 true /* emit name */, die);
11040 if (i >= non_default)
11041 add_AT_flag (parm_die, DW_AT_default_value, 1);
11046 /* Create and return a DIE for PARM which should be
11047 the representation of a generic type parameter.
11048 For instance, in the C++ front end, PARM would be a template parameter.
11049 ARG is the argument to PARM.
11050 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11052 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11053 as a child node. */
11056 generic_parameter_die (tree parm, tree arg,
11058 dw_die_ref parent_die)
11060 dw_die_ref tmpl_die = NULL;
11061 const char *name = NULL;
11063 if (!parm || !DECL_NAME (parm) || !arg)
11066 /* We support non-type generic parameters and arguments,
11067 type generic parameters and arguments, as well as
11068 generic generic parameters (a.k.a. template template parameters in C++)
11070 if (TREE_CODE (parm) == PARM_DECL)
11071 /* PARM is a nontype generic parameter */
11072 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
11073 else if (TREE_CODE (parm) == TYPE_DECL)
11074 /* PARM is a type generic parameter. */
11075 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
11076 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
11077 /* PARM is a generic generic parameter.
11078 Its DIE is a GNU extension. It shall have a
11079 DW_AT_name attribute to represent the name of the template template
11080 parameter, and a DW_AT_GNU_template_name attribute to represent the
11081 name of the template template argument. */
11082 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
11085 gcc_unreachable ();
11091 /* If PARM is a generic parameter pack, it means we are
11092 emitting debug info for a template argument pack element.
11093 In other terms, ARG is a template argument pack element.
11094 In that case, we don't emit any DW_AT_name attribute for
11098 name = IDENTIFIER_POINTER (DECL_NAME (parm));
11100 add_AT_string (tmpl_die, DW_AT_name, name);
11103 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
11105 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11106 TMPL_DIE should have a child DW_AT_type attribute that is set
11107 to the type of the argument to PARM, which is ARG.
11108 If PARM is a type generic parameter, TMPL_DIE should have a
11109 child DW_AT_type that is set to ARG. */
11110 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
11111 add_type_attribute (tmpl_die, tmpl_type,
11112 (TREE_THIS_VOLATILE (tmpl_type)
11113 ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED),
11118 /* So TMPL_DIE is a DIE representing a
11119 a generic generic template parameter, a.k.a template template
11120 parameter in C++ and arg is a template. */
11122 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11123 to the name of the argument. */
11124 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
11126 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
11129 if (TREE_CODE (parm) == PARM_DECL)
11130 /* So PARM is a non-type generic parameter.
11131 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11132 attribute of TMPL_DIE which value represents the value
11134 We must be careful here:
11135 The value of ARG might reference some function decls.
11136 We might currently be emitting debug info for a generic
11137 type and types are emitted before function decls, we don't
11138 know if the function decls referenced by ARG will actually be
11139 emitted after cgraph computations.
11140 So must defer the generation of the DW_AT_const_value to
11141 after cgraph is ready. */
11142 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
11148 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11149 PARM_PACK must be a template parameter pack. The returned DIE
11150 will be child DIE of PARENT_DIE. */
11153 template_parameter_pack_die (tree parm_pack,
11154 tree parm_pack_args,
11155 dw_die_ref parent_die)
11160 gcc_assert (parent_die && parm_pack);
11162 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
11163 add_name_and_src_coords_attributes (die, parm_pack);
11164 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
11165 generic_parameter_die (parm_pack,
11166 TREE_VEC_ELT (parm_pack_args, j),
11167 false /* Don't emit DW_AT_name */,
11172 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11173 an enumerated type. */
11176 type_is_enum (const_tree type)
11178 return TREE_CODE (type) == ENUMERAL_TYPE;
11181 /* Return the DBX register number described by a given RTL node. */
11183 static unsigned int
11184 dbx_reg_number (const_rtx rtl)
11186 unsigned regno = REGNO (rtl);
11188 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
11190 #ifdef LEAF_REG_REMAP
11191 if (crtl->uses_only_leaf_regs)
11193 int leaf_reg = LEAF_REG_REMAP (regno);
11194 if (leaf_reg != -1)
11195 regno = (unsigned) leaf_reg;
11199 regno = DBX_REGISTER_NUMBER (regno);
11200 gcc_assert (regno != INVALID_REGNUM);
11204 /* Optionally add a DW_OP_piece term to a location description expression.
11205 DW_OP_piece is only added if the location description expression already
11206 doesn't end with DW_OP_piece. */
11209 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
11211 dw_loc_descr_ref loc;
11213 if (*list_head != NULL)
11215 /* Find the end of the chain. */
11216 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
11219 if (loc->dw_loc_opc != DW_OP_piece)
11220 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
11224 /* Return a location descriptor that designates a machine register or
11225 zero if there is none. */
11227 static dw_loc_descr_ref
11228 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
11232 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
11235 /* We only use "frame base" when we're sure we're talking about the
11236 post-prologue local stack frame. We do this by *not* running
11237 register elimination until this point, and recognizing the special
11238 argument pointer and soft frame pointer rtx's.
11239 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11240 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
11241 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
11243 dw_loc_descr_ref result = NULL;
11245 if (dwarf_version >= 4 || !dwarf_strict)
11247 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
11250 add_loc_descr (&result,
11251 new_loc_descr (DW_OP_stack_value, 0, 0));
11256 regs = targetm.dwarf_register_span (rtl);
11258 if (REG_NREGS (rtl) > 1 || regs)
11259 return multiple_reg_loc_descriptor (rtl, regs, initialized);
11262 unsigned int dbx_regnum = dbx_reg_number (rtl);
11263 if (dbx_regnum == IGNORED_DWARF_REGNUM)
11265 return one_reg_loc_descriptor (dbx_regnum, initialized);
11269 /* Return a location descriptor that designates a machine register for
11270 a given hard register number. */
11272 static dw_loc_descr_ref
11273 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
11275 dw_loc_descr_ref reg_loc_descr;
11279 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
11281 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
11283 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11284 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11286 return reg_loc_descr;
11289 /* Given an RTL of a register, return a location descriptor that
11290 designates a value that spans more than one register. */
11292 static dw_loc_descr_ref
11293 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
11294 enum var_init_status initialized)
11297 dw_loc_descr_ref loc_result = NULL;
11299 /* Simple, contiguous registers. */
11300 if (regs == NULL_RTX)
11302 unsigned reg = REGNO (rtl);
11305 #ifdef LEAF_REG_REMAP
11306 if (crtl->uses_only_leaf_regs)
11308 int leaf_reg = LEAF_REG_REMAP (reg);
11309 if (leaf_reg != -1)
11310 reg = (unsigned) leaf_reg;
11314 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
11315 nregs = REG_NREGS (rtl);
11317 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
11322 dw_loc_descr_ref t;
11324 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
11325 VAR_INIT_STATUS_INITIALIZED);
11326 add_loc_descr (&loc_result, t);
11327 add_loc_descr_op_piece (&loc_result, size);
11333 /* Now onto stupid register sets in non contiguous locations. */
11335 gcc_assert (GET_CODE (regs) == PARALLEL);
11337 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
11340 for (i = 0; i < XVECLEN (regs, 0); ++i)
11342 dw_loc_descr_ref t;
11344 t = one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs, 0, i)),
11345 VAR_INIT_STATUS_INITIALIZED);
11346 add_loc_descr (&loc_result, t);
11347 add_loc_descr_op_piece (&loc_result, size);
11350 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11351 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11355 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
11357 /* Return a location descriptor that designates a constant i,
11358 as a compound operation from constant (i >> shift), constant shift
11361 static dw_loc_descr_ref
11362 int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
11364 dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
11365 add_loc_descr (&ret, int_loc_descriptor (shift));
11366 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11370 /* Return a location descriptor that designates a constant. */
11372 static dw_loc_descr_ref
11373 int_loc_descriptor (HOST_WIDE_INT i)
11375 enum dwarf_location_atom op;
11377 /* Pick the smallest representation of a constant, rather than just
11378 defaulting to the LEB encoding. */
11381 int clz = clz_hwi (i);
11382 int ctz = ctz_hwi (i);
11384 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
11385 else if (i <= 0xff)
11386 op = DW_OP_const1u;
11387 else if (i <= 0xffff)
11388 op = DW_OP_const2u;
11389 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
11390 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
11391 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11392 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11393 while DW_OP_const4u is 5 bytes. */
11394 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
11395 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
11396 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
11397 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11398 while DW_OP_const4u is 5 bytes. */
11399 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
11400 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
11401 op = DW_OP_const4u;
11402 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
11403 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
11404 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11405 while DW_OP_constu of constant >= 0x100000000 takes at least
11407 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
11408 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
11409 && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
11410 >= HOST_BITS_PER_WIDE_INT)
11411 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11412 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11413 while DW_OP_constu takes in this case at least 6 bytes. */
11414 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
11415 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
11416 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
11417 && size_of_uleb128 (i) > 6)
11418 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11419 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
11426 op = DW_OP_const1s;
11427 else if (i >= -0x8000)
11428 op = DW_OP_const2s;
11429 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
11431 if (size_of_int_loc_descriptor (i) < 5)
11433 dw_loc_descr_ref ret = int_loc_descriptor (-i);
11434 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11437 op = DW_OP_const4s;
11441 if (size_of_int_loc_descriptor (i)
11442 < (unsigned long) 1 + size_of_sleb128 (i))
11444 dw_loc_descr_ref ret = int_loc_descriptor (-i);
11445 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11452 return new_loc_descr (op, i, 0);
11455 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11456 without actually allocating it. */
11458 static unsigned long
11459 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
11461 return size_of_int_loc_descriptor (i >> shift)
11462 + size_of_int_loc_descriptor (shift)
11466 /* Return size_of_locs (int_loc_descriptor (i)) without
11467 actually allocating it. */
11469 static unsigned long
11470 size_of_int_loc_descriptor (HOST_WIDE_INT i)
11479 else if (i <= 0xff)
11481 else if (i <= 0xffff)
11485 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
11486 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
11487 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
11489 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
11490 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
11491 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
11493 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
11495 s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
11496 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
11497 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
11498 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
11500 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
11501 && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
11502 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
11504 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
11505 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
11507 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
11516 else if (i >= -0x8000)
11518 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
11520 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
11522 s = size_of_int_loc_descriptor (-i) + 1;
11530 unsigned long r = 1 + size_of_sleb128 (i);
11531 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
11533 s = size_of_int_loc_descriptor (-i) + 1;
11542 /* Return loc description representing "address" of integer value.
11543 This can appear only as toplevel expression. */
11545 static dw_loc_descr_ref
11546 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
11549 dw_loc_descr_ref loc_result = NULL;
11551 if (!(dwarf_version >= 4 || !dwarf_strict))
11554 litsize = size_of_int_loc_descriptor (i);
11555 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11556 is more compact. For DW_OP_stack_value we need:
11557 litsize + 1 (DW_OP_stack_value)
11558 and for DW_OP_implicit_value:
11559 1 (DW_OP_implicit_value) + 1 (length) + size. */
11560 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
11562 loc_result = int_loc_descriptor (i);
11563 add_loc_descr (&loc_result,
11564 new_loc_descr (DW_OP_stack_value, 0, 0));
11568 loc_result = new_loc_descr (DW_OP_implicit_value,
11570 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
11571 loc_result->dw_loc_oprnd2.v.val_int = i;
11575 /* Return a location descriptor that designates a base+offset location. */
11577 static dw_loc_descr_ref
11578 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
11579 enum var_init_status initialized)
11581 unsigned int regno;
11582 dw_loc_descr_ref result;
11583 dw_fde_ref fde = cfun->fde;
11585 /* We only use "frame base" when we're sure we're talking about the
11586 post-prologue local stack frame. We do this by *not* running
11587 register elimination until this point, and recognizing the special
11588 argument pointer and soft frame pointer rtx's. */
11589 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
11591 rtx elim = (ira_use_lra_p
11592 ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
11593 : eliminate_regs (reg, VOIDmode, NULL_RTX));
11597 if (GET_CODE (elim) == PLUS)
11599 offset += INTVAL (XEXP (elim, 1));
11600 elim = XEXP (elim, 0);
11602 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11603 && (elim == hard_frame_pointer_rtx
11604 || elim == stack_pointer_rtx))
11605 || elim == (frame_pointer_needed
11606 ? hard_frame_pointer_rtx
11607 : stack_pointer_rtx));
11609 /* If drap register is used to align stack, use frame
11610 pointer + offset to access stack variables. If stack
11611 is aligned without drap, use stack pointer + offset to
11612 access stack variables. */
11613 if (crtl->stack_realign_tried
11614 && reg == frame_pointer_rtx)
11617 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
11618 ? HARD_FRAME_POINTER_REGNUM
11620 return new_reg_loc_descr (base_reg, offset);
11623 gcc_assert (frame_pointer_fb_offset_valid);
11624 offset += frame_pointer_fb_offset;
11625 return new_loc_descr (DW_OP_fbreg, offset, 0);
11629 regno = REGNO (reg);
11630 #ifdef LEAF_REG_REMAP
11631 if (crtl->uses_only_leaf_regs)
11633 int leaf_reg = LEAF_REG_REMAP (regno);
11634 if (leaf_reg != -1)
11635 regno = (unsigned) leaf_reg;
11638 regno = DWARF_FRAME_REGNUM (regno);
11640 if (!optimize && fde
11641 && (fde->drap_reg == regno || fde->vdrap_reg == regno))
11643 /* Use cfa+offset to represent the location of arguments passed
11644 on the stack when drap is used to align stack.
11645 Only do this when not optimizing, for optimized code var-tracking
11646 is supposed to track where the arguments live and the register
11647 used as vdrap or drap in some spot might be used for something
11648 else in other part of the routine. */
11649 return new_loc_descr (DW_OP_fbreg, offset, 0);
11653 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
11656 result = new_loc_descr (DW_OP_bregx, regno, offset);
11658 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11659 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11664 /* Return true if this RTL expression describes a base+offset calculation. */
11667 is_based_loc (const_rtx rtl)
11669 return (GET_CODE (rtl) == PLUS
11670 && ((REG_P (XEXP (rtl, 0))
11671 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
11672 && CONST_INT_P (XEXP (rtl, 1)))));
11675 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11678 static dw_loc_descr_ref
11679 tls_mem_loc_descriptor (rtx mem)
11682 dw_loc_descr_ref loc_result;
11684 if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
11687 base = get_base_address (MEM_EXPR (mem));
11689 || TREE_CODE (base) != VAR_DECL
11690 || !DECL_THREAD_LOCAL_P (base))
11693 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1, NULL);
11694 if (loc_result == NULL)
11697 if (MEM_OFFSET (mem))
11698 loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
11703 /* Output debug info about reason why we failed to expand expression as dwarf
11707 expansion_failed (tree expr, rtx rtl, char const *reason)
11709 if (dump_file && (dump_flags & TDF_DETAILS))
11711 fprintf (dump_file, "Failed to expand as dwarf: ");
11713 print_generic_expr (dump_file, expr, dump_flags);
11716 fprintf (dump_file, "\n");
11717 print_rtl (dump_file, rtl);
11719 fprintf (dump_file, "\nReason: %s\n", reason);
11723 /* Helper function for const_ok_for_output. */
11726 const_ok_for_output_1 (rtx rtl)
11728 if (GET_CODE (rtl) == UNSPEC)
11730 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11731 we can't express it in the debug info. */
11732 #ifdef ENABLE_CHECKING
11733 /* Don't complain about TLS UNSPECs, those are just too hard to
11734 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11735 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11736 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11737 if (XVECLEN (rtl, 0) == 0
11738 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
11739 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl, 0, 0)) == TLS_MODEL_NONE)
11740 inform (current_function_decl
11741 ? DECL_SOURCE_LOCATION (current_function_decl)
11742 : UNKNOWN_LOCATION,
11743 #if NUM_UNSPEC_VALUES > 0
11744 "non-delegitimized UNSPEC %s (%d) found in variable location",
11745 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
11746 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
11749 "non-delegitimized UNSPEC %d found in variable location",
11753 expansion_failed (NULL_TREE, rtl,
11754 "UNSPEC hasn't been delegitimized.\n");
11758 if (targetm.const_not_ok_for_debug_p (rtl))
11760 expansion_failed (NULL_TREE, rtl,
11761 "Expression rejected for debug by the backend.\n");
11765 /* FIXME: Refer to PR60655. It is possible for simplification
11766 of rtl expressions in var tracking to produce such expressions.
11767 We should really identify / validate expressions
11768 enclosed in CONST that can be handled by assemblers on various
11769 targets and only handle legitimate cases here. */
11770 if (GET_CODE (rtl) != SYMBOL_REF)
11772 if (GET_CODE (rtl) == NOT)
11777 if (CONSTANT_POOL_ADDRESS_P (rtl))
11780 get_pool_constant_mark (rtl, &marked);
11781 /* If all references to this pool constant were optimized away,
11782 it was not output and thus we can't represent it. */
11785 expansion_failed (NULL_TREE, rtl,
11786 "Constant was removed from constant pool.\n");
11791 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11794 /* Avoid references to external symbols in debug info, on several targets
11795 the linker might even refuse to link when linking a shared library,
11796 and in many other cases the relocations for .debug_info/.debug_loc are
11797 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11798 to be defined within the same shared library or executable are fine. */
11799 if (SYMBOL_REF_EXTERNAL_P (rtl))
11801 tree decl = SYMBOL_REF_DECL (rtl);
11803 if (decl == NULL || !targetm.binds_local_p (decl))
11805 expansion_failed (NULL_TREE, rtl,
11806 "Symbol not defined in current TU.\n");
11814 /* Return true if constant RTL can be emitted in DW_OP_addr or
11815 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11816 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11819 const_ok_for_output (rtx rtl)
11821 if (GET_CODE (rtl) == SYMBOL_REF)
11822 return const_ok_for_output_1 (rtl);
11824 if (GET_CODE (rtl) == CONST)
11826 subrtx_var_iterator::array_type array;
11827 FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
11828 if (!const_ok_for_output_1 (*iter))
11836 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11837 if possible, NULL otherwise. */
11840 base_type_for_mode (machine_mode mode, bool unsignedp)
11842 dw_die_ref type_die;
11843 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
11847 switch (TREE_CODE (type))
11855 type_die = lookup_type_die (type);
11857 type_die = modified_type_die (type, TYPE_UNQUALIFIED, comp_unit_die ());
11858 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
11863 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11864 type matching MODE, or, if MODE is narrower than or as wide as
11865 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11868 static dw_loc_descr_ref
11869 convert_descriptor_to_mode (machine_mode mode, dw_loc_descr_ref op)
11871 machine_mode outer_mode = mode;
11872 dw_die_ref type_die;
11873 dw_loc_descr_ref cvt;
11875 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11877 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
11880 type_die = base_type_for_mode (outer_mode, 1);
11881 if (type_die == NULL)
11883 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11884 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11885 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11886 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11887 add_loc_descr (&op, cvt);
11891 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11893 static dw_loc_descr_ref
11894 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
11895 dw_loc_descr_ref op1)
11897 dw_loc_descr_ref ret = op0;
11898 add_loc_descr (&ret, op1);
11899 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11900 if (STORE_FLAG_VALUE != 1)
11902 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
11903 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
11908 /* Return location descriptor for signed comparison OP RTL. */
11910 static dw_loc_descr_ref
11911 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
11912 machine_mode mem_mode)
11914 machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
11915 dw_loc_descr_ref op0, op1;
11918 if (op_mode == VOIDmode)
11919 op_mode = GET_MODE (XEXP (rtl, 1));
11920 if (op_mode == VOIDmode)
11924 && (GET_MODE_CLASS (op_mode) != MODE_INT
11925 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
11928 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
11929 VAR_INIT_STATUS_INITIALIZED);
11930 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
11931 VAR_INIT_STATUS_INITIALIZED);
11933 if (op0 == NULL || op1 == NULL)
11936 if (GET_MODE_CLASS (op_mode) != MODE_INT
11937 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
11938 return compare_loc_descriptor (op, op0, op1);
11940 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
11942 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
11943 dw_loc_descr_ref cvt;
11945 if (type_die == NULL)
11947 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11948 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11949 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11950 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11951 add_loc_descr (&op0, cvt);
11952 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11953 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11954 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11955 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11956 add_loc_descr (&op1, cvt);
11957 return compare_loc_descriptor (op, op0, op1);
11960 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
11961 /* For eq/ne, if the operands are known to be zero-extended,
11962 there is no need to do the fancy shifting up. */
11963 if (op == DW_OP_eq || op == DW_OP_ne)
11965 dw_loc_descr_ref last0, last1;
11966 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
11968 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
11970 /* deref_size zero extends, and for constants we can check
11971 whether they are zero extended or not. */
11972 if (((last0->dw_loc_opc == DW_OP_deref_size
11973 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
11974 || (CONST_INT_P (XEXP (rtl, 0))
11975 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
11976 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
11977 && ((last1->dw_loc_opc == DW_OP_deref_size
11978 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
11979 || (CONST_INT_P (XEXP (rtl, 1))
11980 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
11981 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
11982 return compare_loc_descriptor (op, op0, op1);
11984 /* EQ/NE comparison against constant in narrower type than
11985 DWARF2_ADDR_SIZE can be performed either as
11986 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11989 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11990 DW_OP_{eq,ne}. Pick whatever is shorter. */
11991 if (CONST_INT_P (XEXP (rtl, 1))
11992 && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
11993 && (size_of_int_loc_descriptor (shift) + 1
11994 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift)
11995 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
11996 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
11997 & GET_MODE_MASK (op_mode))))
11999 add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
12000 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
12001 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
12002 & GET_MODE_MASK (op_mode));
12003 return compare_loc_descriptor (op, op0, op1);
12006 add_loc_descr (&op0, int_loc_descriptor (shift));
12007 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
12008 if (CONST_INT_P (XEXP (rtl, 1)))
12009 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
12012 add_loc_descr (&op1, int_loc_descriptor (shift));
12013 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
12015 return compare_loc_descriptor (op, op0, op1);
12018 /* Return location descriptor for unsigned comparison OP RTL. */
12020 static dw_loc_descr_ref
12021 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
12022 machine_mode mem_mode)
12024 machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
12025 dw_loc_descr_ref op0, op1;
12027 if (op_mode == VOIDmode)
12028 op_mode = GET_MODE (XEXP (rtl, 1));
12029 if (op_mode == VOIDmode)
12031 if (GET_MODE_CLASS (op_mode) != MODE_INT)
12034 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
12037 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
12038 VAR_INIT_STATUS_INITIALIZED);
12039 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
12040 VAR_INIT_STATUS_INITIALIZED);
12042 if (op0 == NULL || op1 == NULL)
12045 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
12047 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
12048 dw_loc_descr_ref last0, last1;
12049 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
12051 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
12053 if (CONST_INT_P (XEXP (rtl, 0)))
12054 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
12055 /* deref_size zero extends, so no need to mask it again. */
12056 else if (last0->dw_loc_opc != DW_OP_deref_size
12057 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
12059 add_loc_descr (&op0, int_loc_descriptor (mask));
12060 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
12062 if (CONST_INT_P (XEXP (rtl, 1)))
12063 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
12064 /* deref_size zero extends, so no need to mask it again. */
12065 else if (last1->dw_loc_opc != DW_OP_deref_size
12066 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
12068 add_loc_descr (&op1, int_loc_descriptor (mask));
12069 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
12072 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
12074 HOST_WIDE_INT bias = 1;
12075 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
12076 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
12077 if (CONST_INT_P (XEXP (rtl, 1)))
12078 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
12079 + INTVAL (XEXP (rtl, 1)));
12081 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
12084 return compare_loc_descriptor (op, op0, op1);
12087 /* Return location descriptor for {U,S}{MIN,MAX}. */
12089 static dw_loc_descr_ref
12090 minmax_loc_descriptor (rtx rtl, machine_mode mode,
12091 machine_mode mem_mode)
12093 enum dwarf_location_atom op;
12094 dw_loc_descr_ref op0, op1, ret;
12095 dw_loc_descr_ref bra_node, drop_node;
12098 && (GET_MODE_CLASS (mode) != MODE_INT
12099 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
12102 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12103 VAR_INIT_STATUS_INITIALIZED);
12104 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12105 VAR_INIT_STATUS_INITIALIZED);
12107 if (op0 == NULL || op1 == NULL)
12110 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
12111 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
12112 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
12113 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
12115 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
12117 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
12118 add_loc_descr (&op0, int_loc_descriptor (mask));
12119 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
12120 add_loc_descr (&op1, int_loc_descriptor (mask));
12121 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
12123 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
12125 HOST_WIDE_INT bias = 1;
12126 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
12127 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
12128 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
12131 else if (GET_MODE_CLASS (mode) == MODE_INT
12132 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
12134 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
12135 add_loc_descr (&op0, int_loc_descriptor (shift));
12136 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
12137 add_loc_descr (&op1, int_loc_descriptor (shift));
12138 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
12140 else if (GET_MODE_CLASS (mode) == MODE_INT
12141 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12143 dw_die_ref type_die = base_type_for_mode (mode, 0);
12144 dw_loc_descr_ref cvt;
12145 if (type_die == NULL)
12147 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12148 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12149 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12150 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12151 add_loc_descr (&op0, cvt);
12152 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12153 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12154 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12155 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12156 add_loc_descr (&op1, cvt);
12159 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
12164 add_loc_descr (&ret, op1);
12165 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
12166 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12167 add_loc_descr (&ret, bra_node);
12168 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12169 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
12170 add_loc_descr (&ret, drop_node);
12171 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12172 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
12173 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
12174 && GET_MODE_CLASS (mode) == MODE_INT
12175 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12176 ret = convert_descriptor_to_mode (mode, ret);
12180 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12181 but after converting arguments to type_die, afterwards
12182 convert back to unsigned. */
12184 static dw_loc_descr_ref
12185 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
12186 machine_mode mode, machine_mode mem_mode)
12188 dw_loc_descr_ref cvt, op0, op1;
12190 if (type_die == NULL)
12192 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12193 VAR_INIT_STATUS_INITIALIZED);
12194 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12195 VAR_INIT_STATUS_INITIALIZED);
12196 if (op0 == NULL || op1 == NULL)
12198 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12199 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12200 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12201 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12202 add_loc_descr (&op0, cvt);
12203 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12204 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12205 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12206 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12207 add_loc_descr (&op1, cvt);
12208 add_loc_descr (&op0, op1);
12209 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
12210 return convert_descriptor_to_mode (mode, op0);
12213 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12214 const0 is DW_OP_lit0 or corresponding typed constant,
12215 const1 is DW_OP_lit1 or corresponding typed constant
12216 and constMSB is constant with just the MSB bit set
12218 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12219 L1: const0 DW_OP_swap
12220 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12221 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12226 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12227 L1: const0 DW_OP_swap
12228 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12229 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12234 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12235 L1: const1 DW_OP_swap
12236 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12237 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12241 static dw_loc_descr_ref
12242 clz_loc_descriptor (rtx rtl, machine_mode mode,
12243 machine_mode mem_mode)
12245 dw_loc_descr_ref op0, ret, tmp;
12246 HOST_WIDE_INT valv;
12247 dw_loc_descr_ref l1jump, l1label;
12248 dw_loc_descr_ref l2jump, l2label;
12249 dw_loc_descr_ref l3jump, l3label;
12250 dw_loc_descr_ref l4jump, l4label;
12253 if (GET_MODE_CLASS (mode) != MODE_INT
12254 || GET_MODE (XEXP (rtl, 0)) != mode)
12257 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12258 VAR_INIT_STATUS_INITIALIZED);
12262 if (GET_CODE (rtl) == CLZ)
12264 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
12265 valv = GET_MODE_BITSIZE (mode);
12267 else if (GET_CODE (rtl) == FFS)
12269 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
12270 valv = GET_MODE_BITSIZE (mode);
12271 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
12272 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
12273 add_loc_descr (&ret, l1jump);
12274 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
12275 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
12276 VAR_INIT_STATUS_INITIALIZED);
12279 add_loc_descr (&ret, tmp);
12280 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
12281 add_loc_descr (&ret, l4jump);
12282 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
12283 ? const1_rtx : const0_rtx,
12285 VAR_INIT_STATUS_INITIALIZED);
12286 if (l1label == NULL)
12288 add_loc_descr (&ret, l1label);
12289 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12290 l2label = new_loc_descr (DW_OP_dup, 0, 0);
12291 add_loc_descr (&ret, l2label);
12292 if (GET_CODE (rtl) != CLZ)
12294 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
12295 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
12296 << (GET_MODE_BITSIZE (mode) - 1));
12298 msb = immed_wide_int_const
12299 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode) - 1,
12300 GET_MODE_PRECISION (mode)), mode);
12301 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
12302 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
12303 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
12304 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
12306 tmp = mem_loc_descriptor (msb, mode, mem_mode,
12307 VAR_INIT_STATUS_INITIALIZED);
12310 add_loc_descr (&ret, tmp);
12311 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
12312 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
12313 add_loc_descr (&ret, l3jump);
12314 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
12315 VAR_INIT_STATUS_INITIALIZED);
12318 add_loc_descr (&ret, tmp);
12319 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
12320 ? DW_OP_shl : DW_OP_shr, 0, 0));
12321 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12322 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
12323 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12324 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
12325 add_loc_descr (&ret, l2jump);
12326 l3label = new_loc_descr (DW_OP_drop, 0, 0);
12327 add_loc_descr (&ret, l3label);
12328 l4label = new_loc_descr (DW_OP_nop, 0, 0);
12329 add_loc_descr (&ret, l4label);
12330 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12331 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
12332 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12333 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
12334 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12335 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
12336 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12337 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
12341 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
12342 const1 is DW_OP_lit1 or corresponding typed constant):
12344 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12345 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12349 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12350 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12353 static dw_loc_descr_ref
12354 popcount_loc_descriptor (rtx rtl, machine_mode mode,
12355 machine_mode mem_mode)
12357 dw_loc_descr_ref op0, ret, tmp;
12358 dw_loc_descr_ref l1jump, l1label;
12359 dw_loc_descr_ref l2jump, l2label;
12361 if (GET_MODE_CLASS (mode) != MODE_INT
12362 || GET_MODE (XEXP (rtl, 0)) != mode)
12365 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12366 VAR_INIT_STATUS_INITIALIZED);
12370 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
12371 VAR_INIT_STATUS_INITIALIZED);
12374 add_loc_descr (&ret, tmp);
12375 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12376 l1label = new_loc_descr (DW_OP_dup, 0, 0);
12377 add_loc_descr (&ret, l1label);
12378 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
12379 add_loc_descr (&ret, l2jump);
12380 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
12381 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
12382 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
12383 VAR_INIT_STATUS_INITIALIZED);
12386 add_loc_descr (&ret, tmp);
12387 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
12388 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
12389 ? DW_OP_plus : DW_OP_xor, 0, 0));
12390 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12391 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
12392 VAR_INIT_STATUS_INITIALIZED);
12393 add_loc_descr (&ret, tmp);
12394 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
12395 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
12396 add_loc_descr (&ret, l1jump);
12397 l2label = new_loc_descr (DW_OP_drop, 0, 0);
12398 add_loc_descr (&ret, l2label);
12399 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12400 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
12401 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12402 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
12406 /* BSWAP (constS is initial shift count, either 56 or 24):
12408 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12409 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12410 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12411 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12412 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12414 static dw_loc_descr_ref
12415 bswap_loc_descriptor (rtx rtl, machine_mode mode,
12416 machine_mode mem_mode)
12418 dw_loc_descr_ref op0, ret, tmp;
12419 dw_loc_descr_ref l1jump, l1label;
12420 dw_loc_descr_ref l2jump, l2label;
12422 if (GET_MODE_CLASS (mode) != MODE_INT
12423 || BITS_PER_UNIT != 8
12424 || (GET_MODE_BITSIZE (mode) != 32
12425 && GET_MODE_BITSIZE (mode) != 64))
12428 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12429 VAR_INIT_STATUS_INITIALIZED);
12434 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
12436 VAR_INIT_STATUS_INITIALIZED);
12439 add_loc_descr (&ret, tmp);
12440 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
12441 VAR_INIT_STATUS_INITIALIZED);
12444 add_loc_descr (&ret, tmp);
12445 l1label = new_loc_descr (DW_OP_pick, 2, 0);
12446 add_loc_descr (&ret, l1label);
12447 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
12449 VAR_INIT_STATUS_INITIALIZED);
12450 add_loc_descr (&ret, tmp);
12451 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
12452 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
12453 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
12454 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
12455 VAR_INIT_STATUS_INITIALIZED);
12458 add_loc_descr (&ret, tmp);
12459 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
12460 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
12461 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
12462 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
12463 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12464 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
12465 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
12466 VAR_INIT_STATUS_INITIALIZED);
12467 add_loc_descr (&ret, tmp);
12468 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
12469 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
12470 add_loc_descr (&ret, l2jump);
12471 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
12472 VAR_INIT_STATUS_INITIALIZED);
12473 add_loc_descr (&ret, tmp);
12474 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
12475 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12476 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
12477 add_loc_descr (&ret, l1jump);
12478 l2label = new_loc_descr (DW_OP_drop, 0, 0);
12479 add_loc_descr (&ret, l2label);
12480 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12481 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
12482 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12483 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
12484 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
12485 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
12489 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12490 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12491 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12492 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12494 ROTATERT is similar:
12495 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12496 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12497 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12499 static dw_loc_descr_ref
12500 rotate_loc_descriptor (rtx rtl, machine_mode mode,
12501 machine_mode mem_mode)
12503 rtx rtlop1 = XEXP (rtl, 1);
12504 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
12507 if (GET_MODE_CLASS (mode) != MODE_INT)
12510 if (GET_MODE (rtlop1) != VOIDmode
12511 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
12512 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
12513 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12514 VAR_INIT_STATUS_INITIALIZED);
12515 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
12516 VAR_INIT_STATUS_INITIALIZED);
12517 if (op0 == NULL || op1 == NULL)
12519 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
12520 for (i = 0; i < 2; i++)
12522 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
12523 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
12525 VAR_INIT_STATUS_INITIALIZED);
12526 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
12527 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
12529 : HOST_BITS_PER_WIDE_INT == 64
12530 ? DW_OP_const8u : DW_OP_constu,
12531 GET_MODE_MASK (mode), 0);
12534 if (mask[i] == NULL)
12536 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
12539 add_loc_descr (&ret, op1);
12540 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
12541 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
12542 if (GET_CODE (rtl) == ROTATERT)
12544 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
12545 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
12546 GET_MODE_BITSIZE (mode), 0));
12548 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
12549 if (mask[0] != NULL)
12550 add_loc_descr (&ret, mask[0]);
12551 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
12552 if (mask[1] != NULL)
12554 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12555 add_loc_descr (&ret, mask[1]);
12556 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
12558 if (GET_CODE (rtl) == ROTATE)
12560 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
12561 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
12562 GET_MODE_BITSIZE (mode), 0));
12564 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
12565 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
12569 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12570 for DEBUG_PARAMETER_REF RTL. */
12572 static dw_loc_descr_ref
12573 parameter_ref_descriptor (rtx rtl)
12575 dw_loc_descr_ref ret;
12580 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
12581 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
12582 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
12585 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12586 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
12587 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
12591 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
12592 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
12597 /* The following routine converts the RTL for a variable or parameter
12598 (resident in memory) into an equivalent Dwarf representation of a
12599 mechanism for getting the address of that same variable onto the top of a
12600 hypothetical "address evaluation" stack.
12602 When creating memory location descriptors, we are effectively transforming
12603 the RTL for a memory-resident object into its Dwarf postfix expression
12604 equivalent. This routine recursively descends an RTL tree, turning
12605 it into Dwarf postfix code as it goes.
12607 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12609 MEM_MODE is the mode of the memory reference, needed to handle some
12610 autoincrement addressing modes.
12612 Return 0 if we can't represent the location. */
12615 mem_loc_descriptor (rtx rtl, machine_mode mode,
12616 machine_mode mem_mode,
12617 enum var_init_status initialized)
12619 dw_loc_descr_ref mem_loc_result = NULL;
12620 enum dwarf_location_atom op;
12621 dw_loc_descr_ref op0, op1;
12622 rtx inner = NULL_RTX;
12624 if (mode == VOIDmode)
12625 mode = GET_MODE (rtl);
12627 /* Note that for a dynamically sized array, the location we will generate a
12628 description of here will be the lowest numbered location which is
12629 actually within the array. That's *not* necessarily the same as the
12630 zeroth element of the array. */
12632 rtl = targetm.delegitimize_address (rtl);
12634 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
12637 switch (GET_CODE (rtl))
12642 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
12645 /* The case of a subreg may arise when we have a local (register)
12646 variable or a formal (register) parameter which doesn't quite fill
12647 up an entire register. For now, just assume that it is
12648 legitimate to make the Dwarf info refer to the whole register which
12649 contains the given subreg. */
12650 if (!subreg_lowpart_p (rtl))
12652 inner = SUBREG_REG (rtl);
12654 if (inner == NULL_RTX)
12655 inner = XEXP (rtl, 0);
12656 if (GET_MODE_CLASS (mode) == MODE_INT
12657 && GET_MODE_CLASS (GET_MODE (inner)) == MODE_INT
12658 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12659 #ifdef POINTERS_EXTEND_UNSIGNED
12660 || (mode == Pmode && mem_mode != VOIDmode)
12663 && GET_MODE_SIZE (GET_MODE (inner)) <= DWARF2_ADDR_SIZE)
12665 mem_loc_result = mem_loc_descriptor (inner,
12667 mem_mode, initialized);
12672 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (inner)))
12674 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (inner))
12675 && (GET_MODE_CLASS (mode) != MODE_INT
12676 || GET_MODE_CLASS (GET_MODE (inner)) != MODE_INT))
12680 dw_die_ref type_die;
12681 dw_loc_descr_ref cvt;
12683 mem_loc_result = mem_loc_descriptor (inner,
12685 mem_mode, initialized);
12686 if (mem_loc_result == NULL)
12688 type_die = base_type_for_mode (mode,
12689 GET_MODE_CLASS (mode) == MODE_INT);
12690 if (type_die == NULL)
12692 mem_loc_result = NULL;
12695 if (GET_MODE_SIZE (mode)
12696 != GET_MODE_SIZE (GET_MODE (inner)))
12697 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12699 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
12700 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12701 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12702 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12703 add_loc_descr (&mem_loc_result, cvt);
12708 if (GET_MODE_CLASS (mode) != MODE_INT
12709 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12710 && rtl != arg_pointer_rtx
12711 && rtl != frame_pointer_rtx
12712 #ifdef POINTERS_EXTEND_UNSIGNED
12713 && (mode != Pmode || mem_mode == VOIDmode)
12717 dw_die_ref type_die;
12718 unsigned int dbx_regnum;
12722 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
12724 type_die = base_type_for_mode (mode,
12725 GET_MODE_CLASS (mode) == MODE_INT);
12726 if (type_die == NULL)
12729 dbx_regnum = dbx_reg_number (rtl);
12730 if (dbx_regnum == IGNORED_DWARF_REGNUM)
12732 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
12734 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
12735 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
12736 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
12739 /* Whenever a register number forms a part of the description of the
12740 method for calculating the (dynamic) address of a memory resident
12741 object, DWARF rules require the register number be referred to as
12742 a "base register". This distinction is not based in any way upon
12743 what category of register the hardware believes the given register
12744 belongs to. This is strictly DWARF terminology we're dealing with
12745 here. Note that in cases where the location of a memory-resident
12746 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12747 OP_CONST (0)) the actual DWARF location descriptor that we generate
12748 may just be OP_BASEREG (basereg). This may look deceptively like
12749 the object in question was allocated to a register (rather than in
12750 memory) so DWARF consumers need to be aware of the subtle
12751 distinction between OP_REG and OP_BASEREG. */
12752 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
12753 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
12754 else if (stack_realign_drap
12756 && crtl->args.internal_arg_pointer == rtl
12757 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
12759 /* If RTL is internal_arg_pointer, which has been optimized
12760 out, use DRAP instead. */
12761 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
12762 VAR_INIT_STATUS_INITIALIZED);
12768 if (GET_MODE_CLASS (mode) != MODE_INT)
12770 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12771 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12774 else if (GET_CODE (rtl) == ZERO_EXTEND
12775 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12776 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
12777 < HOST_BITS_PER_WIDE_INT
12778 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12779 to expand zero extend as two shifts instead of
12781 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
12783 machine_mode imode = GET_MODE (XEXP (rtl, 0));
12784 mem_loc_result = op0;
12785 add_loc_descr (&mem_loc_result,
12786 int_loc_descriptor (GET_MODE_MASK (imode)));
12787 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
12789 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
12791 int shift = DWARF2_ADDR_SIZE
12792 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
12793 shift *= BITS_PER_UNIT;
12794 if (GET_CODE (rtl) == SIGN_EXTEND)
12798 mem_loc_result = op0;
12799 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
12800 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
12801 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
12802 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12804 else if (!dwarf_strict)
12806 dw_die_ref type_die1, type_die2;
12807 dw_loc_descr_ref cvt;
12809 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12810 GET_CODE (rtl) == ZERO_EXTEND);
12811 if (type_die1 == NULL)
12813 type_die2 = base_type_for_mode (mode, 1);
12814 if (type_die2 == NULL)
12816 mem_loc_result = op0;
12817 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12818 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12819 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
12820 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12821 add_loc_descr (&mem_loc_result, cvt);
12822 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12823 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12824 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
12825 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12826 add_loc_descr (&mem_loc_result, cvt);
12832 rtx new_rtl = avoid_constant_pool_reference (rtl);
12833 if (new_rtl != rtl)
12835 mem_loc_result = mem_loc_descriptor (new_rtl, mode, mem_mode,
12837 if (mem_loc_result != NULL)
12838 return mem_loc_result;
12841 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
12842 get_address_mode (rtl), mode,
12843 VAR_INIT_STATUS_INITIALIZED);
12844 if (mem_loc_result == NULL)
12845 mem_loc_result = tls_mem_loc_descriptor (rtl);
12846 if (mem_loc_result != NULL)
12848 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12849 || GET_MODE_CLASS (mode) != MODE_INT)
12851 dw_die_ref type_die;
12852 dw_loc_descr_ref deref;
12857 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
12858 if (type_die == NULL)
12860 deref = new_loc_descr (DW_OP_GNU_deref_type,
12861 GET_MODE_SIZE (mode), 0);
12862 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
12863 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
12864 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
12865 add_loc_descr (&mem_loc_result, deref);
12867 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
12868 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
12870 add_loc_descr (&mem_loc_result,
12871 new_loc_descr (DW_OP_deref_size,
12872 GET_MODE_SIZE (mode), 0));
12877 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
12880 /* Some ports can transform a symbol ref into a label ref, because
12881 the symbol ref is too far away and has to be dumped into a constant
12885 if ((GET_MODE_CLASS (mode) != MODE_INT
12886 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
12887 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12888 #ifdef POINTERS_EXTEND_UNSIGNED
12889 && (mode != Pmode || mem_mode == VOIDmode)
12893 if (GET_CODE (rtl) == SYMBOL_REF
12894 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
12896 dw_loc_descr_ref temp;
12898 /* If this is not defined, we have no way to emit the data. */
12899 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
12902 temp = new_addr_loc_descr (rtl, dtprel_true);
12904 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
12905 add_loc_descr (&mem_loc_result, temp);
12910 if (!const_ok_for_output (rtl))
12912 if (GET_CODE (rtl) == CONST)
12913 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12919 mem_loc_result = new_addr_loc_descr (rtl, dtprel_false);
12920 vec_safe_push (used_rtx_array, rtl);
12926 case DEBUG_IMPLICIT_PTR:
12927 expansion_failed (NULL_TREE, rtl,
12928 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12934 if (REG_P (ENTRY_VALUE_EXP (rtl)))
12936 if (GET_MODE_CLASS (mode) != MODE_INT
12937 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12938 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
12939 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12942 unsigned int dbx_regnum = dbx_reg_number (ENTRY_VALUE_EXP (rtl));
12943 if (dbx_regnum == IGNORED_DWARF_REGNUM)
12945 op0 = one_reg_loc_descriptor (dbx_regnum,
12946 VAR_INIT_STATUS_INITIALIZED);
12949 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
12950 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
12952 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
12953 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12954 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
12958 gcc_unreachable ();
12961 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
12962 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
12963 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
12966 case DEBUG_PARAMETER_REF:
12967 mem_loc_result = parameter_ref_descriptor (rtl);
12971 /* Extract the PLUS expression nested inside and fall into
12972 PLUS code below. */
12973 rtl = XEXP (rtl, 1);
12978 /* Turn these into a PLUS expression and fall into the PLUS code
12980 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
12981 gen_int_mode (GET_CODE (rtl) == PRE_INC
12982 ? GET_MODE_UNIT_SIZE (mem_mode)
12983 : -GET_MODE_UNIT_SIZE (mem_mode),
12986 /* ... fall through ... */
12990 if (is_based_loc (rtl)
12991 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12992 || XEXP (rtl, 0) == arg_pointer_rtx
12993 || XEXP (rtl, 0) == frame_pointer_rtx)
12994 && GET_MODE_CLASS (mode) == MODE_INT)
12995 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
12996 INTVAL (XEXP (rtl, 1)),
12997 VAR_INIT_STATUS_INITIALIZED);
13000 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13001 VAR_INIT_STATUS_INITIALIZED);
13002 if (mem_loc_result == 0)
13005 if (CONST_INT_P (XEXP (rtl, 1))
13006 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
13007 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13010 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13011 VAR_INIT_STATUS_INITIALIZED);
13014 add_loc_descr (&mem_loc_result, op1);
13015 add_loc_descr (&mem_loc_result,
13016 new_loc_descr (DW_OP_plus, 0, 0));
13021 /* If a pseudo-reg is optimized away, it is possible for it to
13022 be replaced with a MEM containing a multiply or shift. */
13033 && GET_MODE_CLASS (mode) == MODE_INT
13034 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
13036 mem_loc_result = typed_binop (DW_OP_div, rtl,
13037 base_type_for_mode (mode, 0),
13061 if (GET_MODE_CLASS (mode) != MODE_INT)
13063 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13064 VAR_INIT_STATUS_INITIALIZED);
13066 rtx rtlop1 = XEXP (rtl, 1);
13067 if (GET_MODE (rtlop1) != VOIDmode
13068 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
13069 < GET_MODE_BITSIZE (mode))
13070 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
13071 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
13072 VAR_INIT_STATUS_INITIALIZED);
13075 if (op0 == 0 || op1 == 0)
13078 mem_loc_result = op0;
13079 add_loc_descr (&mem_loc_result, op1);
13080 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13096 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13097 VAR_INIT_STATUS_INITIALIZED);
13098 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13099 VAR_INIT_STATUS_INITIALIZED);
13101 if (op0 == 0 || op1 == 0)
13104 mem_loc_result = op0;
13105 add_loc_descr (&mem_loc_result, op1);
13106 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13110 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
13112 mem_loc_result = typed_binop (DW_OP_mod, rtl,
13113 base_type_for_mode (mode, 0),
13118 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13119 VAR_INIT_STATUS_INITIALIZED);
13120 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13121 VAR_INIT_STATUS_INITIALIZED);
13123 if (op0 == 0 || op1 == 0)
13126 mem_loc_result = op0;
13127 add_loc_descr (&mem_loc_result, op1);
13128 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
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_div, 0, 0));
13131 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13132 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
13136 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
13138 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
13143 mem_loc_result = typed_binop (DW_OP_div, rtl,
13144 base_type_for_mode (mode, 1),
13162 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
13163 VAR_INIT_STATUS_INITIALIZED);
13168 mem_loc_result = op0;
13169 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13173 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
13174 #ifdef POINTERS_EXTEND_UNSIGNED
13176 && mem_mode != VOIDmode
13177 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
13181 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13185 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
13186 || GET_MODE_BITSIZE (mode) == HOST_BITS_PER_DOUBLE_INT))
13188 dw_die_ref type_die = base_type_for_mode (mode, 1);
13189 machine_mode amode;
13190 if (type_die == NULL)
13192 amode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
13194 if (INTVAL (rtl) >= 0
13195 && amode != BLKmode
13196 && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
13197 /* const DW_OP_GNU_convert <XXX> vs.
13198 DW_OP_GNU_const_type <XXX, 1, const>. */
13199 && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
13200 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode))
13202 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13203 op0 = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13204 op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13205 op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13206 op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
13207 add_loc_descr (&mem_loc_result, op0);
13208 return mem_loc_result;
13210 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
13212 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13213 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13214 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
13215 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
13216 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13219 mem_loc_result->dw_loc_oprnd2.val_class
13220 = dw_val_class_const_double;
13221 mem_loc_result->dw_loc_oprnd2.v.val_double
13222 = double_int::from_shwi (INTVAL (rtl));
13230 dw_die_ref type_die;
13232 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13233 CONST_DOUBLE rtx could represent either a large integer
13234 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13235 the value is always a floating point constant.
13237 When it is an integer, a CONST_DOUBLE is used whenever
13238 the constant requires 2 HWIs to be adequately represented.
13239 We output CONST_DOUBLEs as blocks. */
13240 if (mode == VOIDmode
13241 || (GET_MODE (rtl) == VOIDmode
13242 && GET_MODE_BITSIZE (mode) != HOST_BITS_PER_DOUBLE_INT))
13244 type_die = base_type_for_mode (mode,
13245 GET_MODE_CLASS (mode) == MODE_INT);
13246 if (type_die == NULL)
13248 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
13249 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13250 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13251 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
13252 #if TARGET_SUPPORTS_WIDE_INT == 0
13253 if (!SCALAR_FLOAT_MODE_P (mode))
13255 mem_loc_result->dw_loc_oprnd2.val_class
13256 = dw_val_class_const_double;
13257 mem_loc_result->dw_loc_oprnd2.v.val_double
13258 = rtx_to_double_int (rtl);
13263 unsigned int length = GET_MODE_SIZE (mode);
13264 unsigned char *array = ggc_vec_alloc<unsigned char> (length);
13266 insert_float (rtl, array);
13267 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13268 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
13269 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
13270 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13275 case CONST_WIDE_INT:
13278 dw_die_ref type_die;
13280 type_die = base_type_for_mode (mode,
13281 GET_MODE_CLASS (mode) == MODE_INT);
13282 if (type_die == NULL)
13284 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
13285 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13286 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13287 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
13288 mem_loc_result->dw_loc_oprnd2.val_class
13289 = dw_val_class_wide_int;
13290 mem_loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc<wide_int> ();
13291 *mem_loc_result->dw_loc_oprnd2.v.val_wide = std::make_pair (rtl, mode);
13296 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
13300 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
13304 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
13308 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
13312 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
13316 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
13320 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
13324 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
13328 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
13332 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
13337 if (GET_MODE_CLASS (mode) != MODE_INT)
13342 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
13347 if (CONST_INT_P (XEXP (rtl, 1))
13348 && CONST_INT_P (XEXP (rtl, 2))
13349 && ((unsigned) INTVAL (XEXP (rtl, 1))
13350 + (unsigned) INTVAL (XEXP (rtl, 2))
13351 <= GET_MODE_BITSIZE (mode))
13352 && GET_MODE_CLASS (mode) == MODE_INT
13353 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
13354 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
13357 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
13358 mem_mode, VAR_INIT_STATUS_INITIALIZED);
13361 if (GET_CODE (rtl) == SIGN_EXTRACT)
13365 mem_loc_result = op0;
13366 size = INTVAL (XEXP (rtl, 1));
13367 shift = INTVAL (XEXP (rtl, 2));
13368 if (BITS_BIG_ENDIAN)
13369 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
13371 if (shift + size != (int) DWARF2_ADDR_SIZE)
13373 add_loc_descr (&mem_loc_result,
13374 int_loc_descriptor (DWARF2_ADDR_SIZE
13376 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13378 if (size != (int) DWARF2_ADDR_SIZE)
13380 add_loc_descr (&mem_loc_result,
13381 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
13382 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13389 dw_loc_descr_ref op2, bra_node, drop_node;
13390 op0 = mem_loc_descriptor (XEXP (rtl, 0),
13391 GET_MODE (XEXP (rtl, 0)) == VOIDmode
13392 ? word_mode : GET_MODE (XEXP (rtl, 0)),
13393 mem_mode, VAR_INIT_STATUS_INITIALIZED);
13394 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
13395 VAR_INIT_STATUS_INITIALIZED);
13396 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
13397 VAR_INIT_STATUS_INITIALIZED);
13398 if (op0 == NULL || op1 == NULL || op2 == NULL)
13401 mem_loc_result = op1;
13402 add_loc_descr (&mem_loc_result, op2);
13403 add_loc_descr (&mem_loc_result, op0);
13404 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
13405 add_loc_descr (&mem_loc_result, bra_node);
13406 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
13407 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
13408 add_loc_descr (&mem_loc_result, drop_node);
13409 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13410 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
13415 case FLOAT_TRUNCATE:
13417 case UNSIGNED_FLOAT:
13422 dw_die_ref type_die;
13423 dw_loc_descr_ref cvt;
13425 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
13426 mem_mode, VAR_INIT_STATUS_INITIALIZED);
13429 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
13430 && (GET_CODE (rtl) == FLOAT
13431 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
13432 <= DWARF2_ADDR_SIZE))
13434 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
13435 GET_CODE (rtl) == UNSIGNED_FLOAT);
13436 if (type_die == NULL)
13438 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13439 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13440 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13441 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13442 add_loc_descr (&op0, cvt);
13444 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
13445 if (type_die == NULL)
13447 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
13448 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13449 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
13450 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
13451 add_loc_descr (&op0, cvt);
13452 if (GET_MODE_CLASS (mode) == MODE_INT
13453 && (GET_CODE (rtl) == FIX
13454 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
13456 op0 = convert_descriptor_to_mode (mode, op0);
13460 mem_loc_result = op0;
13467 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
13472 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
13476 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
13481 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
13485 /* In theory, we could implement the above. */
13486 /* DWARF cannot represent the unsigned compare operations
13511 case FRACT_CONVERT:
13512 case UNSIGNED_FRACT_CONVERT:
13514 case UNSIGNED_SAT_FRACT:
13520 case VEC_DUPLICATE:
13524 case STRICT_LOW_PART:
13529 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13530 can't express it in the debug info. This can happen e.g. with some
13535 resolve_one_addr (&rtl);
13539 #ifdef ENABLE_CHECKING
13540 print_rtl (stderr, rtl);
13541 gcc_unreachable ();
13547 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13548 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13550 return mem_loc_result;
13553 /* Return a descriptor that describes the concatenation of two locations.
13554 This is typically a complex variable. */
13556 static dw_loc_descr_ref
13557 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
13559 dw_loc_descr_ref cc_loc_result = NULL;
13560 dw_loc_descr_ref x0_ref
13561 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
13562 dw_loc_descr_ref x1_ref
13563 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
13565 if (x0_ref == 0 || x1_ref == 0)
13568 cc_loc_result = x0_ref;
13569 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
13571 add_loc_descr (&cc_loc_result, x1_ref);
13572 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
13574 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13575 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13577 return cc_loc_result;
13580 /* Return a descriptor that describes the concatenation of N
13583 static dw_loc_descr_ref
13584 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
13587 dw_loc_descr_ref cc_loc_result = NULL;
13588 unsigned int n = XVECLEN (concatn, 0);
13590 for (i = 0; i < n; ++i)
13592 dw_loc_descr_ref ref;
13593 rtx x = XVECEXP (concatn, 0, i);
13595 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
13599 add_loc_descr (&cc_loc_result, ref);
13600 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
13603 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13604 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13606 return cc_loc_result;
13609 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13610 for DEBUG_IMPLICIT_PTR RTL. */
13612 static dw_loc_descr_ref
13613 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
13615 dw_loc_descr_ref ret;
13620 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
13621 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
13622 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
13623 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
13624 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
13625 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
13628 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
13629 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
13630 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
13634 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
13635 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
13640 /* Output a proper Dwarf location descriptor for a variable or parameter
13641 which is either allocated in a register or in a memory location. For a
13642 register, we just generate an OP_REG and the register number. For a
13643 memory location we provide a Dwarf postfix expression describing how to
13644 generate the (dynamic) address of the object onto the address stack.
13646 MODE is mode of the decl if this loc_descriptor is going to be used in
13647 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13648 allowed, VOIDmode otherwise.
13650 If we don't know how to describe it, return 0. */
13652 static dw_loc_descr_ref
13653 loc_descriptor (rtx rtl, machine_mode mode,
13654 enum var_init_status initialized)
13656 dw_loc_descr_ref loc_result = NULL;
13658 switch (GET_CODE (rtl))
13661 /* The case of a subreg may arise when we have a local (register)
13662 variable or a formal (register) parameter which doesn't quite fill
13663 up an entire register. For now, just assume that it is
13664 legitimate to make the Dwarf info refer to the whole register which
13665 contains the given subreg. */
13666 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
13667 loc_result = loc_descriptor (SUBREG_REG (rtl),
13668 GET_MODE (SUBREG_REG (rtl)), initialized);
13674 loc_result = reg_loc_descriptor (rtl, initialized);
13678 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
13679 GET_MODE (rtl), initialized);
13680 if (loc_result == NULL)
13681 loc_result = tls_mem_loc_descriptor (rtl);
13682 if (loc_result == NULL)
13684 rtx new_rtl = avoid_constant_pool_reference (rtl);
13685 if (new_rtl != rtl)
13686 loc_result = loc_descriptor (new_rtl, mode, initialized);
13691 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
13696 loc_result = concatn_loc_descriptor (rtl, initialized);
13701 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
13703 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
13704 if (GET_CODE (loc) == EXPR_LIST)
13705 loc = XEXP (loc, 0);
13706 loc_result = loc_descriptor (loc, mode, initialized);
13710 rtl = XEXP (rtl, 1);
13715 rtvec par_elems = XVEC (rtl, 0);
13716 int num_elem = GET_NUM_ELEM (par_elems);
13720 /* Create the first one, so we have something to add to. */
13721 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
13722 VOIDmode, initialized);
13723 if (loc_result == NULL)
13725 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
13726 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
13727 for (i = 1; i < num_elem; i++)
13729 dw_loc_descr_ref temp;
13731 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
13732 VOIDmode, initialized);
13735 add_loc_descr (&loc_result, temp);
13736 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
13737 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
13743 if (mode != VOIDmode && mode != BLKmode)
13744 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
13749 if (mode == VOIDmode)
13750 mode = GET_MODE (rtl);
13752 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
13754 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
13756 /* Note that a CONST_DOUBLE rtx could represent either an integer
13757 or a floating-point constant. A CONST_DOUBLE is used whenever
13758 the constant requires more than one word in order to be
13759 adequately represented. We output CONST_DOUBLEs as blocks. */
13760 loc_result = new_loc_descr (DW_OP_implicit_value,
13761 GET_MODE_SIZE (mode), 0);
13762 #if TARGET_SUPPORTS_WIDE_INT == 0
13763 if (!SCALAR_FLOAT_MODE_P (mode))
13765 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
13766 loc_result->dw_loc_oprnd2.v.val_double
13767 = rtx_to_double_int (rtl);
13772 unsigned int length = GET_MODE_SIZE (mode);
13773 unsigned char *array = ggc_vec_alloc<unsigned char> (length);
13775 insert_float (rtl, array);
13776 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13777 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
13778 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
13779 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13784 case CONST_WIDE_INT:
13785 if (mode == VOIDmode)
13786 mode = GET_MODE (rtl);
13788 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
13790 loc_result = new_loc_descr (DW_OP_implicit_value,
13791 GET_MODE_SIZE (mode), 0);
13792 loc_result->dw_loc_oprnd2.val_class = dw_val_class_wide_int;
13793 loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc<wide_int> ();
13794 *loc_result->dw_loc_oprnd2.v.val_wide = std::make_pair (rtl, mode);
13799 if (mode == VOIDmode)
13800 mode = GET_MODE (rtl);
13802 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
13804 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
13805 unsigned int length = CONST_VECTOR_NUNITS (rtl);
13806 unsigned char *array
13807 = ggc_vec_alloc<unsigned char> (length * elt_size);
13810 machine_mode imode = GET_MODE_INNER (mode);
13812 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
13813 switch (GET_MODE_CLASS (mode))
13815 case MODE_VECTOR_INT:
13816 for (i = 0, p = array; i < length; i++, p += elt_size)
13818 rtx elt = CONST_VECTOR_ELT (rtl, i);
13819 insert_wide_int (std::make_pair (elt, imode), p, elt_size);
13823 case MODE_VECTOR_FLOAT:
13824 for (i = 0, p = array; i < length; i++, p += elt_size)
13826 rtx elt = CONST_VECTOR_ELT (rtl, i);
13827 insert_float (elt, p);
13832 gcc_unreachable ();
13835 loc_result = new_loc_descr (DW_OP_implicit_value,
13836 length * elt_size, 0);
13837 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13838 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
13839 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
13840 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13845 if (mode == VOIDmode
13846 || CONST_SCALAR_INT_P (XEXP (rtl, 0))
13847 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl, 0))
13848 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
13850 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
13855 if (!const_ok_for_output (rtl))
13858 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
13859 && (dwarf_version >= 4 || !dwarf_strict))
13861 loc_result = new_addr_loc_descr (rtl, dtprel_false);
13862 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
13863 vec_safe_push (used_rtx_array, rtl);
13867 case DEBUG_IMPLICIT_PTR:
13868 loc_result = implicit_ptr_descriptor (rtl, 0);
13872 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
13873 && CONST_INT_P (XEXP (rtl, 1)))
13876 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
13882 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
13883 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
13884 && dwarf_version >= 4)
13885 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
13887 /* Value expression. */
13888 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
13890 add_loc_descr (&loc_result,
13891 new_loc_descr (DW_OP_stack_value, 0, 0));
13899 /* We need to figure out what section we should use as the base for the
13900 address ranges where a given location is valid.
13901 1. If this particular DECL has a section associated with it, use that.
13902 2. If this function has a section associated with it, use that.
13903 3. Otherwise, use the text section.
13904 XXX: If you split a variable across multiple sections, we won't notice. */
13906 static const char *
13907 secname_for_decl (const_tree decl)
13909 const char *secname;
13911 if (VAR_OR_FUNCTION_DECL_P (decl)
13912 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl) || TREE_STATIC (decl))
13913 && DECL_SECTION_NAME (decl))
13914 secname = DECL_SECTION_NAME (decl);
13915 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
13916 secname = DECL_SECTION_NAME (current_function_decl);
13917 else if (cfun && in_cold_section_p)
13918 secname = crtl->subsections.cold_section_label;
13920 secname = text_section_label;
13925 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13928 decl_by_reference_p (tree decl)
13930 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
13931 || TREE_CODE (decl) == VAR_DECL)
13932 && DECL_BY_REFERENCE (decl));
13935 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13938 static dw_loc_descr_ref
13939 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
13940 enum var_init_status initialized)
13942 int have_address = 0;
13943 dw_loc_descr_ref descr;
13946 if (want_address != 2)
13948 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
13950 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
13952 varloc = PAT_VAR_LOCATION_LOC (varloc);
13953 if (GET_CODE (varloc) == EXPR_LIST)
13954 varloc = XEXP (varloc, 0);
13955 mode = GET_MODE (varloc);
13956 if (MEM_P (varloc))
13958 rtx addr = XEXP (varloc, 0);
13959 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
13960 mode, initialized);
13965 rtx x = avoid_constant_pool_reference (varloc);
13967 descr = mem_loc_descriptor (x, mode, VOIDmode,
13972 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
13979 if (GET_CODE (varloc) == VAR_LOCATION)
13980 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
13982 mode = DECL_MODE (loc);
13983 descr = loc_descriptor (varloc, mode, initialized);
13990 if (want_address == 2 && !have_address
13991 && (dwarf_version >= 4 || !dwarf_strict))
13993 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
13995 expansion_failed (loc, NULL_RTX,
13996 "DWARF address size mismatch");
13999 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14002 /* Show if we can't fill the request for an address. */
14003 if (want_address && !have_address)
14005 expansion_failed (loc, NULL_RTX,
14006 "Want address and only have value");
14010 /* If we've got an address and don't want one, dereference. */
14011 if (!want_address && have_address)
14013 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14014 enum dwarf_location_atom op;
14016 if (size > DWARF2_ADDR_SIZE || size == -1)
14018 expansion_failed (loc, NULL_RTX,
14019 "DWARF address size mismatch");
14022 else if (size == DWARF2_ADDR_SIZE)
14025 op = DW_OP_deref_size;
14027 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14033 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14034 if it is not possible. */
14036 static dw_loc_descr_ref
14037 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14039 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14040 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14041 else if (dwarf_version >= 3 || !dwarf_strict)
14042 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14047 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14048 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14050 static dw_loc_descr_ref
14051 dw_sra_loc_expr (tree decl, rtx loc)
14054 unsigned HOST_WIDE_INT padsize = 0;
14055 dw_loc_descr_ref descr, *descr_tail;
14056 unsigned HOST_WIDE_INT decl_size;
14058 enum var_init_status initialized;
14060 if (DECL_SIZE (decl) == NULL
14061 || !tree_fits_uhwi_p (DECL_SIZE (decl)))
14064 decl_size = tree_to_uhwi (DECL_SIZE (decl));
14066 descr_tail = &descr;
14068 for (p = loc; p; p = XEXP (p, 1))
14070 unsigned HOST_WIDE_INT bitsize = decl_piece_bitsize (p);
14071 rtx loc_note = *decl_piece_varloc_ptr (p);
14072 dw_loc_descr_ref cur_descr;
14073 dw_loc_descr_ref *tail, last = NULL;
14074 unsigned HOST_WIDE_INT opsize = 0;
14076 if (loc_note == NULL_RTX
14077 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14079 padsize += bitsize;
14082 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14083 varloc = NOTE_VAR_LOCATION (loc_note);
14084 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14085 if (cur_descr == NULL)
14087 padsize += bitsize;
14091 /* Check that cur_descr either doesn't use
14092 DW_OP_*piece operations, or their sum is equal
14093 to bitsize. Otherwise we can't embed it. */
14094 for (tail = &cur_descr; *tail != NULL;
14095 tail = &(*tail)->dw_loc_next)
14096 if ((*tail)->dw_loc_opc == DW_OP_piece)
14098 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14102 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14104 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14108 if (last != NULL && opsize != bitsize)
14110 padsize += bitsize;
14111 /* Discard the current piece of the descriptor and release any
14112 addr_table entries it uses. */
14113 remove_loc_list_addr_table_entries (cur_descr);
14117 /* If there is a hole, add DW_OP_*piece after empty DWARF
14118 expression, which means that those bits are optimized out. */
14121 if (padsize > decl_size)
14123 remove_loc_list_addr_table_entries (cur_descr);
14124 goto discard_descr;
14126 decl_size -= padsize;
14127 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14128 if (*descr_tail == NULL)
14130 remove_loc_list_addr_table_entries (cur_descr);
14131 goto discard_descr;
14133 descr_tail = &(*descr_tail)->dw_loc_next;
14136 *descr_tail = cur_descr;
14138 if (bitsize > decl_size)
14139 goto discard_descr;
14140 decl_size -= bitsize;
14143 HOST_WIDE_INT offset = 0;
14144 if (GET_CODE (varloc) == VAR_LOCATION
14145 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14147 varloc = PAT_VAR_LOCATION_LOC (varloc);
14148 if (GET_CODE (varloc) == EXPR_LIST)
14149 varloc = XEXP (varloc, 0);
14153 if (GET_CODE (varloc) == CONST
14154 || GET_CODE (varloc) == SIGN_EXTEND
14155 || GET_CODE (varloc) == ZERO_EXTEND)
14156 varloc = XEXP (varloc, 0);
14157 else if (GET_CODE (varloc) == SUBREG)
14158 varloc = SUBREG_REG (varloc);
14163 /* DW_OP_bit_size offset should be zero for register
14164 or implicit location descriptions and empty location
14165 descriptions, but for memory addresses needs big endian
14167 if (MEM_P (varloc))
14169 unsigned HOST_WIDE_INT memsize
14170 = MEM_SIZE (varloc) * BITS_PER_UNIT;
14171 if (memsize != bitsize)
14173 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
14174 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
14175 goto discard_descr;
14176 if (memsize < bitsize)
14177 goto discard_descr;
14178 if (BITS_BIG_ENDIAN)
14179 offset = memsize - bitsize;
14183 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
14184 if (*descr_tail == NULL)
14185 goto discard_descr;
14186 descr_tail = &(*descr_tail)->dw_loc_next;
14190 /* If there were any non-empty expressions, add padding till the end of
14192 if (descr != NULL && decl_size != 0)
14194 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
14195 if (*descr_tail == NULL)
14196 goto discard_descr;
14201 /* Discard the descriptor and release any addr_table entries it uses. */
14202 remove_loc_list_addr_table_entries (descr);
14206 /* Return the dwarf representation of the location list LOC_LIST of
14207 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14210 static dw_loc_list_ref
14211 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
14213 const char *endname, *secname;
14215 enum var_init_status initialized;
14216 struct var_loc_node *node;
14217 dw_loc_descr_ref descr;
14218 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
14219 dw_loc_list_ref list = NULL;
14220 dw_loc_list_ref *listp = &list;
14222 /* Now that we know what section we are using for a base,
14223 actually construct the list of locations.
14224 The first location information is what is passed to the
14225 function that creates the location list, and the remaining
14226 locations just get added on to that list.
14227 Note that we only know the start address for a location
14228 (IE location changes), so to build the range, we use
14229 the range [current location start, next location start].
14230 This means we have to special case the last node, and generate
14231 a range of [last location start, end of function label]. */
14233 secname = secname_for_decl (decl);
14235 for (node = loc_list->first; node; node = node->next)
14236 if (GET_CODE (node->loc) == EXPR_LIST
14237 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
14239 if (GET_CODE (node->loc) == EXPR_LIST)
14241 /* This requires DW_OP_{,bit_}piece, which is not usable
14242 inside DWARF expressions. */
14243 if (want_address != 2)
14245 descr = dw_sra_loc_expr (decl, node->loc);
14251 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
14252 varloc = NOTE_VAR_LOCATION (node->loc);
14253 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
14257 bool range_across_switch = false;
14258 /* If section switch happens in between node->label
14259 and node->next->label (or end of function) and
14260 we can't emit it as a single entry list,
14261 emit two ranges, first one ending at the end
14262 of first partition and second one starting at the
14263 beginning of second partition. */
14264 if (node == loc_list->last_before_switch
14265 && (node != loc_list->first || loc_list->first->next)
14266 && current_function_decl)
14268 endname = cfun->fde->dw_fde_end;
14269 range_across_switch = true;
14271 /* The variable has a location between NODE->LABEL and
14272 NODE->NEXT->LABEL. */
14273 else if (node->next)
14274 endname = node->next->label;
14275 /* If the variable has a location at the last label
14276 it keeps its location until the end of function. */
14277 else if (!current_function_decl)
14278 endname = text_end_label;
14281 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
14282 current_function_funcdef_no);
14283 endname = ggc_strdup (label_id);
14286 *listp = new_loc_list (descr, node->label, endname, secname);
14287 if (TREE_CODE (decl) == PARM_DECL
14288 && node == loc_list->first
14289 && NOTE_P (node->loc)
14290 && strcmp (node->label, endname) == 0)
14291 (*listp)->force = true;
14292 listp = &(*listp)->dw_loc_next;
14294 if (range_across_switch)
14296 if (GET_CODE (node->loc) == EXPR_LIST)
14297 descr = dw_sra_loc_expr (decl, node->loc);
14300 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
14301 varloc = NOTE_VAR_LOCATION (node->loc);
14302 descr = dw_loc_list_1 (decl, varloc, want_address,
14305 gcc_assert (descr);
14306 /* The variable has a location between NODE->LABEL and
14307 NODE->NEXT->LABEL. */
14309 endname = node->next->label;
14311 endname = cfun->fde->dw_fde_second_end;
14312 *listp = new_loc_list (descr,
14313 cfun->fde->dw_fde_second_begin,
14315 listp = &(*listp)->dw_loc_next;
14320 /* Try to avoid the overhead of a location list emitting a location
14321 expression instead, but only if we didn't have more than one
14322 location entry in the first place. If some entries were not
14323 representable, we don't want to pretend a single entry that was
14324 applies to the entire scope in which the variable is
14326 if (list && loc_list->first->next)
14332 /* Return if the loc_list has only single element and thus can be represented
14333 as location description. */
14336 single_element_loc_list_p (dw_loc_list_ref list)
14338 gcc_assert (!list->dw_loc_next || list->ll_symbol);
14339 return !list->ll_symbol;
14342 /* To each location in list LIST add loc descr REF. */
14345 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
14347 dw_loc_descr_ref copy;
14348 add_loc_descr (&list->expr, ref);
14349 list = list->dw_loc_next;
14352 copy = ggc_alloc<dw_loc_descr_node> ();
14353 memcpy (copy, ref, sizeof (dw_loc_descr_node));
14354 add_loc_descr (&list->expr, copy);
14355 while (copy->dw_loc_next)
14357 dw_loc_descr_ref new_copy = ggc_alloc<dw_loc_descr_node> ();
14358 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
14359 copy->dw_loc_next = new_copy;
14362 list = list->dw_loc_next;
14366 /* Given two lists RET and LIST
14367 produce location list that is result of adding expression in LIST
14368 to expression in RET on each position in program.
14369 Might be destructive on both RET and LIST.
14371 TODO: We handle only simple cases of RET or LIST having at most one
14372 element. General case would inolve sorting the lists in program order
14373 and merging them that will need some additional work.
14374 Adding that will improve quality of debug info especially for SRA-ed
14378 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
14387 if (!list->dw_loc_next)
14389 add_loc_descr_to_each (*ret, list->expr);
14392 if (!(*ret)->dw_loc_next)
14394 add_loc_descr_to_each (list, (*ret)->expr);
14398 expansion_failed (NULL_TREE, NULL_RTX,
14399 "Don't know how to merge two non-trivial"
14400 " location lists.\n");
14405 /* LOC is constant expression. Try a luck, look it up in constant
14406 pool and return its loc_descr of its address. */
14408 static dw_loc_descr_ref
14409 cst_pool_loc_descr (tree loc)
14411 /* Get an RTL for this, if something has been emitted. */
14412 rtx rtl = lookup_constant_def (loc);
14414 if (!rtl || !MEM_P (rtl))
14419 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
14421 /* TODO: We might get more coverage if we was actually delaying expansion
14422 of all expressions till end of compilation when constant pools are fully
14424 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
14426 expansion_failed (loc, NULL_RTX,
14427 "CST value in contant pool but not marked.");
14430 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
14431 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
14434 /* Return dw_loc_list representing address of addr_expr LOC
14435 by looking for inner INDIRECT_REF expression and turning
14436 it into simple arithmetics.
14438 See loc_list_from_tree for the meaning of CONTEXT. */
14440 static dw_loc_list_ref
14441 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev,
14442 const loc_descr_context *context)
14445 HOST_WIDE_INT bitsize, bitpos, bytepos;
14447 int unsignedp, volatilep = 0;
14448 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
14450 obj = get_inner_reference (TREE_OPERAND (loc, 0),
14451 &bitsize, &bitpos, &offset, &mode,
14452 &unsignedp, &volatilep, false);
14454 if (bitpos % BITS_PER_UNIT)
14456 expansion_failed (loc, NULL_RTX, "bitfield access");
14459 if (!INDIRECT_REF_P (obj))
14461 expansion_failed (obj,
14462 NULL_RTX, "no indirect ref in inner refrence");
14465 if (!offset && !bitpos)
14466 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1,
14469 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
14470 && (dwarf_version >= 4 || !dwarf_strict))
14472 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0, context);
14477 /* Variable offset. */
14478 list_ret1 = loc_list_from_tree (offset, 0, context);
14479 if (list_ret1 == 0)
14481 add_loc_list (&list_ret, list_ret1);
14484 add_loc_descr_to_each (list_ret,
14485 new_loc_descr (DW_OP_plus, 0, 0));
14487 bytepos = bitpos / BITS_PER_UNIT;
14489 add_loc_descr_to_each (list_ret,
14490 new_loc_descr (DW_OP_plus_uconst,
14492 else if (bytepos < 0)
14493 loc_list_plus_const (list_ret, bytepos);
14494 add_loc_descr_to_each (list_ret,
14495 new_loc_descr (DW_OP_stack_value, 0, 0));
14501 /* Helper structure for location descriptions generation. */
14502 struct loc_descr_context
14504 /* The type that is implicitly referenced by DW_OP_push_object_address, or
14505 NULL_TREE if DW_OP_push_object_address in invalid for this location
14506 description. This is used when processing PLACEHOLDER_EXPR nodes. */
14508 /* The ..._DECL node that should be translated as a
14509 DW_OP_push_object_address operation. */
14513 /* Generate Dwarf location list representing LOC.
14514 If WANT_ADDRESS is false, expression computing LOC will be computed
14515 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14516 if WANT_ADDRESS is 2, expression computing address useable in location
14517 will be returned (i.e. DW_OP_reg can be used
14518 to refer to register values).
14520 CONTEXT provides information to customize the location descriptions
14521 generation. Its context_type field specifies what type is implicitly
14522 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
14523 will not be generated.
14525 If CONTEXT is NULL, the behavior is the same as if both context_type and
14526 base_decl fields were NULL_TREE. */
14528 static dw_loc_list_ref
14529 loc_list_from_tree (tree loc, int want_address,
14530 const struct loc_descr_context *context)
14532 dw_loc_descr_ref ret = NULL, ret1 = NULL;
14533 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
14534 int have_address = 0;
14535 enum dwarf_location_atom op;
14537 /* ??? Most of the time we do not take proper care for sign/zero
14538 extending the values properly. Hopefully this won't be a real
14541 if (context != NULL
14542 && context->base_decl == loc
14543 && want_address == 0)
14545 if (dwarf_version >= 3 || !dwarf_strict)
14546 return new_loc_list (new_loc_descr (DW_OP_push_object_address, 0, 0),
14552 switch (TREE_CODE (loc))
14555 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
14558 case PLACEHOLDER_EXPR:
14559 /* This case involves extracting fields from an object to determine the
14560 position of other fields. It is supposed to appear only as the first
14561 operand of COMPONENT_REF nodes and to reference precisely the type
14562 that the context allows. */
14563 if (context != NULL
14564 && TREE_TYPE (loc) == context->context_type
14565 && want_address >= 1)
14567 if (dwarf_version >= 3 || !dwarf_strict)
14569 ret = new_loc_descr (DW_OP_push_object_address, 0, 0);
14577 expansion_failed (loc, NULL_RTX,
14578 "PLACEHOLDER_EXPR for an unexpected type");
14582 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
14583 /* There are no opcodes for these operations. */
14586 case PREINCREMENT_EXPR:
14587 case PREDECREMENT_EXPR:
14588 case POSTINCREMENT_EXPR:
14589 case POSTDECREMENT_EXPR:
14590 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
14591 /* There are no opcodes for these operations. */
14595 /* If we already want an address, see if there is INDIRECT_REF inside
14596 e.g. for &this->field. */
14599 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
14600 (loc, want_address == 2, context);
14603 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
14604 && (ret = cst_pool_loc_descr (loc)))
14607 /* Otherwise, process the argument and look for the address. */
14608 if (!list_ret && !ret)
14609 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1, context);
14613 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
14619 if (DECL_THREAD_LOCAL_P (loc))
14622 enum dwarf_location_atom tls_op;
14623 enum dtprel_bool dtprel = dtprel_false;
14625 if (targetm.have_tls)
14627 /* If this is not defined, we have no way to emit the
14629 if (!targetm.asm_out.output_dwarf_dtprel)
14632 /* The way DW_OP_GNU_push_tls_address is specified, we
14633 can only look up addresses of objects in the current
14634 module. We used DW_OP_addr as first op, but that's
14635 wrong, because DW_OP_addr is relocated by the debug
14636 info consumer, while DW_OP_GNU_push_tls_address
14637 operand shouldn't be. */
14638 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
14640 dtprel = dtprel_true;
14641 tls_op = DW_OP_GNU_push_tls_address;
14645 if (!targetm.emutls.debug_form_tls_address
14646 || !(dwarf_version >= 3 || !dwarf_strict))
14648 /* We stuffed the control variable into the DECL_VALUE_EXPR
14649 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14650 no longer appear in gimple code. We used the control
14651 variable in specific so that we could pick it up here. */
14652 loc = DECL_VALUE_EXPR (loc);
14653 tls_op = DW_OP_form_tls_address;
14656 rtl = rtl_for_decl_location (loc);
14657 if (rtl == NULL_RTX)
14662 rtl = XEXP (rtl, 0);
14663 if (! CONSTANT_P (rtl))
14666 ret = new_addr_loc_descr (rtl, dtprel);
14667 ret1 = new_loc_descr (tls_op, 0, 0);
14668 add_loc_descr (&ret, ret1);
14677 if (DECL_HAS_VALUE_EXPR_P (loc))
14678 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
14679 want_address, context);
14682 case FUNCTION_DECL:
14685 var_loc_list *loc_list = lookup_decl_loc (loc);
14687 if (loc_list && loc_list->first)
14689 list_ret = dw_loc_list (loc_list, loc, want_address);
14690 have_address = want_address != 0;
14693 rtl = rtl_for_decl_location (loc);
14694 if (rtl == NULL_RTX)
14696 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
14699 else if (CONST_INT_P (rtl))
14701 HOST_WIDE_INT val = INTVAL (rtl);
14702 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
14703 val &= GET_MODE_MASK (DECL_MODE (loc));
14704 ret = int_loc_descriptor (val);
14706 else if (GET_CODE (rtl) == CONST_STRING)
14708 expansion_failed (loc, NULL_RTX, "CONST_STRING");
14711 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
14712 ret = new_addr_loc_descr (rtl, dtprel_false);
14715 machine_mode mode, mem_mode;
14717 /* Certain constructs can only be represented at top-level. */
14718 if (want_address == 2)
14720 ret = loc_descriptor (rtl, VOIDmode,
14721 VAR_INIT_STATUS_INITIALIZED);
14726 mode = GET_MODE (rtl);
14727 mem_mode = VOIDmode;
14731 mode = get_address_mode (rtl);
14732 rtl = XEXP (rtl, 0);
14735 ret = mem_loc_descriptor (rtl, mode, mem_mode,
14736 VAR_INIT_STATUS_INITIALIZED);
14739 expansion_failed (loc, rtl,
14740 "failed to produce loc descriptor for rtl");
14746 if (!integer_zerop (TREE_OPERAND (loc, 1)))
14753 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
14757 case TARGET_MEM_REF:
14759 case DEBUG_EXPR_DECL:
14762 case COMPOUND_EXPR:
14763 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address, context);
14766 case VIEW_CONVERT_EXPR:
14769 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address, context);
14771 case COMPONENT_REF:
14772 case BIT_FIELD_REF:
14774 case ARRAY_RANGE_REF:
14775 case REALPART_EXPR:
14776 case IMAGPART_EXPR:
14779 HOST_WIDE_INT bitsize, bitpos, bytepos;
14781 int unsignedp, volatilep = 0;
14783 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
14784 &unsignedp, &volatilep, false);
14786 gcc_assert (obj != loc);
14788 list_ret = loc_list_from_tree (obj,
14790 && !bitpos && !offset ? 2 : 1,
14792 /* TODO: We can extract value of the small expression via shifting even
14793 for nonzero bitpos. */
14796 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
14798 expansion_failed (loc, NULL_RTX,
14799 "bitfield access");
14803 if (offset != NULL_TREE)
14805 /* Variable offset. */
14806 list_ret1 = loc_list_from_tree (offset, 0, context);
14807 if (list_ret1 == 0)
14809 add_loc_list (&list_ret, list_ret1);
14812 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
14815 bytepos = bitpos / BITS_PER_UNIT;
14817 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
14818 else if (bytepos < 0)
14819 loc_list_plus_const (list_ret, bytepos);
14826 if ((want_address || !tree_fits_shwi_p (loc))
14827 && (ret = cst_pool_loc_descr (loc)))
14829 else if (want_address == 2
14830 && tree_fits_shwi_p (loc)
14831 && (ret = address_of_int_loc_descriptor
14832 (int_size_in_bytes (TREE_TYPE (loc)),
14833 tree_to_shwi (loc))))
14835 else if (tree_fits_shwi_p (loc))
14836 ret = int_loc_descriptor (tree_to_shwi (loc));
14839 expansion_failed (loc, NULL_RTX,
14840 "Integer operand is not host integer");
14849 if ((ret = cst_pool_loc_descr (loc)))
14852 /* We can construct small constants here using int_loc_descriptor. */
14853 expansion_failed (loc, NULL_RTX,
14854 "constructor or constant not in constant pool");
14857 case TRUTH_AND_EXPR:
14858 case TRUTH_ANDIF_EXPR:
14863 case TRUTH_XOR_EXPR:
14868 case TRUTH_OR_EXPR:
14869 case TRUTH_ORIF_EXPR:
14874 case FLOOR_DIV_EXPR:
14875 case CEIL_DIV_EXPR:
14876 case ROUND_DIV_EXPR:
14877 case TRUNC_DIV_EXPR:
14878 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
14887 case FLOOR_MOD_EXPR:
14888 case CEIL_MOD_EXPR:
14889 case ROUND_MOD_EXPR:
14890 case TRUNC_MOD_EXPR:
14891 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
14896 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
14897 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
14898 if (list_ret == 0 || list_ret1 == 0)
14901 add_loc_list (&list_ret, list_ret1);
14904 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
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_div, 0, 0));
14907 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
14908 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
14920 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
14923 case POINTER_PLUS_EXPR:
14926 if (tree_fits_shwi_p (TREE_OPERAND (loc, 1)))
14928 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
14932 loc_list_plus_const (list_ret, tree_to_shwi (TREE_OPERAND (loc, 1)));
14940 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14947 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14954 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14961 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14976 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
14977 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
14978 if (list_ret == 0 || list_ret1 == 0)
14981 add_loc_list (&list_ret, list_ret1);
14984 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
14987 case TRUTH_NOT_EXPR:
15001 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
15005 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15011 const enum tree_code code =
15012 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15014 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15015 build2 (code, integer_type_node,
15016 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15017 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15020 /* ... fall through ... */
15024 dw_loc_descr_ref lhs
15025 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0, context);
15026 dw_loc_list_ref rhs
15027 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0, context);
15028 dw_loc_descr_ref bra_node, jump_node, tmp;
15030 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
15031 if (list_ret == 0 || lhs == 0 || rhs == 0)
15034 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15035 add_loc_descr_to_each (list_ret, bra_node);
15037 add_loc_list (&list_ret, rhs);
15038 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15039 add_loc_descr_to_each (list_ret, jump_node);
15041 add_loc_descr_to_each (list_ret, lhs);
15042 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15043 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15045 /* ??? Need a node to point the skip at. Use a nop. */
15046 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15047 add_loc_descr_to_each (list_ret, tmp);
15048 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15049 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15053 case FIX_TRUNC_EXPR:
15057 /* Leave front-end specific codes as simply unknown. This comes
15058 up, for instance, with the C STMT_EXPR. */
15059 if ((unsigned int) TREE_CODE (loc)
15060 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15062 expansion_failed (loc, NULL_RTX,
15063 "language specific tree node");
15067 #ifdef ENABLE_CHECKING
15068 /* Otherwise this is a generic code; we should just lists all of
15069 these explicitly. We forgot one. */
15070 gcc_unreachable ();
15072 /* In a release build, we want to degrade gracefully: better to
15073 generate incomplete debugging information than to crash. */
15078 if (!ret && !list_ret)
15081 if (want_address == 2 && !have_address
15082 && (dwarf_version >= 4 || !dwarf_strict))
15084 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15086 expansion_failed (loc, NULL_RTX,
15087 "DWARF address size mismatch");
15091 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15093 add_loc_descr_to_each (list_ret,
15094 new_loc_descr (DW_OP_stack_value, 0, 0));
15097 /* Show if we can't fill the request for an address. */
15098 if (want_address && !have_address)
15100 expansion_failed (loc, NULL_RTX,
15101 "Want address and only have value");
15105 gcc_assert (!ret || !list_ret);
15107 /* If we've got an address and don't want one, dereference. */
15108 if (!want_address && have_address)
15110 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15112 if (size > DWARF2_ADDR_SIZE || size == -1)
15114 expansion_failed (loc, NULL_RTX,
15115 "DWARF address size mismatch");
15118 else if (size == DWARF2_ADDR_SIZE)
15121 op = DW_OP_deref_size;
15124 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15126 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15129 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15134 /* Same as above but return only single location expression. */
15135 static dw_loc_descr_ref
15136 loc_descriptor_from_tree (tree loc, int want_address,
15137 const struct loc_descr_context *context)
15139 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address, context);
15142 if (ret->dw_loc_next)
15144 expansion_failed (loc, NULL_RTX,
15145 "Location list where only loc descriptor needed");
15151 /* Given a value, round it up to the lowest multiple of `boundary'
15152 which is not less than the value itself. */
15154 static inline HOST_WIDE_INT
15155 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15157 return (((value + boundary - 1) / boundary) * boundary);
15160 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15161 pointer to the declared type for the relevant field variable, or return
15162 `integer_type_node' if the given node turns out to be an
15163 ERROR_MARK node. */
15166 field_type (const_tree decl)
15170 if (TREE_CODE (decl) == ERROR_MARK)
15171 return integer_type_node;
15173 type = DECL_BIT_FIELD_TYPE (decl);
15174 if (type == NULL_TREE)
15175 type = TREE_TYPE (decl);
15180 /* Given a pointer to a tree node, return the alignment in bits for
15181 it, or else return BITS_PER_WORD if the node actually turns out to
15182 be an ERROR_MARK node. */
15184 static inline unsigned
15185 simple_type_align_in_bits (const_tree type)
15187 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15190 static inline unsigned
15191 simple_decl_align_in_bits (const_tree decl)
15193 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15196 /* Return the result of rounding T up to ALIGN. */
15198 static inline offset_int
15199 round_up_to_align (const offset_int &t, unsigned int align)
15201 return wi::udiv_trunc (t + align - 1, align) * align;
15204 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15205 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15206 or return 0 if we are unable to determine what that offset is, either
15207 because the argument turns out to be a pointer to an ERROR_MARK node, or
15208 because the offset is actually variable. (We can't handle the latter case
15211 static HOST_WIDE_INT
15212 field_byte_offset (const_tree decl)
15214 offset_int object_offset_in_bits;
15215 offset_int object_offset_in_bytes;
15216 offset_int bitpos_int;
15218 if (TREE_CODE (decl) == ERROR_MARK)
15221 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
15223 /* We cannot yet cope with fields whose positions are variable, so
15224 for now, when we see such things, we simply return 0. Someday, we may
15225 be able to handle such cases, but it will be damn difficult. */
15226 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
15229 bitpos_int = wi::to_offset (bit_position (decl));
15231 if (PCC_BITFIELD_TYPE_MATTERS)
15234 tree field_size_tree;
15235 offset_int deepest_bitpos;
15236 offset_int field_size_in_bits;
15237 unsigned int type_align_in_bits;
15238 unsigned int decl_align_in_bits;
15239 offset_int type_size_in_bits;
15241 type = field_type (decl);
15242 type_size_in_bits = offset_int_type_size_in_bits (type);
15243 type_align_in_bits = simple_type_align_in_bits (type);
15245 field_size_tree = DECL_SIZE (decl);
15247 /* The size could be unspecified if there was an error, or for
15248 a flexible array member. */
15249 if (!field_size_tree)
15250 field_size_tree = bitsize_zero_node;
15252 /* If the size of the field is not constant, use the type size. */
15253 if (TREE_CODE (field_size_tree) == INTEGER_CST)
15254 field_size_in_bits = wi::to_offset (field_size_tree);
15256 field_size_in_bits = type_size_in_bits;
15258 decl_align_in_bits = simple_decl_align_in_bits (decl);
15260 /* The GCC front-end doesn't make any attempt to keep track of the
15261 starting bit offset (relative to the start of the containing
15262 structure type) of the hypothetical "containing object" for a
15263 bit-field. Thus, when computing the byte offset value for the
15264 start of the "containing object" of a bit-field, we must deduce
15265 this information on our own. This can be rather tricky to do in
15266 some cases. For example, handling the following structure type
15267 definition when compiling for an i386/i486 target (which only
15268 aligns long long's to 32-bit boundaries) can be very tricky:
15270 struct S { int field1; long long field2:31; };
15272 Fortunately, there is a simple rule-of-thumb which can be used
15273 in such cases. When compiling for an i386/i486, GCC will
15274 allocate 8 bytes for the structure shown above. It decides to
15275 do this based upon one simple rule for bit-field allocation.
15276 GCC allocates each "containing object" for each bit-field at
15277 the first (i.e. lowest addressed) legitimate alignment boundary
15278 (based upon the required minimum alignment for the declared
15279 type of the field) which it can possibly use, subject to the
15280 condition that there is still enough available space remaining
15281 in the containing object (when allocated at the selected point)
15282 to fully accommodate all of the bits of the bit-field itself.
15284 This simple rule makes it obvious why GCC allocates 8 bytes for
15285 each object of the structure type shown above. When looking
15286 for a place to allocate the "containing object" for `field2',
15287 the compiler simply tries to allocate a 64-bit "containing
15288 object" at each successive 32-bit boundary (starting at zero)
15289 until it finds a place to allocate that 64- bit field such that
15290 at least 31 contiguous (and previously unallocated) bits remain
15291 within that selected 64 bit field. (As it turns out, for the
15292 example above, the compiler finds it is OK to allocate the
15293 "containing object" 64-bit field at bit-offset zero within the
15296 Here we attempt to work backwards from the limited set of facts
15297 we're given, and we try to deduce from those facts, where GCC
15298 must have believed that the containing object started (within
15299 the structure type). The value we deduce is then used (by the
15300 callers of this routine) to generate DW_AT_location and
15301 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15302 the case of DW_AT_location, regular fields as well). */
15304 /* Figure out the bit-distance from the start of the structure to
15305 the "deepest" bit of the bit-field. */
15306 deepest_bitpos = bitpos_int + field_size_in_bits;
15308 /* This is the tricky part. Use some fancy footwork to deduce
15309 where the lowest addressed bit of the containing object must
15311 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
15313 /* Round up to type_align by default. This works best for
15315 object_offset_in_bits
15316 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
15318 if (wi::gtu_p (object_offset_in_bits, bitpos_int))
15320 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
15322 /* Round up to decl_align instead. */
15323 object_offset_in_bits
15324 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
15328 object_offset_in_bits = bitpos_int;
15330 object_offset_in_bytes
15331 = wi::lrshift (object_offset_in_bits, LOG2_BITS_PER_UNIT);
15332 return object_offset_in_bytes.to_shwi ();
15335 /* The following routines define various Dwarf attributes and any data
15336 associated with them. */
15338 /* Add a location description attribute value to a DIE.
15340 This emits location attributes suitable for whole variables and
15341 whole parameters. Note that the location attributes for struct fields are
15342 generated by the routine `data_member_location_attribute' below. */
15345 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
15346 dw_loc_list_ref descr)
15350 if (single_element_loc_list_p (descr))
15351 add_AT_loc (die, attr_kind, descr->expr);
15353 add_AT_loc_list (die, attr_kind, descr);
15356 /* Add DW_AT_accessibility attribute to DIE if needed. */
15359 add_accessibility_attribute (dw_die_ref die, tree decl)
15361 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
15362 children, otherwise the default is DW_ACCESS_public. In DWARF2
15363 the default has always been DW_ACCESS_public. */
15364 if (TREE_PROTECTED (decl))
15365 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
15366 else if (TREE_PRIVATE (decl))
15368 if (dwarf_version == 2
15369 || die->die_parent == NULL
15370 || die->die_parent->die_tag != DW_TAG_class_type)
15371 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
15373 else if (dwarf_version > 2
15375 && die->die_parent->die_tag == DW_TAG_class_type)
15376 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
15379 /* Attach the specialized form of location attribute used for data members of
15380 struct and union types. In the special case of a FIELD_DECL node which
15381 represents a bit-field, the "offset" part of this special location
15382 descriptor must indicate the distance in bytes from the lowest-addressed
15383 byte of the containing struct or union type to the lowest-addressed byte of
15384 the "containing object" for the bit-field. (See the `field_byte_offset'
15387 For any given bit-field, the "containing object" is a hypothetical object
15388 (of some integral or enum type) within which the given bit-field lives. The
15389 type of this hypothetical "containing object" is always the same as the
15390 declared type of the individual bit-field itself (for GCC anyway... the
15391 DWARF spec doesn't actually mandate this). Note that it is the size (in
15392 bytes) of the hypothetical "containing object" which will be given in the
15393 DW_AT_byte_size attribute for this bit-field. (See the
15394 `byte_size_attribute' function below.) It is also used when calculating the
15395 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15396 function below.) */
15399 add_data_member_location_attribute (dw_die_ref die, tree decl)
15401 HOST_WIDE_INT offset;
15402 dw_loc_descr_ref loc_descr = 0;
15404 if (TREE_CODE (decl) == TREE_BINFO)
15406 /* We're working on the TAG_inheritance for a base class. */
15407 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
15409 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15410 aren't at a fixed offset from all (sub)objects of the same
15411 type. We need to extract the appropriate offset from our
15412 vtable. The following dwarf expression means
15414 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15416 This is specific to the V3 ABI, of course. */
15418 dw_loc_descr_ref tmp;
15420 /* Make a copy of the object address. */
15421 tmp = new_loc_descr (DW_OP_dup, 0, 0);
15422 add_loc_descr (&loc_descr, tmp);
15424 /* Extract the vtable address. */
15425 tmp = new_loc_descr (DW_OP_deref, 0, 0);
15426 add_loc_descr (&loc_descr, tmp);
15428 /* Calculate the address of the offset. */
15429 offset = tree_to_shwi (BINFO_VPTR_FIELD (decl));
15430 gcc_assert (offset < 0);
15432 tmp = int_loc_descriptor (-offset);
15433 add_loc_descr (&loc_descr, tmp);
15434 tmp = new_loc_descr (DW_OP_minus, 0, 0);
15435 add_loc_descr (&loc_descr, tmp);
15437 /* Extract the offset. */
15438 tmp = new_loc_descr (DW_OP_deref, 0, 0);
15439 add_loc_descr (&loc_descr, tmp);
15441 /* Add it to the object address. */
15442 tmp = new_loc_descr (DW_OP_plus, 0, 0);
15443 add_loc_descr (&loc_descr, tmp);
15446 offset = tree_to_shwi (BINFO_OFFSET (decl));
15449 offset = field_byte_offset (decl);
15453 if (dwarf_version > 2)
15455 /* Don't need to output a location expression, just the constant. */
15457 add_AT_int (die, DW_AT_data_member_location, offset);
15459 add_AT_unsigned (die, DW_AT_data_member_location, offset);
15464 enum dwarf_location_atom op;
15466 /* The DWARF2 standard says that we should assume that the structure
15467 address is already on the stack, so we can specify a structure
15468 field address by using DW_OP_plus_uconst. */
15469 op = DW_OP_plus_uconst;
15470 loc_descr = new_loc_descr (op, offset, 0);
15474 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
15477 /* Writes integer values to dw_vec_const array. */
15480 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
15484 *dest++ = val & 0xff;
15490 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15492 static HOST_WIDE_INT
15493 extract_int (const unsigned char *src, unsigned int size)
15495 HOST_WIDE_INT val = 0;
15501 val |= *--src & 0xff;
15507 /* Writes wide_int values to dw_vec_const array. */
15510 insert_wide_int (const wide_int &val, unsigned char *dest, int elt_size)
15514 if (elt_size <= HOST_BITS_PER_WIDE_INT/BITS_PER_UNIT)
15516 insert_int ((HOST_WIDE_INT) val.elt (0), elt_size, dest);
15520 /* We'd have to extend this code to support odd sizes. */
15521 gcc_assert (elt_size % (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT) == 0);
15523 int n = elt_size / (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
15525 if (WORDS_BIG_ENDIAN)
15526 for (i = n - 1; i >= 0; i--)
15528 insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
15529 dest += sizeof (HOST_WIDE_INT);
15532 for (i = 0; i < n; i++)
15534 insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
15535 dest += sizeof (HOST_WIDE_INT);
15539 /* Writes floating point values to dw_vec_const array. */
15542 insert_float (const_rtx rtl, unsigned char *array)
15544 REAL_VALUE_TYPE rv;
15548 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
15549 real_to_target (val, &rv, GET_MODE (rtl));
15551 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15552 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
15554 insert_int (val[i], 4, array);
15559 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15560 does not have a "location" either in memory or in a register. These
15561 things can arise in GNU C when a constant is passed as an actual parameter
15562 to an inlined function. They can also arise in C++ where declared
15563 constants do not necessarily get memory "homes". */
15566 add_const_value_attribute (dw_die_ref die, rtx rtl)
15568 switch (GET_CODE (rtl))
15572 HOST_WIDE_INT val = INTVAL (rtl);
15575 add_AT_int (die, DW_AT_const_value, val);
15577 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
15581 case CONST_WIDE_INT:
15582 add_AT_wide (die, DW_AT_const_value,
15583 std::make_pair (rtl, GET_MODE (rtl)));
15587 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15588 floating-point constant. A CONST_DOUBLE is used whenever the
15589 constant requires more than one word in order to be adequately
15592 machine_mode mode = GET_MODE (rtl);
15594 if (TARGET_SUPPORTS_WIDE_INT == 0 && !SCALAR_FLOAT_MODE_P (mode))
15595 add_AT_double (die, DW_AT_const_value,
15596 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
15599 unsigned int length = GET_MODE_SIZE (mode);
15600 unsigned char *array = ggc_vec_alloc<unsigned char> (length);
15602 insert_float (rtl, array);
15603 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
15610 machine_mode mode = GET_MODE (rtl);
15611 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
15612 unsigned int length = CONST_VECTOR_NUNITS (rtl);
15613 unsigned char *array
15614 = ggc_vec_alloc<unsigned char> (length * elt_size);
15617 machine_mode imode = GET_MODE_INNER (mode);
15619 switch (GET_MODE_CLASS (mode))
15621 case MODE_VECTOR_INT:
15622 for (i = 0, p = array; i < length; i++, p += elt_size)
15624 rtx elt = CONST_VECTOR_ELT (rtl, i);
15625 insert_wide_int (std::make_pair (elt, imode), p, elt_size);
15629 case MODE_VECTOR_FLOAT:
15630 for (i = 0, p = array; i < length; i++, p += elt_size)
15632 rtx elt = CONST_VECTOR_ELT (rtl, i);
15633 insert_float (elt, p);
15638 gcc_unreachable ();
15641 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
15646 if (dwarf_version >= 4 || !dwarf_strict)
15648 dw_loc_descr_ref loc_result;
15649 resolve_one_addr (&rtl);
15651 loc_result = new_addr_loc_descr (rtl, dtprel_false);
15652 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
15653 add_AT_loc (die, DW_AT_location, loc_result);
15654 vec_safe_push (used_rtx_array, rtl);
15660 if (CONSTANT_P (XEXP (rtl, 0)))
15661 return add_const_value_attribute (die, XEXP (rtl, 0));
15664 if (!const_ok_for_output (rtl))
15667 if (dwarf_version >= 4 || !dwarf_strict)
15672 /* In cases where an inlined instance of an inline function is passed
15673 the address of an `auto' variable (which is local to the caller) we
15674 can get a situation where the DECL_RTL of the artificial local
15675 variable (for the inlining) which acts as a stand-in for the
15676 corresponding formal parameter (of the inline function) will look
15677 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15678 exactly a compile-time constant expression, but it isn't the address
15679 of the (artificial) local variable either. Rather, it represents the
15680 *value* which the artificial local variable always has during its
15681 lifetime. We currently have no way to represent such quasi-constant
15682 values in Dwarf, so for now we just punt and generate nothing. */
15690 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
15691 && MEM_READONLY_P (rtl)
15692 && GET_MODE (rtl) == BLKmode)
15694 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
15700 /* No other kinds of rtx should be possible here. */
15701 gcc_unreachable ();
15706 /* Determine whether the evaluation of EXPR references any variables
15707 or functions which aren't otherwise used (and therefore may not be
15710 reference_to_unused (tree * tp, int * walk_subtrees,
15711 void * data ATTRIBUTE_UNUSED)
15713 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
15714 *walk_subtrees = 0;
15716 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
15717 && ! TREE_ASM_WRITTEN (*tp))
15719 /* ??? The C++ FE emits debug information for using decls, so
15720 putting gcc_unreachable here falls over. See PR31899. For now
15721 be conservative. */
15722 else if (!symtab->global_info_ready
15723 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
15725 else if (TREE_CODE (*tp) == VAR_DECL)
15727 varpool_node *node = varpool_node::get (*tp);
15728 if (!node || !node->definition)
15731 else if (TREE_CODE (*tp) == FUNCTION_DECL
15732 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
15734 /* The call graph machinery must have finished analyzing,
15735 optimizing and gimplifying the CU by now.
15736 So if *TP has no call graph node associated
15737 to it, it means *TP will not be emitted. */
15738 if (!cgraph_node::get (*tp))
15741 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
15747 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15748 for use in a later add_const_value_attribute call. */
15751 rtl_for_decl_init (tree init, tree type)
15753 rtx rtl = NULL_RTX;
15757 /* If a variable is initialized with a string constant without embedded
15758 zeros, build CONST_STRING. */
15759 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
15761 tree enttype = TREE_TYPE (type);
15762 tree domain = TYPE_DOMAIN (type);
15763 machine_mode mode = TYPE_MODE (enttype);
15765 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
15767 && integer_zerop (TYPE_MIN_VALUE (domain))
15768 && compare_tree_int (TYPE_MAX_VALUE (domain),
15769 TREE_STRING_LENGTH (init) - 1) == 0
15770 && ((size_t) TREE_STRING_LENGTH (init)
15771 == strlen (TREE_STRING_POINTER (init)) + 1))
15773 rtl = gen_rtx_CONST_STRING (VOIDmode,
15774 ggc_strdup (TREE_STRING_POINTER (init)));
15775 rtl = gen_rtx_MEM (BLKmode, rtl);
15776 MEM_READONLY_P (rtl) = 1;
15779 /* Other aggregates, and complex values, could be represented using
15781 else if (AGGREGATE_TYPE_P (type)
15782 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
15783 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
15784 || TREE_CODE (type) == COMPLEX_TYPE)
15786 /* Vectors only work if their mode is supported by the target.
15787 FIXME: generic vectors ought to work too. */
15788 else if (TREE_CODE (type) == VECTOR_TYPE
15789 && !VECTOR_MODE_P (TYPE_MODE (type)))
15791 /* If the initializer is something that we know will expand into an
15792 immediate RTL constant, expand it now. We must be careful not to
15793 reference variables which won't be output. */
15794 else if (initializer_constant_valid_p (init, type)
15795 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
15797 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15799 if (TREE_CODE (type) == VECTOR_TYPE)
15800 switch (TREE_CODE (init))
15805 if (TREE_CONSTANT (init))
15807 vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (init);
15808 bool constant_p = true;
15810 unsigned HOST_WIDE_INT ix;
15812 /* Even when ctor is constant, it might contain non-*_CST
15813 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15814 belong into VECTOR_CST nodes. */
15815 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
15816 if (!CONSTANT_CLASS_P (value))
15818 constant_p = false;
15824 init = build_vector_from_ctor (type, elts);
15834 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
15836 /* If expand_expr returns a MEM, it wasn't immediate. */
15837 gcc_assert (!rtl || !MEM_P (rtl));
15843 /* Generate RTL for the variable DECL to represent its location. */
15846 rtl_for_decl_location (tree decl)
15850 /* Here we have to decide where we are going to say the parameter "lives"
15851 (as far as the debugger is concerned). We only have a couple of
15852 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15854 DECL_RTL normally indicates where the parameter lives during most of the
15855 activation of the function. If optimization is enabled however, this
15856 could be either NULL or else a pseudo-reg. Both of those cases indicate
15857 that the parameter doesn't really live anywhere (as far as the code
15858 generation parts of GCC are concerned) during most of the function's
15859 activation. That will happen (for example) if the parameter is never
15860 referenced within the function.
15862 We could just generate a location descriptor here for all non-NULL
15863 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15864 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15865 where DECL_RTL is NULL or is a pseudo-reg.
15867 Note however that we can only get away with using DECL_INCOMING_RTL as
15868 a backup substitute for DECL_RTL in certain limited cases. In cases
15869 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15870 we can be sure that the parameter was passed using the same type as it is
15871 declared to have within the function, and that its DECL_INCOMING_RTL
15872 points us to a place where a value of that type is passed.
15874 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15875 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15876 because in these cases DECL_INCOMING_RTL points us to a value of some
15877 type which is *different* from the type of the parameter itself. Thus,
15878 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15879 such cases, the debugger would end up (for example) trying to fetch a
15880 `float' from a place which actually contains the first part of a
15881 `double'. That would lead to really incorrect and confusing
15882 output at debug-time.
15884 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15885 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15886 are a couple of exceptions however. On little-endian machines we can
15887 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15888 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15889 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15890 when (on a little-endian machine) a non-prototyped function has a
15891 parameter declared to be of type `short' or `char'. In such cases,
15892 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15893 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15894 passed `int' value. If the debugger then uses that address to fetch
15895 a `short' or a `char' (on a little-endian machine) the result will be
15896 the correct data, so we allow for such exceptional cases below.
15898 Note that our goal here is to describe the place where the given formal
15899 parameter lives during most of the function's activation (i.e. between the
15900 end of the prologue and the start of the epilogue). We'll do that as best
15901 as we can. Note however that if the given formal parameter is modified
15902 sometime during the execution of the function, then a stack backtrace (at
15903 debug-time) will show the function as having been called with the *new*
15904 value rather than the value which was originally passed in. This happens
15905 rarely enough that it is not a major problem, but it *is* a problem, and
15906 I'd like to fix it.
15908 A future version of dwarf2out.c may generate two additional attributes for
15909 any given DW_TAG_formal_parameter DIE which will describe the "passed
15910 type" and the "passed location" for the given formal parameter in addition
15911 to the attributes we now generate to indicate the "declared type" and the
15912 "active location" for each parameter. This additional set of attributes
15913 could be used by debuggers for stack backtraces. Separately, note that
15914 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15915 This happens (for example) for inlined-instances of inline function formal
15916 parameters which are never referenced. This really shouldn't be
15917 happening. All PARM_DECL nodes should get valid non-NULL
15918 DECL_INCOMING_RTL values. FIXME. */
15920 /* Use DECL_RTL as the "location" unless we find something better. */
15921 rtl = DECL_RTL_IF_SET (decl);
15923 /* When generating abstract instances, ignore everything except
15924 constants, symbols living in memory, and symbols living in
15925 fixed registers. */
15926 if (! reload_completed)
15929 && (CONSTANT_P (rtl)
15931 && CONSTANT_P (XEXP (rtl, 0)))
15933 && TREE_CODE (decl) == VAR_DECL
15934 && TREE_STATIC (decl))))
15936 rtl = targetm.delegitimize_address (rtl);
15941 else if (TREE_CODE (decl) == PARM_DECL)
15943 if (rtl == NULL_RTX
15944 || is_pseudo_reg (rtl)
15946 && is_pseudo_reg (XEXP (rtl, 0))
15947 && DECL_INCOMING_RTL (decl)
15948 && MEM_P (DECL_INCOMING_RTL (decl))
15949 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
15951 tree declared_type = TREE_TYPE (decl);
15952 tree passed_type = DECL_ARG_TYPE (decl);
15953 machine_mode dmode = TYPE_MODE (declared_type);
15954 machine_mode pmode = TYPE_MODE (passed_type);
15956 /* This decl represents a formal parameter which was optimized out.
15957 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15958 all cases where (rtl == NULL_RTX) just below. */
15959 if (dmode == pmode)
15960 rtl = DECL_INCOMING_RTL (decl);
15961 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
15962 && SCALAR_INT_MODE_P (dmode)
15963 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
15964 && DECL_INCOMING_RTL (decl))
15966 rtx inc = DECL_INCOMING_RTL (decl);
15969 else if (MEM_P (inc))
15971 if (BYTES_BIG_ENDIAN)
15972 rtl = adjust_address_nv (inc, dmode,
15973 GET_MODE_SIZE (pmode)
15974 - GET_MODE_SIZE (dmode));
15981 /* If the parm was passed in registers, but lives on the stack, then
15982 make a big endian correction if the mode of the type of the
15983 parameter is not the same as the mode of the rtl. */
15984 /* ??? This is the same series of checks that are made in dbxout.c before
15985 we reach the big endian correction code there. It isn't clear if all
15986 of these checks are necessary here, but keeping them all is the safe
15988 else if (MEM_P (rtl)
15989 && XEXP (rtl, 0) != const0_rtx
15990 && ! CONSTANT_P (XEXP (rtl, 0))
15991 /* Not passed in memory. */
15992 && !MEM_P (DECL_INCOMING_RTL (decl))
15993 /* Not passed by invisible reference. */
15994 && (!REG_P (XEXP (rtl, 0))
15995 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
15996 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
15997 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15998 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16001 /* Big endian correction check. */
16002 && BYTES_BIG_ENDIAN
16003 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16004 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16007 machine_mode addr_mode = get_address_mode (rtl);
16008 int offset = (UNITS_PER_WORD
16009 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16011 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16012 plus_constant (addr_mode, XEXP (rtl, 0), offset));
16015 else if (TREE_CODE (decl) == VAR_DECL
16018 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16019 && BYTES_BIG_ENDIAN)
16021 machine_mode addr_mode = get_address_mode (rtl);
16022 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16023 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16025 /* If a variable is declared "register" yet is smaller than
16026 a register, then if we store the variable to memory, it
16027 looks like we're storing a register-sized value, when in
16028 fact we are not. We need to adjust the offset of the
16029 storage location to reflect the actual value's bytes,
16030 else gdb will not be able to display it. */
16032 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16033 plus_constant (addr_mode, XEXP (rtl, 0),
16037 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16038 and will have been substituted directly into all expressions that use it.
16039 C does not have such a concept, but C++ and other languages do. */
16040 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16041 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16044 rtl = targetm.delegitimize_address (rtl);
16046 /* If we don't look past the constant pool, we risk emitting a
16047 reference to a constant pool entry that isn't referenced from
16048 code, and thus is not emitted. */
16050 rtl = avoid_constant_pool_reference (rtl);
16052 /* Try harder to get a rtl. If this symbol ends up not being emitted
16053 in the current CU, resolve_addr will remove the expression referencing
16055 if (rtl == NULL_RTX
16056 && TREE_CODE (decl) == VAR_DECL
16057 && !DECL_EXTERNAL (decl)
16058 && TREE_STATIC (decl)
16059 && DECL_NAME (decl)
16060 && !DECL_HARD_REGISTER (decl)
16061 && DECL_MODE (decl) != VOIDmode)
16063 rtl = make_decl_rtl_for_debug (decl);
16065 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16066 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16073 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16074 returned. If so, the decl for the COMMON block is returned, and the
16075 value is the offset into the common block for the symbol. */
16078 fortran_common (tree decl, HOST_WIDE_INT *value)
16080 tree val_expr, cvar;
16082 HOST_WIDE_INT bitsize, bitpos;
16084 int unsignedp, volatilep = 0;
16086 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16087 it does not have a value (the offset into the common area), or if it
16088 is thread local (as opposed to global) then it isn't common, and shouldn't
16089 be handled as such. */
16090 if (TREE_CODE (decl) != VAR_DECL
16091 || !TREE_STATIC (decl)
16092 || !DECL_HAS_VALUE_EXPR_P (decl)
16096 val_expr = DECL_VALUE_EXPR (decl);
16097 if (TREE_CODE (val_expr) != COMPONENT_REF)
16100 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16101 &mode, &unsignedp, &volatilep, true);
16103 if (cvar == NULL_TREE
16104 || TREE_CODE (cvar) != VAR_DECL
16105 || DECL_ARTIFICIAL (cvar)
16106 || !TREE_PUBLIC (cvar))
16110 if (offset != NULL)
16112 if (!tree_fits_shwi_p (offset))
16114 *value = tree_to_shwi (offset);
16117 *value += bitpos / BITS_PER_UNIT;
16122 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16123 data attribute for a variable or a parameter. We generate the
16124 DW_AT_const_value attribute only in those cases where the given variable
16125 or parameter does not have a true "location" either in memory or in a
16126 register. This can happen (for example) when a constant is passed as an
16127 actual argument in a call to an inline function. (It's possible that
16128 these things can crop up in other ways also.) Note that one type of
16129 constant value which can be passed into an inlined function is a constant
16130 pointer. This can happen for example if an actual argument in an inlined
16131 function call evaluates to a compile-time constant address.
16133 CACHE_P is true if it is worth caching the location list for DECL,
16134 so that future calls can reuse it rather than regenerate it from scratch.
16135 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16136 since we will need to refer to them each time the function is inlined. */
16139 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
16140 enum dwarf_attribute attr)
16143 dw_loc_list_ref list;
16144 var_loc_list *loc_list;
16145 cached_dw_loc_list *cache;
16150 if (TREE_CODE (decl) == ERROR_MARK)
16153 if (get_AT (die, attr))
16156 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16157 || TREE_CODE (decl) == RESULT_DECL);
16159 /* Try to get some constant RTL for this decl, and use that as the value of
16162 rtl = rtl_for_decl_location (decl);
16163 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16164 && add_const_value_attribute (die, rtl))
16167 /* See if we have single element location list that is equivalent to
16168 a constant value. That way we are better to use add_const_value_attribute
16169 rather than expanding constant value equivalent. */
16170 loc_list = lookup_decl_loc (decl);
16173 && loc_list->first->next == NULL
16174 && NOTE_P (loc_list->first->loc)
16175 && NOTE_VAR_LOCATION (loc_list->first->loc)
16176 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16178 struct var_loc_node *node;
16180 node = loc_list->first;
16181 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16182 if (GET_CODE (rtl) == EXPR_LIST)
16183 rtl = XEXP (rtl, 0);
16184 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16185 && add_const_value_attribute (die, rtl))
16188 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16189 list several times. See if we've already cached the contents. */
16191 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
16195 cache = cached_dw_loc_list_table->find_with_hash (decl, DECL_UID (decl));
16197 list = cache->loc_list;
16201 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2,
16203 /* It is usually worth caching this result if the decl is from
16204 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
16205 if (cache_p && list && list->dw_loc_next)
16207 cached_dw_loc_list **slot
16208 = cached_dw_loc_list_table->find_slot_with_hash (decl,
16211 cache = ggc_cleared_alloc<cached_dw_loc_list> ();
16212 cache->decl_id = DECL_UID (decl);
16213 cache->loc_list = list;
16219 add_AT_location_description (die, attr, list);
16222 /* None of that worked, so it must not really have a location;
16223 try adding a constant value attribute from the DECL_INITIAL. */
16224 return tree_add_const_value_attribute_for_decl (die, decl);
16227 /* Helper function for tree_add_const_value_attribute. Natively encode
16228 initializer INIT into an array. Return true if successful. */
16231 native_encode_initializer (tree init, unsigned char *array, int size)
16235 if (init == NULL_TREE)
16239 switch (TREE_CODE (init))
16242 type = TREE_TYPE (init);
16243 if (TREE_CODE (type) == ARRAY_TYPE)
16245 tree enttype = TREE_TYPE (type);
16246 machine_mode mode = TYPE_MODE (enttype);
16248 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
16250 if (int_size_in_bytes (type) != size)
16252 if (size > TREE_STRING_LENGTH (init))
16254 memcpy (array, TREE_STRING_POINTER (init),
16255 TREE_STRING_LENGTH (init));
16256 memset (array + TREE_STRING_LENGTH (init),
16257 '\0', size - TREE_STRING_LENGTH (init));
16260 memcpy (array, TREE_STRING_POINTER (init), size);
16265 type = TREE_TYPE (init);
16266 if (int_size_in_bytes (type) != size)
16268 if (TREE_CODE (type) == ARRAY_TYPE)
16270 HOST_WIDE_INT min_index;
16271 unsigned HOST_WIDE_INT cnt;
16272 int curpos = 0, fieldsize;
16273 constructor_elt *ce;
16275 if (TYPE_DOMAIN (type) == NULL_TREE
16276 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type))))
16279 fieldsize = int_size_in_bytes (TREE_TYPE (type));
16280 if (fieldsize <= 0)
16283 min_index = tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type)));
16284 memset (array, '\0', size);
16285 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init), cnt, ce)
16287 tree val = ce->value;
16288 tree index = ce->index;
16290 if (index && TREE_CODE (index) == RANGE_EXPR)
16291 pos = (tree_to_shwi (TREE_OPERAND (index, 0)) - min_index)
16294 pos = (tree_to_shwi (index) - min_index) * fieldsize;
16299 if (!native_encode_initializer (val, array + pos, fieldsize))
16302 curpos = pos + fieldsize;
16303 if (index && TREE_CODE (index) == RANGE_EXPR)
16305 int count = tree_to_shwi (TREE_OPERAND (index, 1))
16306 - tree_to_shwi (TREE_OPERAND (index, 0));
16307 while (count-- > 0)
16310 memcpy (array + curpos, array + pos, fieldsize);
16311 curpos += fieldsize;
16314 gcc_assert (curpos <= size);
16318 else if (TREE_CODE (type) == RECORD_TYPE
16319 || TREE_CODE (type) == UNION_TYPE)
16321 tree field = NULL_TREE;
16322 unsigned HOST_WIDE_INT cnt;
16323 constructor_elt *ce;
16325 if (int_size_in_bytes (type) != size)
16328 if (TREE_CODE (type) == RECORD_TYPE)
16329 field = TYPE_FIELDS (type);
16331 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init), cnt, ce)
16333 tree val = ce->value;
16334 int pos, fieldsize;
16336 if (ce->index != 0)
16342 if (field == NULL_TREE || DECL_BIT_FIELD (field))
16345 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
16346 && TYPE_DOMAIN (TREE_TYPE (field))
16347 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
16349 else if (DECL_SIZE_UNIT (field) == NULL_TREE
16350 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field)))
16352 fieldsize = tree_to_shwi (DECL_SIZE_UNIT (field));
16353 pos = int_byte_position (field);
16354 gcc_assert (pos + fieldsize <= size);
16356 && !native_encode_initializer (val, array + pos, fieldsize))
16362 case VIEW_CONVERT_EXPR:
16363 case NON_LVALUE_EXPR:
16364 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
16366 return native_encode_expr (init, array, size) == size;
16370 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16371 attribute is the const value T. */
16374 tree_add_const_value_attribute (dw_die_ref die, tree t)
16377 tree type = TREE_TYPE (t);
16380 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
16384 gcc_assert (!DECL_P (init));
16386 rtl = rtl_for_decl_init (init, type);
16388 return add_const_value_attribute (die, rtl);
16389 /* If the host and target are sane, try harder. */
16390 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
16391 && initializer_constant_valid_p (init, type))
16393 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
16394 if (size > 0 && (int) size == size)
16396 unsigned char *array = ggc_cleared_vec_alloc<unsigned char> (size);
16398 if (native_encode_initializer (init, array, size))
16400 add_AT_vec (die, DW_AT_const_value, size, 1, array);
16409 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16410 attribute is the const value of T, where T is an integral constant
16411 variable with static storage duration
16412 (so it can't be a PARM_DECL or a RESULT_DECL). */
16415 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
16419 || (TREE_CODE (decl) != VAR_DECL
16420 && TREE_CODE (decl) != CONST_DECL)
16421 || (TREE_CODE (decl) == VAR_DECL
16422 && !TREE_STATIC (decl)))
16425 if (TREE_READONLY (decl)
16426 && ! TREE_THIS_VOLATILE (decl)
16427 && DECL_INITIAL (decl))
16432 /* Don't add DW_AT_const_value if abstract origin already has one. */
16433 if (get_AT (var_die, DW_AT_const_value))
16436 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
16439 /* Convert the CFI instructions for the current function into a
16440 location list. This is used for DW_AT_frame_base when we targeting
16441 a dwarf2 consumer that does not support the dwarf3
16442 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16445 static dw_loc_list_ref
16446 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
16450 dw_loc_list_ref list, *list_tail;
16452 dw_cfa_location last_cfa, next_cfa;
16453 const char *start_label, *last_label, *section;
16454 dw_cfa_location remember;
16457 gcc_assert (fde != NULL);
16459 section = secname_for_decl (current_function_decl);
16463 memset (&next_cfa, 0, sizeof (next_cfa));
16464 next_cfa.reg = INVALID_REGNUM;
16465 remember = next_cfa;
16467 start_label = fde->dw_fde_begin;
16469 /* ??? Bald assumption that the CIE opcode list does not contain
16470 advance opcodes. */
16471 FOR_EACH_VEC_ELT (*cie_cfi_vec, ix, cfi)
16472 lookup_cfa_1 (cfi, &next_cfa, &remember);
16474 last_cfa = next_cfa;
16475 last_label = start_label;
16477 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
16479 /* If the first partition contained no CFI adjustments, the
16480 CIE opcodes apply to the whole first partition. */
16481 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16482 fde->dw_fde_begin, fde->dw_fde_end, section);
16483 list_tail =&(*list_tail)->dw_loc_next;
16484 start_label = last_label = fde->dw_fde_second_begin;
16487 FOR_EACH_VEC_SAFE_ELT (fde->dw_fde_cfi, ix, cfi)
16489 switch (cfi->dw_cfi_opc)
16491 case DW_CFA_set_loc:
16492 case DW_CFA_advance_loc1:
16493 case DW_CFA_advance_loc2:
16494 case DW_CFA_advance_loc4:
16495 if (!cfa_equal_p (&last_cfa, &next_cfa))
16497 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16498 start_label, last_label, section);
16500 list_tail = &(*list_tail)->dw_loc_next;
16501 last_cfa = next_cfa;
16502 start_label = last_label;
16504 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
16507 case DW_CFA_advance_loc:
16508 /* The encoding is complex enough that we should never emit this. */
16509 gcc_unreachable ();
16512 lookup_cfa_1 (cfi, &next_cfa, &remember);
16515 if (ix + 1 == fde->dw_fde_switch_cfi_index)
16517 if (!cfa_equal_p (&last_cfa, &next_cfa))
16519 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16520 start_label, last_label, section);
16522 list_tail = &(*list_tail)->dw_loc_next;
16523 last_cfa = next_cfa;
16524 start_label = last_label;
16526 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16527 start_label, fde->dw_fde_end, section);
16528 list_tail = &(*list_tail)->dw_loc_next;
16529 start_label = last_label = fde->dw_fde_second_begin;
16533 if (!cfa_equal_p (&last_cfa, &next_cfa))
16535 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
16536 start_label, last_label, section);
16537 list_tail = &(*list_tail)->dw_loc_next;
16538 start_label = last_label;
16541 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
16543 fde->dw_fde_second_begin
16544 ? fde->dw_fde_second_end : fde->dw_fde_end,
16547 if (list && list->dw_loc_next)
16553 /* Compute a displacement from the "steady-state frame pointer" to the
16554 frame base (often the same as the CFA), and store it in
16555 frame_pointer_fb_offset. OFFSET is added to the displacement
16556 before the latter is negated. */
16559 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
16563 #ifdef FRAME_POINTER_CFA_OFFSET
16564 reg = frame_pointer_rtx;
16565 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
16567 reg = arg_pointer_rtx;
16568 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
16571 elim = (ira_use_lra_p
16572 ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
16573 : eliminate_regs (reg, VOIDmode, NULL_RTX));
16574 if (GET_CODE (elim) == PLUS)
16576 offset += INTVAL (XEXP (elim, 1));
16577 elim = XEXP (elim, 0);
16580 frame_pointer_fb_offset = -offset;
16582 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16583 in which to eliminate. This is because it's stack pointer isn't
16584 directly accessible as a register within the ISA. To work around
16585 this, assume that while we cannot provide a proper value for
16586 frame_pointer_fb_offset, we won't need one either. */
16587 frame_pointer_fb_offset_valid
16588 = ((SUPPORTS_STACK_ALIGNMENT
16589 && (elim == hard_frame_pointer_rtx
16590 || elim == stack_pointer_rtx))
16591 || elim == (frame_pointer_needed
16592 ? hard_frame_pointer_rtx
16593 : stack_pointer_rtx));
16596 /* Generate a DW_AT_name attribute given some string value to be included as
16597 the value of the attribute. */
16600 add_name_attribute (dw_die_ref die, const char *name_string)
16602 if (name_string != NULL && *name_string != 0)
16604 if (demangle_name_func)
16605 name_string = (*demangle_name_func) (name_string);
16607 add_AT_string (die, DW_AT_name, name_string);
16611 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16612 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16613 of TYPE accordingly.
16615 ??? This is a temporary measure until after we're able to generate
16616 regular DWARF for the complex Ada type system. */
16619 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
16620 dw_die_ref context_die)
16623 dw_die_ref dtype_die;
16625 if (!lang_hooks.types.descriptive_type)
16628 dtype = lang_hooks.types.descriptive_type (type);
16632 dtype_die = lookup_type_die (dtype);
16635 gen_type_die (dtype, context_die);
16636 dtype_die = lookup_type_die (dtype);
16637 gcc_assert (dtype_die);
16640 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
16643 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16645 static const char *
16646 comp_dir_string (void)
16650 static const char *cached_wd = NULL;
16652 if (cached_wd != NULL)
16655 wd = get_src_pwd ();
16659 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
16663 wdlen = strlen (wd);
16664 wd1 = ggc_vec_alloc<char> (wdlen + 2);
16666 wd1 [wdlen] = DIR_SEPARATOR;
16667 wd1 [wdlen + 1] = 0;
16671 cached_wd = remap_debug_filename (wd);
16675 /* Generate a DW_AT_comp_dir attribute for DIE. */
16678 add_comp_dir_attribute (dw_die_ref die)
16680 const char * wd = comp_dir_string ();
16682 add_AT_string (die, DW_AT_comp_dir, wd);
16685 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
16686 pointer computation, ...), output a representation for that bound according
16687 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
16688 loc_list_from_tree for the meaning of CONTEXT. */
16691 add_scalar_info (dw_die_ref die, enum dwarf_attribute attr, tree value,
16692 int forms, const struct loc_descr_context *context)
16694 dw_die_ref ctx, decl_die;
16695 dw_loc_list_ref list;
16697 bool strip_conversions = true;
16699 while (strip_conversions)
16700 switch (TREE_CODE (value))
16707 case VIEW_CONVERT_EXPR:
16708 value = TREE_OPERAND (value, 0);
16712 strip_conversions = false;
16716 /* If possible and permitted, output the attribute as a constant. */
16717 if ((forms & dw_scalar_form_constant) != 0
16718 && TREE_CODE (value) == INTEGER_CST)
16720 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (value));
16722 /* If HOST_WIDE_INT is big enough then represent the bound as
16723 a constant value. We need to choose a form based on
16724 whether the type is signed or unsigned. We cannot just
16725 call add_AT_unsigned if the value itself is positive
16726 (add_AT_unsigned might add the unsigned value encoded as
16727 DW_FORM_data[1248]). Some DWARF consumers will lookup the
16728 bounds type and then sign extend any unsigned values found
16729 for signed types. This is needed only for
16730 DW_AT_{lower,upper}_bound, since for most other attributes,
16731 consumers will treat DW_FORM_data[1248] as unsigned values,
16732 regardless of the underlying type. */
16733 if (prec <= HOST_BITS_PER_WIDE_INT
16734 || tree_fits_uhwi_p (value))
16736 if (TYPE_UNSIGNED (TREE_TYPE (value)))
16737 add_AT_unsigned (die, attr, TREE_INT_CST_LOW (value));
16739 add_AT_int (die, attr, TREE_INT_CST_LOW (value));
16742 /* Otherwise represent the bound as an unsigned value with
16743 the precision of its type. The precision and signedness
16744 of the type will be necessary to re-interpret it
16746 add_AT_wide (die, attr, value);
16750 /* Otherwise, if it's possible and permitted too, output a reference to
16752 if ((forms & dw_scalar_form_reference) != 0)
16754 tree decl = NULL_TREE;
16756 /* Some type attributes reference an outer type. For instance, the upper
16757 bound of an array may reference an embedding record (this happens in
16759 if (TREE_CODE (value) == COMPONENT_REF
16760 && TREE_CODE (TREE_OPERAND (value, 0)) == PLACEHOLDER_EXPR
16761 && TREE_CODE (TREE_OPERAND (value, 1)) == FIELD_DECL)
16762 decl = TREE_OPERAND (value, 1);
16764 else if (TREE_CODE (value) == VAR_DECL
16765 || TREE_CODE (value) == PARM_DECL
16766 || TREE_CODE (value) == RESULT_DECL)
16769 if (decl != NULL_TREE)
16771 dw_die_ref decl_die = lookup_decl_die (decl);
16773 /* ??? Can this happen, or should the variable have been bound
16774 first? Probably it can, since I imagine that we try to create
16775 the types of parameters in the order in which they exist in
16776 the list, and won't have created a forward reference to a
16777 later parameter. */
16778 if (decl_die != NULL)
16780 add_AT_die_ref (die, attr, decl_die);
16786 /* Last chance: try to create a stack operation procedure to evaluate the
16787 value. Do nothing if even that is not possible or permitted. */
16788 if ((forms & dw_scalar_form_exprloc) == 0)
16791 list = loc_list_from_tree (value, 2, context);
16792 if (list == NULL || single_element_loc_list_p (list))
16794 /* If this attribute is not a reference nor constant, it is
16795 a DWARF expression rather than location description. For that
16796 loc_list_from_tree (value, 0, &context) is needed. */
16797 dw_loc_list_ref list2 = loc_list_from_tree (value, 0, context);
16798 if (list2 && single_element_loc_list_p (list2))
16800 add_AT_loc (die, attr, list2->expr);
16805 /* If that failed to give a single element location list, fall back to
16806 outputting this as a reference... still if permitted. */
16807 if (list == NULL || (forms & dw_scalar_form_reference) == 0)
16810 if (current_function_decl == 0)
16811 ctx = comp_unit_die ();
16813 ctx = lookup_decl_die (current_function_decl);
16815 decl_die = new_die (DW_TAG_variable, ctx, value);
16816 add_AT_flag (decl_die, DW_AT_artificial, 1);
16817 add_type_attribute (decl_die, TREE_TYPE (value), TYPE_QUAL_CONST, ctx);
16818 add_AT_location_description (decl_die, DW_AT_location, list);
16819 add_AT_die_ref (die, attr, decl_die);
16822 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16826 lower_bound_default (void)
16828 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
16834 case DW_LANG_C_plus_plus:
16835 case DW_LANG_C_plus_plus_11:
16836 case DW_LANG_C_plus_plus_14:
16838 case DW_LANG_ObjC_plus_plus:
16841 case DW_LANG_Fortran77:
16842 case DW_LANG_Fortran90:
16843 case DW_LANG_Fortran95:
16844 case DW_LANG_Fortran03:
16845 case DW_LANG_Fortran08:
16849 case DW_LANG_Python:
16850 return dwarf_version >= 4 ? 0 : -1;
16851 case DW_LANG_Ada95:
16852 case DW_LANG_Ada83:
16853 case DW_LANG_Cobol74:
16854 case DW_LANG_Cobol85:
16855 case DW_LANG_Pascal83:
16856 case DW_LANG_Modula2:
16858 return dwarf_version >= 4 ? 1 : -1;
16864 /* Given a tree node describing an array bound (either lower or upper) output
16865 a representation for that bound. */
16868 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr,
16869 tree bound, const struct loc_descr_context *context)
16874 switch (TREE_CODE (bound))
16876 /* Strip all conversions. */
16878 case VIEW_CONVERT_EXPR:
16879 bound = TREE_OPERAND (bound, 0);
16882 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
16883 are even omitted when they are the default. */
16885 /* If the value for this bound is the default one, we can even omit the
16887 if (bound_attr == DW_AT_lower_bound
16888 && tree_fits_shwi_p (bound)
16889 && (dflt = lower_bound_default ()) != -1
16890 && tree_to_shwi (bound) == dflt)
16896 add_scalar_info (subrange_die, bound_attr, bound,
16897 dw_scalar_form_constant
16898 | dw_scalar_form_exprloc
16899 | dw_scalar_form_reference,
16905 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16906 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16907 Note that the block of subscript information for an array type also
16908 includes information about the element type of the given array type.
16910 This function reuses previously set type and bound information if
16914 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
16916 unsigned dimension_number;
16918 dw_die_ref child = type_die->die_child;
16920 for (dimension_number = 0;
16921 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
16922 type = TREE_TYPE (type), dimension_number++)
16924 tree domain = TYPE_DOMAIN (type);
16926 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
16929 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16930 and (in GNU C only) variable bounds. Handle all three forms
16933 /* Find and reuse a previously generated DW_TAG_subrange_type if
16936 For multi-dimensional arrays, as we iterate through the
16937 various dimensions in the enclosing for loop above, we also
16938 iterate through the DIE children and pick at each
16939 DW_TAG_subrange_type previously generated (if available).
16940 Each child DW_TAG_subrange_type DIE describes the range of
16941 the current dimension. At this point we should have as many
16942 DW_TAG_subrange_type's as we have dimensions in the
16944 dw_die_ref subrange_die = NULL;
16948 child = child->die_sib;
16949 if (child->die_tag == DW_TAG_subrange_type)
16950 subrange_die = child;
16951 if (child == type_die->die_child)
16953 /* If we wrapped around, stop looking next time. */
16957 if (child->die_tag == DW_TAG_subrange_type)
16961 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
16965 /* We have an array type with specified bounds. */
16966 lower = TYPE_MIN_VALUE (domain);
16967 upper = TYPE_MAX_VALUE (domain);
16969 /* Define the index type. */
16970 if (TREE_TYPE (domain)
16971 && !get_AT (subrange_die, DW_AT_type))
16973 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16974 TREE_TYPE field. We can't emit debug info for this
16975 because it is an unnamed integral type. */
16976 if (TREE_CODE (domain) == INTEGER_TYPE
16977 && TYPE_NAME (domain) == NULL_TREE
16978 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
16979 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
16982 add_type_attribute (subrange_die, TREE_TYPE (domain),
16983 TYPE_UNQUALIFIED, type_die);
16986 /* ??? If upper is NULL, the array has unspecified length,
16987 but it does have a lower bound. This happens with Fortran
16989 Since the debugger is definitely going to need to know N
16990 to produce useful results, go ahead and output the lower
16991 bound solo, and hope the debugger can cope. */
16993 if (!get_AT (subrange_die, DW_AT_lower_bound))
16994 add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL);
16995 if (upper && !get_AT (subrange_die, DW_AT_upper_bound))
16996 add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
16999 /* Otherwise we have an array type with an unspecified length. The
17000 DWARF-2 spec does not say how to handle this; let's just leave out the
17005 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
17008 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17010 dw_die_ref decl_die;
17011 HOST_WIDE_INT size;
17013 switch (TREE_CODE (tree_node))
17018 case ENUMERAL_TYPE:
17021 case QUAL_UNION_TYPE:
17022 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node)) == VAR_DECL
17023 && (decl_die = lookup_decl_die (TYPE_SIZE_UNIT (tree_node))))
17025 add_AT_die_ref (die, DW_AT_byte_size, decl_die);
17028 size = int_size_in_bytes (tree_node);
17031 /* For a data member of a struct or union, the DW_AT_byte_size is
17032 generally given as the number of bytes normally allocated for an
17033 object of the *declared* type of the member itself. This is true
17034 even for bit-fields. */
17035 size = int_size_in_bytes (field_type (tree_node));
17038 gcc_unreachable ();
17041 /* Note that `size' might be -1 when we get to this point. If it is, that
17042 indicates that the byte size of the entity in question is variable. We
17043 have no good way of expressing this fact in Dwarf at the present time,
17044 when location description was not used by the caller code instead. */
17046 add_AT_unsigned (die, DW_AT_byte_size, size);
17049 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17050 which specifies the distance in bits from the highest order bit of the
17051 "containing object" for the bit-field to the highest order bit of the
17054 For any given bit-field, the "containing object" is a hypothetical object
17055 (of some integral or enum type) within which the given bit-field lives. The
17056 type of this hypothetical "containing object" is always the same as the
17057 declared type of the individual bit-field itself. The determination of the
17058 exact location of the "containing object" for a bit-field is rather
17059 complicated. It's handled by the `field_byte_offset' function (above).
17061 Note that it is the size (in bytes) of the hypothetical "containing object"
17062 which will be given in the DW_AT_byte_size attribute for this bit-field.
17063 (See `byte_size_attribute' above). */
17066 add_bit_offset_attribute (dw_die_ref die, tree decl)
17068 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17069 tree type = DECL_BIT_FIELD_TYPE (decl);
17070 HOST_WIDE_INT bitpos_int;
17071 HOST_WIDE_INT highest_order_object_bit_offset;
17072 HOST_WIDE_INT highest_order_field_bit_offset;
17073 HOST_WIDE_INT bit_offset;
17075 /* Must be a field and a bit field. */
17076 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17078 /* We can't yet handle bit-fields whose offsets are variable, so if we
17079 encounter such things, just return without generating any attribute
17080 whatsoever. Likewise for variable or too large size. */
17081 if (! tree_fits_shwi_p (bit_position (decl))
17082 || ! tree_fits_uhwi_p (DECL_SIZE (decl)))
17085 bitpos_int = int_bit_position (decl);
17087 /* Note that the bit offset is always the distance (in bits) from the
17088 highest-order bit of the "containing object" to the highest-order bit of
17089 the bit-field itself. Since the "high-order end" of any object or field
17090 is different on big-endian and little-endian machines, the computation
17091 below must take account of these differences. */
17092 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17093 highest_order_field_bit_offset = bitpos_int;
17095 if (! BYTES_BIG_ENDIAN)
17097 highest_order_field_bit_offset += tree_to_shwi (DECL_SIZE (decl));
17098 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17102 = (! BYTES_BIG_ENDIAN
17103 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17104 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17106 if (bit_offset < 0)
17107 add_AT_int (die, DW_AT_bit_offset, bit_offset);
17109 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
17112 /* For a FIELD_DECL node which represents a bit field, output an attribute
17113 which specifies the length in bits of the given field. */
17116 add_bit_size_attribute (dw_die_ref die, tree decl)
17118 /* Must be a field and a bit field. */
17119 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17120 && DECL_BIT_FIELD_TYPE (decl));
17122 if (tree_fits_uhwi_p (DECL_SIZE (decl)))
17123 add_AT_unsigned (die, DW_AT_bit_size, tree_to_uhwi (DECL_SIZE (decl)));
17126 /* If the compiled language is ANSI C, then add a 'prototyped'
17127 attribute, if arg types are given for the parameters of a function. */
17130 add_prototyped_attribute (dw_die_ref die, tree func_type)
17132 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17139 if (prototype_p (func_type))
17140 add_AT_flag (die, DW_AT_prototyped, 1);
17147 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17148 by looking in either the type declaration or object declaration
17151 static inline dw_die_ref
17152 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17154 dw_die_ref origin_die = NULL;
17156 if (TREE_CODE (origin) != FUNCTION_DECL)
17158 /* We may have gotten separated from the block for the inlined
17159 function, if we're in an exception handler or some such; make
17160 sure that the abstract function has been written out.
17162 Doing this for nested functions is wrong, however; functions are
17163 distinct units, and our context might not even be inline. */
17167 fn = TYPE_STUB_DECL (fn);
17169 fn = decl_function_context (fn);
17171 dwarf2out_abstract_function (fn);
17174 if (DECL_P (origin))
17175 origin_die = lookup_decl_die (origin);
17176 else if (TYPE_P (origin))
17177 origin_die = lookup_type_die (origin);
17179 /* XXX: Functions that are never lowered don't always have correct block
17180 trees (in the case of java, they simply have no block tree, in some other
17181 languages). For these functions, there is nothing we can really do to
17182 output correct debug info for inlined functions in all cases. Rather
17183 than die, we'll just produce deficient debug info now, in that we will
17184 have variables without a proper abstract origin. In the future, when all
17185 functions are lowered, we should re-add a gcc_assert (origin_die)
17189 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17193 /* We do not currently support the pure_virtual attribute. */
17196 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17198 if (DECL_VINDEX (func_decl))
17200 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17202 if (tree_fits_shwi_p (DECL_VINDEX (func_decl)))
17203 add_AT_loc (die, DW_AT_vtable_elem_location,
17204 new_loc_descr (DW_OP_constu,
17205 tree_to_shwi (DECL_VINDEX (func_decl)),
17208 /* GNU extension: Record what type this method came from originally. */
17209 if (debug_info_level > DINFO_LEVEL_TERSE
17210 && DECL_CONTEXT (func_decl))
17211 add_AT_die_ref (die, DW_AT_containing_type,
17212 lookup_type_die (DECL_CONTEXT (func_decl)));
17216 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17217 given decl. This used to be a vendor extension until after DWARF 4
17218 standardized it. */
17221 add_linkage_attr (dw_die_ref die, tree decl)
17223 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17225 /* Mimic what assemble_name_raw does with a leading '*'. */
17226 if (name[0] == '*')
17229 if (dwarf_version >= 4)
17230 add_AT_string (die, DW_AT_linkage_name, name);
17232 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17235 /* Add source coordinate attributes for the given decl. */
17238 add_src_coords_attributes (dw_die_ref die, tree decl)
17240 expanded_location s;
17242 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl)) == UNKNOWN_LOCATION)
17244 s = expand_location (DECL_SOURCE_LOCATION (decl));
17245 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17246 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17249 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17252 add_linkage_name (dw_die_ref die, tree decl)
17254 if (debug_info_level > DINFO_LEVEL_NONE
17255 && (TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17256 && TREE_PUBLIC (decl)
17257 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17258 && die->die_tag != DW_TAG_member)
17260 /* Defer until we have an assembler name set. */
17261 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17263 limbo_die_node *asm_name;
17265 asm_name = ggc_cleared_alloc<limbo_die_node> ();
17266 asm_name->die = die;
17267 asm_name->created_for = decl;
17268 asm_name->next = deferred_asm_name;
17269 deferred_asm_name = asm_name;
17271 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17272 add_linkage_attr (die, decl);
17276 /* Add a DW_AT_name attribute and source coordinate attribute for the
17277 given decl, but only if it actually has a name. */
17280 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17284 decl_name = DECL_NAME (decl);
17285 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17287 const char *name = dwarf2_name (decl, 0);
17289 add_name_attribute (die, name);
17290 if (! DECL_ARTIFICIAL (decl))
17291 add_src_coords_attributes (die, decl);
17293 add_linkage_name (die, decl);
17296 #ifdef VMS_DEBUGGING_INFO
17297 /* Get the function's name, as described by its RTL. This may be different
17298 from the DECL_NAME name used in the source file. */
17299 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17301 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17302 XEXP (DECL_RTL (decl), 0), false);
17303 vec_safe_push (used_rtx_array, XEXP (DECL_RTL (decl), 0));
17305 #endif /* VMS_DEBUGGING_INFO */
17308 #ifdef VMS_DEBUGGING_INFO
17309 /* Output the debug main pointer die for VMS */
17312 dwarf2out_vms_debug_main_pointer (void)
17314 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17317 /* Allocate the VMS debug main subprogram die. */
17318 die = ggc_cleared_alloc<die_node> ();
17319 die->die_tag = DW_TAG_subprogram;
17320 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17321 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17322 current_function_funcdef_no);
17323 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17325 /* Make it the first child of comp_unit_die (). */
17326 die->die_parent = comp_unit_die ();
17327 if (comp_unit_die ()->die_child)
17329 die->die_sib = comp_unit_die ()->die_child->die_sib;
17330 comp_unit_die ()->die_child->die_sib = die;
17334 die->die_sib = die;
17335 comp_unit_die ()->die_child = die;
17338 #endif /* VMS_DEBUGGING_INFO */
17340 /* Push a new declaration scope. */
17343 push_decl_scope (tree scope)
17345 vec_safe_push (decl_scope_table, scope);
17348 /* Pop a declaration scope. */
17351 pop_decl_scope (void)
17353 decl_scope_table->pop ();
17356 /* walk_tree helper function for uses_local_type, below. */
17359 uses_local_type_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
17362 *walk_subtrees = 0;
17365 tree name = TYPE_NAME (*tp);
17366 if (name && DECL_P (name) && decl_function_context (name))
17372 /* If TYPE involves a function-local type (including a local typedef to a
17373 non-local type), returns that type; otherwise returns NULL_TREE. */
17376 uses_local_type (tree type)
17378 tree used = walk_tree_without_duplicates (&type, uses_local_type_r, NULL);
17382 /* Return the DIE for the scope that immediately contains this type.
17383 Non-named types that do not involve a function-local type get global
17384 scope. Named types nested in namespaces or other types get their
17385 containing scope. All other types (i.e. function-local named types) get
17386 the current active scope. */
17389 scope_die_for (tree t, dw_die_ref context_die)
17391 dw_die_ref scope_die = NULL;
17392 tree containing_scope;
17394 /* Non-types always go in the current scope. */
17395 gcc_assert (TYPE_P (t));
17397 /* Use the scope of the typedef, rather than the scope of the type
17399 if (TYPE_NAME (t) && DECL_P (TYPE_NAME (t)))
17400 containing_scope = DECL_CONTEXT (TYPE_NAME (t));
17402 containing_scope = TYPE_CONTEXT (t);
17404 /* Use the containing namespace if there is one. */
17405 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17407 if (context_die == lookup_decl_die (containing_scope))
17409 else if (debug_info_level > DINFO_LEVEL_TERSE)
17410 context_die = get_context_die (containing_scope);
17412 containing_scope = NULL_TREE;
17415 /* Ignore function type "scopes" from the C frontend. They mean that
17416 a tagged type is local to a parmlist of a function declarator, but
17417 that isn't useful to DWARF. */
17418 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
17419 containing_scope = NULL_TREE;
17421 if (SCOPE_FILE_SCOPE_P (containing_scope))
17423 /* If T uses a local type keep it local as well, to avoid references
17424 to function-local DIEs from outside the function. */
17425 if (current_function_decl && uses_local_type (t))
17426 scope_die = context_die;
17428 scope_die = comp_unit_die ();
17430 else if (TYPE_P (containing_scope))
17432 /* For types, we can just look up the appropriate DIE. */
17433 if (debug_info_level > DINFO_LEVEL_TERSE)
17434 scope_die = get_context_die (containing_scope);
17437 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
17438 if (scope_die == NULL)
17439 scope_die = comp_unit_die ();
17443 scope_die = context_die;
17448 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17451 local_scope_p (dw_die_ref context_die)
17453 for (; context_die; context_die = context_die->die_parent)
17454 if (context_die->die_tag == DW_TAG_inlined_subroutine
17455 || context_die->die_tag == DW_TAG_subprogram)
17461 /* Returns nonzero if CONTEXT_DIE is a class. */
17464 class_scope_p (dw_die_ref context_die)
17466 return (context_die
17467 && (context_die->die_tag == DW_TAG_structure_type
17468 || context_die->die_tag == DW_TAG_class_type
17469 || context_die->die_tag == DW_TAG_interface_type
17470 || context_die->die_tag == DW_TAG_union_type));
17473 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17474 whether or not to treat a DIE in this context as a declaration. */
17477 class_or_namespace_scope_p (dw_die_ref context_die)
17479 return (class_scope_p (context_die)
17480 || (context_die && context_die->die_tag == DW_TAG_namespace));
17483 /* Many forms of DIEs require a "type description" attribute. This
17484 routine locates the proper "type descriptor" die for the type given
17485 by 'type' plus any additional qualifiers given by 'cv_quals', and
17486 adds a DW_AT_type attribute below the given die. */
17489 add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
17490 dw_die_ref context_die)
17492 enum tree_code code = TREE_CODE (type);
17493 dw_die_ref type_die = NULL;
17495 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17496 or fixed-point type, use the inner type. This is because we have no
17497 support for unnamed types in base_type_die. This can happen if this is
17498 an Ada subrange type. Correct solution is emit a subrange type die. */
17499 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
17500 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
17501 type = TREE_TYPE (type), code = TREE_CODE (type);
17503 if (code == ERROR_MARK
17504 /* Handle a special case. For functions whose return type is void, we
17505 generate *no* type attribute. (Note that no object may have type
17506 `void', so this only applies to function return types). */
17507 || code == VOID_TYPE)
17510 type_die = modified_type_die (type,
17511 cv_quals | TYPE_QUALS_NO_ADDR_SPACE (type),
17514 if (type_die != NULL)
17515 add_AT_die_ref (object_die, DW_AT_type, type_die);
17518 /* Given an object die, add the calling convention attribute for the
17519 function call type. */
17521 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
17523 enum dwarf_calling_convention value = DW_CC_normal;
17525 value = ((enum dwarf_calling_convention)
17526 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
17529 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
17531 /* DWARF 2 doesn't provide a way to identify a program's source-level
17532 entry point. DW_AT_calling_convention attributes are only meant
17533 to describe functions' calling conventions. However, lacking a
17534 better way to signal the Fortran main program, we used this for
17535 a long time, following existing custom. Now, DWARF 4 has
17536 DW_AT_main_subprogram, which we add below, but some tools still
17537 rely on the old way, which we thus keep. */
17538 value = DW_CC_program;
17540 if (dwarf_version >= 4 || !dwarf_strict)
17541 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
17544 /* Only add the attribute if the backend requests it, and
17545 is not DW_CC_normal. */
17546 if (value && (value != DW_CC_normal))
17547 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
17550 /* Given a tree pointer to a struct, class, union, or enum type node, return
17551 a pointer to the (string) tag name for the given type, or zero if the type
17552 was declared without a tag. */
17554 static const char *
17555 type_tag (const_tree type)
17557 const char *name = 0;
17559 if (TYPE_NAME (type) != 0)
17563 /* Find the IDENTIFIER_NODE for the type name. */
17564 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
17565 && !TYPE_NAMELESS (type))
17566 t = TYPE_NAME (type);
17568 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17569 a TYPE_DECL node, regardless of whether or not a `typedef' was
17571 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
17572 && ! DECL_IGNORED_P (TYPE_NAME (type)))
17574 /* We want to be extra verbose. Don't call dwarf_name if
17575 DECL_NAME isn't set. The default hook for decl_printable_name
17576 doesn't like that, and in this context it's correct to return
17577 0, instead of "<anonymous>" or the like. */
17578 if (DECL_NAME (TYPE_NAME (type))
17579 && !DECL_NAMELESS (TYPE_NAME (type)))
17580 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
17583 /* Now get the name as a string, or invent one. */
17584 if (!name && t != 0)
17585 name = IDENTIFIER_POINTER (t);
17588 return (name == 0 || *name == '\0') ? 0 : name;
17591 /* Return the type associated with a data member, make a special check
17592 for bit field types. */
17595 member_declared_type (const_tree member)
17597 return (DECL_BIT_FIELD_TYPE (member)
17598 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
17601 /* Get the decl's label, as described by its RTL. This may be different
17602 from the DECL_NAME name used in the source file. */
17605 static const char *
17606 decl_start_label (tree decl)
17609 const char *fnname;
17611 x = DECL_RTL (decl);
17612 gcc_assert (MEM_P (x));
17615 gcc_assert (GET_CODE (x) == SYMBOL_REF);
17617 fnname = XSTR (x, 0);
17622 /* For variable-length arrays that have been previously generated, but
17623 may be incomplete due to missing subscript info, fill the subscript
17624 info. Return TRUE if this is one of those cases. */
17626 fill_variable_array_bounds (tree type)
17628 if (TREE_ASM_WRITTEN (type)
17629 && TREE_CODE (type) == ARRAY_TYPE
17630 && variably_modified_type_p (type, NULL))
17632 dw_die_ref array_die = lookup_type_die (type);
17635 add_subscript_info (array_die, type, !is_ada ());
17641 /* These routines generate the internal representation of the DIE's for
17642 the compilation unit. Debugging information is collected by walking
17643 the declaration trees passed in from dwarf2out_decl(). */
17646 gen_array_type_die (tree type, dw_die_ref context_die)
17648 dw_die_ref array_die;
17650 /* GNU compilers represent multidimensional array types as sequences of one
17651 dimensional array types whose element types are themselves array types.
17652 We sometimes squish that down to a single array_type DIE with multiple
17653 subscripts in the Dwarf debugging info. The draft Dwarf specification
17654 say that we are allowed to do this kind of compression in C, because
17655 there is no difference between an array of arrays and a multidimensional
17656 array. We don't do this for Ada to remain as close as possible to the
17657 actual representation, which is especially important against the language
17658 flexibilty wrt arrays of variable size. */
17660 bool collapse_nested_arrays = !is_ada ();
17662 if (fill_variable_array_bounds (type))
17665 dw_die_ref scope_die = scope_die_for (type, context_die);
17668 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17669 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17670 if (TYPE_STRING_FLAG (type)
17671 && TREE_CODE (type) == ARRAY_TYPE
17673 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
17675 HOST_WIDE_INT size;
17677 array_die = new_die (DW_TAG_string_type, scope_die, type);
17678 add_name_attribute (array_die, type_tag (type));
17679 equate_type_number_to_die (type, array_die);
17680 size = int_size_in_bytes (type);
17682 add_AT_unsigned (array_die, DW_AT_byte_size, size);
17683 else if (TYPE_DOMAIN (type) != NULL_TREE
17684 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
17685 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
17687 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
17688 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2, NULL);
17690 size = int_size_in_bytes (TREE_TYPE (szdecl));
17691 if (loc && size > 0)
17693 add_AT_location_description (array_die, DW_AT_string_length, loc);
17694 if (size != DWARF2_ADDR_SIZE)
17695 add_AT_unsigned (array_die, DW_AT_byte_size, size);
17701 array_die = new_die (DW_TAG_array_type, scope_die, type);
17702 add_name_attribute (array_die, type_tag (type));
17703 equate_type_number_to_die (type, array_die);
17705 if (TREE_CODE (type) == VECTOR_TYPE)
17706 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
17708 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17710 && TREE_CODE (type) == ARRAY_TYPE
17711 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
17712 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
17713 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
17716 /* We default the array ordering. SDB will probably do
17717 the right things even if DW_AT_ordering is not present. It's not even
17718 an issue until we start to get into multidimensional arrays anyway. If
17719 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17720 then we'll have to put the DW_AT_ordering attribute back in. (But if
17721 and when we find out that we need to put these in, we will only do so
17722 for multidimensional arrays. */
17723 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
17726 if (TREE_CODE (type) == VECTOR_TYPE)
17728 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17729 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
17730 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node, NULL);
17731 add_bound_info (subrange_die, DW_AT_upper_bound,
17732 size_int (TYPE_VECTOR_SUBPARTS (type) - 1), NULL);
17735 add_subscript_info (array_die, type, collapse_nested_arrays);
17737 /* Add representation of the type of the elements of this array type and
17738 emit the corresponding DIE if we haven't done it already. */
17739 element_type = TREE_TYPE (type);
17740 if (collapse_nested_arrays)
17741 while (TREE_CODE (element_type) == ARRAY_TYPE)
17743 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
17745 element_type = TREE_TYPE (element_type);
17748 add_type_attribute (array_die, element_type, TYPE_UNQUALIFIED, context_die);
17750 add_gnat_descriptive_type_attribute (array_die, type, context_die);
17751 if (TYPE_ARTIFICIAL (type))
17752 add_AT_flag (array_die, DW_AT_artificial, 1);
17754 if (get_AT (array_die, DW_AT_name))
17755 add_pubtype (type, array_die);
17758 /* This routine generates DIE for array with hidden descriptor, details
17759 are filled into *info by a langhook. */
17762 gen_descr_array_type_die (tree type, struct array_descr_info *info,
17763 dw_die_ref context_die)
17765 const dw_die_ref scope_die = scope_die_for (type, context_die);
17766 const dw_die_ref array_die = new_die (DW_TAG_array_type, scope_die, type);
17767 const struct loc_descr_context context = { type, info->base_decl };
17770 add_name_attribute (array_die, type_tag (type));
17771 equate_type_number_to_die (type, array_die);
17773 if (info->ndimensions > 1)
17774 switch (info->ordering)
17776 case array_descr_ordering_row_major:
17777 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
17779 case array_descr_ordering_column_major:
17780 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
17786 if (dwarf_version >= 3 || !dwarf_strict)
17788 if (info->data_location)
17789 add_scalar_info (array_die, DW_AT_data_location, info->data_location,
17790 dw_scalar_form_exprloc, &context);
17791 if (info->associated)
17792 add_scalar_info (array_die, DW_AT_associated, info->associated,
17793 dw_scalar_form_constant
17794 | dw_scalar_form_exprloc
17795 | dw_scalar_form_reference, &context);
17796 if (info->allocated)
17797 add_scalar_info (array_die, DW_AT_allocated, info->allocated,
17798 dw_scalar_form_constant
17799 | dw_scalar_form_exprloc
17800 | dw_scalar_form_reference, &context);
17803 add_gnat_descriptive_type_attribute (array_die, type, context_die);
17805 for (dim = 0; dim < info->ndimensions; dim++)
17807 dw_die_ref subrange_die
17808 = new_die (DW_TAG_subrange_type, array_die, NULL);
17810 if (info->dimen[dim].bounds_type)
17811 add_type_attribute (subrange_die,
17812 info->dimen[dim].bounds_type, 0,
17814 if (info->dimen[dim].lower_bound)
17815 add_bound_info (subrange_die, DW_AT_lower_bound,
17816 info->dimen[dim].lower_bound, &context);
17817 if (info->dimen[dim].upper_bound)
17818 add_bound_info (subrange_die, DW_AT_upper_bound,
17819 info->dimen[dim].upper_bound, &context);
17820 if ((dwarf_version >= 3 || !dwarf_strict) && info->dimen[dim].stride)
17821 add_scalar_info (subrange_die, DW_AT_byte_stride,
17822 info->dimen[dim].stride,
17823 dw_scalar_form_constant
17824 | dw_scalar_form_exprloc
17825 | dw_scalar_form_reference,
17829 gen_type_die (info->element_type, context_die);
17830 add_type_attribute (array_die, info->element_type, TYPE_UNQUALIFIED,
17833 if (get_AT (array_die, DW_AT_name))
17834 add_pubtype (type, array_die);
17839 gen_entry_point_die (tree decl, dw_die_ref context_die)
17841 tree origin = decl_ultimate_origin (decl);
17842 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
17844 if (origin != NULL)
17845 add_abstract_origin_attribute (decl_die, origin);
17848 add_name_and_src_coords_attributes (decl_die, decl);
17849 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
17850 TYPE_UNQUALIFIED, context_die);
17853 if (DECL_ABSTRACT_P (decl))
17854 equate_decl_number_to_die (decl, decl_die);
17856 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
17860 /* Walk through the list of incomplete types again, trying once more to
17861 emit full debugging info for them. */
17864 retry_incomplete_types (void)
17868 for (i = vec_safe_length (incomplete_types) - 1; i >= 0; i--)
17869 if (should_emit_struct_debug ((*incomplete_types)[i], DINFO_USAGE_DIR_USE))
17870 gen_type_die ((*incomplete_types)[i], comp_unit_die ());
17873 /* Determine what tag to use for a record type. */
17875 static enum dwarf_tag
17876 record_type_tag (tree type)
17878 if (! lang_hooks.types.classify_record)
17879 return DW_TAG_structure_type;
17881 switch (lang_hooks.types.classify_record (type))
17883 case RECORD_IS_STRUCT:
17884 return DW_TAG_structure_type;
17886 case RECORD_IS_CLASS:
17887 return DW_TAG_class_type;
17889 case RECORD_IS_INTERFACE:
17890 if (dwarf_version >= 3 || !dwarf_strict)
17891 return DW_TAG_interface_type;
17892 return DW_TAG_structure_type;
17895 gcc_unreachable ();
17899 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17900 include all of the information about the enumeration values also. Each
17901 enumerated type name/value is listed as a child of the enumerated type
17905 gen_enumeration_type_die (tree type, dw_die_ref context_die)
17907 dw_die_ref type_die = lookup_type_die (type);
17909 if (type_die == NULL)
17911 type_die = new_die (DW_TAG_enumeration_type,
17912 scope_die_for (type, context_die), type);
17913 equate_type_number_to_die (type, type_die);
17914 add_name_attribute (type_die, type_tag (type));
17915 if (dwarf_version >= 4 || !dwarf_strict)
17917 if (ENUM_IS_SCOPED (type))
17918 add_AT_flag (type_die, DW_AT_enum_class, 1);
17919 if (ENUM_IS_OPAQUE (type))
17920 add_AT_flag (type_die, DW_AT_declaration, 1);
17923 else if (! TYPE_SIZE (type))
17926 remove_AT (type_die, DW_AT_declaration);
17928 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17929 given enum type is incomplete, do not generate the DW_AT_byte_size
17930 attribute or the DW_AT_element_list attribute. */
17931 if (TYPE_SIZE (type))
17935 TREE_ASM_WRITTEN (type) = 1;
17936 add_byte_size_attribute (type_die, type);
17937 if (dwarf_version >= 3 || !dwarf_strict)
17939 tree underlying = lang_hooks.types.enum_underlying_base_type (type);
17940 add_type_attribute (type_die, underlying, TYPE_UNQUALIFIED,
17943 if (TYPE_STUB_DECL (type) != NULL_TREE)
17945 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
17946 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
17949 /* If the first reference to this type was as the return type of an
17950 inline function, then it may not have a parent. Fix this now. */
17951 if (type_die->die_parent == NULL)
17952 add_child_die (scope_die_for (type, context_die), type_die);
17954 for (link = TYPE_VALUES (type);
17955 link != NULL; link = TREE_CHAIN (link))
17957 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
17958 tree value = TREE_VALUE (link);
17960 add_name_attribute (enum_die,
17961 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
17963 if (TREE_CODE (value) == CONST_DECL)
17964 value = DECL_INITIAL (value);
17966 if (simple_type_size_in_bits (TREE_TYPE (value))
17967 <= HOST_BITS_PER_WIDE_INT || tree_fits_shwi_p (value))
17969 /* For constant forms created by add_AT_unsigned DWARF
17970 consumers (GDB, elfutils, etc.) always zero extend
17971 the value. Only when the actual value is negative
17972 do we need to use add_AT_int to generate a constant
17973 form that can represent negative values. */
17974 HOST_WIDE_INT val = TREE_INT_CST_LOW (value);
17975 if (TYPE_UNSIGNED (TREE_TYPE (value)) || val >= 0)
17976 add_AT_unsigned (enum_die, DW_AT_const_value,
17977 (unsigned HOST_WIDE_INT) val);
17979 add_AT_int (enum_die, DW_AT_const_value, val);
17982 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17983 that here. TODO: This should be re-worked to use correct
17984 signed/unsigned double tags for all cases. */
17985 add_AT_wide (enum_die, DW_AT_const_value, value);
17988 add_gnat_descriptive_type_attribute (type_die, type, context_die);
17989 if (TYPE_ARTIFICIAL (type))
17990 add_AT_flag (type_die, DW_AT_artificial, 1);
17993 add_AT_flag (type_die, DW_AT_declaration, 1);
17995 add_pubtype (type, type_die);
18000 /* Generate a DIE to represent either a real live formal parameter decl or to
18001 represent just the type of some formal parameter position in some function
18004 Note that this routine is a bit unusual because its argument may be a
18005 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18006 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18007 node. If it's the former then this function is being called to output a
18008 DIE to represent a formal parameter object (or some inlining thereof). If
18009 it's the latter, then this function is only being called to output a
18010 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18011 argument type of some subprogram type.
18012 If EMIT_NAME_P is true, name and source coordinate attributes
18016 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18017 dw_die_ref context_die)
18019 tree node_or_origin = node ? node : origin;
18020 tree ultimate_origin;
18021 dw_die_ref parm_die = NULL;
18023 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin)) == tcc_declaration)
18025 parm_die = lookup_decl_die (node);
18027 /* If the contexts differ, we may not be talking about the same
18029 if (parm_die && parm_die->die_parent != context_die)
18031 if (!DECL_ABSTRACT_P (node))
18033 /* This can happen when creating an inlined instance, in
18034 which case we need to create a new DIE that will get
18035 annotated with DW_AT_abstract_origin. */
18040 /* FIXME: Reuse DIE even with a differing context.
18042 This can happen when calling
18043 dwarf2out_abstract_function to build debug info for
18044 the abstract instance of a function for which we have
18045 already generated a DIE in
18046 dwarf2out_early_global_decl.
18048 Once we remove dwarf2out_abstract_function, we should
18049 have a call to gcc_unreachable here. */
18053 if (parm_die && parm_die->die_parent == NULL)
18055 /* Check that parm_die already has the right attributes that
18056 we would have added below. If any attributes are
18057 missing, fall through to add them. */
18058 if (! DECL_ABSTRACT_P (node_or_origin)
18059 && !get_AT (parm_die, DW_AT_location)
18060 && !get_AT (parm_die, DW_AT_const_value))
18061 /* We are missing location info, and are about to add it. */
18065 add_child_die (context_die, parm_die);
18071 /* If we have a previously generated DIE, use it, unless this is an
18072 concrete instance (origin != NULL), in which case we need a new
18073 DIE with a corresponding DW_AT_abstract_origin. */
18075 if (parm_die && origin == NULL)
18076 reusing_die = true;
18079 parm_die = new_die (DW_TAG_formal_parameter, context_die, node);
18080 reusing_die = false;
18083 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18085 case tcc_declaration:
18086 ultimate_origin = decl_ultimate_origin (node_or_origin);
18087 if (node || ultimate_origin)
18088 origin = ultimate_origin;
18093 if (origin != NULL)
18094 add_abstract_origin_attribute (parm_die, origin);
18095 else if (emit_name_p)
18096 add_name_and_src_coords_attributes (parm_die, node);
18098 || (! DECL_ABSTRACT_P (node_or_origin)
18099 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18100 decl_function_context
18101 (node_or_origin))))
18103 tree type = TREE_TYPE (node_or_origin);
18104 if (decl_by_reference_p (node_or_origin))
18105 add_type_attribute (parm_die, TREE_TYPE (type),
18106 TYPE_UNQUALIFIED, context_die);
18108 add_type_attribute (parm_die, type,
18109 decl_quals (node_or_origin),
18112 if (origin == NULL && DECL_ARTIFICIAL (node))
18113 add_AT_flag (parm_die, DW_AT_artificial, 1);
18115 if (node && node != origin)
18116 equate_decl_number_to_die (node, parm_die);
18117 if (! DECL_ABSTRACT_P (node_or_origin))
18118 add_location_or_const_value_attribute (parm_die, node_or_origin,
18119 node == NULL, DW_AT_location);
18124 /* We were called with some kind of a ..._TYPE node. */
18125 add_type_attribute (parm_die, node_or_origin, TYPE_UNQUALIFIED,
18130 gcc_unreachable ();
18136 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18137 children DW_TAG_formal_parameter DIEs representing the arguments of the
18140 PARM_PACK must be a function parameter pack.
18141 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18142 must point to the subsequent arguments of the function PACK_ARG belongs to.
18143 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18144 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18145 following the last one for which a DIE was generated. */
18148 gen_formal_parameter_pack_die (tree parm_pack,
18150 dw_die_ref subr_die,
18154 dw_die_ref parm_pack_die;
18156 gcc_assert (parm_pack
18157 && lang_hooks.function_parameter_pack_p (parm_pack)
18160 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18161 add_src_coords_attributes (parm_pack_die, parm_pack);
18163 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18165 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18168 gen_formal_parameter_die (arg, NULL,
18169 false /* Don't emit name attribute. */,
18174 return parm_pack_die;
18177 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18178 at the end of an (ANSI prototyped) formal parameters list. */
18181 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18183 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18186 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18187 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18188 parameters as specified in some function type specification (except for
18189 those which appear as part of a function *definition*). */
18192 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18195 tree formal_type = NULL;
18196 tree first_parm_type;
18199 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18201 arg = DECL_ARGUMENTS (function_or_method_type);
18202 function_or_method_type = TREE_TYPE (function_or_method_type);
18207 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18209 /* Make our first pass over the list of formal parameter types and output a
18210 DW_TAG_formal_parameter DIE for each one. */
18211 for (link = first_parm_type; link; )
18213 dw_die_ref parm_die;
18215 formal_type = TREE_VALUE (link);
18216 if (formal_type == void_type_node)
18219 /* Output a (nameless) DIE to represent the formal parameter itself. */
18220 if (!POINTER_BOUNDS_TYPE_P (formal_type))
18222 parm_die = gen_formal_parameter_die (formal_type, NULL,
18223 true /* Emit name attribute. */,
18225 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18226 && link == first_parm_type)
18228 add_AT_flag (parm_die, DW_AT_artificial, 1);
18229 if (dwarf_version >= 3 || !dwarf_strict)
18230 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18232 else if (arg && DECL_ARTIFICIAL (arg))
18233 add_AT_flag (parm_die, DW_AT_artificial, 1);
18236 link = TREE_CHAIN (link);
18238 arg = DECL_CHAIN (arg);
18241 /* If this function type has an ellipsis, add a
18242 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18243 if (formal_type != void_type_node)
18244 gen_unspecified_parameters_die (function_or_method_type, context_die);
18246 /* Make our second (and final) pass over the list of formal parameter types
18247 and output DIEs to represent those types (as necessary). */
18248 for (link = TYPE_ARG_TYPES (function_or_method_type);
18249 link && TREE_VALUE (link);
18250 link = TREE_CHAIN (link))
18251 gen_type_die (TREE_VALUE (link), context_die);
18254 /* We want to generate the DIE for TYPE so that we can generate the
18255 die for MEMBER, which has been defined; we will need to refer back
18256 to the member declaration nested within TYPE. If we're trying to
18257 generate minimal debug info for TYPE, processing TYPE won't do the
18258 trick; we need to attach the member declaration by hand. */
18261 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18263 gen_type_die (type, context_die);
18265 /* If we're trying to avoid duplicate debug info, we may not have
18266 emitted the member decl for this function. Emit it now. */
18267 if (TYPE_STUB_DECL (type)
18268 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18269 && ! lookup_decl_die (member))
18271 dw_die_ref type_die;
18272 gcc_assert (!decl_ultimate_origin (member));
18274 push_decl_scope (type);
18275 type_die = lookup_type_die_strip_naming_typedef (type);
18276 if (TREE_CODE (member) == FUNCTION_DECL)
18277 gen_subprogram_die (member, type_die);
18278 else if (TREE_CODE (member) == FIELD_DECL)
18280 /* Ignore the nameless fields that are used to skip bits but handle
18281 C++ anonymous unions and structs. */
18282 if (DECL_NAME (member) != NULL_TREE
18283 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18284 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18286 gen_type_die (member_declared_type (member), type_die);
18287 gen_field_die (member, type_die);
18291 gen_variable_die (member, NULL_TREE, type_die);
18297 /* Forward declare these functions, because they are mutually recursive
18298 with their set_block_* pairing functions. */
18299 static void set_decl_origin_self (tree);
18300 static void set_decl_abstract_flags (tree, vec<tree> &);
18302 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
18303 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
18304 that it points to the node itself, thus indicating that the node is its
18305 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
18306 the given node is NULL, recursively descend the decl/block tree which
18307 it is the root of, and for each other ..._DECL or BLOCK node contained
18308 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
18309 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
18310 values to point to themselves. */
18313 set_block_origin_self (tree stmt)
18315 if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
18317 BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
18322 for (local_decl = BLOCK_VARS (stmt);
18323 local_decl != NULL_TREE;
18324 local_decl = DECL_CHAIN (local_decl))
18325 /* Do not recurse on nested functions since the inlining status
18326 of parent and child can be different as per the DWARF spec. */
18327 if (TREE_CODE (local_decl) != FUNCTION_DECL
18328 && !DECL_EXTERNAL (local_decl))
18329 set_decl_origin_self (local_decl);
18335 for (subblock = BLOCK_SUBBLOCKS (stmt);
18336 subblock != NULL_TREE;
18337 subblock = BLOCK_CHAIN (subblock))
18338 set_block_origin_self (subblock); /* Recurse. */
18343 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
18344 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
18345 node to so that it points to the node itself, thus indicating that the
18346 node represents its own (abstract) origin. Additionally, if the
18347 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
18348 the decl/block tree of which the given node is the root of, and for
18349 each other ..._DECL or BLOCK node contained therein whose
18350 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
18351 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
18352 point to themselves. */
18355 set_decl_origin_self (tree decl)
18357 if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
18359 DECL_ABSTRACT_ORIGIN (decl) = decl;
18360 if (TREE_CODE (decl) == FUNCTION_DECL)
18364 for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
18365 DECL_ABSTRACT_ORIGIN (arg) = arg;
18366 if (DECL_INITIAL (decl) != NULL_TREE
18367 && DECL_INITIAL (decl) != error_mark_node)
18368 set_block_origin_self (DECL_INITIAL (decl));
18373 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
18374 and if it wasn't 1 before, push it to abstract_vec vector.
18375 For all local decls and all local sub-blocks (recursively) do it
18379 set_block_abstract_flags (tree stmt, vec<tree> &abstract_vec)
18385 if (!BLOCK_ABSTRACT (stmt))
18387 abstract_vec.safe_push (stmt);
18388 BLOCK_ABSTRACT (stmt) = 1;
18391 for (local_decl = BLOCK_VARS (stmt);
18392 local_decl != NULL_TREE;
18393 local_decl = DECL_CHAIN (local_decl))
18394 if (! DECL_EXTERNAL (local_decl))
18395 set_decl_abstract_flags (local_decl, abstract_vec);
18397 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
18399 local_decl = BLOCK_NONLOCALIZED_VAR (stmt, i);
18400 if ((TREE_CODE (local_decl) == VAR_DECL && !TREE_STATIC (local_decl))
18401 || TREE_CODE (local_decl) == PARM_DECL)
18402 set_decl_abstract_flags (local_decl, abstract_vec);
18405 for (subblock = BLOCK_SUBBLOCKS (stmt);
18406 subblock != NULL_TREE;
18407 subblock = BLOCK_CHAIN (subblock))
18408 set_block_abstract_flags (subblock, abstract_vec);
18411 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
18412 to 1 and if it wasn't 1 before, push to abstract_vec vector.
18413 In the case where the decl is a FUNCTION_DECL also set the abstract
18414 flags for all of the parameters, local vars, local
18415 blocks and sub-blocks (recursively). */
18418 set_decl_abstract_flags (tree decl, vec<tree> &abstract_vec)
18420 if (!DECL_ABSTRACT_P (decl))
18422 abstract_vec.safe_push (decl);
18423 DECL_ABSTRACT_P (decl) = 1;
18426 if (TREE_CODE (decl) == FUNCTION_DECL)
18430 for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
18431 if (!DECL_ABSTRACT_P (arg))
18433 abstract_vec.safe_push (arg);
18434 DECL_ABSTRACT_P (arg) = 1;
18436 if (DECL_INITIAL (decl) != NULL_TREE
18437 && DECL_INITIAL (decl) != error_mark_node)
18438 set_block_abstract_flags (DECL_INITIAL (decl), abstract_vec);
18442 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18443 may later generate inlined and/or out-of-line instances of.
18445 FIXME: In the early-dwarf world, this function, and most of the
18446 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
18447 the abstract instance. All we would need to do is annotate
18448 the early DIE with the appropriate DW_AT_inline in late
18449 dwarf (perhaps in gen_inlined_subroutine_die).
18451 However, we can't do this yet, because LTO streaming of DIEs
18452 has not been implemented yet. */
18455 dwarf2out_abstract_function (tree decl)
18457 dw_die_ref old_die;
18460 hash_table<decl_loc_hasher> *old_decl_loc_table;
18461 hash_table<dw_loc_list_hasher> *old_cached_dw_loc_list_table;
18462 int old_call_site_count, old_tail_call_site_count;
18463 struct call_arg_loc_node *old_call_arg_locations;
18465 /* Make sure we have the actual abstract inline, not a clone. */
18466 decl = DECL_ORIGIN (decl);
18468 old_die = lookup_decl_die (decl);
18469 if (old_die && get_AT (old_die, DW_AT_inline))
18470 /* We've already generated the abstract instance. */
18473 /* We can be called while recursively when seeing block defining inlined subroutine
18474 DIE. Be sure to not clobber the outer location table nor use it or we would
18475 get locations in abstract instantces. */
18476 old_decl_loc_table = decl_loc_table;
18477 decl_loc_table = NULL;
18478 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
18479 cached_dw_loc_list_table = NULL;
18480 old_call_arg_locations = call_arg_locations;
18481 call_arg_locations = NULL;
18482 old_call_site_count = call_site_count;
18483 call_site_count = -1;
18484 old_tail_call_site_count = tail_call_site_count;
18485 tail_call_site_count = -1;
18487 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18488 we don't get confused by DECL_ABSTRACT_P. */
18489 if (debug_info_level > DINFO_LEVEL_TERSE)
18491 context = decl_class_context (decl);
18493 gen_type_die_for_member
18494 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
18497 /* Pretend we've just finished compiling this function. */
18498 save_fn = current_function_decl;
18499 current_function_decl = decl;
18501 auto_vec<tree, 64> abstract_vec;
18502 set_decl_abstract_flags (decl, abstract_vec);
18503 dwarf2out_decl (decl);
18506 FOR_EACH_VEC_ELT (abstract_vec, i, t)
18507 if (TREE_CODE (t) == BLOCK)
18508 BLOCK_ABSTRACT (t) = 0;
18510 DECL_ABSTRACT_P (t) = 0;
18512 current_function_decl = save_fn;
18513 decl_loc_table = old_decl_loc_table;
18514 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
18515 call_arg_locations = old_call_arg_locations;
18516 call_site_count = old_call_site_count;
18517 tail_call_site_count = old_tail_call_site_count;
18520 /* Helper function of premark_used_types() which gets called through
18523 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18524 marked as unused by prune_unused_types. */
18527 premark_used_types_helper (tree const &type, void *)
18531 die = lookup_type_die (type);
18533 die->die_perennial_p = 1;
18537 /* Helper function of premark_types_used_by_global_vars which gets called
18538 through htab_traverse.
18540 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18541 marked as unused by prune_unused_types. The DIE of the type is marked
18542 only if the global variable using the type will actually be emitted. */
18545 premark_types_used_by_global_vars_helper (types_used_by_vars_entry **slot,
18548 struct types_used_by_vars_entry *entry;
18551 entry = (struct types_used_by_vars_entry *) *slot;
18552 gcc_assert (entry->type != NULL
18553 && entry->var_decl != NULL);
18554 die = lookup_type_die (entry->type);
18557 /* Ask cgraph if the global variable really is to be emitted.
18558 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18559 varpool_node *node = varpool_node::get (entry->var_decl);
18560 if (node && node->definition)
18562 die->die_perennial_p = 1;
18563 /* Keep the parent DIEs as well. */
18564 while ((die = die->die_parent) && die->die_perennial_p == 0)
18565 die->die_perennial_p = 1;
18571 /* Mark all members of used_types_hash as perennial. */
18574 premark_used_types (struct function *fun)
18576 if (fun && fun->used_types_hash)
18577 fun->used_types_hash->traverse<void *, premark_used_types_helper> (NULL);
18580 /* Mark all members of types_used_by_vars_entry as perennial. */
18583 premark_types_used_by_global_vars (void)
18585 if (types_used_by_vars_hash)
18586 types_used_by_vars_hash
18587 ->traverse<void *, premark_types_used_by_global_vars_helper> (NULL);
18590 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18591 for CA_LOC call arg loc node. */
18594 gen_call_site_die (tree decl, dw_die_ref subr_die,
18595 struct call_arg_loc_node *ca_loc)
18597 dw_die_ref stmt_die = NULL, die;
18598 tree block = ca_loc->block;
18601 && block != DECL_INITIAL (decl)
18602 && TREE_CODE (block) == BLOCK)
18604 stmt_die = BLOCK_DIE (block);
18607 block = BLOCK_SUPERCONTEXT (block);
18609 if (stmt_die == NULL)
18610 stmt_die = subr_die;
18611 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
18612 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
18613 if (ca_loc->tail_call_p)
18614 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
18615 if (ca_loc->symbol_ref)
18617 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
18619 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
18621 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref, false);
18626 /* Generate a DIE to represent a declared function (either file-scope or
18630 gen_subprogram_die (tree decl, dw_die_ref context_die)
18632 tree origin = decl_ultimate_origin (decl);
18633 dw_die_ref subr_die;
18634 dw_die_ref old_die = lookup_decl_die (decl);
18636 /* This function gets called multiple times for different stages of
18637 the debug process. For example, for func() in this code:
18641 void func() { ... }
18644 ...we get called 4 times. Twice in early debug and twice in
18650 1. Once while generating func() within the namespace. This is
18651 the declaration. The declaration bit below is set, as the
18652 context is the namespace.
18654 A new DIE will be generated with DW_AT_declaration set.
18656 2. Once for func() itself. This is the specification. The
18657 declaration bit below is clear as the context is the CU.
18659 We will use the cached DIE from (1) to create a new DIE with
18660 DW_AT_specification pointing to the declaration in (1).
18662 Late debug via rest_of_handle_final()
18663 -------------------------------------
18665 3. Once generating func() within the namespace. This is also the
18666 declaration, as in (1), but this time we will early exit below
18667 as we have a cached DIE and a declaration needs no additional
18668 annotations (no locations), as the source declaration line
18671 4. Once for func() itself. As in (2), this is the specification,
18672 but this time we will re-use the cached DIE, and just annotate
18673 it with the location information that should now be available.
18675 For something without namespaces, but with abstract instances, we
18676 are also called a multiple times:
18681 Base (); // constructor declaration (1)
18684 Base::Base () { } // constructor specification (2)
18689 1. Once for the Base() constructor by virtue of it being a
18690 member of the Base class. This is done via
18691 rest_of_type_compilation.
18693 This is a declaration, so a new DIE will be created with
18696 2. Once for the Base() constructor definition, but this time
18697 while generating the abstract instance of the base
18698 constructor (__base_ctor) which is being generated via early
18699 debug of reachable functions.
18701 Even though we have a cached version of the declaration (1),
18702 we will create a DW_AT_specification of the declaration DIE
18705 3. Once for the __base_ctor itself, but this time, we generate
18706 an DW_AT_abstract_origin version of the DW_AT_specification in
18709 Late debug via rest_of_handle_final
18710 -----------------------------------
18712 4. One final time for the __base_ctor (which will have a cached
18713 DIE with DW_AT_abstract_origin created in (3). This time,
18714 we will just annotate the location information now
18717 int declaration = (current_function_decl != decl
18718 || class_or_namespace_scope_p (context_die));
18720 premark_used_types (DECL_STRUCT_FUNCTION (decl));
18722 /* Now that the C++ front end lazily declares artificial member fns, we
18723 might need to retrofit the declaration into its class. */
18724 if (!declaration && !origin && !old_die
18725 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
18726 && !class_or_namespace_scope_p (context_die)
18727 && debug_info_level > DINFO_LEVEL_TERSE)
18728 old_die = force_decl_die (decl);
18730 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
18731 if (origin != NULL)
18733 gcc_assert (!declaration || local_scope_p (context_die));
18735 /* Fixup die_parent for the abstract instance of a nested
18736 inline function. */
18737 if (old_die && old_die->die_parent == NULL)
18738 add_child_die (context_die, old_die);
18740 if (old_die && get_AT_ref (old_die, DW_AT_abstract_origin))
18742 /* If we have a DW_AT_abstract_origin we have a working
18744 subr_die = old_die;
18748 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18749 add_abstract_origin_attribute (subr_die, origin);
18750 /* This is where the actual code for a cloned function is.
18751 Let's emit linkage name attribute for it. This helps
18752 debuggers to e.g, set breakpoints into
18753 constructors/destructors when the user asks "break
18755 add_linkage_name (subr_die, decl);
18758 /* A cached copy, possibly from early dwarf generation. Reuse as
18759 much as possible. */
18762 /* A declaration that has been previously dumped needs no
18763 additional information. */
18767 if (!get_AT_flag (old_die, DW_AT_declaration)
18768 /* We can have a normal definition following an inline one in the
18769 case of redefinition of GNU C extern inlines.
18770 It seems reasonable to use AT_specification in this case. */
18771 && !get_AT (old_die, DW_AT_inline))
18773 /* Detect and ignore this case, where we are trying to output
18774 something we have already output. */
18775 if (get_AT (old_die, DW_AT_low_pc)
18776 || get_AT (old_die, DW_AT_ranges))
18779 /* If we have no location information, this must be a
18780 partially generated DIE from early dwarf generation.
18781 Fall through and generate it. */
18784 /* If the definition comes from the same place as the declaration,
18785 maybe use the old DIE. We always want the DIE for this function
18786 that has the *_pc attributes to be under comp_unit_die so the
18787 debugger can find it. We also need to do this for abstract
18788 instances of inlines, since the spec requires the out-of-line copy
18789 to have the same parent. For local class methods, this doesn't
18790 apply; we just use the old DIE. */
18791 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
18792 struct dwarf_file_data * file_index = lookup_filename (s.file);
18793 if ((is_cu_die (old_die->die_parent)
18794 /* This condition fixes the inconsistency/ICE with the
18795 following Fortran test (or some derivative thereof) while
18796 building libgfortran:
18800 logical function funky (FLAG)
18805 || (old_die->die_parent
18806 && old_die->die_parent->die_tag == DW_TAG_module)
18807 || context_die == NULL)
18808 && (DECL_ARTIFICIAL (decl)
18809 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
18810 && (get_AT_unsigned (old_die, DW_AT_decl_line)
18811 == (unsigned) s.line))))
18813 subr_die = old_die;
18815 /* Clear out the declaration attribute, but leave the
18816 parameters so they can be augmented with location
18817 information later. Unless this was a declaration, in
18818 which case, wipe out the nameless parameters and recreate
18819 them further down. */
18820 if (remove_AT (subr_die, DW_AT_declaration))
18823 remove_AT (subr_die, DW_AT_object_pointer);
18824 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
18827 /* Make a specification pointing to the previously built
18831 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18832 add_AT_specification (subr_die, old_die);
18833 add_pubname (decl, subr_die);
18834 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
18835 add_AT_file (subr_die, DW_AT_decl_file, file_index);
18836 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
18837 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
18839 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18840 emit the real type on the definition die. */
18841 if (is_cxx() && debug_info_level > DINFO_LEVEL_TERSE)
18843 dw_die_ref die = get_AT_ref (old_die, DW_AT_type);
18844 if (die == auto_die || die == decltype_auto_die)
18845 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
18846 TYPE_UNQUALIFIED, context_die);
18850 /* Create a fresh DIE for anything else. */
18853 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18855 if (TREE_PUBLIC (decl))
18856 add_AT_flag (subr_die, DW_AT_external, 1);
18858 add_name_and_src_coords_attributes (subr_die, decl);
18859 add_pubname (decl, subr_die);
18860 if (debug_info_level > DINFO_LEVEL_TERSE)
18862 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
18863 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
18864 TYPE_UNQUALIFIED, context_die);
18867 add_pure_or_virtual_attribute (subr_die, decl);
18868 if (DECL_ARTIFICIAL (decl))
18869 add_AT_flag (subr_die, DW_AT_artificial, 1);
18871 if (TREE_THIS_VOLATILE (decl) && (dwarf_version >= 5 || !dwarf_strict))
18872 add_AT_flag (subr_die, DW_AT_noreturn, 1);
18874 add_accessibility_attribute (subr_die, decl);
18877 /* Unless we have an existing non-declaration DIE, equate the new
18879 if (!old_die || is_declaration_die (old_die))
18880 equate_decl_number_to_die (decl, subr_die);
18884 if (!old_die || !get_AT (old_die, DW_AT_inline))
18886 add_AT_flag (subr_die, DW_AT_declaration, 1);
18888 /* If this is an explicit function declaration then generate
18889 a DW_AT_explicit attribute. */
18890 if (lang_hooks.decls.function_decl_explicit_p (decl)
18891 && (dwarf_version >= 3 || !dwarf_strict))
18892 add_AT_flag (subr_die, DW_AT_explicit, 1);
18894 /* If this is a C++11 deleted special function member then generate
18895 a DW_AT_GNU_deleted attribute. */
18896 if (lang_hooks.decls.function_decl_deleted_p (decl)
18897 && (! dwarf_strict))
18898 add_AT_flag (subr_die, DW_AT_GNU_deleted, 1);
18901 /* Tag abstract instances with DW_AT_inline. */
18902 else if (DECL_ABSTRACT_P (decl))
18904 if (DECL_DECLARED_INLINE_P (decl))
18906 if (cgraph_function_possibly_inlined_p (decl))
18907 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
18909 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
18913 if (cgraph_function_possibly_inlined_p (decl))
18914 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
18916 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
18919 if (DECL_DECLARED_INLINE_P (decl)
18920 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
18921 add_AT_flag (subr_die, DW_AT_artificial, 1);
18923 /* For non DECL_EXTERNALs, if range information is available, fill
18924 the DIE with it. */
18925 else if (!DECL_EXTERNAL (decl) && !early_dwarf)
18927 HOST_WIDE_INT cfa_fb_offset;
18929 struct function *fun = DECL_STRUCT_FUNCTION (decl);
18931 if (!flag_reorder_blocks_and_partition)
18933 dw_fde_ref fde = fun->fde;
18934 if (fde->dw_fde_begin)
18936 /* We have already generated the labels. */
18937 add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
18938 fde->dw_fde_end, false);
18942 /* Create start/end labels and add the range. */
18943 char label_id_low[MAX_ARTIFICIAL_LABEL_BYTES];
18944 char label_id_high[MAX_ARTIFICIAL_LABEL_BYTES];
18945 ASM_GENERATE_INTERNAL_LABEL (label_id_low, FUNC_BEGIN_LABEL,
18946 current_function_funcdef_no);
18947 ASM_GENERATE_INTERNAL_LABEL (label_id_high, FUNC_END_LABEL,
18948 current_function_funcdef_no);
18949 add_AT_low_high_pc (subr_die, label_id_low, label_id_high,
18953 #if VMS_DEBUGGING_INFO
18954 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18955 Section 2.3 Prologue and Epilogue Attributes:
18956 When a breakpoint is set on entry to a function, it is generally
18957 desirable for execution to be suspended, not on the very first
18958 instruction of the function, but rather at a point after the
18959 function's frame has been set up, after any language defined local
18960 declaration processing has been completed, and before execution of
18961 the first statement of the function begins. Debuggers generally
18962 cannot properly determine where this point is. Similarly for a
18963 breakpoint set on exit from a function. The prologue and epilogue
18964 attributes allow a compiler to communicate the location(s) to use. */
18967 if (fde->dw_fde_vms_end_prologue)
18968 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
18969 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
18971 if (fde->dw_fde_vms_begin_epilogue)
18972 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
18973 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
18980 /* Generate pubnames entries for the split function code ranges. */
18981 dw_fde_ref fde = fun->fde;
18983 if (fde->dw_fde_second_begin)
18985 if (dwarf_version >= 3 || !dwarf_strict)
18987 /* We should use ranges for non-contiguous code section
18988 addresses. Use the actual code range for the initial
18989 section, since the HOT/COLD labels might precede an
18990 alignment offset. */
18991 bool range_list_added = false;
18992 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
18993 fde->dw_fde_end, &range_list_added,
18995 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
18996 fde->dw_fde_second_end,
18997 &range_list_added, false);
18998 if (range_list_added)
19003 /* There is no real support in DW2 for this .. so we make
19004 a work-around. First, emit the pub name for the segment
19005 containing the function label. Then make and emit a
19006 simplified subprogram DIE for the second segment with the
19007 name pre-fixed by __hot/cold_sect_of_. We use the same
19008 linkage name for the second die so that gdb will find both
19009 sections when given "b foo". */
19010 const char *name = NULL;
19011 tree decl_name = DECL_NAME (decl);
19012 dw_die_ref seg_die;
19014 /* Do the 'primary' section. */
19015 add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
19016 fde->dw_fde_end, false);
19018 /* Build a minimal DIE for the secondary section. */
19019 seg_die = new_die (DW_TAG_subprogram,
19020 subr_die->die_parent, decl);
19022 if (TREE_PUBLIC (decl))
19023 add_AT_flag (seg_die, DW_AT_external, 1);
19025 if (decl_name != NULL
19026 && IDENTIFIER_POINTER (decl_name) != NULL)
19028 name = dwarf2_name (decl, 1);
19029 if (! DECL_ARTIFICIAL (decl))
19030 add_src_coords_attributes (seg_die, decl);
19032 add_linkage_name (seg_die, decl);
19034 gcc_assert (name != NULL);
19035 add_pure_or_virtual_attribute (seg_die, decl);
19036 if (DECL_ARTIFICIAL (decl))
19037 add_AT_flag (seg_die, DW_AT_artificial, 1);
19039 name = concat ("__second_sect_of_", name, NULL);
19040 add_AT_low_high_pc (seg_die, fde->dw_fde_second_begin,
19041 fde->dw_fde_second_end, false);
19042 add_name_attribute (seg_die, name);
19043 if (want_pubnames ())
19044 add_pubname_string (name, seg_die);
19048 add_AT_low_high_pc (subr_die, fde->dw_fde_begin, fde->dw_fde_end,
19052 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19054 /* We define the "frame base" as the function's CFA. This is more
19055 convenient for several reasons: (1) It's stable across the prologue
19056 and epilogue, which makes it better than just a frame pointer,
19057 (2) With dwarf3, there exists a one-byte encoding that allows us
19058 to reference the .debug_frame data by proxy, but failing that,
19059 (3) We can at least reuse the code inspection and interpretation
19060 code that determines the CFA position at various points in the
19062 if (dwarf_version >= 3 && targetm.debug_unwind_info () == UI_DWARF2)
19064 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19065 add_AT_loc (subr_die, DW_AT_frame_base, op);
19069 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19070 if (list->dw_loc_next)
19071 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19073 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19076 /* Compute a displacement from the "steady-state frame pointer" to
19077 the CFA. The former is what all stack slots and argument slots
19078 will reference in the rtl; the latter is what we've told the
19079 debugger about. We'll need to adjust all frame_base references
19080 by this displacement. */
19081 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19083 if (fun->static_chain_decl)
19084 add_AT_location_description
19085 (subr_die, DW_AT_static_link,
19086 loc_list_from_tree (fun->static_chain_decl, 2, NULL));
19089 /* Generate child dies for template paramaters. */
19090 if (early_dwarf && debug_info_level > DINFO_LEVEL_TERSE)
19091 gen_generic_params_dies (decl);
19093 /* Now output descriptions of the arguments for this function. This gets
19094 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19095 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19096 `...' at the end of the formal parameter list. In order to find out if
19097 there was a trailing ellipsis or not, we must instead look at the type
19098 associated with the FUNCTION_DECL. This will be a node of type
19099 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19100 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19101 an ellipsis at the end. */
19103 /* In the case where we are describing a mere function declaration, all we
19104 need to do here (and all we *can* do here) is to describe the *types* of
19105 its formal parameters. */
19106 if (debug_info_level <= DINFO_LEVEL_TERSE)
19108 else if (declaration)
19109 gen_formal_types_die (decl, subr_die);
19112 /* Generate DIEs to represent all known formal parameters. */
19113 tree parm = DECL_ARGUMENTS (decl);
19114 tree generic_decl = early_dwarf
19115 ? lang_hooks.decls.get_generic_function_decl (decl) : NULL;
19116 tree generic_decl_parm = generic_decl
19117 ? DECL_ARGUMENTS (generic_decl)
19120 /* Now we want to walk the list of parameters of the function and
19121 emit their relevant DIEs.
19123 We consider the case of DECL being an instance of a generic function
19124 as well as it being a normal function.
19126 If DECL is an instance of a generic function we walk the
19127 parameters of the generic function declaration _and_ the parameters of
19128 DECL itself. This is useful because we want to emit specific DIEs for
19129 function parameter packs and those are declared as part of the
19130 generic function declaration. In that particular case,
19131 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19132 That DIE has children DIEs representing the set of arguments
19133 of the pack. Note that the set of pack arguments can be empty.
19134 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19137 Otherwise, we just consider the parameters of DECL. */
19138 while (generic_decl_parm || parm)
19140 if (generic_decl_parm
19141 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19142 gen_formal_parameter_pack_die (generic_decl_parm,
19145 else if (parm && !POINTER_BOUNDS_P (parm))
19147 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19149 if (parm == DECL_ARGUMENTS (decl)
19150 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19152 && (dwarf_version >= 3 || !dwarf_strict))
19153 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19155 parm = DECL_CHAIN (parm);
19158 parm = DECL_CHAIN (parm);
19160 if (generic_decl_parm)
19161 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19164 /* Decide whether we need an unspecified_parameters DIE at the end.
19165 There are 2 more cases to do this for: 1) the ansi ... declaration -
19166 this is detectable when the end of the arg list is not a
19167 void_type_node 2) an unprototyped function declaration (not a
19168 definition). This just means that we have no info about the
19169 parameters at all. */
19170 if (prototype_p (TREE_TYPE (decl)))
19172 /* This is the prototyped case, check for.... */
19173 if (stdarg_p (TREE_TYPE (decl)))
19174 gen_unspecified_parameters_die (decl, subr_die);
19176 else if (DECL_INITIAL (decl) == NULL_TREE)
19177 gen_unspecified_parameters_die (decl, subr_die);
19180 if (subr_die != old_die)
19181 /* Add the calling convention attribute if requested. */
19182 add_calling_convention_attribute (subr_die, decl);
19184 /* Output Dwarf info for all of the stuff within the body of the function
19185 (if it has one - it may be just a declaration).
19187 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19188 a function. This BLOCK actually represents the outermost binding contour
19189 for the function, i.e. the contour in which the function's formal
19190 parameters and labels get declared. Curiously, it appears that the front
19191 end doesn't actually put the PARM_DECL nodes for the current function onto
19192 the BLOCK_VARS list for this outer scope, but are strung off of the
19193 DECL_ARGUMENTS list for the function instead.
19195 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19196 the LABEL_DECL nodes for the function however, and we output DWARF info
19197 for those in decls_for_scope. Just within the `outer_scope' there will be
19198 a BLOCK node representing the function's outermost pair of curly braces,
19199 and any blocks used for the base and member initializers of a C++
19200 constructor function. */
19201 tree outer_scope = DECL_INITIAL (decl);
19202 if (! declaration && outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
19204 int call_site_note_count = 0;
19205 int tail_call_site_note_count = 0;
19207 /* Emit a DW_TAG_variable DIE for a named return value. */
19208 if (DECL_NAME (DECL_RESULT (decl)))
19209 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19211 /* The first time through decls_for_scope we will generate the
19212 DIEs for the locals. The second time, we fill in the
19214 decls_for_scope (outer_scope, subr_die);
19216 if (call_arg_locations && !dwarf_strict)
19218 struct call_arg_loc_node *ca_loc;
19219 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
19221 dw_die_ref die = NULL;
19222 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
19225 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
19226 arg; arg = next_arg)
19228 dw_loc_descr_ref reg, val;
19229 machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
19230 dw_die_ref cdie, tdie = NULL;
19232 next_arg = XEXP (arg, 1);
19233 if (REG_P (XEXP (XEXP (arg, 0), 0))
19235 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
19236 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
19237 && REGNO (XEXP (XEXP (arg, 0), 0))
19238 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
19239 next_arg = XEXP (next_arg, 1);
19240 if (mode == VOIDmode)
19242 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
19243 if (mode == VOIDmode)
19244 mode = GET_MODE (XEXP (arg, 0));
19246 if (mode == VOIDmode || mode == BLKmode)
19248 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
19250 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19251 tloc = XEXP (XEXP (arg, 0), 1);
19254 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
19255 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
19257 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19258 tlocc = XEXP (XEXP (arg, 0), 1);
19262 if (REG_P (XEXP (XEXP (arg, 0), 0)))
19263 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
19264 VAR_INIT_STATUS_INITIALIZED);
19265 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
19267 rtx mem = XEXP (XEXP (arg, 0), 0);
19268 reg = mem_loc_descriptor (XEXP (mem, 0),
19269 get_address_mode (mem),
19271 VAR_INIT_STATUS_INITIALIZED);
19273 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
19274 == DEBUG_PARAMETER_REF)
19277 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
19278 tdie = lookup_decl_die (tdecl);
19285 && GET_CODE (XEXP (XEXP (arg, 0), 0))
19286 != DEBUG_PARAMETER_REF)
19288 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
19290 VAR_INIT_STATUS_INITIALIZED);
19294 die = gen_call_site_die (decl, subr_die, ca_loc);
19295 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
19298 add_AT_loc (cdie, DW_AT_location, reg);
19299 else if (tdie != NULL)
19300 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
19301 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
19302 if (next_arg != XEXP (arg, 1))
19304 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
19305 if (mode == VOIDmode)
19306 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
19307 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
19310 VAR_INIT_STATUS_INITIALIZED);
19312 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
19316 && (ca_loc->symbol_ref || tloc))
19317 die = gen_call_site_die (decl, subr_die, ca_loc);
19318 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
19320 dw_loc_descr_ref tval = NULL;
19322 if (tloc != NULL_RTX)
19323 tval = mem_loc_descriptor (tloc,
19324 GET_MODE (tloc) == VOIDmode
19325 ? Pmode : GET_MODE (tloc),
19327 VAR_INIT_STATUS_INITIALIZED);
19329 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
19330 else if (tlocc != NULL_RTX)
19332 tval = mem_loc_descriptor (tlocc,
19333 GET_MODE (tlocc) == VOIDmode
19334 ? Pmode : GET_MODE (tlocc),
19336 VAR_INIT_STATUS_INITIALIZED);
19338 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
19344 call_site_note_count++;
19345 if (ca_loc->tail_call_p)
19346 tail_call_site_note_count++;
19350 call_arg_locations = NULL;
19351 call_arg_loc_last = NULL;
19352 if (tail_call_site_count >= 0
19353 && tail_call_site_count == tail_call_site_note_count
19356 if (call_site_count >= 0
19357 && call_site_count == call_site_note_count)
19358 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
19360 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
19362 call_site_count = -1;
19363 tail_call_site_count = -1;
19367 /* Returns a hash value for X (which really is a die_struct). */
19370 block_die_hasher::hash (die_struct *d)
19372 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19375 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19376 as decl_id and die_parent of die_struct Y. */
19379 block_die_hasher::equal (die_struct *x, die_struct *y)
19381 return x->decl_id == y->decl_id && x->die_parent == y->die_parent;
19384 /* Return TRUE if DECL, which may have been previously generated as
19385 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
19386 true if decl (or its origin) is either an extern declaration or a
19387 class/namespace scoped declaration.
19389 The declare_in_namespace support causes us to get two DIEs for one
19390 variable, both of which are declarations. We want to avoid
19391 considering one to be a specification, so we must test for
19392 DECLARATION and DW_AT_declaration. */
19394 decl_will_get_specification_p (dw_die_ref old_die, tree decl, bool declaration)
19396 return (old_die && TREE_STATIC (decl) && !declaration
19397 && get_AT_flag (old_die, DW_AT_declaration) == 1);
19400 /* Return true if DECL is a local static. */
19403 local_function_static (tree decl)
19405 gcc_assert (TREE_CODE (decl) == VAR_DECL);
19406 return TREE_STATIC (decl)
19407 && DECL_CONTEXT (decl)
19408 && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL;
19411 /* Generate a DIE to represent a declared data object.
19412 Either DECL or ORIGIN must be non-null. */
19415 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19417 HOST_WIDE_INT off = 0;
19419 tree decl_or_origin = decl ? decl : origin;
19420 tree ultimate_origin;
19421 dw_die_ref var_die;
19422 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19423 dw_die_ref origin_die = NULL;
19424 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19425 || class_or_namespace_scope_p (context_die));
19426 bool specialization_p = false;
19428 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19429 if (decl || ultimate_origin)
19430 origin = ultimate_origin;
19431 com_decl = fortran_common (decl_or_origin, &off);
19433 /* Symbol in common gets emitted as a child of the common block, in the form
19434 of a data member. */
19437 dw_die_ref com_die;
19438 dw_loc_list_ref loc;
19439 die_node com_die_arg;
19441 var_die = lookup_decl_die (decl_or_origin);
19444 if (get_AT (var_die, DW_AT_location) == NULL)
19446 loc = loc_list_from_tree (com_decl, off ? 1 : 2, NULL);
19451 /* Optimize the common case. */
19452 if (single_element_loc_list_p (loc)
19453 && loc->expr->dw_loc_opc == DW_OP_addr
19454 && loc->expr->dw_loc_next == NULL
19455 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19458 rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
19459 loc->expr->dw_loc_oprnd1.v.val_addr
19460 = plus_constant (GET_MODE (x), x , off);
19463 loc_list_plus_const (loc, off);
19465 add_AT_location_description (var_die, DW_AT_location, loc);
19466 remove_AT (var_die, DW_AT_declaration);
19472 if (common_block_die_table == NULL)
19473 common_block_die_table = hash_table<block_die_hasher>::create_ggc (10);
19475 com_die_arg.decl_id = DECL_UID (com_decl);
19476 com_die_arg.die_parent = context_die;
19477 com_die = common_block_die_table->find (&com_die_arg);
19478 loc = loc_list_from_tree (com_decl, 2, NULL);
19479 if (com_die == NULL)
19482 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19485 com_die = new_die (DW_TAG_common_block, context_die, decl);
19486 add_name_and_src_coords_attributes (com_die, com_decl);
19489 add_AT_location_description (com_die, DW_AT_location, loc);
19490 /* Avoid sharing the same loc descriptor between
19491 DW_TAG_common_block and DW_TAG_variable. */
19492 loc = loc_list_from_tree (com_decl, 2, NULL);
19494 else if (DECL_EXTERNAL (decl))
19495 add_AT_flag (com_die, DW_AT_declaration, 1);
19496 if (want_pubnames ())
19497 add_pubname_string (cnam, com_die); /* ??? needed? */
19498 com_die->decl_id = DECL_UID (com_decl);
19499 slot = common_block_die_table->find_slot (com_die, INSERT);
19502 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19504 add_AT_location_description (com_die, DW_AT_location, loc);
19505 loc = loc_list_from_tree (com_decl, 2, NULL);
19506 remove_AT (com_die, DW_AT_declaration);
19508 var_die = new_die (DW_TAG_variable, com_die, decl);
19509 add_name_and_src_coords_attributes (var_die, decl);
19510 add_type_attribute (var_die, TREE_TYPE (decl), decl_quals (decl),
19512 add_AT_flag (var_die, DW_AT_external, 1);
19517 /* Optimize the common case. */
19518 if (single_element_loc_list_p (loc)
19519 && loc->expr->dw_loc_opc == DW_OP_addr
19520 && loc->expr->dw_loc_next == NULL
19521 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19523 rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
19524 loc->expr->dw_loc_oprnd1.v.val_addr
19525 = plus_constant (GET_MODE (x), x, off);
19528 loc_list_plus_const (loc, off);
19530 add_AT_location_description (var_die, DW_AT_location, loc);
19532 else if (DECL_EXTERNAL (decl))
19533 add_AT_flag (var_die, DW_AT_declaration, 1);
19534 equate_decl_number_to_die (decl, var_die);
19542 /* A declaration that has been previously dumped, needs no
19543 further annotations, since it doesn't need location on
19544 the second pass. */
19547 else if (decl_will_get_specification_p (old_die, decl, declaration)
19548 && !get_AT (old_die, DW_AT_specification))
19550 /* Fall-thru so we can make a new variable die along with a
19551 DW_AT_specification. */
19553 else if (origin && old_die->die_parent != context_die)
19555 /* If we will be creating an inlined instance, we need a
19556 new DIE that will get annotated with
19557 DW_AT_abstract_origin. Clear things so we can get a
19559 gcc_assert (!DECL_ABSTRACT_P (decl));
19564 /* If a DIE was dumped early, it still needs location info.
19565 Skip to where we fill the location bits. */
19567 goto gen_variable_die_location;
19571 /* For static data members, the declaration in the class is supposed
19572 to have DW_TAG_member tag; the specification should still be
19573 DW_TAG_variable referencing the DW_TAG_member DIE. */
19574 if (declaration && class_scope_p (context_die))
19575 var_die = new_die (DW_TAG_member, context_die, decl);
19577 var_die = new_die (DW_TAG_variable, context_die, decl);
19579 if (origin != NULL)
19580 origin_die = add_abstract_origin_attribute (var_die, origin);
19582 /* Loop unrolling can create multiple blocks that refer to the same
19583 static variable, so we must test for the DW_AT_declaration flag.
19585 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19586 copy decls and set the DECL_ABSTRACT_P flag on them instead of
19589 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
19590 else if (decl_will_get_specification_p (old_die, decl, declaration))
19592 /* This is a definition of a C++ class level static. */
19593 add_AT_specification (var_die, old_die);
19594 specialization_p = true;
19595 if (DECL_NAME (decl))
19597 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19598 struct dwarf_file_data * file_index = lookup_filename (s.file);
19600 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19601 add_AT_file (var_die, DW_AT_decl_file, file_index);
19603 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19604 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19606 if (old_die->die_tag == DW_TAG_member)
19607 add_linkage_name (var_die, decl);
19611 add_name_and_src_coords_attributes (var_die, decl);
19613 if ((origin == NULL && !specialization_p)
19615 && !DECL_ABSTRACT_P (decl_or_origin)
19616 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19617 decl_function_context
19618 (decl_or_origin))))
19620 tree type = TREE_TYPE (decl_or_origin);
19622 if (decl_by_reference_p (decl_or_origin))
19623 add_type_attribute (var_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
19626 add_type_attribute (var_die, type, decl_quals (decl_or_origin),
19630 if (origin == NULL && !specialization_p)
19632 if (TREE_PUBLIC (decl))
19633 add_AT_flag (var_die, DW_AT_external, 1);
19635 if (DECL_ARTIFICIAL (decl))
19636 add_AT_flag (var_die, DW_AT_artificial, 1);
19638 add_accessibility_attribute (var_die, decl);
19642 add_AT_flag (var_die, DW_AT_declaration, 1);
19644 if (decl && (DECL_ABSTRACT_P (decl)
19645 || !old_die || is_declaration_die (old_die)))
19646 equate_decl_number_to_die (decl, var_die);
19648 gen_variable_die_location:
19650 && (! DECL_ABSTRACT_P (decl_or_origin)
19651 /* Local static vars are shared between all clones/inlines,
19652 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19654 || (TREE_CODE (decl_or_origin) == VAR_DECL
19655 && TREE_STATIC (decl_or_origin)
19656 && DECL_RTL_SET_P (decl_or_origin)))
19657 /* When abstract origin already has DW_AT_location attribute, no need
19658 to add it again. */
19659 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19662 add_pubname (decl_or_origin, var_die);
19664 add_location_or_const_value_attribute (var_die, decl_or_origin,
19665 decl == NULL, DW_AT_location);
19668 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19671 /* Generate a DIE to represent a named constant. */
19674 gen_const_die (tree decl, dw_die_ref context_die)
19676 dw_die_ref const_die;
19677 tree type = TREE_TYPE (decl);
19679 const_die = lookup_decl_die (decl);
19683 const_die = new_die (DW_TAG_constant, context_die, decl);
19684 equate_decl_number_to_die (decl, const_die);
19685 add_name_and_src_coords_attributes (const_die, decl);
19686 add_type_attribute (const_die, type, TYPE_QUAL_CONST, context_die);
19687 if (TREE_PUBLIC (decl))
19688 add_AT_flag (const_die, DW_AT_external, 1);
19689 if (DECL_ARTIFICIAL (decl))
19690 add_AT_flag (const_die, DW_AT_artificial, 1);
19691 tree_add_const_value_attribute_for_decl (const_die, decl);
19694 /* Generate a DIE to represent a label identifier. */
19697 gen_label_die (tree decl, dw_die_ref context_die)
19699 tree origin = decl_ultimate_origin (decl);
19700 dw_die_ref lbl_die = lookup_decl_die (decl);
19702 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19706 lbl_die = new_die (DW_TAG_label, context_die, decl);
19707 equate_decl_number_to_die (decl, lbl_die);
19709 if (origin != NULL)
19710 add_abstract_origin_attribute (lbl_die, origin);
19712 add_name_and_src_coords_attributes (lbl_die, decl);
19715 if (DECL_ABSTRACT_P (decl))
19716 equate_decl_number_to_die (decl, lbl_die);
19719 insn = DECL_RTL_IF_SET (decl);
19721 /* Deleted labels are programmer specified labels which have been
19722 eliminated because of various optimizations. We still emit them
19723 here so that it is possible to put breakpoints on them. */
19727 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19729 /* When optimization is enabled (via -O) some parts of the compiler
19730 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19731 represent source-level labels which were explicitly declared by
19732 the user. This really shouldn't be happening though, so catch
19733 it if it ever does happen. */
19734 gcc_assert (!as_a<rtx_insn *> (insn)->deleted ());
19736 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19737 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19741 && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL
19742 && CODE_LABEL_NUMBER (insn) != -1)
19744 ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn));
19745 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19750 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19751 attributes to the DIE for a block STMT, to describe where the inlined
19752 function was called from. This is similar to add_src_coords_attributes. */
19755 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19757 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19759 if (dwarf_version >= 3 || !dwarf_strict)
19761 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19762 add_AT_unsigned (die, DW_AT_call_line, s.line);
19767 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19768 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19771 add_high_low_attributes (tree stmt, dw_die_ref die)
19773 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19775 if (BLOCK_FRAGMENT_CHAIN (stmt)
19776 && (dwarf_version >= 3 || !dwarf_strict))
19778 tree chain, superblock = NULL_TREE;
19780 dw_attr_node *attr = NULL;
19782 if (inlined_function_outer_scope_p (stmt))
19784 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19785 BLOCK_NUMBER (stmt));
19786 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19789 /* Optimize duplicate .debug_ranges lists or even tails of
19790 lists. If this BLOCK has same ranges as its supercontext,
19791 lookup DW_AT_ranges attribute in the supercontext (and
19792 recursively so), verify that the ranges_table contains the
19793 right values and use it instead of adding a new .debug_range. */
19794 for (chain = stmt, pdie = die;
19795 BLOCK_SAME_RANGE (chain);
19796 chain = BLOCK_SUPERCONTEXT (chain))
19798 dw_attr_node *new_attr;
19800 pdie = pdie->die_parent;
19803 if (BLOCK_SUPERCONTEXT (chain) == NULL_TREE)
19805 new_attr = get_AT (pdie, DW_AT_ranges);
19806 if (new_attr == NULL
19807 || new_attr->dw_attr_val.val_class != dw_val_class_range_list)
19810 superblock = BLOCK_SUPERCONTEXT (chain);
19813 && (ranges_table[attr->dw_attr_val.v.val_offset
19814 / 2 / DWARF2_ADDR_SIZE].num
19815 == BLOCK_NUMBER (superblock))
19816 && BLOCK_FRAGMENT_CHAIN (superblock))
19818 unsigned long off = attr->dw_attr_val.v.val_offset
19819 / 2 / DWARF2_ADDR_SIZE;
19820 unsigned long supercnt = 0, thiscnt = 0;
19821 for (chain = BLOCK_FRAGMENT_CHAIN (superblock);
19822 chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
19825 gcc_checking_assert (ranges_table[off + supercnt].num
19826 == BLOCK_NUMBER (chain));
19828 gcc_checking_assert (ranges_table[off + supercnt + 1].num == 0);
19829 for (chain = BLOCK_FRAGMENT_CHAIN (stmt);
19830 chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
19832 gcc_assert (supercnt >= thiscnt);
19833 add_AT_range_list (die, DW_AT_ranges,
19834 ((off + supercnt - thiscnt)
19835 * 2 * DWARF2_ADDR_SIZE),
19840 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt), false);
19842 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19845 add_ranges (chain);
19846 chain = BLOCK_FRAGMENT_CHAIN (chain);
19853 char label_high[MAX_ARTIFICIAL_LABEL_BYTES];
19854 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19855 BLOCK_NUMBER (stmt));
19856 ASM_GENERATE_INTERNAL_LABEL (label_high, BLOCK_END_LABEL,
19857 BLOCK_NUMBER (stmt));
19858 add_AT_low_high_pc (die, label, label_high, false);
19862 /* Generate a DIE for a lexical block. */
19865 gen_lexical_block_die (tree stmt, dw_die_ref context_die)
19867 dw_die_ref old_die = BLOCK_DIE (stmt);
19868 dw_die_ref stmt_die = NULL;
19871 stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19872 BLOCK_DIE (stmt) = stmt_die;
19875 if (BLOCK_ABSTRACT (stmt))
19879 #ifdef ENABLE_CHECKING
19880 /* This must have been generated early and it won't even
19881 need location information since it's a DW_AT_inline
19883 for (dw_die_ref c = context_die; c; c = c->die_parent)
19884 if (c->die_tag == DW_TAG_inlined_subroutine
19885 || c->die_tag == DW_TAG_subprogram)
19887 gcc_assert (get_AT (c, DW_AT_inline));
19894 else if (BLOCK_ABSTRACT_ORIGIN (stmt))
19896 /* If this is an inlined instance, create a new lexical die for
19897 anything below to attach DW_AT_abstract_origin to. */
19900 stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19901 BLOCK_DIE (stmt) = stmt_die;
19907 stmt_die = old_die;
19909 /* A non abstract block whose blocks have already been reordered
19910 should have the instruction range for this block. If so, set the
19911 high/low attributes. */
19912 if (!early_dwarf && !BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19914 gcc_assert (stmt_die);
19915 add_high_low_attributes (stmt, stmt_die);
19918 decls_for_scope (stmt, stmt_die);
19921 /* Generate a DIE for an inlined subprogram. */
19924 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die)
19928 /* The instance of function that is effectively being inlined shall not
19930 gcc_assert (! BLOCK_ABSTRACT (stmt));
19932 decl = block_ultimate_origin (stmt);
19934 /* Make sure any inlined functions are known to be inlineable. */
19935 gcc_checking_assert (DECL_ABSTRACT_P (decl)
19936 || cgraph_function_possibly_inlined_p (decl));
19938 /* Emit info for the abstract instance first, if we haven't yet. We
19939 must emit this even if the block is abstract, otherwise when we
19940 emit the block below (or elsewhere), we may end up trying to emit
19941 a die whose origin die hasn't been emitted, and crashing. */
19942 dwarf2out_abstract_function (decl);
19944 if (! BLOCK_ABSTRACT (stmt))
19946 dw_die_ref subr_die
19947 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
19949 if (call_arg_locations)
19950 BLOCK_DIE (stmt) = subr_die;
19951 add_abstract_origin_attribute (subr_die, decl);
19952 if (TREE_ASM_WRITTEN (stmt))
19953 add_high_low_attributes (stmt, subr_die);
19954 add_call_src_coords_attributes (stmt, subr_die);
19956 decls_for_scope (stmt, subr_die);
19960 /* Generate a DIE for a field in a record, or structure. */
19963 gen_field_die (tree decl, dw_die_ref context_die)
19965 dw_die_ref decl_die;
19967 if (TREE_TYPE (decl) == error_mark_node)
19970 decl_die = new_die (DW_TAG_member, context_die, decl);
19971 add_name_and_src_coords_attributes (decl_die, decl);
19972 add_type_attribute (decl_die, member_declared_type (decl),
19973 decl_quals (decl), context_die);
19975 if (DECL_BIT_FIELD_TYPE (decl))
19977 add_byte_size_attribute (decl_die, decl);
19978 add_bit_size_attribute (decl_die, decl);
19979 add_bit_offset_attribute (decl_die, decl);
19982 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
19983 add_data_member_location_attribute (decl_die, decl);
19985 if (DECL_ARTIFICIAL (decl))
19986 add_AT_flag (decl_die, DW_AT_artificial, 1);
19988 add_accessibility_attribute (decl_die, decl);
19990 /* Equate decl number to die, so that we can look up this decl later on. */
19991 equate_decl_number_to_die (decl, decl_die);
19995 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19996 Use modified_type_die instead.
19997 We keep this code here just in case these types of DIEs may be needed to
19998 represent certain things in other languages (e.g. Pascal) someday. */
20001 gen_pointer_type_die (tree type, dw_die_ref context_die)
20004 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
20006 equate_type_number_to_die (type, ptr_die);
20007 add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
20009 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20012 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20013 Use modified_type_die instead.
20014 We keep this code here just in case these types of DIEs may be needed to
20015 represent certain things in other languages (e.g. Pascal) someday. */
20018 gen_reference_type_die (tree type, dw_die_ref context_die)
20020 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
20022 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
20023 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
20025 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
20027 equate_type_number_to_die (type, ref_die);
20028 add_type_attribute (ref_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
20030 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20034 /* Generate a DIE for a pointer to a member type. */
20037 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
20040 = new_die (DW_TAG_ptr_to_member_type,
20041 scope_die_for (type, context_die), type);
20043 equate_type_number_to_die (type, ptr_die);
20044 add_AT_die_ref (ptr_die, DW_AT_containing_type,
20045 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
20046 add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED,
20050 static char *producer_string;
20052 /* Return a heap allocated producer string including command line options
20053 if -grecord-gcc-switches. */
20056 gen_producer_string (void)
20059 auto_vec<const char *> switches;
20060 const char *language_string = lang_hooks.name;
20061 char *producer, *tail;
20063 size_t len = dwarf_record_gcc_switches ? 0 : 3;
20064 size_t plen = strlen (language_string) + 1 + strlen (version_string);
20066 for (j = 1; dwarf_record_gcc_switches && j < save_decoded_options_count; j++)
20067 switch (save_decoded_options[j].opt_index)
20074 case OPT_auxbase_strip:
20083 case OPT_SPECIAL_unknown:
20084 case OPT_SPECIAL_ignore:
20085 case OPT_SPECIAL_program_name:
20086 case OPT_SPECIAL_input_file:
20087 case OPT_grecord_gcc_switches:
20088 case OPT_gno_record_gcc_switches:
20089 case OPT__output_pch_:
20090 case OPT_fdiagnostics_show_location_:
20091 case OPT_fdiagnostics_show_option:
20092 case OPT_fdiagnostics_show_caret:
20093 case OPT_fdiagnostics_color_:
20094 case OPT_fverbose_asm:
20096 case OPT__sysroot_:
20098 case OPT_nostdinc__:
20099 case OPT_fpreprocessed:
20100 case OPT_fltrans_output_list_:
20101 case OPT_fresolution_:
20102 /* Ignore these. */
20105 if (cl_options[save_decoded_options[j].opt_index].flags
20106 & CL_NO_DWARF_RECORD)
20108 gcc_checking_assert (save_decoded_options[j].canonical_option[0][0]
20110 switch (save_decoded_options[j].canonical_option[0][1])
20117 if (strncmp (save_decoded_options[j].canonical_option[0] + 2,
20124 switches.safe_push (save_decoded_options[j].orig_option_with_args_text);
20125 len += strlen (save_decoded_options[j].orig_option_with_args_text) + 1;
20129 producer = XNEWVEC (char, plen + 1 + len + 1);
20131 sprintf (tail, "%s %s", language_string, version_string);
20134 FOR_EACH_VEC_ELT (switches, j, p)
20138 memcpy (tail + 1, p, len);
20146 /* Given a C and/or C++ language/version string return the "highest".
20147 C++ is assumed to be "higher" than C in this case. Used for merging
20148 LTO translation unit languages. */
20149 static const char *
20150 highest_c_language (const char *lang1, const char *lang2)
20152 if (strcmp ("GNU C++14", lang1) == 0 || strcmp ("GNU C++14", lang2) == 0)
20153 return "GNU C++14";
20154 if (strcmp ("GNU C++11", lang1) == 0 || strcmp ("GNU C++11", lang2) == 0)
20155 return "GNU C++11";
20156 if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) == 0)
20157 return "GNU C++98";
20159 if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
20161 if (strcmp ("GNU C99", lang1) == 0 || strcmp ("GNU C99", lang2) == 0)
20163 if (strcmp ("GNU C89", lang1) == 0 || strcmp ("GNU C89", lang2) == 0)
20166 gcc_unreachable ();
20170 /* Generate the DIE for the compilation unit. */
20173 gen_compile_unit_die (const char *filename)
20176 const char *language_string = lang_hooks.name;
20179 die = new_die (DW_TAG_compile_unit, NULL, NULL);
20183 add_name_attribute (die, filename);
20184 /* Don't add cwd for <built-in>. */
20185 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
20186 add_comp_dir_attribute (die);
20189 add_AT_string (die, DW_AT_producer, producer_string ? producer_string : "");
20191 /* If our producer is LTO try to figure out a common language to use
20192 from the global list of translation units. */
20193 if (strcmp (language_string, "GNU GIMPLE") == 0)
20197 const char *common_lang = NULL;
20199 FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t)
20201 if (!TRANSLATION_UNIT_LANGUAGE (t))
20204 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
20205 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
20207 else if (strncmp (common_lang, "GNU C", 5) == 0
20208 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
20209 /* Mixing C and C++ is ok, use C++ in that case. */
20210 common_lang = highest_c_language (common_lang,
20211 TRANSLATION_UNIT_LANGUAGE (t));
20214 /* Fall back to C. */
20215 common_lang = NULL;
20221 language_string = common_lang;
20224 language = DW_LANG_C;
20225 if (strncmp (language_string, "GNU C", 5) == 0
20226 && ISDIGIT (language_string[5]))
20228 language = DW_LANG_C89;
20229 if (dwarf_version >= 3 || !dwarf_strict)
20231 if (strcmp (language_string, "GNU C89") != 0)
20232 language = DW_LANG_C99;
20234 if (dwarf_version >= 5 /* || !dwarf_strict */)
20235 if (strcmp (language_string, "GNU C11") == 0)
20236 language = DW_LANG_C11;
20239 else if (strncmp (language_string, "GNU C++", 7) == 0)
20241 language = DW_LANG_C_plus_plus;
20242 if (dwarf_version >= 5 /* || !dwarf_strict */)
20244 if (strcmp (language_string, "GNU C++11") == 0)
20245 language = DW_LANG_C_plus_plus_11;
20246 else if (strcmp (language_string, "GNU C++14") == 0)
20247 language = DW_LANG_C_plus_plus_14;
20250 else if (strcmp (language_string, "GNU F77") == 0)
20251 language = DW_LANG_Fortran77;
20252 else if (strcmp (language_string, "GNU Pascal") == 0)
20253 language = DW_LANG_Pascal83;
20254 else if (dwarf_version >= 3 || !dwarf_strict)
20256 if (strcmp (language_string, "GNU Ada") == 0)
20257 language = DW_LANG_Ada95;
20258 else if (strncmp (language_string, "GNU Fortran", 11) == 0)
20260 language = DW_LANG_Fortran95;
20261 if (dwarf_version >= 5 /* || !dwarf_strict */)
20263 if (strcmp (language_string, "GNU Fortran2003") == 0)
20264 language = DW_LANG_Fortran03;
20265 else if (strcmp (language_string, "GNU Fortran2008") == 0)
20266 language = DW_LANG_Fortran08;
20269 else if (strcmp (language_string, "GNU Java") == 0)
20270 language = DW_LANG_Java;
20271 else if (strcmp (language_string, "GNU Objective-C") == 0)
20272 language = DW_LANG_ObjC;
20273 else if (strcmp (language_string, "GNU Objective-C++") == 0)
20274 language = DW_LANG_ObjC_plus_plus;
20275 else if (dwarf_version >= 5 || !dwarf_strict)
20277 if (strcmp (language_string, "GNU Go") == 0)
20278 language = DW_LANG_Go;
20281 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
20282 else if (strncmp (language_string, "GNU Fortran", 11) == 0)
20283 language = DW_LANG_Fortran90;
20285 add_AT_unsigned (die, DW_AT_language, language);
20289 case DW_LANG_Fortran77:
20290 case DW_LANG_Fortran90:
20291 case DW_LANG_Fortran95:
20292 case DW_LANG_Fortran03:
20293 case DW_LANG_Fortran08:
20294 /* Fortran has case insensitive identifiers and the front-end
20295 lowercases everything. */
20296 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
20299 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20305 /* Generate the DIE for a base class. */
20308 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
20310 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
20312 add_type_attribute (die, BINFO_TYPE (binfo), TYPE_UNQUALIFIED, context_die);
20313 add_data_member_location_attribute (die, binfo);
20315 if (BINFO_VIRTUAL_P (binfo))
20316 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
20318 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20319 children, otherwise the default is DW_ACCESS_public. In DWARF2
20320 the default has always been DW_ACCESS_private. */
20321 if (access == access_public_node)
20323 if (dwarf_version == 2
20324 || context_die->die_tag == DW_TAG_class_type)
20325 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20327 else if (access == access_protected_node)
20328 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20329 else if (dwarf_version > 2
20330 && context_die->die_tag != DW_TAG_class_type)
20331 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20334 /* Generate a DIE for a class member. */
20337 gen_member_die (tree type, dw_die_ref context_die)
20340 tree binfo = TYPE_BINFO (type);
20343 /* If this is not an incomplete type, output descriptions of each of its
20344 members. Note that as we output the DIEs necessary to represent the
20345 members of this record or union type, we will also be trying to output
20346 DIEs to represent the *types* of those members. However the `type'
20347 function (above) will specifically avoid generating type DIEs for member
20348 types *within* the list of member DIEs for this (containing) type except
20349 for those types (of members) which are explicitly marked as also being
20350 members of this (containing) type themselves. The g++ front- end can
20351 force any given type to be treated as a member of some other (containing)
20352 type by setting the TYPE_CONTEXT of the given (member) type to point to
20353 the TREE node representing the appropriate (containing) type. */
20355 /* First output info about the base classes. */
20358 vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
20362 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
20363 gen_inheritance_die (base,
20364 (accesses ? (*accesses)[i] : access_public_node),
20368 /* Now output info about the data members and type members. */
20369 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
20371 /* If we thought we were generating minimal debug info for TYPE
20372 and then changed our minds, some of the member declarations
20373 may have already been defined. Don't define them again, but
20374 do put them in the right order. */
20376 child = lookup_decl_die (member);
20378 splice_child_die (context_die, child);
20380 gen_decl_die (member, NULL, context_die);
20383 /* We do not keep type methods in type variants. */
20384 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
20385 /* Now output info about the function members (if any). */
20386 if (TYPE_METHODS (type) != error_mark_node)
20387 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
20389 /* Don't include clones in the member list. */
20390 if (DECL_ABSTRACT_ORIGIN (member))
20392 /* Nor constructors for anonymous classes. */
20393 if (DECL_ARTIFICIAL (member)
20394 && dwarf2_name (member, 0) == NULL)
20397 child = lookup_decl_die (member);
20399 splice_child_die (context_die, child);
20401 gen_decl_die (member, NULL, context_die);
20405 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20406 is set, we pretend that the type was never defined, so we only get the
20407 member DIEs needed by later specification DIEs. */
20410 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
20411 enum debug_info_usage usage)
20413 if (TREE_ASM_WRITTEN (type))
20415 /* Fill in the bound of variable-length fields in late dwarf if
20416 still incomplete. */
20417 if (!early_dwarf && variably_modified_type_p (type, NULL))
20418 for (tree member = TYPE_FIELDS (type);
20420 member = DECL_CHAIN (member))
20421 fill_variable_array_bounds (TREE_TYPE (member));
20425 dw_die_ref type_die = lookup_type_die (type);
20426 dw_die_ref scope_die = 0;
20428 int complete = (TYPE_SIZE (type)
20429 && (! TYPE_STUB_DECL (type)
20430 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20431 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20432 complete = complete && should_emit_struct_debug (type, usage);
20434 if (type_die && ! complete)
20437 if (TYPE_CONTEXT (type) != NULL_TREE
20438 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20439 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20442 scope_die = scope_die_for (type, context_die);
20444 /* Generate child dies for template paramaters. */
20445 if (!type_die && debug_info_level > DINFO_LEVEL_TERSE)
20446 schedule_generic_params_dies_gen (type);
20448 if (! type_die || (nested && is_cu_die (scope_die)))
20449 /* First occurrence of type or toplevel definition of nested class. */
20451 dw_die_ref old_die = type_die;
20453 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20454 ? record_type_tag (type) : DW_TAG_union_type,
20456 equate_type_number_to_die (type, type_die);
20458 add_AT_specification (type_die, old_die);
20460 add_name_attribute (type_die, type_tag (type));
20463 remove_AT (type_die, DW_AT_declaration);
20465 /* If this type has been completed, then give it a byte_size attribute and
20466 then give a list of members. */
20467 if (complete && !ns_decl)
20469 /* Prevent infinite recursion in cases where the type of some member of
20470 this type is expressed in terms of this type itself. */
20471 TREE_ASM_WRITTEN (type) = 1;
20472 add_byte_size_attribute (type_die, type);
20473 if (TYPE_STUB_DECL (type) != NULL_TREE)
20475 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20476 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20479 /* If the first reference to this type was as the return type of an
20480 inline function, then it may not have a parent. Fix this now. */
20481 if (type_die->die_parent == NULL)
20482 add_child_die (scope_die, type_die);
20484 push_decl_scope (type);
20485 gen_member_die (type, type_die);
20488 add_gnat_descriptive_type_attribute (type_die, type, context_die);
20489 if (TYPE_ARTIFICIAL (type))
20490 add_AT_flag (type_die, DW_AT_artificial, 1);
20492 /* GNU extension: Record what type our vtable lives in. */
20493 if (TYPE_VFIELD (type))
20495 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20497 gen_type_die (vtype, context_die);
20498 add_AT_die_ref (type_die, DW_AT_containing_type,
20499 lookup_type_die (vtype));
20504 add_AT_flag (type_die, DW_AT_declaration, 1);
20506 /* We don't need to do this for function-local types. */
20507 if (TYPE_STUB_DECL (type)
20508 && ! decl_function_context (TYPE_STUB_DECL (type)))
20509 vec_safe_push (incomplete_types, type);
20512 if (get_AT (type_die, DW_AT_name))
20513 add_pubtype (type, type_die);
20516 /* Generate a DIE for a subroutine _type_. */
20519 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20521 tree return_type = TREE_TYPE (type);
20522 dw_die_ref subr_die
20523 = new_die (DW_TAG_subroutine_type,
20524 scope_die_for (type, context_die), type);
20526 equate_type_number_to_die (type, subr_die);
20527 add_prototyped_attribute (subr_die, type);
20528 add_type_attribute (subr_die, return_type, TYPE_UNQUALIFIED, context_die);
20529 gen_formal_types_die (type, subr_die);
20531 if (get_AT (subr_die, DW_AT_name))
20532 add_pubtype (type, subr_die);
20535 /* Generate a DIE for a type definition. */
20538 gen_typedef_die (tree decl, dw_die_ref context_die)
20540 dw_die_ref type_die;
20543 if (TREE_ASM_WRITTEN (decl))
20545 if (DECL_ORIGINAL_TYPE (decl))
20546 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl));
20550 TREE_ASM_WRITTEN (decl) = 1;
20551 type_die = new_die (DW_TAG_typedef, context_die, decl);
20552 origin = decl_ultimate_origin (decl);
20553 if (origin != NULL)
20554 add_abstract_origin_attribute (type_die, origin);
20559 add_name_and_src_coords_attributes (type_die, decl);
20560 if (DECL_ORIGINAL_TYPE (decl))
20562 type = DECL_ORIGINAL_TYPE (decl);
20564 if (type == error_mark_node)
20567 gcc_assert (type != TREE_TYPE (decl));
20568 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20572 type = TREE_TYPE (decl);
20574 if (type == error_mark_node)
20577 if (is_naming_typedef_decl (TYPE_NAME (type)))
20579 /* Here, we are in the case of decl being a typedef naming
20580 an anonymous type, e.g:
20581 typedef struct {...} foo;
20582 In that case TREE_TYPE (decl) is not a typedef variant
20583 type and TYPE_NAME of the anonymous type is set to the
20584 TYPE_DECL of the typedef. This construct is emitted by
20587 TYPE is the anonymous struct named by the typedef
20588 DECL. As we need the DW_AT_type attribute of the
20589 DW_TAG_typedef to point to the DIE of TYPE, let's
20590 generate that DIE right away. add_type_attribute
20591 called below will then pick (via lookup_type_die) that
20592 anonymous struct DIE. */
20593 if (!TREE_ASM_WRITTEN (type))
20594 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20596 /* This is a GNU Extension. We are adding a
20597 DW_AT_linkage_name attribute to the DIE of the
20598 anonymous struct TYPE. The value of that attribute
20599 is the name of the typedef decl naming the anonymous
20600 struct. This greatly eases the work of consumers of
20601 this debug info. */
20602 add_linkage_attr (lookup_type_die (type), decl);
20606 add_type_attribute (type_die, type, decl_quals (decl), context_die);
20608 if (is_naming_typedef_decl (decl))
20609 /* We want that all subsequent calls to lookup_type_die with
20610 TYPE in argument yield the DW_TAG_typedef we have just
20612 equate_type_number_to_die (type, type_die);
20614 add_accessibility_attribute (type_die, decl);
20617 if (DECL_ABSTRACT_P (decl))
20618 equate_decl_number_to_die (decl, type_die);
20620 if (get_AT (type_die, DW_AT_name))
20621 add_pubtype (decl, type_die);
20624 /* Generate a DIE for a struct, class, enum or union type. */
20627 gen_tagged_type_die (tree type,
20628 dw_die_ref context_die,
20629 enum debug_info_usage usage)
20633 if (type == NULL_TREE
20634 || !is_tagged_type (type))
20637 if (TREE_ASM_WRITTEN (type))
20639 /* If this is a nested type whose containing class hasn't been written
20640 out yet, writing it out will cover this one, too. This does not apply
20641 to instantiations of member class templates; they need to be added to
20642 the containing class as they are generated. FIXME: This hurts the
20643 idea of combining type decls from multiple TUs, since we can't predict
20644 what set of template instantiations we'll get. */
20645 else if (TYPE_CONTEXT (type)
20646 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20647 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20649 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20651 if (TREE_ASM_WRITTEN (type))
20654 /* If that failed, attach ourselves to the stub. */
20655 push_decl_scope (TYPE_CONTEXT (type));
20656 context_die = lookup_type_die (TYPE_CONTEXT (type));
20659 else if (TYPE_CONTEXT (type) != NULL_TREE
20660 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20662 /* If this type is local to a function that hasn't been written
20663 out yet, use a NULL context for now; it will be fixed up in
20664 decls_for_scope. */
20665 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20666 /* A declaration DIE doesn't count; nested types need to go in the
20668 if (context_die && is_declaration_die (context_die))
20669 context_die = NULL;
20674 context_die = declare_in_namespace (type, context_die);
20678 if (TREE_CODE (type) == ENUMERAL_TYPE)
20680 /* This might have been written out by the call to
20681 declare_in_namespace. */
20682 if (!TREE_ASM_WRITTEN (type))
20683 gen_enumeration_type_die (type, context_die);
20686 gen_struct_or_union_type_die (type, context_die, usage);
20691 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20692 it up if it is ever completed. gen_*_type_die will set it for us
20693 when appropriate. */
20696 /* Generate a type description DIE. */
20699 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20700 enum debug_info_usage usage)
20702 struct array_descr_info info;
20704 if (type == NULL_TREE || type == error_mark_node)
20707 #ifdef ENABLE_CHECKING
20709 verify_type (type);
20712 if (TYPE_NAME (type) != NULL_TREE
20713 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
20714 && is_redundant_typedef (TYPE_NAME (type))
20715 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
20716 /* The DECL of this type is a typedef we don't want to emit debug
20717 info for but we want debug info for its underlying typedef.
20718 This can happen for e.g, the injected-class-name of a C++
20720 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
20722 /* If TYPE is a typedef type variant, let's generate debug info
20723 for the parent typedef which TYPE is a type of. */
20724 if (typedef_variant_p (type))
20726 if (TREE_ASM_WRITTEN (type))
20729 /* Prevent broken recursion; we can't hand off to the same type. */
20730 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20732 /* Give typedefs the right scope. */
20733 context_die = scope_die_for (type, context_die);
20735 TREE_ASM_WRITTEN (type) = 1;
20737 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20741 /* If type is an anonymous tagged type named by a typedef, let's
20742 generate debug info for the typedef. */
20743 if (is_naming_typedef_decl (TYPE_NAME (type)))
20745 /* Use the DIE of the containing namespace as the parent DIE of
20746 the type description DIE we want to generate. */
20747 if (DECL_CONTEXT (TYPE_NAME (type))
20748 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20749 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20751 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20755 /* We are going to output a DIE to represent the unqualified version
20756 of this type (i.e. without any const or volatile qualifiers) so
20757 get the main variant (i.e. the unqualified version) of this type
20758 now. (Vectors are special because the debugging info is in the
20759 cloned type itself). */
20760 if (TREE_CODE (type) != VECTOR_TYPE)
20761 type = type_main_variant (type);
20763 /* If this is an array type with hidden descriptor, handle it first. */
20764 if (!TREE_ASM_WRITTEN (type)
20765 && lang_hooks.types.get_array_descr_info)
20767 memset (&info, 0, sizeof (info));
20768 if (lang_hooks.types.get_array_descr_info (type, &info))
20770 gen_descr_array_type_die (type, &info, context_die);
20771 TREE_ASM_WRITTEN (type) = 1;
20776 if (TREE_ASM_WRITTEN (type))
20778 /* Variable-length types may be incomplete even if
20779 TREE_ASM_WRITTEN. For such types, fall through to
20780 gen_array_type_die() and possibly fill in
20781 DW_AT_{upper,lower}_bound attributes. */
20782 if ((TREE_CODE (type) != ARRAY_TYPE
20783 && TREE_CODE (type) != RECORD_TYPE
20784 && TREE_CODE (type) != UNION_TYPE
20785 && TREE_CODE (type) != QUAL_UNION_TYPE)
20786 || !variably_modified_type_p (type, NULL))
20790 switch (TREE_CODE (type))
20796 case REFERENCE_TYPE:
20797 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20798 ensures that the gen_type_die recursion will terminate even if the
20799 type is recursive. Recursive types are possible in Ada. */
20800 /* ??? We could perhaps do this for all types before the switch
20802 TREE_ASM_WRITTEN (type) = 1;
20804 /* For these types, all that is required is that we output a DIE (or a
20805 set of DIEs) to represent the "basis" type. */
20806 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20807 DINFO_USAGE_IND_USE);
20811 /* This code is used for C++ pointer-to-data-member types.
20812 Output a description of the relevant class type. */
20813 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20814 DINFO_USAGE_IND_USE);
20816 /* Output a description of the type of the object pointed to. */
20817 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20818 DINFO_USAGE_IND_USE);
20820 /* Now output a DIE to represent this pointer-to-data-member type
20822 gen_ptr_to_mbr_type_die (type, context_die);
20825 case FUNCTION_TYPE:
20826 /* Force out return type (in case it wasn't forced out already). */
20827 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20828 DINFO_USAGE_DIR_USE);
20829 gen_subroutine_type_die (type, context_die);
20833 /* Force out return type (in case it wasn't forced out already). */
20834 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20835 DINFO_USAGE_DIR_USE);
20836 gen_subroutine_type_die (type, context_die);
20841 gen_array_type_die (type, context_die);
20844 case ENUMERAL_TYPE:
20847 case QUAL_UNION_TYPE:
20848 gen_tagged_type_die (type, context_die, usage);
20854 case FIXED_POINT_TYPE:
20857 case POINTER_BOUNDS_TYPE:
20858 /* No DIEs needed for fundamental types. */
20863 /* Just use DW_TAG_unspecified_type. */
20865 dw_die_ref type_die = lookup_type_die (type);
20866 if (type_die == NULL)
20868 tree name = TYPE_IDENTIFIER (type);
20869 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (),
20871 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20872 equate_type_number_to_die (type, type_die);
20878 if (is_cxx_auto (type))
20880 tree name = TYPE_IDENTIFIER (type);
20881 dw_die_ref *die = (name == get_identifier ("auto")
20882 ? &auto_die : &decltype_auto_die);
20885 *die = new_die (DW_TAG_unspecified_type,
20886 comp_unit_die (), NULL_TREE);
20887 add_name_attribute (*die, IDENTIFIER_POINTER (name));
20889 equate_type_number_to_die (type, *die);
20892 gcc_unreachable ();
20895 TREE_ASM_WRITTEN (type) = 1;
20899 gen_type_die (tree type, dw_die_ref context_die)
20901 if (type != error_mark_node)
20903 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20904 #ifdef ENABLE_CHECKING
20905 dw_die_ref die = lookup_type_die (type);
20912 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20913 things which are local to the given block. */
20916 gen_block_die (tree stmt, dw_die_ref context_die)
20918 int must_output_die = 0;
20921 /* Ignore blocks that are NULL. */
20922 if (stmt == NULL_TREE)
20925 inlined_func = inlined_function_outer_scope_p (stmt);
20927 /* If the block is one fragment of a non-contiguous block, do not
20928 process the variables, since they will have been done by the
20929 origin block. Do process subblocks. */
20930 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20934 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20935 gen_block_die (sub, context_die);
20940 /* Determine if we need to output any Dwarf DIEs at all to represent this
20943 /* The outer scopes for inlinings *must* always be represented. We
20944 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20945 must_output_die = 1;
20948 /* Determine if this block directly contains any "significant"
20949 local declarations which we will need to output DIEs for. */
20950 if (debug_info_level > DINFO_LEVEL_TERSE)
20951 /* We are not in terse mode so *any* local declaration counts
20952 as being a "significant" one. */
20953 must_output_die = ((BLOCK_VARS (stmt) != NULL
20954 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20955 && (TREE_USED (stmt)
20956 || TREE_ASM_WRITTEN (stmt)
20957 || BLOCK_ABSTRACT (stmt)));
20958 else if ((TREE_USED (stmt)
20959 || TREE_ASM_WRITTEN (stmt)
20960 || BLOCK_ABSTRACT (stmt))
20961 && !dwarf2out_ignore_block (stmt))
20962 must_output_die = 1;
20965 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20966 DIE for any block which contains no significant local declarations at
20967 all. Rather, in such cases we just call `decls_for_scope' so that any
20968 needed Dwarf info for any sub-blocks will get properly generated. Note
20969 that in terse mode, our definition of what constitutes a "significant"
20970 local declaration gets restricted to include only inlined function
20971 instances and local (nested) function definitions. */
20972 if (must_output_die)
20976 /* If STMT block is abstract, that means we have been called
20977 indirectly from dwarf2out_abstract_function.
20978 That function rightfully marks the descendent blocks (of
20979 the abstract function it is dealing with) as being abstract,
20980 precisely to prevent us from emitting any
20981 DW_TAG_inlined_subroutine DIE as a descendent
20982 of an abstract function instance. So in that case, we should
20983 not call gen_inlined_subroutine_die.
20985 Later though, when cgraph asks dwarf2out to emit info
20986 for the concrete instance of the function decl into which
20987 the concrete instance of STMT got inlined, the later will lead
20988 to the generation of a DW_TAG_inlined_subroutine DIE. */
20989 if (! BLOCK_ABSTRACT (stmt))
20990 gen_inlined_subroutine_die (stmt, context_die);
20993 gen_lexical_block_die (stmt, context_die);
20996 decls_for_scope (stmt, context_die);
20999 /* Process variable DECL (or variable with origin ORIGIN) within
21000 block STMT and add it to CONTEXT_DIE. */
21002 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
21005 tree decl_or_origin = decl ? decl : origin;
21007 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
21008 die = lookup_decl_die (decl_or_origin);
21009 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
21010 && TYPE_DECL_IS_STUB (decl_or_origin))
21011 die = lookup_type_die (TREE_TYPE (decl_or_origin));
21015 if (die != NULL && die->die_parent == NULL)
21016 add_child_die (context_die, die);
21017 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
21020 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
21021 stmt, context_die);
21024 gen_decl_die (decl, origin, context_die);
21027 /* Generate all of the decls declared within a given scope and (recursively)
21028 all of its sub-blocks. */
21031 decls_for_scope (tree stmt, dw_die_ref context_die)
21037 /* Ignore NULL blocks. */
21038 if (stmt == NULL_TREE)
21041 /* Output the DIEs to represent all of the data objects and typedefs
21042 declared directly within this block but not within any nested
21043 sub-blocks. Also, nested function and tag DIEs have been
21044 generated with a parent of NULL; fix that up now. We don't
21045 have to do this if we're at -g1. */
21046 if (debug_info_level > DINFO_LEVEL_TERSE)
21048 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
21049 process_scope_var (stmt, decl, NULL_TREE, context_die);
21050 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
21051 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
21055 /* Even if we're at -g1, we need to process the subblocks in order to get
21056 inlined call information. */
21058 /* Output the DIEs to represent all sub-blocks (and the items declared
21059 therein) of this block. */
21060 for (subblocks = BLOCK_SUBBLOCKS (stmt);
21062 subblocks = BLOCK_CHAIN (subblocks))
21063 gen_block_die (subblocks, context_die);
21066 /* Is this a typedef we can avoid emitting? */
21069 is_redundant_typedef (const_tree decl)
21071 if (TYPE_DECL_IS_STUB (decl))
21074 if (DECL_ARTIFICIAL (decl)
21075 && DECL_CONTEXT (decl)
21076 && is_tagged_type (DECL_CONTEXT (decl))
21077 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
21078 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
21079 /* Also ignore the artificial member typedef for the class name. */
21085 /* Return TRUE if TYPE is a typedef that names a type for linkage
21086 purposes. This kind of typedefs is produced by the C++ FE for
21089 typedef struct {...} foo;
21091 In that case, there is no typedef variant type produced for foo.
21092 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
21096 is_naming_typedef_decl (const_tree decl)
21098 if (decl == NULL_TREE
21099 || TREE_CODE (decl) != TYPE_DECL
21100 || !is_tagged_type (TREE_TYPE (decl))
21101 || DECL_IS_BUILTIN (decl)
21102 || is_redundant_typedef (decl)
21103 /* It looks like Ada produces TYPE_DECLs that are very similar
21104 to C++ naming typedefs but that have different
21105 semantics. Let's be specific to c++ for now. */
21109 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
21110 && TYPE_NAME (TREE_TYPE (decl)) == decl
21111 && (TYPE_STUB_DECL (TREE_TYPE (decl))
21112 != TYPE_NAME (TREE_TYPE (decl))));
21115 /* Looks up the DIE for a context. */
21117 static inline dw_die_ref
21118 lookup_context_die (tree context)
21122 /* Find die that represents this context. */
21123 if (TYPE_P (context))
21125 context = TYPE_MAIN_VARIANT (context);
21126 dw_die_ref ctx = lookup_type_die (context);
21129 return strip_naming_typedef (context, ctx);
21132 return lookup_decl_die (context);
21134 return comp_unit_die ();
21137 /* Returns the DIE for a context. */
21139 static inline dw_die_ref
21140 get_context_die (tree context)
21144 /* Find die that represents this context. */
21145 if (TYPE_P (context))
21147 context = TYPE_MAIN_VARIANT (context);
21148 return strip_naming_typedef (context, force_type_die (context));
21151 return force_decl_die (context);
21153 return comp_unit_die ();
21156 /* Returns the DIE for decl. A DIE will always be returned. */
21159 force_decl_die (tree decl)
21161 dw_die_ref decl_die;
21162 unsigned saved_external_flag;
21163 tree save_fn = NULL_TREE;
21164 decl_die = lookup_decl_die (decl);
21167 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
21169 decl_die = lookup_decl_die (decl);
21173 switch (TREE_CODE (decl))
21175 case FUNCTION_DECL:
21176 /* Clear current_function_decl, so that gen_subprogram_die thinks
21177 that this is a declaration. At this point, we just want to force
21178 declaration die. */
21179 save_fn = current_function_decl;
21180 current_function_decl = NULL_TREE;
21181 gen_subprogram_die (decl, context_die);
21182 current_function_decl = save_fn;
21186 /* Set external flag to force declaration die. Restore it after
21187 gen_decl_die() call. */
21188 saved_external_flag = DECL_EXTERNAL (decl);
21189 DECL_EXTERNAL (decl) = 1;
21190 gen_decl_die (decl, NULL, context_die);
21191 DECL_EXTERNAL (decl) = saved_external_flag;
21194 case NAMESPACE_DECL:
21195 if (dwarf_version >= 3 || !dwarf_strict)
21196 dwarf2out_decl (decl);
21198 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21199 decl_die = comp_unit_die ();
21202 case TRANSLATION_UNIT_DECL:
21203 decl_die = comp_unit_die ();
21207 gcc_unreachable ();
21210 /* We should be able to find the DIE now. */
21212 decl_die = lookup_decl_die (decl);
21213 gcc_assert (decl_die);
21219 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21220 always returned. */
21223 force_type_die (tree type)
21225 dw_die_ref type_die;
21227 type_die = lookup_type_die (type);
21230 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
21232 type_die = modified_type_die (type, TYPE_QUALS_NO_ADDR_SPACE (type),
21234 gcc_assert (type_die);
21239 /* Force out any required namespaces to be able to output DECL,
21240 and return the new context_die for it, if it's changed. */
21243 setup_namespace_context (tree thing, dw_die_ref context_die)
21245 tree context = (DECL_P (thing)
21246 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
21247 if (context && TREE_CODE (context) == NAMESPACE_DECL)
21248 /* Force out the namespace. */
21249 context_die = force_decl_die (context);
21251 return context_die;
21254 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21255 type) within its namespace, if appropriate.
21257 For compatibility with older debuggers, namespace DIEs only contain
21258 declarations; all definitions are emitted at CU scope, with
21259 DW_AT_specification pointing to the declaration (like with class
21263 declare_in_namespace (tree thing, dw_die_ref context_die)
21265 dw_die_ref ns_context;
21267 if (debug_info_level <= DINFO_LEVEL_TERSE)
21268 return context_die;
21270 /* External declarations in the local scope only need to be emitted
21271 once, not once in the namespace and once in the scope.
21273 This avoids declaring the `extern' below in the
21274 namespace DIE as well as in the innermost scope:
21287 if (DECL_P (thing) && DECL_EXTERNAL (thing) && local_scope_p (context_die))
21288 return context_die;
21290 /* If this decl is from an inlined function, then don't try to emit it in its
21291 namespace, as we will get confused. It would have already been emitted
21292 when the abstract instance of the inline function was emitted anyways. */
21293 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
21294 return context_die;
21296 ns_context = setup_namespace_context (thing, context_die);
21298 if (ns_context != context_die)
21302 if (DECL_P (thing))
21303 gen_decl_die (thing, NULL, ns_context);
21305 gen_type_die (thing, ns_context);
21307 return context_die;
21310 /* Generate a DIE for a namespace or namespace alias. */
21313 gen_namespace_die (tree decl, dw_die_ref context_die)
21315 dw_die_ref namespace_die;
21317 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21318 they are an alias of. */
21319 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
21321 /* Output a real namespace or module. */
21322 context_die = setup_namespace_context (decl, comp_unit_die ());
21323 namespace_die = new_die (is_fortran ()
21324 ? DW_TAG_module : DW_TAG_namespace,
21325 context_die, decl);
21326 /* For Fortran modules defined in different CU don't add src coords. */
21327 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
21329 const char *name = dwarf2_name (decl, 0);
21331 add_name_attribute (namespace_die, name);
21334 add_name_and_src_coords_attributes (namespace_die, decl);
21335 if (DECL_EXTERNAL (decl))
21336 add_AT_flag (namespace_die, DW_AT_declaration, 1);
21337 equate_decl_number_to_die (decl, namespace_die);
21341 /* Output a namespace alias. */
21343 /* Force out the namespace we are an alias of, if necessary. */
21344 dw_die_ref origin_die
21345 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
21347 if (DECL_FILE_SCOPE_P (decl)
21348 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
21349 context_die = setup_namespace_context (decl, comp_unit_die ());
21350 /* Now create the namespace alias DIE. */
21351 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
21352 add_name_and_src_coords_attributes (namespace_die, decl);
21353 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
21354 equate_decl_number_to_die (decl, namespace_die);
21356 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
21357 if (want_pubnames ())
21358 add_pubname_string (lang_hooks.dwarf_name (decl, 1), namespace_die);
21361 /* Generate Dwarf debug information for a decl described by DECL.
21362 The return value is currently only meaningful for PARM_DECLs,
21363 for all other decls it returns NULL. */
21366 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
21368 tree decl_or_origin = decl ? decl : origin;
21369 tree class_origin = NULL, ultimate_origin;
21371 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
21374 /* Ignore pointer bounds decls. */
21375 if (DECL_P (decl_or_origin)
21376 && TREE_TYPE (decl_or_origin)
21377 && POINTER_BOUNDS_P (decl_or_origin))
21380 switch (TREE_CODE (decl_or_origin))
21386 if (!is_fortran () && !is_ada ())
21388 /* The individual enumerators of an enum type get output when we output
21389 the Dwarf representation of the relevant enum type itself. */
21393 /* Emit its type. */
21394 gen_type_die (TREE_TYPE (decl), context_die);
21396 /* And its containing namespace. */
21397 context_die = declare_in_namespace (decl, context_die);
21399 gen_const_die (decl, context_die);
21402 case FUNCTION_DECL:
21403 /* Don't output any DIEs to represent mere function declarations,
21404 unless they are class members or explicit block externs. */
21405 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
21406 && DECL_FILE_SCOPE_P (decl_or_origin)
21407 && (current_function_decl == NULL_TREE
21408 || DECL_ARTIFICIAL (decl_or_origin)))
21413 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21414 on local redeclarations of global functions. That seems broken. */
21415 if (current_function_decl != decl)
21416 /* This is only a declaration. */;
21419 /* If we're emitting a clone, emit info for the abstract instance. */
21420 if (origin || DECL_ORIGIN (decl) != decl)
21421 dwarf2out_abstract_function (origin
21422 ? DECL_ORIGIN (origin)
21423 : DECL_ABSTRACT_ORIGIN (decl));
21425 /* If we're emitting an out-of-line copy of an inline function,
21426 emit info for the abstract instance and set up to refer to it. */
21427 else if (cgraph_function_possibly_inlined_p (decl)
21428 && ! DECL_ABSTRACT_P (decl)
21429 && ! class_or_namespace_scope_p (context_die)
21430 /* dwarf2out_abstract_function won't emit a die if this is just
21431 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21432 that case, because that works only if we have a die. */
21433 && DECL_INITIAL (decl) != NULL_TREE)
21435 dwarf2out_abstract_function (decl);
21436 set_decl_origin_self (decl);
21439 /* Otherwise we're emitting the primary DIE for this decl. */
21440 else if (debug_info_level > DINFO_LEVEL_TERSE)
21442 /* Before we describe the FUNCTION_DECL itself, make sure that we
21443 have its containing type. */
21445 origin = decl_class_context (decl);
21446 if (origin != NULL_TREE)
21447 gen_type_die (origin, context_die);
21449 /* And its return type. */
21450 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
21452 /* And its virtual context. */
21453 if (DECL_VINDEX (decl) != NULL_TREE)
21454 gen_type_die (DECL_CONTEXT (decl), context_die);
21456 /* Make sure we have a member DIE for decl. */
21457 if (origin != NULL_TREE)
21458 gen_type_die_for_member (origin, decl, context_die);
21460 /* And its containing namespace. */
21461 context_die = declare_in_namespace (decl, context_die);
21464 /* Now output a DIE to represent the function itself. */
21466 gen_subprogram_die (decl, context_die);
21470 /* If we are in terse mode, don't generate any DIEs to represent any
21471 actual typedefs. */
21472 if (debug_info_level <= DINFO_LEVEL_TERSE)
21475 /* In the special case of a TYPE_DECL node representing the declaration
21476 of some type tag, if the given TYPE_DECL is marked as having been
21477 instantiated from some other (original) TYPE_DECL node (e.g. one which
21478 was generated within the original definition of an inline function) we
21479 used to generate a special (abbreviated) DW_TAG_structure_type,
21480 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21481 should be actually referencing those DIEs, as variable DIEs with that
21482 type would be emitted already in the abstract origin, so it was always
21483 removed during unused type prunning. Don't add anything in this
21485 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
21488 if (is_redundant_typedef (decl))
21489 gen_type_die (TREE_TYPE (decl), context_die);
21491 /* Output a DIE to represent the typedef itself. */
21492 gen_typedef_die (decl, context_die);
21496 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21497 gen_label_die (decl, context_die);
21502 /* If we are in terse mode, don't generate any DIEs to represent any
21503 variable declarations or definitions. */
21504 if (debug_info_level <= DINFO_LEVEL_TERSE)
21507 /* Output any DIEs that are needed to specify the type of this data
21509 if (decl_by_reference_p (decl_or_origin))
21510 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21512 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21514 /* And its containing type. */
21515 class_origin = decl_class_context (decl_or_origin);
21516 if (class_origin != NULL_TREE)
21517 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
21519 /* And its containing namespace. */
21520 context_die = declare_in_namespace (decl_or_origin, context_die);
21522 /* Now output the DIE to represent the data object itself. This gets
21523 complicated because of the possibility that the VAR_DECL really
21524 represents an inlined instance of a formal parameter for an inline
21526 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21527 if (ultimate_origin != NULL_TREE
21528 && TREE_CODE (ultimate_origin) == PARM_DECL)
21529 gen_formal_parameter_die (decl, origin,
21530 true /* Emit name attribute. */,
21533 gen_variable_die (decl, origin, context_die);
21537 /* Ignore the nameless fields that are used to skip bits but handle C++
21538 anonymous unions and structs. */
21539 if (DECL_NAME (decl) != NULL_TREE
21540 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
21541 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
21543 gen_type_die (member_declared_type (decl), context_die);
21544 gen_field_die (decl, context_die);
21549 if (DECL_BY_REFERENCE (decl_or_origin))
21550 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21552 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21553 return gen_formal_parameter_die (decl, origin,
21554 true /* Emit name attribute. */,
21557 case NAMESPACE_DECL:
21558 case IMPORTED_DECL:
21559 if (dwarf_version >= 3 || !dwarf_strict)
21560 gen_namespace_die (decl, context_die);
21563 case NAMELIST_DECL:
21564 gen_namelist_decl (DECL_NAME (decl), context_die,
21565 NAMELIST_DECL_ASSOCIATED_DECL (decl));
21569 /* Probably some frontend-internal decl. Assume we don't care. */
21570 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21577 /* Output initial debug information for global DECL. Called at the
21578 end of the parsing process.
21580 This is the initial debug generation process. As such, the DIEs
21581 generated may be incomplete. A later debug generation pass
21582 (dwarf2out_late_global_decl) will augment the information generated
21583 in this pass (e.g., with complete location info). */
21586 dwarf2out_early_global_decl (tree decl)
21590 /* gen_decl_die() will set DECL_ABSTRACT because
21591 cgraph_function_possibly_inlined_p() returns true. This is in
21592 turn will cause DW_AT_inline attributes to be set.
21594 This happens because at early dwarf generation, there is no
21595 cgraph information, causing cgraph_function_possibly_inlined_p()
21596 to return true. Trick cgraph_function_possibly_inlined_p()
21597 while we generate dwarf early. */
21598 bool save = symtab->global_info_ready;
21599 symtab->global_info_ready = true;
21601 /* We don't handle TYPE_DECLs. If required, they'll be reached via
21602 other DECLs and they can point to template types or other things
21603 that dwarf2out can't handle when done via dwarf2out_decl. */
21604 if (TREE_CODE (decl) != TYPE_DECL
21605 && TREE_CODE (decl) != PARM_DECL)
21607 tree save_fndecl = current_function_decl;
21608 if (TREE_CODE (decl) == FUNCTION_DECL)
21610 /* No cfun means the symbol has no body, so there's nothing
21612 if (!DECL_STRUCT_FUNCTION (decl))
21613 goto early_decl_exit;
21615 current_function_decl = decl;
21617 dwarf2out_decl (decl);
21618 if (TREE_CODE (decl) == FUNCTION_DECL)
21619 current_function_decl = save_fndecl;
21622 symtab->global_info_ready = save;
21625 /* Output debug information for global decl DECL. Called from
21626 toplev.c after compilation proper has finished. */
21629 dwarf2out_late_global_decl (tree decl)
21631 /* We have to generate early debug late for LTO. */
21633 dwarf2out_early_global_decl (decl);
21635 /* Fill-in any location information we were unable to determine
21636 on the first pass. */
21637 if (TREE_CODE (decl) == VAR_DECL
21638 && !POINTER_BOUNDS_P (decl))
21640 dw_die_ref die = lookup_decl_die (decl);
21642 add_location_or_const_value_attribute (die, decl, false,
21647 /* Output debug information for type decl DECL. Called from toplev.c
21648 and from language front ends (to record built-in types). */
21650 dwarf2out_type_decl (tree decl, int local)
21655 dwarf2out_decl (decl);
21659 /* Output debug information for imported module or decl DECL.
21660 NAME is non-NULL name in the lexical block if the decl has been renamed.
21661 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21662 that DECL belongs to.
21663 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21665 dwarf2out_imported_module_or_decl_1 (tree decl,
21667 tree lexical_block,
21668 dw_die_ref lexical_block_die)
21670 expanded_location xloc;
21671 dw_die_ref imported_die = NULL;
21672 dw_die_ref at_import_die;
21674 if (TREE_CODE (decl) == IMPORTED_DECL)
21676 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21677 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21681 xloc = expand_location (input_location);
21683 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21685 at_import_die = force_type_die (TREE_TYPE (decl));
21686 /* For namespace N { typedef void T; } using N::T; base_type_die
21687 returns NULL, but DW_TAG_imported_declaration requires
21688 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21689 if (!at_import_die)
21691 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21692 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21693 at_import_die = lookup_type_die (TREE_TYPE (decl));
21694 gcc_assert (at_import_die);
21699 at_import_die = lookup_decl_die (decl);
21700 if (!at_import_die)
21702 /* If we're trying to avoid duplicate debug info, we may not have
21703 emitted the member decl for this field. Emit it now. */
21704 if (TREE_CODE (decl) == FIELD_DECL)
21706 tree type = DECL_CONTEXT (decl);
21708 if (TYPE_CONTEXT (type)
21709 && TYPE_P (TYPE_CONTEXT (type))
21710 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21711 DINFO_USAGE_DIR_USE))
21713 gen_type_die_for_member (type, decl,
21714 get_context_die (TYPE_CONTEXT (type)));
21716 if (TREE_CODE (decl) == NAMELIST_DECL)
21717 at_import_die = gen_namelist_decl (DECL_NAME (decl),
21718 get_context_die (DECL_CONTEXT (decl)),
21721 at_import_die = force_decl_die (decl);
21725 if (TREE_CODE (decl) == NAMESPACE_DECL)
21727 if (dwarf_version >= 3 || !dwarf_strict)
21728 imported_die = new_die (DW_TAG_imported_module,
21735 imported_die = new_die (DW_TAG_imported_declaration,
21739 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21740 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21742 add_AT_string (imported_die, DW_AT_name,
21743 IDENTIFIER_POINTER (name));
21744 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21747 /* Output debug information for imported module or decl DECL.
21748 NAME is non-NULL name in context if the decl has been renamed.
21749 CHILD is true if decl is one of the renamed decls as part of
21750 importing whole module. */
21753 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21756 /* dw_die_ref at_import_die; */
21757 dw_die_ref scope_die;
21759 if (debug_info_level <= DINFO_LEVEL_TERSE)
21766 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21767 We need decl DIE for reference and scope die. First, get DIE for the decl
21770 /* Get the scope die for decl context. Use comp_unit_die for global module
21771 or decl. If die is not found for non globals, force new die. */
21773 && TYPE_P (context)
21774 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21777 if (!(dwarf_version >= 3 || !dwarf_strict))
21780 scope_die = get_context_die (context);
21784 gcc_assert (scope_die->die_child);
21785 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21786 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21787 scope_die = scope_die->die_child;
21790 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21791 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21794 /* Output debug information for namelists. */
21797 gen_namelist_decl (tree name, dw_die_ref scope_die, tree item_decls)
21799 dw_die_ref nml_die, nml_item_die, nml_item_ref_die;
21803 if (debug_info_level <= DINFO_LEVEL_TERSE)
21806 gcc_assert (scope_die != NULL);
21807 nml_die = new_die (DW_TAG_namelist, scope_die, NULL);
21808 add_AT_string (nml_die, DW_AT_name, IDENTIFIER_POINTER (name));
21810 /* If there are no item_decls, we have a nondefining namelist, e.g.
21811 with USE association; hence, set DW_AT_declaration. */
21812 if (item_decls == NULL_TREE)
21814 add_AT_flag (nml_die, DW_AT_declaration, 1);
21818 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls), i, value)
21820 nml_item_ref_die = lookup_decl_die (value);
21821 if (!nml_item_ref_die)
21822 nml_item_ref_die = force_decl_die (value);
21824 nml_item_die = new_die (DW_TAG_namelist_item, nml_die, NULL);
21825 add_AT_die_ref (nml_item_die, DW_AT_namelist_items, nml_item_ref_die);
21831 /* Write the debugging output for DECL and return the DIE. */
21834 dwarf2out_decl (tree decl)
21836 dw_die_ref context_die = comp_unit_die ();
21838 switch (TREE_CODE (decl))
21843 case FUNCTION_DECL:
21844 /* What we would really like to do here is to filter out all mere
21845 file-scope declarations of file-scope functions which are never
21846 referenced later within this translation unit (and keep all of ones
21847 that *are* referenced later on) but we aren't clairvoyant, so we have
21848 no idea which functions will be referenced in the future (i.e. later
21849 on within the current translation unit). So here we just ignore all
21850 file-scope function declarations which are not also definitions. If
21851 and when the debugger needs to know something about these functions,
21852 it will have to hunt around and find the DWARF information associated
21853 with the definition of the function.
21855 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21856 nodes represent definitions and which ones represent mere
21857 declarations. We have to check DECL_INITIAL instead. That's because
21858 the C front-end supports some weird semantics for "extern inline"
21859 function definitions. These can get inlined within the current
21860 translation unit (and thus, we need to generate Dwarf info for their
21861 abstract instances so that the Dwarf info for the concrete inlined
21862 instances can have something to refer to) but the compiler never
21863 generates any out-of-lines instances of such things (despite the fact
21864 that they *are* definitions).
21866 The important point is that the C front-end marks these "extern
21867 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21868 them anyway. Note that the C++ front-end also plays some similar games
21869 for inline function definitions appearing within include files which
21870 also contain `#pragma interface' pragmas.
21872 If we are called from dwarf2out_abstract_function output a DIE
21873 anyway. We can end up here this way with early inlining and LTO
21874 where the inlined function is output in a different LTRANS unit
21876 if (DECL_INITIAL (decl) == NULL_TREE
21877 && ! DECL_ABSTRACT_P (decl))
21880 /* If we're a nested function, initially use a parent of NULL; if we're
21881 a plain function, this will be fixed up in decls_for_scope. If
21882 we're a method, it will be ignored, since we already have a DIE. */
21883 if (decl_function_context (decl)
21884 /* But if we're in terse mode, we don't care about scope. */
21885 && debug_info_level > DINFO_LEVEL_TERSE)
21886 context_die = NULL;
21890 /* For local statics lookup proper context die. */
21891 if (local_function_static (decl))
21892 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21894 /* If we are in terse mode, don't generate any DIEs to represent any
21895 variable declarations or definitions. */
21896 if (debug_info_level <= DINFO_LEVEL_TERSE)
21901 if (debug_info_level <= DINFO_LEVEL_TERSE)
21903 if (!is_fortran () && !is_ada ())
21905 if (TREE_STATIC (decl) && decl_function_context (decl))
21906 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21909 case NAMESPACE_DECL:
21910 case IMPORTED_DECL:
21911 if (debug_info_level <= DINFO_LEVEL_TERSE)
21913 if (lookup_decl_die (decl) != NULL)
21918 /* Don't emit stubs for types unless they are needed by other DIEs. */
21919 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21922 /* Don't bother trying to generate any DIEs to represent any of the
21923 normal built-in types for the language we are compiling. */
21924 if (DECL_IS_BUILTIN (decl))
21927 /* If we are in terse mode, don't generate any DIEs for types. */
21928 if (debug_info_level <= DINFO_LEVEL_TERSE)
21931 /* If we're a function-scope tag, initially use a parent of NULL;
21932 this will be fixed up in decls_for_scope. */
21933 if (decl_function_context (decl))
21934 context_die = NULL;
21938 case NAMELIST_DECL:
21945 gen_decl_die (decl, NULL, context_die);
21947 #ifdef ENABLE_CHECKING
21948 dw_die_ref die = lookup_decl_die (decl);
21954 /* Write the debugging output for DECL. */
21957 dwarf2out_function_decl (tree decl)
21959 dwarf2out_decl (decl);
21960 call_arg_locations = NULL;
21961 call_arg_loc_last = NULL;
21962 call_site_count = -1;
21963 tail_call_site_count = -1;
21964 decl_loc_table->empty ();
21965 cached_dw_loc_list_table->empty ();
21968 /* Output a marker (i.e. a label) for the beginning of the generated code for
21969 a lexical block. */
21972 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21973 unsigned int blocknum)
21975 switch_to_section (current_function_section ());
21976 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21979 /* Output a marker (i.e. a label) for the end of the generated code for a
21983 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21985 switch_to_section (current_function_section ());
21986 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21989 /* Returns nonzero if it is appropriate not to emit any debugging
21990 information for BLOCK, because it doesn't contain any instructions.
21992 Don't allow this for blocks with nested functions or local classes
21993 as we would end up with orphans, and in the presence of scheduling
21994 we may end up calling them anyway. */
21997 dwarf2out_ignore_block (const_tree block)
22002 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
22003 if (TREE_CODE (decl) == FUNCTION_DECL
22004 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22006 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
22008 decl = BLOCK_NONLOCALIZED_VAR (block, i);
22009 if (TREE_CODE (decl) == FUNCTION_DECL
22010 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
22017 /* Hash table routines for file_hash. */
22020 dwarf_file_hasher::equal (dwarf_file_data *p1, const char *p2)
22022 return filename_cmp (p1->filename, p2) == 0;
22026 dwarf_file_hasher::hash (dwarf_file_data *p)
22028 return htab_hash_string (p->filename);
22031 /* Lookup FILE_NAME (in the list of filenames that we know about here in
22032 dwarf2out.c) and return its "index". The index of each (known) filename is
22033 just a unique number which is associated with only that one filename. We
22034 need such numbers for the sake of generating labels (in the .debug_sfnames
22035 section) and references to those files numbers (in the .debug_srcinfo
22036 and.debug_macinfo sections). If the filename given as an argument is not
22037 found in our current list, add it to the list and assign it the next
22038 available unique index number. */
22040 static struct dwarf_file_data *
22041 lookup_filename (const char *file_name)
22043 struct dwarf_file_data * created;
22048 dwarf_file_data **slot
22049 = file_table->find_slot_with_hash (file_name, htab_hash_string (file_name),
22054 created = ggc_alloc<dwarf_file_data> ();
22055 created->filename = file_name;
22056 created->emitted_number = 0;
22061 /* If the assembler will construct the file table, then translate the compiler
22062 internal file table number into the assembler file table number, and emit
22063 a .file directive if we haven't already emitted one yet. The file table
22064 numbers are different because we prune debug info for unused variables and
22065 types, which may include filenames. */
22068 maybe_emit_file (struct dwarf_file_data * fd)
22070 if (! fd->emitted_number)
22072 if (last_emitted_file)
22073 fd->emitted_number = last_emitted_file->emitted_number + 1;
22075 fd->emitted_number = 1;
22076 last_emitted_file = fd;
22078 if (DWARF2_ASM_LINE_DEBUG_INFO)
22080 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
22081 output_quoted_string (asm_out_file,
22082 remap_debug_filename (fd->filename));
22083 fputc ('\n', asm_out_file);
22087 return fd->emitted_number;
22090 /* Schedule generation of a DW_AT_const_value attribute to DIE.
22091 That generation should happen after function debug info has been
22092 generated. The value of the attribute is the constant value of ARG. */
22095 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
22097 die_arg_entry entry;
22102 gcc_assert (early_dwarf);
22104 if (!tmpl_value_parm_die_table)
22105 vec_alloc (tmpl_value_parm_die_table, 32);
22109 vec_safe_push (tmpl_value_parm_die_table, entry);
22112 /* Return TRUE if T is an instance of generic type, FALSE
22116 generic_type_p (tree t)
22118 if (t == NULL_TREE || !TYPE_P (t))
22120 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
22123 /* Schedule the generation of the generic parameter dies for the
22124 instance of generic type T. The proper generation itself is later
22125 done by gen_scheduled_generic_parms_dies. */
22128 schedule_generic_params_dies_gen (tree t)
22130 if (!generic_type_p (t))
22133 gcc_assert (early_dwarf);
22135 if (!generic_type_instances)
22136 vec_alloc (generic_type_instances, 256);
22138 vec_safe_push (generic_type_instances, t);
22141 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
22142 by append_entry_to_tmpl_value_parm_die_table. This function must
22143 be called after function DIEs have been generated. */
22146 gen_remaining_tmpl_value_param_die_attribute (void)
22148 if (tmpl_value_parm_die_table)
22153 /* We do this in two phases - first get the cases we can
22154 handle during early-finish, preserving those we cannot
22155 (containing symbolic constants where we don't yet know
22156 whether we are going to output the referenced symbols).
22157 For those we try again at late-finish. */
22159 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table, i, e)
22161 if (!tree_add_const_value_attribute (e->die, e->arg))
22162 (*tmpl_value_parm_die_table)[j++] = *e;
22164 tmpl_value_parm_die_table->truncate (j);
22168 /* Generate generic parameters DIEs for instances of generic types
22169 that have been previously scheduled by
22170 schedule_generic_params_dies_gen. This function must be called
22171 after all the types of the CU have been laid out. */
22174 gen_scheduled_generic_parms_dies (void)
22179 if (!generic_type_instances)
22182 /* We end up "recursing" into schedule_generic_params_dies_gen, so
22183 pretend this generation is part of "early dwarf" as well. */
22186 FOR_EACH_VEC_ELT (*generic_type_instances, i, t)
22187 if (COMPLETE_TYPE_P (t))
22188 gen_generic_params_dies (t);
22190 generic_type_instances = NULL;
22194 /* Replace DW_AT_name for the decl with name. */
22197 dwarf2out_set_name (tree decl, tree name)
22200 dw_attr_node *attr;
22203 die = TYPE_SYMTAB_DIE (decl);
22207 dname = dwarf2_name (name, 0);
22211 attr = get_AT (die, DW_AT_name);
22214 struct indirect_string_node *node;
22216 node = find_AT_string (dname);
22217 /* replace the string. */
22218 attr->dw_attr_val.v.val_str = node;
22222 add_name_attribute (die, dname);
22225 /* True if before or during processing of the first function being emitted. */
22226 static bool in_first_function_p = true;
22227 /* True if loc_note during dwarf2out_var_location call might still be
22228 before first real instruction at address equal to .Ltext0. */
22229 static bool maybe_at_text_label_p = true;
22230 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
22231 static unsigned int first_loclabel_num_not_at_text_label;
22233 /* Called by the final INSN scan whenever we see a var location. We
22234 use it to drop labels in the right places, and throw the location in
22235 our lookup table. */
22238 dwarf2out_var_location (rtx_insn *loc_note)
22240 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
22241 struct var_loc_node *newloc;
22242 rtx_insn *next_real, *next_note;
22243 static const char *last_label;
22244 static const char *last_postcall_label;
22245 static bool last_in_cold_section_p;
22246 static rtx_insn *expected_next_loc_note;
22250 if (!NOTE_P (loc_note))
22252 if (CALL_P (loc_note))
22255 if (SIBLING_CALL_P (loc_note))
22256 tail_call_site_count++;
22261 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
22262 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
22265 /* Optimize processing a large consecutive sequence of location
22266 notes so we don't spend too much time in next_real_insn. If the
22267 next insn is another location note, remember the next_real_insn
22268 calculation for next time. */
22269 next_real = cached_next_real_insn;
22272 if (expected_next_loc_note != loc_note)
22276 next_note = NEXT_INSN (loc_note);
22278 || next_note->deleted ()
22279 || ! NOTE_P (next_note)
22280 || (NOTE_KIND (next_note) != NOTE_INSN_VAR_LOCATION
22281 && NOTE_KIND (next_note) != NOTE_INSN_CALL_ARG_LOCATION))
22285 next_real = next_real_insn (loc_note);
22289 expected_next_loc_note = next_note;
22290 cached_next_real_insn = next_real;
22293 cached_next_real_insn = NULL;
22295 /* If there are no instructions which would be affected by this note,
22296 don't do anything. */
22298 && next_real == NULL_RTX
22299 && !NOTE_DURING_CALL_P (loc_note))
22302 if (next_real == NULL_RTX)
22303 next_real = get_last_insn ();
22305 /* If there were any real insns between note we processed last time
22306 and this note (or if it is the first note), clear
22307 last_{,postcall_}label so that they are not reused this time. */
22308 if (last_var_location_insn == NULL_RTX
22309 || last_var_location_insn != next_real
22310 || last_in_cold_section_p != in_cold_section_p)
22313 last_postcall_label = NULL;
22318 decl = NOTE_VAR_LOCATION_DECL (loc_note);
22319 newloc = add_var_loc_to_decl (decl, loc_note,
22320 NOTE_DURING_CALL_P (loc_note)
22321 ? last_postcall_label : last_label);
22322 if (newloc == NULL)
22331 /* If there were no real insns between note we processed last time
22332 and this note, use the label we emitted last time. Otherwise
22333 create a new label and emit it. */
22334 if (last_label == NULL)
22336 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
22337 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
22339 last_label = ggc_strdup (loclabel);
22340 /* See if loclabel might be equal to .Ltext0. If yes,
22341 bump first_loclabel_num_not_at_text_label. */
22342 if (!have_multiple_function_sections
22343 && in_first_function_p
22344 && maybe_at_text_label_p)
22346 static rtx_insn *last_start;
22348 for (insn = loc_note; insn; insn = previous_insn (insn))
22349 if (insn == last_start)
22351 else if (!NONDEBUG_INSN_P (insn))
22355 rtx body = PATTERN (insn);
22356 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
22358 /* Inline asm could occupy zero bytes. */
22359 else if (GET_CODE (body) == ASM_INPUT
22360 || asm_noperands (body) >= 0)
22362 #ifdef HAVE_attr_length
22363 else if (get_attr_min_length (insn) == 0)
22368 /* Assume insn has non-zero length. */
22369 maybe_at_text_label_p = false;
22373 if (maybe_at_text_label_p)
22375 last_start = loc_note;
22376 first_loclabel_num_not_at_text_label = loclabel_num;
22383 struct call_arg_loc_node *ca_loc
22384 = ggc_cleared_alloc<call_arg_loc_node> ();
22385 rtx_insn *prev = prev_real_insn (loc_note);
22387 ca_loc->call_arg_loc_note = loc_note;
22388 ca_loc->next = NULL;
22389 ca_loc->label = last_label;
22392 || (NONJUMP_INSN_P (prev)
22393 && GET_CODE (PATTERN (prev)) == SEQUENCE
22394 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
22395 if (!CALL_P (prev))
22396 prev = as_a <rtx_sequence *> (PATTERN (prev))->insn (0);
22397 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
22398 x = get_call_rtx_from (PATTERN (prev));
22401 x = XEXP (XEXP (x, 0), 0);
22402 if (GET_CODE (x) == SYMBOL_REF
22403 && SYMBOL_REF_DECL (x)
22404 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
22405 ca_loc->symbol_ref = x;
22407 ca_loc->block = insn_scope (prev);
22408 if (call_arg_locations)
22409 call_arg_loc_last->next = ca_loc;
22411 call_arg_locations = ca_loc;
22412 call_arg_loc_last = ca_loc;
22414 else if (!NOTE_DURING_CALL_P (loc_note))
22415 newloc->label = last_label;
22418 if (!last_postcall_label)
22420 sprintf (loclabel, "%s-1", last_label);
22421 last_postcall_label = ggc_strdup (loclabel);
22423 newloc->label = last_postcall_label;
22426 last_var_location_insn = next_real;
22427 last_in_cold_section_p = in_cold_section_p;
22430 /* Note in one location list that text section has changed. */
22433 var_location_switch_text_section_1 (var_loc_list **slot, void *)
22435 var_loc_list *list = *slot;
22437 list->last_before_switch
22438 = list->last->next ? list->last->next : list->last;
22442 /* Note in all location lists that text section has changed. */
22445 var_location_switch_text_section (void)
22447 if (decl_loc_table == NULL)
22450 decl_loc_table->traverse<void *, var_location_switch_text_section_1> (NULL);
22453 /* Create a new line number table. */
22455 static dw_line_info_table *
22456 new_line_info_table (void)
22458 dw_line_info_table *table;
22460 table = ggc_cleared_alloc<dw_line_info_table> ();
22461 table->file_num = 1;
22462 table->line_num = 1;
22463 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
22468 /* Lookup the "current" table into which we emit line info, so
22469 that we don't have to do it for every source line. */
22472 set_cur_line_info_table (section *sec)
22474 dw_line_info_table *table;
22476 if (sec == text_section)
22477 table = text_section_line_info;
22478 else if (sec == cold_text_section)
22480 table = cold_text_section_line_info;
22483 cold_text_section_line_info = table = new_line_info_table ();
22484 table->end_label = cold_end_label;
22489 const char *end_label;
22491 if (flag_reorder_blocks_and_partition)
22493 if (in_cold_section_p)
22494 end_label = crtl->subsections.cold_section_end_label;
22496 end_label = crtl->subsections.hot_section_end_label;
22500 char label[MAX_ARTIFICIAL_LABEL_BYTES];
22501 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
22502 current_function_funcdef_no);
22503 end_label = ggc_strdup (label);
22506 table = new_line_info_table ();
22507 table->end_label = end_label;
22509 vec_safe_push (separate_line_info, table);
22512 if (DWARF2_ASM_LINE_DEBUG_INFO)
22513 table->is_stmt = (cur_line_info_table
22514 ? cur_line_info_table->is_stmt
22515 : DWARF_LINE_DEFAULT_IS_STMT_START);
22516 cur_line_info_table = table;
22520 /* We need to reset the locations at the beginning of each
22521 function. We can't do this in the end_function hook, because the
22522 declarations that use the locations won't have been output when
22523 that hook is called. Also compute have_multiple_function_sections here. */
22526 dwarf2out_begin_function (tree fun)
22528 section *sec = function_section (fun);
22530 if (sec != text_section)
22531 have_multiple_function_sections = true;
22533 if (flag_reorder_blocks_and_partition && !cold_text_section)
22535 gcc_assert (current_function_decl == fun);
22536 cold_text_section = unlikely_text_section ();
22537 switch_to_section (cold_text_section);
22538 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
22539 switch_to_section (sec);
22542 dwarf2out_note_section_used ();
22543 call_site_count = 0;
22544 tail_call_site_count = 0;
22546 set_cur_line_info_table (sec);
22549 /* Helper function of dwarf2out_end_function, called only after emitting
22550 the very first function into assembly. Check if some .debug_loc range
22551 might end with a .LVL* label that could be equal to .Ltext0.
22552 In that case we must force using absolute addresses in .debug_loc ranges,
22553 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
22554 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
22556 Set have_multiple_function_sections to true in that case and
22557 terminate htab traversal. */
22560 find_empty_loc_ranges_at_text_label (var_loc_list **slot, int)
22562 var_loc_list *entry = *slot;
22563 struct var_loc_node *node;
22565 node = entry->first;
22566 if (node && node->next && node->next->label)
22569 const char *label = node->next->label;
22570 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
22572 for (i = 0; i < first_loclabel_num_not_at_text_label; i++)
22574 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", i);
22575 if (strcmp (label, loclabel) == 0)
22577 have_multiple_function_sections = true;
22585 /* Hook called after emitting a function into assembly.
22586 This does something only for the very first function emitted. */
22589 dwarf2out_end_function (unsigned int)
22591 if (in_first_function_p
22592 && !have_multiple_function_sections
22593 && first_loclabel_num_not_at_text_label
22595 decl_loc_table->traverse<int, find_empty_loc_ranges_at_text_label> (0);
22596 in_first_function_p = false;
22597 maybe_at_text_label_p = false;
22600 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
22601 front-ends register a translation unit even before dwarf2out_init is
22603 static tree main_translation_unit = NULL_TREE;
22605 /* Hook called by front-ends after they built their main translation unit.
22606 Associate comp_unit_die to UNIT. */
22609 dwarf2out_register_main_translation_unit (tree unit)
22611 gcc_assert (TREE_CODE (unit) == TRANSLATION_UNIT_DECL
22612 && main_translation_unit == NULL_TREE);
22613 main_translation_unit = unit;
22614 /* If dwarf2out_init has not been called yet, it will perform the association
22615 itself looking at main_translation_unit. */
22616 if (decl_die_table != NULL)
22617 equate_decl_number_to_die (unit, comp_unit_die ());
22620 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22623 push_dw_line_info_entry (dw_line_info_table *table,
22624 enum dw_line_info_opcode opcode, unsigned int val)
22626 dw_line_info_entry e;
22629 vec_safe_push (table->entries, e);
22632 /* Output a label to mark the beginning of a source code line entry
22633 and record information relating to this source line, in
22634 'line_info_table' for later output of the .debug_line section. */
22635 /* ??? The discriminator parameter ought to be unsigned. */
22638 dwarf2out_source_line (unsigned int line, const char *filename,
22639 int discriminator, bool is_stmt)
22641 unsigned int file_num;
22642 dw_line_info_table *table;
22644 if (debug_info_level < DINFO_LEVEL_TERSE || line == 0)
22647 /* The discriminator column was added in dwarf4. Simplify the below
22648 by simply removing it if we're not supposed to output it. */
22649 if (dwarf_version < 4 && dwarf_strict)
22652 table = cur_line_info_table;
22653 file_num = maybe_emit_file (lookup_filename (filename));
22655 /* ??? TODO: Elide duplicate line number entries. Traditionally,
22656 the debugger has used the second (possibly duplicate) line number
22657 at the beginning of the function to mark the end of the prologue.
22658 We could eliminate any other duplicates within the function. For
22659 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
22660 that second line number entry. */
22661 /* Recall that this end-of-prologue indication is *not* the same thing
22662 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
22663 to which the hook corresponds, follows the last insn that was
22664 emitted by gen_prologue. What we need is to precede the first insn
22665 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
22666 insn that corresponds to something the user wrote. These may be
22667 very different locations once scheduling is enabled. */
22669 if (0 && file_num == table->file_num
22670 && line == table->line_num
22671 && discriminator == table->discrim_num
22672 && is_stmt == table->is_stmt)
22675 switch_to_section (current_function_section ());
22677 /* If requested, emit something human-readable. */
22678 if (flag_debug_asm)
22679 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
22681 if (DWARF2_ASM_LINE_DEBUG_INFO)
22683 /* Emit the .loc directive understood by GNU as. */
22684 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
22685 file_num, line, is_stmt, discriminator */
22686 fputs ("\t.loc ", asm_out_file);
22687 fprint_ul (asm_out_file, file_num);
22688 putc (' ', asm_out_file);
22689 fprint_ul (asm_out_file, line);
22690 putc (' ', asm_out_file);
22691 putc ('0', asm_out_file);
22693 if (is_stmt != table->is_stmt)
22695 fputs (" is_stmt ", asm_out_file);
22696 putc (is_stmt ? '1' : '0', asm_out_file);
22698 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
22700 gcc_assert (discriminator > 0);
22701 fputs (" discriminator ", asm_out_file);
22702 fprint_ul (asm_out_file, (unsigned long) discriminator);
22704 putc ('\n', asm_out_file);
22708 unsigned int label_num = ++line_info_label_num;
22710 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
22712 push_dw_line_info_entry (table, LI_set_address, label_num);
22713 if (file_num != table->file_num)
22714 push_dw_line_info_entry (table, LI_set_file, file_num);
22715 if (discriminator != table->discrim_num)
22716 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
22717 if (is_stmt != table->is_stmt)
22718 push_dw_line_info_entry (table, LI_negate_stmt, 0);
22719 push_dw_line_info_entry (table, LI_set_line, line);
22722 table->file_num = file_num;
22723 table->line_num = line;
22724 table->discrim_num = discriminator;
22725 table->is_stmt = is_stmt;
22726 table->in_use = true;
22729 /* Record the beginning of a new source file. */
22732 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
22734 if (flag_eliminate_dwarf2_dups)
22736 /* Record the beginning of the file for break_out_includes. */
22737 dw_die_ref bincl_die;
22739 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
22740 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
22743 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22746 e.code = DW_MACINFO_start_file;
22748 e.info = ggc_strdup (filename);
22749 vec_safe_push (macinfo_table, e);
22753 /* Record the end of a source file. */
22756 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
22758 if (flag_eliminate_dwarf2_dups)
22759 /* Record the end of the file for break_out_includes. */
22760 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
22762 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22765 e.code = DW_MACINFO_end_file;
22768 vec_safe_push (macinfo_table, e);
22772 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22773 the tail part of the directive line, i.e. the part which is past the
22774 initial whitespace, #, whitespace, directive-name, whitespace part. */
22777 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
22778 const char *buffer ATTRIBUTE_UNUSED)
22780 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22783 /* Insert a dummy first entry to be able to optimize the whole
22784 predefined macro block using DW_MACRO_GNU_transparent_include. */
22785 if (macinfo_table->is_empty () && lineno <= 1)
22790 vec_safe_push (macinfo_table, e);
22792 e.code = DW_MACINFO_define;
22794 e.info = ggc_strdup (buffer);
22795 vec_safe_push (macinfo_table, e);
22799 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22800 the tail part of the directive line, i.e. the part which is past the
22801 initial whitespace, #, whitespace, directive-name, whitespace part. */
22804 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
22805 const char *buffer ATTRIBUTE_UNUSED)
22807 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22810 /* Insert a dummy first entry to be able to optimize the whole
22811 predefined macro block using DW_MACRO_GNU_transparent_include. */
22812 if (macinfo_table->is_empty () && lineno <= 1)
22817 vec_safe_push (macinfo_table, e);
22819 e.code = DW_MACINFO_undef;
22821 e.info = ggc_strdup (buffer);
22822 vec_safe_push (macinfo_table, e);
22826 /* Helpers to manipulate hash table of CUs. */
22828 struct macinfo_entry_hasher : nofree_ptr_hash <macinfo_entry>
22830 static inline hashval_t hash (const macinfo_entry *);
22831 static inline bool equal (const macinfo_entry *, const macinfo_entry *);
22835 macinfo_entry_hasher::hash (const macinfo_entry *entry)
22837 return htab_hash_string (entry->info);
22841 macinfo_entry_hasher::equal (const macinfo_entry *entry1,
22842 const macinfo_entry *entry2)
22844 return !strcmp (entry1->info, entry2->info);
22847 typedef hash_table<macinfo_entry_hasher> macinfo_hash_type;
22849 /* Output a single .debug_macinfo entry. */
22852 output_macinfo_op (macinfo_entry *ref)
22856 struct indirect_string_node *node;
22857 char label[MAX_ARTIFICIAL_LABEL_BYTES];
22858 struct dwarf_file_data *fd;
22862 case DW_MACINFO_start_file:
22863 fd = lookup_filename (ref->info);
22864 file_num = maybe_emit_file (fd);
22865 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
22866 dw2_asm_output_data_uleb128 (ref->lineno,
22867 "Included from line number %lu",
22868 (unsigned long) ref->lineno);
22869 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
22871 case DW_MACINFO_end_file:
22872 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
22874 case DW_MACINFO_define:
22875 case DW_MACINFO_undef:
22876 len = strlen (ref->info) + 1;
22878 && len > DWARF_OFFSET_SIZE
22879 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22880 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
22882 ref->code = ref->code == DW_MACINFO_define
22883 ? DW_MACRO_GNU_define_indirect
22884 : DW_MACRO_GNU_undef_indirect;
22885 output_macinfo_op (ref);
22888 dw2_asm_output_data (1, ref->code,
22889 ref->code == DW_MACINFO_define
22890 ? "Define macro" : "Undefine macro");
22891 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22892 (unsigned long) ref->lineno);
22893 dw2_asm_output_nstring (ref->info, -1, "The macro");
22895 case DW_MACRO_GNU_define_indirect:
22896 case DW_MACRO_GNU_undef_indirect:
22897 node = find_AT_string (ref->info);
22899 && ((node->form == DW_FORM_strp)
22900 || (node->form == DW_FORM_GNU_str_index)));
22901 dw2_asm_output_data (1, ref->code,
22902 ref->code == DW_MACRO_GNU_define_indirect
22903 ? "Define macro indirect"
22904 : "Undefine macro indirect");
22905 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22906 (unsigned long) ref->lineno);
22907 if (node->form == DW_FORM_strp)
22908 dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
22909 debug_str_section, "The macro: \"%s\"",
22912 dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
22915 case DW_MACRO_GNU_transparent_include:
22916 dw2_asm_output_data (1, ref->code, "Transparent include");
22917 ASM_GENERATE_INTERNAL_LABEL (label,
22918 DEBUG_MACRO_SECTION_LABEL, ref->lineno);
22919 dw2_asm_output_offset (DWARF_OFFSET_SIZE, label, NULL, NULL);
22922 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
22923 ASM_COMMENT_START, (unsigned long) ref->code);
22928 /* Attempt to make a sequence of define/undef macinfo ops shareable with
22929 other compilation unit .debug_macinfo sections. IDX is the first
22930 index of a define/undef, return the number of ops that should be
22931 emitted in a comdat .debug_macinfo section and emit
22932 a DW_MACRO_GNU_transparent_include entry referencing it.
22933 If the define/undef entry should be emitted normally, return 0. */
22936 optimize_macinfo_range (unsigned int idx, vec<macinfo_entry, va_gc> *files,
22937 macinfo_hash_type **macinfo_htab)
22939 macinfo_entry *first, *second, *cur, *inc;
22940 char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
22941 unsigned char checksum[16];
22942 struct md5_ctx ctx;
22943 char *grp_name, *tail;
22945 unsigned int i, count, encoded_filename_len, linebuf_len;
22946 macinfo_entry **slot;
22948 first = &(*macinfo_table)[idx];
22949 second = &(*macinfo_table)[idx + 1];
22951 /* Optimize only if there are at least two consecutive define/undef ops,
22952 and either all of them are before first DW_MACINFO_start_file
22953 with lineno {0,1} (i.e. predefined macro block), or all of them are
22954 in some included header file. */
22955 if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
22957 if (vec_safe_is_empty (files))
22959 if (first->lineno > 1 || second->lineno > 1)
22962 else if (first->lineno == 0)
22965 /* Find the last define/undef entry that can be grouped together
22966 with first and at the same time compute md5 checksum of their
22967 codes, linenumbers and strings. */
22968 md5_init_ctx (&ctx);
22969 for (i = idx; macinfo_table->iterate (i, &cur); i++)
22970 if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
22972 else if (vec_safe_is_empty (files) && cur->lineno > 1)
22976 unsigned char code = cur->code;
22977 md5_process_bytes (&code, 1, &ctx);
22978 checksum_uleb128 (cur->lineno, &ctx);
22979 md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
22981 md5_finish_ctx (&ctx, checksum);
22984 /* From the containing include filename (if any) pick up just
22985 usable characters from its basename. */
22986 if (vec_safe_is_empty (files))
22989 base = lbasename (files->last ().info);
22990 for (encoded_filename_len = 0, i = 0; base[i]; i++)
22991 if (ISIDNUM (base[i]) || base[i] == '.')
22992 encoded_filename_len++;
22993 /* Count . at the end. */
22994 if (encoded_filename_len)
22995 encoded_filename_len++;
22997 sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
22998 linebuf_len = strlen (linebuf);
23000 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
23001 grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
23003 memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4);
23004 tail = grp_name + 4;
23005 if (encoded_filename_len)
23007 for (i = 0; base[i]; i++)
23008 if (ISIDNUM (base[i]) || base[i] == '.')
23012 memcpy (tail, linebuf, linebuf_len);
23013 tail += linebuf_len;
23015 for (i = 0; i < 16; i++)
23016 sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
23018 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
23019 in the empty vector entry before the first define/undef. */
23020 inc = &(*macinfo_table)[idx - 1];
23021 inc->code = DW_MACRO_GNU_transparent_include;
23023 inc->info = ggc_strdup (grp_name);
23024 if (!*macinfo_htab)
23025 *macinfo_htab = new macinfo_hash_type (10);
23026 /* Avoid emitting duplicates. */
23027 slot = (*macinfo_htab)->find_slot (inc, INSERT);
23032 /* If such an entry has been used before, just emit
23033 a DW_MACRO_GNU_transparent_include op. */
23035 output_macinfo_op (inc);
23036 /* And clear all macinfo_entry in the range to avoid emitting them
23037 in the second pass. */
23038 for (i = idx; macinfo_table->iterate (i, &cur) && i < idx + count; i++)
23047 inc->lineno = (*macinfo_htab)->elements ();
23048 output_macinfo_op (inc);
23053 /* Save any strings needed by the macinfo table in the debug str
23054 table. All strings must be collected into the table by the time
23055 index_string is called. */
23058 save_macinfo_strings (void)
23062 macinfo_entry *ref;
23064 for (i = 0; macinfo_table && macinfo_table->iterate (i, &ref); i++)
23068 /* Match the logic in output_macinfo_op to decide on
23069 indirect strings. */
23070 case DW_MACINFO_define:
23071 case DW_MACINFO_undef:
23072 len = strlen (ref->info) + 1;
23074 && len > DWARF_OFFSET_SIZE
23075 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
23076 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
23077 set_indirect_string (find_AT_string (ref->info));
23079 case DW_MACRO_GNU_define_indirect:
23080 case DW_MACRO_GNU_undef_indirect:
23081 set_indirect_string (find_AT_string (ref->info));
23089 /* Output macinfo section(s). */
23092 output_macinfo (void)
23095 unsigned long length = vec_safe_length (macinfo_table);
23096 macinfo_entry *ref;
23097 vec<macinfo_entry, va_gc> *files = NULL;
23098 macinfo_hash_type *macinfo_htab = NULL;
23103 /* output_macinfo* uses these interchangeably. */
23104 gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_GNU_define
23105 && (int) DW_MACINFO_undef == (int) DW_MACRO_GNU_undef
23106 && (int) DW_MACINFO_start_file == (int) DW_MACRO_GNU_start_file
23107 && (int) DW_MACINFO_end_file == (int) DW_MACRO_GNU_end_file);
23109 /* For .debug_macro emit the section header. */
23112 dw2_asm_output_data (2, 4, "DWARF macro version number");
23113 if (DWARF_OFFSET_SIZE == 8)
23114 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
23116 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
23117 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
23118 (!dwarf_split_debug_info ? debug_line_section_label
23119 : debug_skeleton_line_section_label),
23120 debug_line_section, NULL);
23123 /* In the first loop, it emits the primary .debug_macinfo section
23124 and after each emitted op the macinfo_entry is cleared.
23125 If a longer range of define/undef ops can be optimized using
23126 DW_MACRO_GNU_transparent_include, the
23127 DW_MACRO_GNU_transparent_include op is emitted and kept in
23128 the vector before the first define/undef in the range and the
23129 whole range of define/undef ops is not emitted and kept. */
23130 for (i = 0; macinfo_table->iterate (i, &ref); i++)
23134 case DW_MACINFO_start_file:
23135 vec_safe_push (files, *ref);
23137 case DW_MACINFO_end_file:
23138 if (!vec_safe_is_empty (files))
23141 case DW_MACINFO_define:
23142 case DW_MACINFO_undef:
23144 && HAVE_COMDAT_GROUP
23145 && vec_safe_length (files) != 1
23148 && (*macinfo_table)[i - 1].code == 0)
23150 unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
23159 /* A dummy entry may be inserted at the beginning to be able
23160 to optimize the whole block of predefined macros. */
23166 output_macinfo_op (ref);
23174 delete macinfo_htab;
23175 macinfo_htab = NULL;
23177 /* If any DW_MACRO_GNU_transparent_include were used, on those
23178 DW_MACRO_GNU_transparent_include entries terminate the
23179 current chain and switch to a new comdat .debug_macinfo
23180 section and emit the define/undef entries within it. */
23181 for (i = 0; macinfo_table->iterate (i, &ref); i++)
23186 case DW_MACRO_GNU_transparent_include:
23188 char label[MAX_ARTIFICIAL_LABEL_BYTES];
23189 tree comdat_key = get_identifier (ref->info);
23190 /* Terminate the previous .debug_macinfo section. */
23191 dw2_asm_output_data (1, 0, "End compilation unit");
23192 targetm.asm_out.named_section (DEBUG_MACRO_SECTION,
23194 | SECTION_LINKONCE,
23196 ASM_GENERATE_INTERNAL_LABEL (label,
23197 DEBUG_MACRO_SECTION_LABEL,
23199 ASM_OUTPUT_LABEL (asm_out_file, label);
23202 dw2_asm_output_data (2, 4, "DWARF macro version number");
23203 if (DWARF_OFFSET_SIZE == 8)
23204 dw2_asm_output_data (1, 1, "Flags: 64-bit");
23206 dw2_asm_output_data (1, 0, "Flags: 32-bit");
23209 case DW_MACINFO_define:
23210 case DW_MACINFO_undef:
23211 output_macinfo_op (ref);
23216 gcc_unreachable ();
23220 /* Set up for Dwarf output at the start of compilation. */
23223 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
23225 /* This option is currently broken, see (PR53118 and PR46102). */
23226 if (flag_eliminate_dwarf2_dups
23227 && strstr (lang_hooks.name, "C++"))
23229 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
23230 flag_eliminate_dwarf2_dups = 0;
23233 /* Allocate the file_table. */
23234 file_table = hash_table<dwarf_file_hasher>::create_ggc (50);
23236 #ifndef DWARF2_LINENO_DEBUGGING_INFO
23237 /* Allocate the decl_die_table. */
23238 decl_die_table = hash_table<decl_die_hasher>::create_ggc (10);
23240 /* Allocate the decl_loc_table. */
23241 decl_loc_table = hash_table<decl_loc_hasher>::create_ggc (10);
23243 /* Allocate the cached_dw_loc_list_table. */
23244 cached_dw_loc_list_table = hash_table<dw_loc_list_hasher>::create_ggc (10);
23246 /* Allocate the initial hunk of the decl_scope_table. */
23247 vec_alloc (decl_scope_table, 256);
23249 /* Allocate the initial hunk of the abbrev_die_table. */
23250 abbrev_die_table = ggc_cleared_vec_alloc<dw_die_ref>
23251 (ABBREV_DIE_TABLE_INCREMENT);
23252 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
23253 /* Zero-th entry is allocated, but unused. */
23254 abbrev_die_table_in_use = 1;
23256 /* Allocate the pubtypes and pubnames vectors. */
23257 vec_alloc (pubname_table, 32);
23258 vec_alloc (pubtype_table, 32);
23260 vec_alloc (incomplete_types, 64);
23262 vec_alloc (used_rtx_array, 32);
23264 if (!dwarf_split_debug_info)
23266 debug_info_section = get_section (DEBUG_INFO_SECTION,
23267 SECTION_DEBUG, NULL);
23268 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
23269 SECTION_DEBUG, NULL);
23270 debug_loc_section = get_section (DEBUG_LOC_SECTION,
23271 SECTION_DEBUG, NULL);
23275 debug_info_section = get_section (DEBUG_DWO_INFO_SECTION,
23276 SECTION_DEBUG | SECTION_EXCLUDE, NULL);
23277 debug_abbrev_section = get_section (DEBUG_DWO_ABBREV_SECTION,
23278 SECTION_DEBUG | SECTION_EXCLUDE,
23280 debug_addr_section = get_section (DEBUG_ADDR_SECTION,
23281 SECTION_DEBUG, NULL);
23282 debug_skeleton_info_section = get_section (DEBUG_INFO_SECTION,
23283 SECTION_DEBUG, NULL);
23284 debug_skeleton_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
23285 SECTION_DEBUG, NULL);
23286 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
23287 DEBUG_SKELETON_ABBREV_SECTION_LABEL, 0);
23289 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
23290 the main .o, but the skeleton_line goes into the split off dwo. */
23291 debug_skeleton_line_section
23292 = get_section (DEBUG_DWO_LINE_SECTION,
23293 SECTION_DEBUG | SECTION_EXCLUDE, NULL);
23294 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
23295 DEBUG_SKELETON_LINE_SECTION_LABEL, 0);
23296 debug_str_offsets_section = get_section (DEBUG_STR_OFFSETS_SECTION,
23297 SECTION_DEBUG | SECTION_EXCLUDE,
23299 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
23300 DEBUG_SKELETON_INFO_SECTION_LABEL, 0);
23301 debug_loc_section = get_section (DEBUG_DWO_LOC_SECTION,
23302 SECTION_DEBUG | SECTION_EXCLUDE, NULL);
23303 debug_str_dwo_section = get_section (DEBUG_STR_DWO_SECTION,
23304 DEBUG_STR_DWO_SECTION_FLAGS, NULL);
23306 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
23307 SECTION_DEBUG, NULL);
23308 debug_macinfo_section = get_section (dwarf_strict
23309 ? DEBUG_MACINFO_SECTION
23310 : DEBUG_MACRO_SECTION,
23311 DEBUG_MACRO_SECTION_FLAGS, NULL);
23312 debug_line_section = get_section (DEBUG_LINE_SECTION,
23313 SECTION_DEBUG, NULL);
23314 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
23315 SECTION_DEBUG, NULL);
23316 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
23317 SECTION_DEBUG, NULL);
23318 debug_str_section = get_section (DEBUG_STR_SECTION,
23319 DEBUG_STR_SECTION_FLAGS, NULL);
23320 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
23321 SECTION_DEBUG, NULL);
23322 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
23323 SECTION_DEBUG, NULL);
23325 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
23326 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
23327 DEBUG_ABBREV_SECTION_LABEL, 0);
23328 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
23329 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
23330 COLD_TEXT_SECTION_LABEL, 0);
23331 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
23333 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
23334 DEBUG_INFO_SECTION_LABEL, 0);
23335 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
23336 DEBUG_LINE_SECTION_LABEL, 0);
23337 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
23338 DEBUG_RANGES_SECTION_LABEL, 0);
23339 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label,
23340 DEBUG_ADDR_SECTION_LABEL, 0);
23341 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
23343 ? DEBUG_MACINFO_SECTION_LABEL
23344 : DEBUG_MACRO_SECTION_LABEL, 0);
23345 ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
23347 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23348 vec_alloc (macinfo_table, 64);
23350 switch_to_section (text_section);
23351 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
23354 /* Make sure the line number table for .text always exists. */
23355 text_section_line_info = new_line_info_table ();
23356 text_section_line_info->end_label = text_end_label;
23358 #ifdef DWARF2_LINENO_DEBUGGING_INFO
23359 cur_line_info_table = text_section_line_info;
23362 /* If front-ends already registered a main translation unit but we were not
23363 ready to perform the association, do this now. */
23364 if (main_translation_unit != NULL_TREE)
23365 equate_decl_number_to_die (main_translation_unit, comp_unit_die ());
23368 /* Called before compile () starts outputtting functions, variables
23369 and toplevel asms into assembly. */
23372 dwarf2out_assembly_start (void)
23374 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23375 && dwarf2out_do_cfi_asm ()
23376 && (!(flag_unwind_tables || flag_exceptions)
23377 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
23378 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
23381 /* A helper function for dwarf2out_finish called through
23382 htab_traverse. Assign a string its index. All strings must be
23383 collected into the table by the time index_string is called,
23384 because the indexing code relies on htab_traverse to traverse nodes
23385 in the same order for each run. */
23388 index_string (indirect_string_node **h, unsigned int *index)
23390 indirect_string_node *node = *h;
23392 find_string_form (node);
23393 if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
23395 gcc_assert (node->index == NO_INDEX_ASSIGNED);
23396 node->index = *index;
23402 /* A helper function for output_indirect_strings called through
23403 htab_traverse. Output the offset to a string and update the
23407 output_index_string_offset (indirect_string_node **h, unsigned int *offset)
23409 indirect_string_node *node = *h;
23411 if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
23413 /* Assert that this node has been assigned an index. */
23414 gcc_assert (node->index != NO_INDEX_ASSIGNED
23415 && node->index != NOT_INDEXED);
23416 dw2_asm_output_data (DWARF_OFFSET_SIZE, *offset,
23417 "indexed string 0x%x: %s", node->index, node->str);
23418 *offset += strlen (node->str) + 1;
23423 /* A helper function for dwarf2out_finish called through
23424 htab_traverse. Output the indexed string. */
23427 output_index_string (indirect_string_node **h, unsigned int *cur_idx)
23429 struct indirect_string_node *node = *h;
23431 if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
23433 /* Assert that the strings are output in the same order as their
23434 indexes were assigned. */
23435 gcc_assert (*cur_idx == node->index);
23436 assemble_string (node->str, strlen (node->str) + 1);
23442 /* A helper function for dwarf2out_finish called through
23443 htab_traverse. Emit one queued .debug_str string. */
23446 output_indirect_string (indirect_string_node **h, void *)
23448 struct indirect_string_node *node = *h;
23450 node->form = find_string_form (node);
23451 if (node->form == DW_FORM_strp && node->refcount > 0)
23453 ASM_OUTPUT_LABEL (asm_out_file, node->label);
23454 assemble_string (node->str, strlen (node->str) + 1);
23460 /* Output the indexed string table. */
23463 output_indirect_strings (void)
23465 switch_to_section (debug_str_section);
23466 if (!dwarf_split_debug_info)
23467 debug_str_hash->traverse<void *, output_indirect_string> (NULL);
23470 unsigned int offset = 0;
23471 unsigned int cur_idx = 0;
23473 skeleton_debug_str_hash->traverse<void *, output_indirect_string> (NULL);
23475 switch_to_section (debug_str_offsets_section);
23476 debug_str_hash->traverse_noresize
23477 <unsigned int *, output_index_string_offset> (&offset);
23478 switch_to_section (debug_str_dwo_section);
23479 debug_str_hash->traverse_noresize<unsigned int *, output_index_string>
23484 /* Callback for htab_traverse to assign an index to an entry in the
23485 table, and to write that entry to the .debug_addr section. */
23488 output_addr_table_entry (addr_table_entry **slot, unsigned int *cur_index)
23490 addr_table_entry *entry = *slot;
23492 if (entry->refcount == 0)
23494 gcc_assert (entry->index == NO_INDEX_ASSIGNED
23495 || entry->index == NOT_INDEXED);
23499 gcc_assert (entry->index == *cur_index);
23502 switch (entry->kind)
23505 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, entry->addr.rtl,
23506 "0x%x", entry->index);
23508 case ate_kind_rtx_dtprel:
23509 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
23510 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
23513 fputc ('\n', asm_out_file);
23515 case ate_kind_label:
23516 dw2_asm_output_addr (DWARF2_ADDR_SIZE, entry->addr.label,
23517 "0x%x", entry->index);
23520 gcc_unreachable ();
23525 /* Produce the .debug_addr section. */
23528 output_addr_table (void)
23530 unsigned int index = 0;
23531 if (addr_index_table == NULL || addr_index_table->size () == 0)
23534 switch_to_section (debug_addr_section);
23536 ->traverse_noresize<unsigned int *, output_addr_table_entry> (&index);
23539 #if ENABLE_ASSERT_CHECKING
23540 /* Verify that all marks are clear. */
23543 verify_marks_clear (dw_die_ref die)
23547 gcc_assert (! die->die_mark);
23548 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
23550 #endif /* ENABLE_ASSERT_CHECKING */
23552 /* Clear the marks for a die and its children.
23553 Be cool if the mark isn't set. */
23556 prune_unmark_dies (dw_die_ref die)
23562 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
23565 /* Given DIE that we're marking as used, find any other dies
23566 it references as attributes and mark them as used. */
23569 prune_unused_types_walk_attribs (dw_die_ref die)
23574 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
23576 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
23578 /* A reference to another DIE.
23579 Make sure that it will get emitted.
23580 If it was broken out into a comdat group, don't follow it. */
23581 if (! AT_ref (a)->comdat_type_p
23582 || a->dw_attr == DW_AT_specification)
23583 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
23585 /* Set the string's refcount to 0 so that prune_unused_types_mark
23586 accounts properly for it. */
23587 if (AT_class (a) == dw_val_class_str)
23588 a->dw_attr_val.v.val_str->refcount = 0;
23592 /* Mark the generic parameters and arguments children DIEs of DIE. */
23595 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
23599 if (die == NULL || die->die_child == NULL)
23601 c = die->die_child;
23604 if (is_template_parameter (c))
23605 prune_unused_types_mark (c, 1);
23607 } while (c && c != die->die_child);
23610 /* Mark DIE as being used. If DOKIDS is true, then walk down
23611 to DIE's children. */
23614 prune_unused_types_mark (dw_die_ref die, int dokids)
23618 if (die->die_mark == 0)
23620 /* We haven't done this node yet. Mark it as used. */
23622 /* If this is the DIE of a generic type instantiation,
23623 mark the children DIEs that describe its generic parms and
23625 prune_unused_types_mark_generic_parms_dies (die);
23627 /* We also have to mark its parents as used.
23628 (But we don't want to mark our parent's kids due to this,
23629 unless it is a class.) */
23630 if (die->die_parent)
23631 prune_unused_types_mark (die->die_parent,
23632 class_scope_p (die->die_parent));
23634 /* Mark any referenced nodes. */
23635 prune_unused_types_walk_attribs (die);
23637 /* If this node is a specification,
23638 also mark the definition, if it exists. */
23639 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
23640 prune_unused_types_mark (die->die_definition, 1);
23643 if (dokids && die->die_mark != 2)
23645 /* We need to walk the children, but haven't done so yet.
23646 Remember that we've walked the kids. */
23649 /* If this is an array type, we need to make sure our
23650 kids get marked, even if they're types. If we're
23651 breaking out types into comdat sections, do this
23652 for all type definitions. */
23653 if (die->die_tag == DW_TAG_array_type
23654 || (use_debug_types
23655 && is_type_die (die) && ! is_declaration_die (die)))
23656 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
23658 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23662 /* For local classes, look if any static member functions were emitted
23663 and if so, mark them. */
23666 prune_unused_types_walk_local_classes (dw_die_ref die)
23670 if (die->die_mark == 2)
23673 switch (die->die_tag)
23675 case DW_TAG_structure_type:
23676 case DW_TAG_union_type:
23677 case DW_TAG_class_type:
23680 case DW_TAG_subprogram:
23681 if (!get_AT_flag (die, DW_AT_declaration)
23682 || die->die_definition != NULL)
23683 prune_unused_types_mark (die, 1);
23690 /* Mark children. */
23691 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
23694 /* Walk the tree DIE and mark types that we actually use. */
23697 prune_unused_types_walk (dw_die_ref die)
23701 /* Don't do anything if this node is already marked and
23702 children have been marked as well. */
23703 if (die->die_mark == 2)
23706 switch (die->die_tag)
23708 case DW_TAG_structure_type:
23709 case DW_TAG_union_type:
23710 case DW_TAG_class_type:
23711 if (die->die_perennial_p)
23714 for (c = die->die_parent; c; c = c->die_parent)
23715 if (c->die_tag == DW_TAG_subprogram)
23718 /* Finding used static member functions inside of classes
23719 is needed just for local classes, because for other classes
23720 static member function DIEs with DW_AT_specification
23721 are emitted outside of the DW_TAG_*_type. If we ever change
23722 it, we'd need to call this even for non-local classes. */
23724 prune_unused_types_walk_local_classes (die);
23726 /* It's a type node --- don't mark it. */
23729 case DW_TAG_const_type:
23730 case DW_TAG_packed_type:
23731 case DW_TAG_pointer_type:
23732 case DW_TAG_reference_type:
23733 case DW_TAG_rvalue_reference_type:
23734 case DW_TAG_volatile_type:
23735 case DW_TAG_typedef:
23736 case DW_TAG_array_type:
23737 case DW_TAG_interface_type:
23738 case DW_TAG_friend:
23739 case DW_TAG_variant_part:
23740 case DW_TAG_enumeration_type:
23741 case DW_TAG_subroutine_type:
23742 case DW_TAG_string_type:
23743 case DW_TAG_set_type:
23744 case DW_TAG_subrange_type:
23745 case DW_TAG_ptr_to_member_type:
23746 case DW_TAG_file_type:
23747 if (die->die_perennial_p)
23750 /* It's a type node --- don't mark it. */
23754 /* Mark everything else. */
23758 if (die->die_mark == 0)
23762 /* Now, mark any dies referenced from here. */
23763 prune_unused_types_walk_attribs (die);
23768 /* Mark children. */
23769 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
23772 /* Increment the string counts on strings referred to from DIE's
23776 prune_unused_types_update_strings (dw_die_ref die)
23781 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
23782 if (AT_class (a) == dw_val_class_str)
23784 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
23786 /* Avoid unnecessarily putting strings that are used less than
23787 twice in the hash table. */
23789 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
23791 indirect_string_node **slot
23792 = debug_str_hash->find_slot_with_hash (s->str,
23793 htab_hash_string (s->str),
23795 gcc_assert (*slot == NULL);
23801 /* Remove from the tree DIE any dies that aren't marked. */
23804 prune_unused_types_prune (dw_die_ref die)
23808 gcc_assert (die->die_mark);
23809 prune_unused_types_update_strings (die);
23811 if (! die->die_child)
23814 c = die->die_child;
23816 dw_die_ref prev = c;
23817 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
23818 if (c == die->die_child)
23820 /* No marked children between 'prev' and the end of the list. */
23822 /* No marked children at all. */
23823 die->die_child = NULL;
23826 prev->die_sib = c->die_sib;
23827 die->die_child = prev;
23832 if (c != prev->die_sib)
23834 prune_unused_types_prune (c);
23835 } while (c != die->die_child);
23838 /* Remove dies representing declarations that we never use. */
23841 prune_unused_types (void)
23844 limbo_die_node *node;
23845 comdat_type_node *ctnode;
23846 pubname_entry *pub;
23847 dw_die_ref base_type;
23849 #if ENABLE_ASSERT_CHECKING
23850 /* All the marks should already be clear. */
23851 verify_marks_clear (comp_unit_die ());
23852 for (node = limbo_die_list; node; node = node->next)
23853 verify_marks_clear (node->die);
23854 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23855 verify_marks_clear (ctnode->root_die);
23856 #endif /* ENABLE_ASSERT_CHECKING */
23858 /* Mark types that are used in global variables. */
23859 premark_types_used_by_global_vars ();
23861 /* Set the mark on nodes that are actually used. */
23862 prune_unused_types_walk (comp_unit_die ());
23863 for (node = limbo_die_list; node; node = node->next)
23864 prune_unused_types_walk (node->die);
23865 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23867 prune_unused_types_walk (ctnode->root_die);
23868 prune_unused_types_mark (ctnode->type_die, 1);
23871 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
23872 are unusual in that they are pubnames that are the children of pubtypes.
23873 They should only be marked via their parent DW_TAG_enumeration_type die,
23874 not as roots in themselves. */
23875 FOR_EACH_VEC_ELT (*pubname_table, i, pub)
23876 if (pub->die->die_tag != DW_TAG_enumerator)
23877 prune_unused_types_mark (pub->die, 1);
23878 for (i = 0; base_types.iterate (i, &base_type); i++)
23879 prune_unused_types_mark (base_type, 1);
23881 if (debug_str_hash)
23882 debug_str_hash->empty ();
23883 if (skeleton_debug_str_hash)
23884 skeleton_debug_str_hash->empty ();
23885 prune_unused_types_prune (comp_unit_die ());
23886 for (limbo_die_node **pnode = &limbo_die_list; *pnode; )
23889 if (!node->die->die_mark)
23890 *pnode = node->next;
23893 prune_unused_types_prune (node->die);
23894 pnode = &node->next;
23897 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23898 prune_unused_types_prune (ctnode->root_die);
23900 /* Leave the marks clear. */
23901 prune_unmark_dies (comp_unit_die ());
23902 for (node = limbo_die_list; node; node = node->next)
23903 prune_unmark_dies (node->die);
23904 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23905 prune_unmark_dies (ctnode->root_die);
23908 /* Set the parameter to true if there are any relative pathnames in
23911 file_table_relative_p (dwarf_file_data **slot, bool *p)
23913 struct dwarf_file_data *d = *slot;
23914 if (!IS_ABSOLUTE_PATH (d->filename))
23922 /* Helpers to manipulate hash table of comdat type units. */
23924 struct comdat_type_hasher : nofree_ptr_hash <comdat_type_node>
23926 static inline hashval_t hash (const comdat_type_node *);
23927 static inline bool equal (const comdat_type_node *, const comdat_type_node *);
23931 comdat_type_hasher::hash (const comdat_type_node *type_node)
23934 memcpy (&h, type_node->signature, sizeof (h));
23939 comdat_type_hasher::equal (const comdat_type_node *type_node_1,
23940 const comdat_type_node *type_node_2)
23942 return (! memcmp (type_node_1->signature, type_node_2->signature,
23943 DWARF_TYPE_SIGNATURE_SIZE));
23946 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23947 to the location it would have been added, should we know its
23948 DECL_ASSEMBLER_NAME when we added other attributes. This will
23949 probably improve compactness of debug info, removing equivalent
23950 abbrevs, and hide any differences caused by deferring the
23951 computation of the assembler name, triggered by e.g. PCH. */
23954 move_linkage_attr (dw_die_ref die)
23956 unsigned ix = vec_safe_length (die->die_attr);
23957 dw_attr_node linkage = (*die->die_attr)[ix - 1];
23959 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
23960 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
23964 dw_attr_node *prev = &(*die->die_attr)[ix - 1];
23966 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
23970 if (ix != vec_safe_length (die->die_attr) - 1)
23972 die->die_attr->pop ();
23973 die->die_attr->quick_insert (ix, linkage);
23977 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
23978 referenced from typed stack ops and count how often they are used. */
23981 mark_base_types (dw_loc_descr_ref loc)
23983 dw_die_ref base_type = NULL;
23985 for (; loc; loc = loc->dw_loc_next)
23987 switch (loc->dw_loc_opc)
23989 case DW_OP_GNU_regval_type:
23990 case DW_OP_GNU_deref_type:
23991 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
23993 case DW_OP_GNU_convert:
23994 case DW_OP_GNU_reinterpret:
23995 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
23998 case DW_OP_GNU_const_type:
23999 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
24001 case DW_OP_GNU_entry_value:
24002 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
24007 gcc_assert (base_type->die_parent == comp_unit_die ());
24008 if (base_type->die_mark)
24009 base_type->die_mark++;
24012 base_types.safe_push (base_type);
24013 base_type->die_mark = 1;
24018 /* Comparison function for sorting marked base types. */
24021 base_type_cmp (const void *x, const void *y)
24023 dw_die_ref dx = *(const dw_die_ref *) x;
24024 dw_die_ref dy = *(const dw_die_ref *) y;
24025 unsigned int byte_size1, byte_size2;
24026 unsigned int encoding1, encoding2;
24027 if (dx->die_mark > dy->die_mark)
24029 if (dx->die_mark < dy->die_mark)
24031 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
24032 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
24033 if (byte_size1 < byte_size2)
24035 if (byte_size1 > byte_size2)
24037 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
24038 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
24039 if (encoding1 < encoding2)
24041 if (encoding1 > encoding2)
24046 /* Move base types marked by mark_base_types as early as possible
24047 in the CU, sorted by decreasing usage count both to make the
24048 uleb128 references as small as possible and to make sure they
24049 will have die_offset already computed by calc_die_sizes when
24050 sizes of typed stack loc ops is computed. */
24053 move_marked_base_types (void)
24056 dw_die_ref base_type, die, c;
24058 if (base_types.is_empty ())
24061 /* Sort by decreasing usage count, they will be added again in that
24063 base_types.qsort (base_type_cmp);
24064 die = comp_unit_die ();
24065 c = die->die_child;
24068 dw_die_ref prev = c;
24070 while (c->die_mark)
24072 remove_child_with_prev (c, prev);
24073 /* As base types got marked, there must be at least
24074 one node other than DW_TAG_base_type. */
24075 gcc_assert (c != c->die_sib);
24079 while (c != die->die_child);
24080 gcc_assert (die->die_child);
24081 c = die->die_child;
24082 for (i = 0; base_types.iterate (i, &base_type); i++)
24084 base_type->die_mark = 0;
24085 base_type->die_sib = c->die_sib;
24086 c->die_sib = base_type;
24091 /* Helper function for resolve_addr, attempt to resolve
24092 one CONST_STRING, return true if successful. Similarly verify that
24093 SYMBOL_REFs refer to variables emitted in the current CU. */
24096 resolve_one_addr (rtx *addr)
24100 if (GET_CODE (rtl) == CONST_STRING)
24102 size_t len = strlen (XSTR (rtl, 0)) + 1;
24103 tree t = build_string (len, XSTR (rtl, 0));
24104 tree tlen = size_int (len - 1);
24106 = build_array_type (char_type_node, build_index_type (tlen));
24107 rtl = lookup_constant_def (t);
24108 if (!rtl || !MEM_P (rtl))
24110 rtl = XEXP (rtl, 0);
24111 if (GET_CODE (rtl) == SYMBOL_REF
24112 && SYMBOL_REF_DECL (rtl)
24113 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
24115 vec_safe_push (used_rtx_array, rtl);
24120 if (GET_CODE (rtl) == SYMBOL_REF
24121 && SYMBOL_REF_DECL (rtl))
24123 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
24125 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
24128 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
24132 if (GET_CODE (rtl) == CONST)
24134 subrtx_ptr_iterator::array_type array;
24135 FOR_EACH_SUBRTX_PTR (iter, array, &XEXP (rtl, 0), ALL)
24136 if (!resolve_one_addr (*iter))
24143 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
24144 if possible, and create DW_TAG_dwarf_procedure that can be referenced
24145 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
24148 string_cst_pool_decl (tree t)
24150 rtx rtl = output_constant_def (t, 1);
24151 unsigned char *array;
24152 dw_loc_descr_ref l;
24157 if (!rtl || !MEM_P (rtl))
24159 rtl = XEXP (rtl, 0);
24160 if (GET_CODE (rtl) != SYMBOL_REF
24161 || SYMBOL_REF_DECL (rtl) == NULL_TREE)
24164 decl = SYMBOL_REF_DECL (rtl);
24165 if (!lookup_decl_die (decl))
24167 len = TREE_STRING_LENGTH (t);
24168 vec_safe_push (used_rtx_array, rtl);
24169 ref = new_die (DW_TAG_dwarf_procedure, comp_unit_die (), decl);
24170 array = ggc_vec_alloc<unsigned char> (len);
24171 memcpy (array, TREE_STRING_POINTER (t), len);
24172 l = new_loc_descr (DW_OP_implicit_value, len, 0);
24173 l->dw_loc_oprnd2.val_class = dw_val_class_vec;
24174 l->dw_loc_oprnd2.v.val_vec.length = len;
24175 l->dw_loc_oprnd2.v.val_vec.elt_size = 1;
24176 l->dw_loc_oprnd2.v.val_vec.array = array;
24177 add_AT_loc (ref, DW_AT_location, l);
24178 equate_decl_number_to_die (decl, ref);
24183 /* Helper function of resolve_addr_in_expr. LOC is
24184 a DW_OP_addr followed by DW_OP_stack_value, either at the start
24185 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
24186 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
24187 with DW_OP_GNU_implicit_pointer if possible
24188 and return true, if unsuccessful, return false. */
24191 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc)
24193 rtx rtl = loc->dw_loc_oprnd1.v.val_addr;
24194 HOST_WIDE_INT offset = 0;
24195 dw_die_ref ref = NULL;
24198 if (GET_CODE (rtl) == CONST
24199 && GET_CODE (XEXP (rtl, 0)) == PLUS
24200 && CONST_INT_P (XEXP (XEXP (rtl, 0), 1)))
24202 offset = INTVAL (XEXP (XEXP (rtl, 0), 1));
24203 rtl = XEXP (XEXP (rtl, 0), 0);
24205 if (GET_CODE (rtl) == CONST_STRING)
24207 size_t len = strlen (XSTR (rtl, 0)) + 1;
24208 tree t = build_string (len, XSTR (rtl, 0));
24209 tree tlen = size_int (len - 1);
24212 = build_array_type (char_type_node, build_index_type (tlen));
24213 rtl = string_cst_pool_decl (t);
24217 if (GET_CODE (rtl) == SYMBOL_REF && SYMBOL_REF_DECL (rtl))
24219 decl = SYMBOL_REF_DECL (rtl);
24220 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
24222 ref = lookup_decl_die (decl);
24223 if (ref && (get_AT (ref, DW_AT_location)
24224 || get_AT (ref, DW_AT_const_value)))
24226 loc->dw_loc_opc = DW_OP_GNU_implicit_pointer;
24227 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
24228 loc->dw_loc_oprnd1.val_entry = NULL;
24229 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
24230 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
24231 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
24232 loc->dw_loc_oprnd2.v.val_int = offset;
24240 /* Helper function for resolve_addr, handle one location
24241 expression, return false if at least one CONST_STRING or SYMBOL_REF in
24242 the location list couldn't be resolved. */
24245 resolve_addr_in_expr (dw_loc_descr_ref loc)
24247 dw_loc_descr_ref keep = NULL;
24248 for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = loc->dw_loc_next)
24249 switch (loc->dw_loc_opc)
24252 if (!resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
24255 || prev->dw_loc_opc == DW_OP_piece
24256 || prev->dw_loc_opc == DW_OP_bit_piece)
24257 && loc->dw_loc_next
24258 && loc->dw_loc_next->dw_loc_opc == DW_OP_stack_value
24260 && optimize_one_addr_into_implicit_ptr (loc))
24265 case DW_OP_GNU_addr_index:
24266 case DW_OP_GNU_const_index:
24267 if (loc->dw_loc_opc == DW_OP_GNU_addr_index
24268 || (loc->dw_loc_opc == DW_OP_GNU_const_index && loc->dtprel))
24270 rtx rtl = loc->dw_loc_oprnd1.val_entry->addr.rtl;
24271 if (!resolve_one_addr (&rtl))
24273 remove_addr_table_entry (loc->dw_loc_oprnd1.val_entry);
24274 loc->dw_loc_oprnd1.val_entry =
24275 add_addr_table_entry (rtl, ate_kind_rtx);
24278 case DW_OP_const4u:
24279 case DW_OP_const8u:
24281 && !resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
24284 case DW_OP_plus_uconst:
24285 if (size_of_loc_descr (loc)
24286 > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
24288 && loc->dw_loc_oprnd1.v.val_unsigned > 0)
24290 dw_loc_descr_ref repl
24291 = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
24292 add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
24293 add_loc_descr (&repl, loc->dw_loc_next);
24297 case DW_OP_implicit_value:
24298 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
24299 && !resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr))
24302 case DW_OP_GNU_implicit_pointer:
24303 case DW_OP_GNU_parameter_ref:
24304 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
24307 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
24310 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
24311 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
24312 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
24315 case DW_OP_GNU_const_type:
24316 case DW_OP_GNU_regval_type:
24317 case DW_OP_GNU_deref_type:
24318 case DW_OP_GNU_convert:
24319 case DW_OP_GNU_reinterpret:
24320 while (loc->dw_loc_next
24321 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
24323 dw_die_ref base1, base2;
24324 unsigned enc1, enc2, size1, size2;
24325 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
24326 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
24327 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
24328 else if (loc->dw_loc_oprnd1.val_class
24329 == dw_val_class_unsigned_const)
24332 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
24333 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
24334 == dw_val_class_unsigned_const)
24336 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
24337 gcc_assert (base1->die_tag == DW_TAG_base_type
24338 && base2->die_tag == DW_TAG_base_type);
24339 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
24340 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
24341 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
24342 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
24344 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
24345 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
24349 /* Optimize away next DW_OP_GNU_convert after
24350 adjusting LOC's base type die reference. */
24351 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
24352 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
24353 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
24355 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
24356 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
24359 /* Don't change integer DW_OP_GNU_convert after e.g. floating
24360 point typed stack entry. */
24361 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
24362 keep = loc->dw_loc_next;
24372 /* Helper function of resolve_addr. DIE had DW_AT_location of
24373 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
24374 and DW_OP_addr couldn't be resolved. resolve_addr has already
24375 removed the DW_AT_location attribute. This function attempts to
24376 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
24377 to it or DW_AT_const_value attribute, if possible. */
24380 optimize_location_into_implicit_ptr (dw_die_ref die, tree decl)
24382 if (TREE_CODE (decl) != VAR_DECL
24383 || lookup_decl_die (decl) != die
24384 || DECL_EXTERNAL (decl)
24385 || !TREE_STATIC (decl)
24386 || DECL_INITIAL (decl) == NULL_TREE
24387 || DECL_P (DECL_INITIAL (decl))
24388 || get_AT (die, DW_AT_const_value))
24391 tree init = DECL_INITIAL (decl);
24392 HOST_WIDE_INT offset = 0;
24393 /* For variables that have been optimized away and thus
24394 don't have a memory location, see if we can emit
24395 DW_AT_const_value instead. */
24396 if (tree_add_const_value_attribute (die, init))
24400 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
24401 and ADDR_EXPR refers to a decl that has DW_AT_location or
24402 DW_AT_const_value (but isn't addressable, otherwise
24403 resolving the original DW_OP_addr wouldn't fail), see if
24404 we can add DW_OP_GNU_implicit_pointer. */
24406 if (TREE_CODE (init) == POINTER_PLUS_EXPR
24407 && tree_fits_shwi_p (TREE_OPERAND (init, 1)))
24409 offset = tree_to_shwi (TREE_OPERAND (init, 1));
24410 init = TREE_OPERAND (init, 0);
24413 if (TREE_CODE (init) != ADDR_EXPR)
24415 if ((TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST
24416 && !TREE_ASM_WRITTEN (TREE_OPERAND (init, 0)))
24417 || (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL
24418 && !DECL_EXTERNAL (TREE_OPERAND (init, 0))
24419 && TREE_OPERAND (init, 0) != decl))
24422 dw_loc_descr_ref l;
24424 if (TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST)
24426 rtx rtl = string_cst_pool_decl (TREE_OPERAND (init, 0));
24429 decl = SYMBOL_REF_DECL (rtl);
24432 decl = TREE_OPERAND (init, 0);
24433 ref = lookup_decl_die (decl);
24435 || (!get_AT (ref, DW_AT_location)
24436 && !get_AT (ref, DW_AT_const_value)))
24438 l = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
24439 l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
24440 l->dw_loc_oprnd1.v.val_die_ref.die = ref;
24441 l->dw_loc_oprnd1.v.val_die_ref.external = 0;
24442 add_AT_loc (die, DW_AT_location, l);
24446 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
24447 an address in .rodata section if the string literal is emitted there,
24448 or remove the containing location list or replace DW_AT_const_value
24449 with DW_AT_location and empty location expression, if it isn't found
24450 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
24451 to something that has been emitted in the current CU. */
24454 resolve_addr (dw_die_ref die)
24458 dw_loc_list_ref *curr, *start, loc;
24461 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
24462 switch (AT_class (a))
24464 case dw_val_class_loc_list:
24465 start = curr = AT_loc_list_ptr (a);
24468 /* The same list can be referenced more than once. See if we have
24469 already recorded the result from a previous pass. */
24471 *curr = loc->dw_loc_next;
24472 else if (!loc->resolved_addr)
24474 /* As things stand, we do not expect or allow one die to
24475 reference a suffix of another die's location list chain.
24476 References must be identical or completely separate.
24477 There is therefore no need to cache the result of this
24478 pass on any list other than the first; doing so
24479 would lead to unnecessary writes. */
24482 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
24483 if (!resolve_addr_in_expr ((*curr)->expr))
24485 dw_loc_list_ref next = (*curr)->dw_loc_next;
24486 dw_loc_descr_ref l = (*curr)->expr;
24488 if (next && (*curr)->ll_symbol)
24490 gcc_assert (!next->ll_symbol);
24491 next->ll_symbol = (*curr)->ll_symbol;
24493 if (dwarf_split_debug_info)
24494 remove_loc_list_addr_table_entries (l);
24499 mark_base_types ((*curr)->expr);
24500 curr = &(*curr)->dw_loc_next;
24504 loc->resolved_addr = 1;
24508 loc->dw_loc_next = *start;
24513 remove_AT (die, a->dw_attr);
24517 case dw_val_class_loc:
24519 dw_loc_descr_ref l = AT_loc (a);
24520 /* For -gdwarf-2 don't attempt to optimize
24521 DW_AT_data_member_location containing
24522 DW_OP_plus_uconst - older consumers might
24523 rely on it being that op instead of a more complex,
24524 but shorter, location description. */
24525 if ((dwarf_version > 2
24526 || a->dw_attr != DW_AT_data_member_location
24528 || l->dw_loc_opc != DW_OP_plus_uconst
24529 || l->dw_loc_next != NULL)
24530 && !resolve_addr_in_expr (l))
24532 if (dwarf_split_debug_info)
24533 remove_loc_list_addr_table_entries (l);
24535 && l->dw_loc_next == NULL
24536 && l->dw_loc_opc == DW_OP_addr
24537 && GET_CODE (l->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF
24538 && SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr)
24539 && a->dw_attr == DW_AT_location)
24541 tree decl = SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr);
24542 remove_AT (die, a->dw_attr);
24544 optimize_location_into_implicit_ptr (die, decl);
24547 remove_AT (die, a->dw_attr);
24551 mark_base_types (l);
24554 case dw_val_class_addr:
24555 if (a->dw_attr == DW_AT_const_value
24556 && !resolve_one_addr (&a->dw_attr_val.v.val_addr))
24558 if (AT_index (a) != NOT_INDEXED)
24559 remove_addr_table_entry (a->dw_attr_val.val_entry);
24560 remove_AT (die, a->dw_attr);
24563 if (die->die_tag == DW_TAG_GNU_call_site
24564 && a->dw_attr == DW_AT_abstract_origin)
24566 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
24567 dw_die_ref tdie = lookup_decl_die (tdecl);
24570 && DECL_EXTERNAL (tdecl)
24571 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE
24572 && (cdie = lookup_context_die (DECL_CONTEXT (tdecl))))
24574 /* Creating a full DIE for tdecl is overly expensive and
24575 at this point even wrong when in the LTO phase
24576 as it can end up generating new type DIEs we didn't
24577 output and thus optimize_external_refs will crash. */
24578 tdie = new_die (DW_TAG_subprogram, cdie, NULL_TREE);
24579 add_AT_flag (tdie, DW_AT_external, 1);
24580 add_AT_flag (tdie, DW_AT_declaration, 1);
24581 add_linkage_attr (tdie, tdecl);
24582 add_name_and_src_coords_attributes (tdie, tdecl);
24583 equate_decl_number_to_die (tdecl, tdie);
24587 a->dw_attr_val.val_class = dw_val_class_die_ref;
24588 a->dw_attr_val.v.val_die_ref.die = tdie;
24589 a->dw_attr_val.v.val_die_ref.external = 0;
24593 if (AT_index (a) != NOT_INDEXED)
24594 remove_addr_table_entry (a->dw_attr_val.val_entry);
24595 remove_AT (die, a->dw_attr);
24604 FOR_EACH_CHILD (die, c, resolve_addr (c));
24607 /* Helper routines for optimize_location_lists.
24608 This pass tries to share identical local lists in .debug_loc
24611 /* Iteratively hash operands of LOC opcode into HSTATE. */
24614 hash_loc_operands (dw_loc_descr_ref loc, inchash::hash &hstate)
24616 dw_val_ref val1 = &loc->dw_loc_oprnd1;
24617 dw_val_ref val2 = &loc->dw_loc_oprnd2;
24619 switch (loc->dw_loc_opc)
24621 case DW_OP_const4u:
24622 case DW_OP_const8u:
24626 case DW_OP_const1u:
24627 case DW_OP_const1s:
24628 case DW_OP_const2u:
24629 case DW_OP_const2s:
24630 case DW_OP_const4s:
24631 case DW_OP_const8s:
24635 case DW_OP_plus_uconst:
24671 case DW_OP_deref_size:
24672 case DW_OP_xderef_size:
24673 hstate.add_object (val1->v.val_int);
24680 gcc_assert (val1->val_class == dw_val_class_loc);
24681 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
24682 hstate.add_object (offset);
24685 case DW_OP_implicit_value:
24686 hstate.add_object (val1->v.val_unsigned);
24687 switch (val2->val_class)
24689 case dw_val_class_const:
24690 hstate.add_object (val2->v.val_int);
24692 case dw_val_class_vec:
24694 unsigned int elt_size = val2->v.val_vec.elt_size;
24695 unsigned int len = val2->v.val_vec.length;
24697 hstate.add_int (elt_size);
24698 hstate.add_int (len);
24699 hstate.add (val2->v.val_vec.array, len * elt_size);
24702 case dw_val_class_const_double:
24703 hstate.add_object (val2->v.val_double.low);
24704 hstate.add_object (val2->v.val_double.high);
24706 case dw_val_class_wide_int:
24707 hstate.add (val2->v.val_wide->get_val (),
24708 get_full_len (*val2->v.val_wide)
24709 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
24711 case dw_val_class_addr:
24712 inchash::add_rtx (val2->v.val_addr, hstate);
24715 gcc_unreachable ();
24719 case DW_OP_bit_piece:
24720 hstate.add_object (val1->v.val_int);
24721 hstate.add_object (val2->v.val_int);
24727 unsigned char dtprel = 0xd1;
24728 hstate.add_object (dtprel);
24730 inchash::add_rtx (val1->v.val_addr, hstate);
24732 case DW_OP_GNU_addr_index:
24733 case DW_OP_GNU_const_index:
24737 unsigned char dtprel = 0xd1;
24738 hstate.add_object (dtprel);
24740 inchash::add_rtx (val1->val_entry->addr.rtl, hstate);
24743 case DW_OP_GNU_implicit_pointer:
24744 hstate.add_int (val2->v.val_int);
24746 case DW_OP_GNU_entry_value:
24747 hstate.add_object (val1->v.val_loc);
24749 case DW_OP_GNU_regval_type:
24750 case DW_OP_GNU_deref_type:
24752 unsigned int byte_size
24753 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
24754 unsigned int encoding
24755 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
24756 hstate.add_object (val1->v.val_int);
24757 hstate.add_object (byte_size);
24758 hstate.add_object (encoding);
24761 case DW_OP_GNU_convert:
24762 case DW_OP_GNU_reinterpret:
24763 if (val1->val_class == dw_val_class_unsigned_const)
24765 hstate.add_object (val1->v.val_unsigned);
24769 case DW_OP_GNU_const_type:
24771 unsigned int byte_size
24772 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
24773 unsigned int encoding
24774 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
24775 hstate.add_object (byte_size);
24776 hstate.add_object (encoding);
24777 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
24779 hstate.add_object (val2->val_class);
24780 switch (val2->val_class)
24782 case dw_val_class_const:
24783 hstate.add_object (val2->v.val_int);
24785 case dw_val_class_vec:
24787 unsigned int elt_size = val2->v.val_vec.elt_size;
24788 unsigned int len = val2->v.val_vec.length;
24790 hstate.add_object (elt_size);
24791 hstate.add_object (len);
24792 hstate.add (val2->v.val_vec.array, len * elt_size);
24795 case dw_val_class_const_double:
24796 hstate.add_object (val2->v.val_double.low);
24797 hstate.add_object (val2->v.val_double.high);
24799 case dw_val_class_wide_int:
24800 hstate.add (val2->v.val_wide->get_val (),
24801 get_full_len (*val2->v.val_wide)
24802 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
24805 gcc_unreachable ();
24811 /* Other codes have no operands. */
24816 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
24819 hash_locs (dw_loc_descr_ref loc, inchash::hash &hstate)
24821 dw_loc_descr_ref l;
24822 bool sizes_computed = false;
24823 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24824 size_of_locs (loc);
24826 for (l = loc; l != NULL; l = l->dw_loc_next)
24828 enum dwarf_location_atom opc = l->dw_loc_opc;
24829 hstate.add_object (opc);
24830 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
24832 size_of_locs (loc);
24833 sizes_computed = true;
24835 hash_loc_operands (l, hstate);
24839 /* Compute hash of the whole location list LIST_HEAD. */
24842 hash_loc_list (dw_loc_list_ref list_head)
24844 dw_loc_list_ref curr = list_head;
24845 inchash::hash hstate;
24847 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
24849 hstate.add (curr->begin, strlen (curr->begin) + 1);
24850 hstate.add (curr->end, strlen (curr->end) + 1);
24852 hstate.add (curr->section, strlen (curr->section) + 1);
24853 hash_locs (curr->expr, hstate);
24855 list_head->hash = hstate.end ();
24858 /* Return true if X and Y opcodes have the same operands. */
24861 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
24863 dw_val_ref valx1 = &x->dw_loc_oprnd1;
24864 dw_val_ref valx2 = &x->dw_loc_oprnd2;
24865 dw_val_ref valy1 = &y->dw_loc_oprnd1;
24866 dw_val_ref valy2 = &y->dw_loc_oprnd2;
24868 switch (x->dw_loc_opc)
24870 case DW_OP_const4u:
24871 case DW_OP_const8u:
24875 case DW_OP_const1u:
24876 case DW_OP_const1s:
24877 case DW_OP_const2u:
24878 case DW_OP_const2s:
24879 case DW_OP_const4s:
24880 case DW_OP_const8s:
24884 case DW_OP_plus_uconst:
24920 case DW_OP_deref_size:
24921 case DW_OP_xderef_size:
24922 return valx1->v.val_int == valy1->v.val_int;
24925 /* If splitting debug info, the use of DW_OP_GNU_addr_index
24926 can cause irrelevant differences in dw_loc_addr. */
24927 gcc_assert (valx1->val_class == dw_val_class_loc
24928 && valy1->val_class == dw_val_class_loc
24929 && (dwarf_split_debug_info
24930 || x->dw_loc_addr == y->dw_loc_addr));
24931 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
24932 case DW_OP_implicit_value:
24933 if (valx1->v.val_unsigned != valy1->v.val_unsigned
24934 || valx2->val_class != valy2->val_class)
24936 switch (valx2->val_class)
24938 case dw_val_class_const:
24939 return valx2->v.val_int == valy2->v.val_int;
24940 case dw_val_class_vec:
24941 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24942 && valx2->v.val_vec.length == valy2->v.val_vec.length
24943 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24944 valx2->v.val_vec.elt_size
24945 * valx2->v.val_vec.length) == 0;
24946 case dw_val_class_const_double:
24947 return valx2->v.val_double.low == valy2->v.val_double.low
24948 && valx2->v.val_double.high == valy2->v.val_double.high;
24949 case dw_val_class_wide_int:
24950 return *valx2->v.val_wide == *valy2->v.val_wide;
24951 case dw_val_class_addr:
24952 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
24954 gcc_unreachable ();
24957 case DW_OP_bit_piece:
24958 return valx1->v.val_int == valy1->v.val_int
24959 && valx2->v.val_int == valy2->v.val_int;
24962 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
24963 case DW_OP_GNU_addr_index:
24964 case DW_OP_GNU_const_index:
24966 rtx ax1 = valx1->val_entry->addr.rtl;
24967 rtx ay1 = valy1->val_entry->addr.rtl;
24968 return rtx_equal_p (ax1, ay1);
24970 case DW_OP_GNU_implicit_pointer:
24971 return valx1->val_class == dw_val_class_die_ref
24972 && valx1->val_class == valy1->val_class
24973 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
24974 && valx2->v.val_int == valy2->v.val_int;
24975 case DW_OP_GNU_entry_value:
24976 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
24977 case DW_OP_GNU_const_type:
24978 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
24979 || valx2->val_class != valy2->val_class)
24981 switch (valx2->val_class)
24983 case dw_val_class_const:
24984 return valx2->v.val_int == valy2->v.val_int;
24985 case dw_val_class_vec:
24986 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
24987 && valx2->v.val_vec.length == valy2->v.val_vec.length
24988 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
24989 valx2->v.val_vec.elt_size
24990 * valx2->v.val_vec.length) == 0;
24991 case dw_val_class_const_double:
24992 return valx2->v.val_double.low == valy2->v.val_double.low
24993 && valx2->v.val_double.high == valy2->v.val_double.high;
24994 case dw_val_class_wide_int:
24995 return *valx2->v.val_wide == *valy2->v.val_wide;
24997 gcc_unreachable ();
24999 case DW_OP_GNU_regval_type:
25000 case DW_OP_GNU_deref_type:
25001 return valx1->v.val_int == valy1->v.val_int
25002 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
25003 case DW_OP_GNU_convert:
25004 case DW_OP_GNU_reinterpret:
25005 if (valx1->val_class != valy1->val_class)
25007 if (valx1->val_class == dw_val_class_unsigned_const)
25008 return valx1->v.val_unsigned == valy1->v.val_unsigned;
25009 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
25010 case DW_OP_GNU_parameter_ref:
25011 return valx1->val_class == dw_val_class_die_ref
25012 && valx1->val_class == valy1->val_class
25013 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
25015 /* Other codes have no operands. */
25020 /* Return true if DWARF location expressions X and Y are the same. */
25023 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
25025 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
25026 if (x->dw_loc_opc != y->dw_loc_opc
25027 || x->dtprel != y->dtprel
25028 || !compare_loc_operands (x, y))
25030 return x == NULL && y == NULL;
25033 /* Hashtable helpers. */
25035 struct loc_list_hasher : nofree_ptr_hash <dw_loc_list_struct>
25037 static inline hashval_t hash (const dw_loc_list_struct *);
25038 static inline bool equal (const dw_loc_list_struct *,
25039 const dw_loc_list_struct *);
25042 /* Return precomputed hash of location list X. */
25045 loc_list_hasher::hash (const dw_loc_list_struct *x)
25050 /* Return true if location lists A and B are the same. */
25053 loc_list_hasher::equal (const dw_loc_list_struct *a,
25054 const dw_loc_list_struct *b)
25058 if (a->hash != b->hash)
25060 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
25061 if (strcmp (a->begin, b->begin) != 0
25062 || strcmp (a->end, b->end) != 0
25063 || (a->section == NULL) != (b->section == NULL)
25064 || (a->section && strcmp (a->section, b->section) != 0)
25065 || !compare_locs (a->expr, b->expr))
25067 return a == NULL && b == NULL;
25070 typedef hash_table<loc_list_hasher> loc_list_hash_type;
25073 /* Recursively optimize location lists referenced from DIE
25074 children and share them whenever possible. */
25077 optimize_location_lists_1 (dw_die_ref die, loc_list_hash_type *htab)
25082 dw_loc_list_struct **slot;
25084 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
25085 if (AT_class (a) == dw_val_class_loc_list)
25087 dw_loc_list_ref list = AT_loc_list (a);
25088 /* TODO: perform some optimizations here, before hashing
25089 it and storing into the hash table. */
25090 hash_loc_list (list);
25091 slot = htab->find_slot_with_hash (list, list->hash, INSERT);
25095 a->dw_attr_val.v.val_loc_list = *slot;
25098 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
25102 /* Recursively assign each location list a unique index into the debug_addr
25106 index_location_lists (dw_die_ref die)
25112 FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
25113 if (AT_class (a) == dw_val_class_loc_list)
25115 dw_loc_list_ref list = AT_loc_list (a);
25116 dw_loc_list_ref curr;
25117 for (curr = list; curr != NULL; curr = curr->dw_loc_next)
25119 /* Don't index an entry that has already been indexed
25120 or won't be output. */
25121 if (curr->begin_entry != NULL
25122 || (strcmp (curr->begin, curr->end) == 0 && !curr->force))
25126 = add_addr_table_entry (xstrdup (curr->begin),
25131 FOR_EACH_CHILD (die, c, index_location_lists (c));
25134 /* Optimize location lists referenced from DIE
25135 children and share them whenever possible. */
25138 optimize_location_lists (dw_die_ref die)
25140 loc_list_hash_type htab (500);
25141 optimize_location_lists_1 (die, &htab);
25144 /* Traverse the limbo die list, and add parent/child links. The only
25145 dies without parents that should be here are concrete instances of
25146 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
25147 For concrete instances, we can get the parent die from the abstract
25151 flush_limbo_die_list (void)
25153 limbo_die_node *node, *next_node;
25155 for (node = limbo_die_list; node; node = next_node)
25157 dw_die_ref die = node->die;
25158 next_node = node->next;
25160 if (die->die_parent == NULL)
25162 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
25164 if (origin && origin->die_parent)
25165 add_child_die (origin->die_parent, die);
25166 else if (is_cu_die (die))
25168 else if (seen_error ())
25169 /* It's OK to be confused by errors in the input. */
25170 add_child_die (comp_unit_die (), die);
25173 /* In certain situations, the lexical block containing a
25174 nested function can be optimized away, which results
25175 in the nested function die being orphaned. Likewise
25176 with the return type of that nested function. Force
25177 this to be a child of the containing function.
25179 It may happen that even the containing function got fully
25180 inlined and optimized out. In that case we are lost and
25181 assign the empty child. This should not be big issue as
25182 the function is likely unreachable too. */
25183 gcc_assert (node->created_for);
25185 if (DECL_P (node->created_for))
25186 origin = get_context_die (DECL_CONTEXT (node->created_for));
25187 else if (TYPE_P (node->created_for))
25188 origin = scope_die_for (node->created_for, comp_unit_die ());
25190 origin = comp_unit_die ();
25192 add_child_die (origin, die);
25197 limbo_die_list = NULL;
25200 /* Output stuff that dwarf requires at the end of every file,
25201 and generate the DWARF-2 debugging info. */
25204 dwarf2out_finish (const char *filename)
25206 comdat_type_node *ctnode;
25207 dw_die_ref main_comp_unit_die;
25209 /* Flush out any latecomers to the limbo party. */
25210 flush_limbo_die_list ();
25212 /* We shouldn't have any symbols with delayed asm names for
25213 DIEs generated after early finish. */
25214 gcc_assert (deferred_asm_name == NULL);
25216 /* PCH might result in DW_AT_producer string being restored from the
25217 header compilation, so always fill it with empty string initially
25218 and overwrite only here. */
25219 dw_attr_node *producer = get_AT (comp_unit_die (), DW_AT_producer);
25220 producer_string = gen_producer_string ();
25221 producer->dw_attr_val.v.val_str->refcount--;
25222 producer->dw_attr_val.v.val_str = find_AT_string (producer_string);
25224 gen_remaining_tmpl_value_param_die_attribute ();
25226 /* Add the name for the main input file now. We delayed this from
25227 dwarf2out_init to avoid complications with PCH.
25228 For LTO produced units use a fixed artificial name to avoid
25229 leaking tempfile names into the dwarf. */
25231 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
25233 add_name_attribute (comp_unit_die (), "<artificial>");
25234 if (!IS_ABSOLUTE_PATH (filename) || targetm.force_at_comp_dir)
25235 add_comp_dir_attribute (comp_unit_die ());
25236 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
25239 file_table->traverse<bool *, file_table_relative_p> (&p);
25241 add_comp_dir_attribute (comp_unit_die ());
25244 #if ENABLE_ASSERT_CHECKING
25246 dw_die_ref die = comp_unit_die (), c;
25247 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
25250 resolve_addr (comp_unit_die ());
25251 move_marked_base_types ();
25253 /* Walk through the list of incomplete types again, trying once more to
25254 emit full debugging info for them. */
25255 retry_incomplete_types ();
25257 if (flag_eliminate_unused_debug_types)
25258 prune_unused_types ();
25260 /* Generate separate COMDAT sections for type DIEs. */
25261 if (use_debug_types)
25263 break_out_comdat_types (comp_unit_die ());
25265 /* Each new type_unit DIE was added to the limbo die list when created.
25266 Since these have all been added to comdat_type_list, clear the
25268 limbo_die_list = NULL;
25270 /* For each new comdat type unit, copy declarations for incomplete
25271 types to make the new unit self-contained (i.e., no direct
25272 references to the main compile unit). */
25273 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25274 copy_decls_for_unworthy_types (ctnode->root_die);
25275 copy_decls_for_unworthy_types (comp_unit_die ());
25277 /* In the process of copying declarations from one unit to another,
25278 we may have left some declarations behind that are no longer
25279 referenced. Prune them. */
25280 prune_unused_types ();
25283 /* Generate separate CUs for each of the include files we've seen.
25284 They will go into limbo_die_list. */
25285 if (flag_eliminate_dwarf2_dups)
25286 break_out_includes (comp_unit_die ());
25288 /* Traverse the DIE's and add sibling attributes to those DIE's that
25290 add_sibling_attributes (comp_unit_die ());
25291 limbo_die_node *node;
25292 for (node = limbo_die_list; node; node = node->next)
25293 add_sibling_attributes (node->die);
25294 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25295 add_sibling_attributes (ctnode->root_die);
25297 /* When splitting DWARF info, we put some attributes in the
25298 skeleton compile_unit DIE that remains in the .o, while
25299 most attributes go in the DWO compile_unit_die. */
25300 if (dwarf_split_debug_info)
25301 main_comp_unit_die = gen_compile_unit_die (NULL);
25303 main_comp_unit_die = comp_unit_die ();
25305 /* Output a terminator label for the .text section. */
25306 switch_to_section (text_section);
25307 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
25308 if (cold_text_section)
25310 switch_to_section (cold_text_section);
25311 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
25314 /* We can only use the low/high_pc attributes if all of the code was
25316 if (!have_multiple_function_sections
25317 || (dwarf_version < 3 && dwarf_strict))
25319 /* Don't add if the CU has no associated code. */
25320 if (text_section_used)
25321 add_AT_low_high_pc (main_comp_unit_die, text_section_label,
25322 text_end_label, true);
25328 bool range_list_added = false;
25330 if (text_section_used)
25331 add_ranges_by_labels (main_comp_unit_die, text_section_label,
25332 text_end_label, &range_list_added, true);
25333 if (cold_text_section_used)
25334 add_ranges_by_labels (main_comp_unit_die, cold_text_section_label,
25335 cold_end_label, &range_list_added, true);
25337 FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
25339 if (DECL_IGNORED_P (fde->decl))
25341 if (!fde->in_std_section)
25342 add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_begin,
25343 fde->dw_fde_end, &range_list_added,
25345 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
25346 add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_second_begin,
25347 fde->dw_fde_second_end, &range_list_added,
25351 if (range_list_added)
25353 /* We need to give .debug_loc and .debug_ranges an appropriate
25354 "base address". Use zero so that these addresses become
25355 absolute. Historically, we've emitted the unexpected
25356 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
25357 Emit both to give time for other tools to adapt. */
25358 add_AT_addr (main_comp_unit_die, DW_AT_low_pc, const0_rtx, true);
25359 if (! dwarf_strict && dwarf_version < 4)
25360 add_AT_addr (main_comp_unit_die, DW_AT_entry_pc, const0_rtx, true);
25366 if (debug_info_level >= DINFO_LEVEL_TERSE)
25367 add_AT_lineptr (main_comp_unit_die, DW_AT_stmt_list,
25368 debug_line_section_label);
25371 add_AT_macptr (comp_unit_die (),
25372 dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros,
25373 macinfo_section_label);
25375 if (dwarf_split_debug_info)
25377 /* optimize_location_lists calculates the size of the lists,
25378 so index them first, and assign indices to the entries.
25379 Although optimize_location_lists will remove entries from
25380 the table, it only does so for duplicates, and therefore
25381 only reduces ref_counts to 1. */
25382 index_location_lists (comp_unit_die ());
25384 if (addr_index_table != NULL)
25386 unsigned int index = 0;
25388 ->traverse_noresize<unsigned int *, index_addr_table_entry>
25393 if (have_location_lists)
25394 optimize_location_lists (comp_unit_die ());
25396 save_macinfo_strings ();
25398 if (dwarf_split_debug_info)
25400 unsigned int index = 0;
25402 /* Add attributes common to skeleton compile_units and
25403 type_units. Because these attributes include strings, it
25404 must be done before freezing the string table. Top-level
25405 skeleton die attrs are added when the skeleton type unit is
25406 created, so ensure it is created by this point. */
25407 add_top_level_skeleton_die_attrs (main_comp_unit_die);
25408 debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
25411 /* Output all of the compilation units. We put the main one last so that
25412 the offsets are available to output_pubnames. */
25413 for (node = limbo_die_list; node; node = node->next)
25414 output_comp_unit (node->die, 0);
25416 hash_table<comdat_type_hasher> comdat_type_table (100);
25417 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
25419 comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
25421 /* Don't output duplicate types. */
25422 if (*slot != HTAB_EMPTY_ENTRY)
25425 /* Add a pointer to the line table for the main compilation unit
25426 so that the debugger can make sense of DW_AT_decl_file
25428 if (debug_info_level >= DINFO_LEVEL_TERSE)
25429 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
25430 (!dwarf_split_debug_info
25431 ? debug_line_section_label
25432 : debug_skeleton_line_section_label));
25434 output_comdat_type_unit (ctnode);
25438 /* The AT_pubnames attribute needs to go in all skeleton dies, including
25439 both the main_cu and all skeleton TUs. Making this call unconditional
25440 would end up either adding a second copy of the AT_pubnames attribute, or
25441 requiring a special case in add_top_level_skeleton_die_attrs. */
25442 if (!dwarf_split_debug_info)
25443 add_AT_pubnames (comp_unit_die ());
25445 if (dwarf_split_debug_info)
25448 unsigned char checksum[16];
25449 struct md5_ctx ctx;
25451 /* Compute a checksum of the comp_unit to use as the dwo_id. */
25452 md5_init_ctx (&ctx);
25454 die_checksum (comp_unit_die (), &ctx, &mark);
25455 unmark_all_dies (comp_unit_die ());
25456 md5_finish_ctx (&ctx, checksum);
25458 /* Use the first 8 bytes of the checksum as the dwo_id,
25459 and add it to both comp-unit DIEs. */
25460 add_AT_data8 (main_comp_unit_die, DW_AT_GNU_dwo_id, checksum);
25461 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id, checksum);
25463 /* Add the base offset of the ranges table to the skeleton
25465 if (ranges_table_in_use)
25466 add_AT_lineptr (main_comp_unit_die, DW_AT_GNU_ranges_base,
25467 ranges_section_label);
25469 switch_to_section (debug_addr_section);
25470 ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
25471 output_addr_table ();
25474 /* Output the main compilation unit if non-empty or if .debug_macinfo
25475 or .debug_macro will be emitted. */
25476 output_comp_unit (comp_unit_die (), have_macinfo);
25478 if (dwarf_split_debug_info && info_section_emitted)
25479 output_skeleton_debug_sections (main_comp_unit_die);
25481 /* Output the abbreviation table. */
25482 if (abbrev_die_table_in_use != 1)
25484 switch_to_section (debug_abbrev_section);
25485 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
25486 output_abbrev_section ();
25489 /* Output location list section if necessary. */
25490 if (have_location_lists)
25492 /* Output the location lists info. */
25493 switch_to_section (debug_loc_section);
25494 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
25495 output_location_lists (comp_unit_die ());
25498 output_pubtables ();
25500 /* Output the address range information if a CU (.debug_info section)
25501 was emitted. We output an empty table even if we had no functions
25502 to put in it. This because the consumer has no way to tell the
25503 difference between an empty table that we omitted and failure to
25504 generate a table that would have contained data. */
25505 if (info_section_emitted)
25507 unsigned long aranges_length = size_of_aranges ();
25509 switch_to_section (debug_aranges_section);
25510 output_aranges (aranges_length);
25513 /* Output ranges section if necessary. */
25514 if (ranges_table_in_use)
25516 switch_to_section (debug_ranges_section);
25517 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
25521 /* Have to end the macro section. */
25524 switch_to_section (debug_macinfo_section);
25525 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
25527 dw2_asm_output_data (1, 0, "End compilation unit");
25530 /* Output the source line correspondence table. We must do this
25531 even if there is no line information. Otherwise, on an empty
25532 translation unit, we will generate a present, but empty,
25533 .debug_info section. IRIX 6.5 `nm' will then complain when
25534 examining the file. This is done late so that any filenames
25535 used by the debug_info section are marked as 'used'. */
25536 switch_to_section (debug_line_section);
25537 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
25538 if (! DWARF2_ASM_LINE_DEBUG_INFO)
25539 output_line_info (false);
25541 if (dwarf_split_debug_info && info_section_emitted)
25543 switch_to_section (debug_skeleton_line_section);
25544 ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_line_section_label);
25545 output_line_info (true);
25548 /* If we emitted any indirect strings, output the string table too. */
25549 if (debug_str_hash || skeleton_debug_str_hash)
25550 output_indirect_strings ();
25553 /* Perform any cleanups needed after the early debug generation pass
25557 dwarf2out_early_finish (void)
25559 limbo_die_node *node;
25561 /* Add DW_AT_linkage_name for all deferred DIEs. */
25562 for (node = deferred_asm_name; node; node = node->next)
25564 tree decl = node->created_for;
25565 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
25566 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
25567 ended up in deferred_asm_name before we knew it was
25568 constant and never written to disk. */
25569 && DECL_ASSEMBLER_NAME (decl))
25571 add_linkage_attr (node->die, decl);
25572 move_linkage_attr (node->die);
25575 deferred_asm_name = NULL;
25577 /* The point here is to flush out the limbo list so that it is empty
25578 and we don't need to stream it for LTO. */
25579 flush_limbo_die_list ();
25581 gen_scheduled_generic_parms_dies ();
25582 gen_remaining_tmpl_value_param_die_attribute ();
25585 /* Reset all state within dwarf2out.c so that we can rerun the compiler
25586 within the same process. For use by toplev::finalize. */
25589 dwarf2out_c_finalize (void)
25591 last_var_location_insn = NULL;
25592 cached_next_real_insn = NULL;
25593 used_rtx_array = NULL;
25594 incomplete_types = NULL;
25595 decl_scope_table = NULL;
25596 debug_info_section = NULL;
25597 debug_skeleton_info_section = NULL;
25598 debug_abbrev_section = NULL;
25599 debug_skeleton_abbrev_section = NULL;
25600 debug_aranges_section = NULL;
25601 debug_addr_section = NULL;
25602 debug_macinfo_section = NULL;
25603 debug_line_section = NULL;
25604 debug_skeleton_line_section = NULL;
25605 debug_loc_section = NULL;
25606 debug_pubnames_section = NULL;
25607 debug_pubtypes_section = NULL;
25608 debug_str_section = NULL;
25609 debug_str_dwo_section = NULL;
25610 debug_str_offsets_section = NULL;
25611 debug_ranges_section = NULL;
25612 debug_frame_section = NULL;
25614 debug_str_hash = NULL;
25615 skeleton_debug_str_hash = NULL;
25616 dw2_string_counter = 0;
25617 have_multiple_function_sections = false;
25618 text_section_used = false;
25619 cold_text_section_used = false;
25620 cold_text_section = NULL;
25621 current_unit_personality = NULL;
25623 next_die_offset = 0;
25624 single_comp_unit_die = NULL;
25625 comdat_type_list = NULL;
25626 limbo_die_list = NULL;
25628 decl_die_table = NULL;
25629 common_block_die_table = NULL;
25630 decl_loc_table = NULL;
25631 call_arg_locations = NULL;
25632 call_arg_loc_last = NULL;
25633 call_site_count = -1;
25634 tail_call_site_count = -1;
25635 cached_dw_loc_list_table = NULL;
25636 abbrev_die_table = NULL;
25637 abbrev_die_table_allocated = 0;
25638 abbrev_die_table_in_use = 0;
25639 line_info_label_num = 0;
25640 cur_line_info_table = NULL;
25641 text_section_line_info = NULL;
25642 cold_text_section_line_info = NULL;
25643 separate_line_info = NULL;
25644 info_section_emitted = false;
25645 pubname_table = NULL;
25646 pubtype_table = NULL;
25647 macinfo_table = NULL;
25648 ranges_table = NULL;
25649 ranges_table_allocated = 0;
25650 ranges_table_in_use = 0;
25651 ranges_by_label = 0;
25652 ranges_by_label_allocated = 0;
25653 ranges_by_label_in_use = 0;
25654 have_location_lists = false;
25657 last_emitted_file = NULL;
25659 tmpl_value_parm_die_table = NULL;
25660 generic_type_instances = NULL;
25661 frame_pointer_fb_offset = 0;
25662 frame_pointer_fb_offset_valid = false;
25663 base_types.release ();
25664 XDELETEVEC (producer_string);
25665 producer_string = NULL;
25668 #include "gt-dwarf2out.h"