1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "common/common-target.h"
89 #include "langhooks.h"
94 #include "tree-pass.h"
95 #include "tree-flow.h"
96 #include "cfglayout.h"
99 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
100 static rtx last_var_location_insn;
101 static rtx cached_next_real_insn;
103 #ifdef VMS_DEBUGGING_INFO
104 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
106 /* Define this macro to be a nonzero value if the directory specifications
107 which are output in the debug info should end with a separator. */
108 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
109 /* Define this macro to evaluate to a nonzero value if GCC should refrain
110 from generating indirect strings in DWARF2 debug information, for instance
111 if your target is stuck with an old version of GDB that is unable to
112 process them properly or uses VMS Debug. */
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
115 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
116 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
119 /* ??? Poison these here until it can be done generically. They've been
120 totally replaced in this file; make sure it stays that way. */
121 #undef DWARF2_UNWIND_INFO
122 #undef DWARF2_FRAME_INFO
123 #if (GCC_VERSION >= 3000)
124 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
127 /* The size of the target's pointer type. */
129 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
132 /* Array of RTXes referenced by the debugging information, which therefore
133 must be kept around forever. */
134 static GTY(()) VEC(rtx,gc) *used_rtx_array;
136 /* A pointer to the base of a list of incomplete types which might be
137 completed at some later time. incomplete_types_list needs to be a
138 VEC(tree,gc) because we want to tell the garbage collector about
140 static GTY(()) VEC(tree,gc) *incomplete_types;
142 /* A pointer to the base of a table of references to declaration
143 scopes. This table is a display which tracks the nesting
144 of declaration scopes at the current scope and containing
145 scopes. This table is used to find the proper place to
146 define type declaration DIE's. */
147 static GTY(()) VEC(tree,gc) *decl_scope_table;
149 /* Pointers to various DWARF2 sections. */
150 static GTY(()) section *debug_info_section;
151 static GTY(()) section *debug_abbrev_section;
152 static GTY(()) section *debug_aranges_section;
153 static GTY(()) section *debug_macinfo_section;
154 static GTY(()) section *debug_line_section;
155 static GTY(()) section *debug_loc_section;
156 static GTY(()) section *debug_pubnames_section;
157 static GTY(()) section *debug_pubtypes_section;
158 static GTY(()) section *debug_str_section;
159 static GTY(()) section *debug_ranges_section;
160 static GTY(()) section *debug_frame_section;
162 /* Maximum size (in bytes) of an artificially generated label. */
163 #define MAX_ARTIFICIAL_LABEL_BYTES 30
165 /* According to the (draft) DWARF 3 specification, the initial length
166 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
167 bytes are 0xffffffff, followed by the length stored in the next 8
170 However, the SGI/MIPS ABI uses an initial length which is equal to
171 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
173 #ifndef DWARF_INITIAL_LENGTH_SIZE
174 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
177 /* Round SIZE up to the nearest BOUNDARY. */
178 #define DWARF_ROUND(SIZE,BOUNDARY) \
179 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
181 /* CIE identifier. */
182 #if HOST_BITS_PER_WIDE_INT >= 64
183 #define DWARF_CIE_ID \
184 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
186 #define DWARF_CIE_ID DW_CIE_ID
189 DEF_VEC_P (dw_fde_ref);
190 DEF_VEC_ALLOC_P (dw_fde_ref, gc);
192 /* A vector for a table that contains frame description
193 information for each routine. */
194 static GTY(()) VEC(dw_fde_ref, gc) *fde_vec;
196 struct GTY(()) indirect_string_node {
198 unsigned int refcount;
199 enum dwarf_form form;
203 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
205 static GTY(()) int dw2_string_counter;
207 /* True if the compilation unit places functions in more than one section. */
208 static GTY(()) bool have_multiple_function_sections = false;
210 /* Whether the default text and cold text sections have been used at all. */
212 static GTY(()) bool text_section_used = false;
213 static GTY(()) bool cold_text_section_used = false;
215 /* The default cold text section. */
216 static GTY(()) section *cold_text_section;
218 /* Forward declarations for functions defined in this file. */
220 static char *stripattributes (const char *);
221 static void output_call_frame_info (int);
222 static void dwarf2out_note_section_used (void);
224 /* Personality decl of current unit. Used only when assembler does not support
226 static GTY(()) rtx current_unit_personality;
228 /* Data and reference forms for relocatable data. */
229 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
230 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
232 #ifndef DEBUG_FRAME_SECTION
233 #define DEBUG_FRAME_SECTION ".debug_frame"
236 #ifndef FUNC_BEGIN_LABEL
237 #define FUNC_BEGIN_LABEL "LFB"
240 #ifndef FUNC_END_LABEL
241 #define FUNC_END_LABEL "LFE"
244 #ifndef PROLOGUE_END_LABEL
245 #define PROLOGUE_END_LABEL "LPE"
248 #ifndef EPILOGUE_BEGIN_LABEL
249 #define EPILOGUE_BEGIN_LABEL "LEB"
252 #ifndef FRAME_BEGIN_LABEL
253 #define FRAME_BEGIN_LABEL "Lframe"
255 #define CIE_AFTER_SIZE_LABEL "LSCIE"
256 #define CIE_END_LABEL "LECIE"
257 #define FDE_LABEL "LSFDE"
258 #define FDE_AFTER_SIZE_LABEL "LASFDE"
259 #define FDE_END_LABEL "LEFDE"
260 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
261 #define LINE_NUMBER_END_LABEL "LELT"
262 #define LN_PROLOG_AS_LABEL "LASLTP"
263 #define LN_PROLOG_END_LABEL "LELTP"
264 #define DIE_LABEL_PREFIX "DW"
266 /* Match the base name of a file to the base name of a compilation unit. */
269 matches_main_base (const char *path)
271 /* Cache the last query. */
272 static const char *last_path = NULL;
273 static int last_match = 0;
274 if (path != last_path)
277 int length = base_of_path (path, &base);
279 last_match = (length == main_input_baselength
280 && memcmp (base, main_input_basename, length) == 0);
285 #ifdef DEBUG_DEBUG_STRUCT
288 dump_struct_debug (tree type, enum debug_info_usage usage,
289 enum debug_struct_file criterion, int generic,
290 int matches, int result)
292 /* Find the type name. */
293 tree type_decl = TYPE_STUB_DECL (type);
295 const char *name = 0;
296 if (TREE_CODE (t) == TYPE_DECL)
299 name = IDENTIFIER_POINTER (t);
301 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
303 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
304 matches ? "bas" : "hdr",
305 generic ? "gen" : "ord",
306 usage == DINFO_USAGE_DFN ? ";" :
307 usage == DINFO_USAGE_DIR_USE ? "." : "*",
309 (void*) type_decl, name);
312 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
313 dump_struct_debug (type, usage, criterion, generic, matches, result)
317 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
323 should_emit_struct_debug (tree type, enum debug_info_usage usage)
325 enum debug_struct_file criterion;
327 bool generic = lang_hooks.types.generic_p (type);
330 criterion = debug_struct_generic[usage];
332 criterion = debug_struct_ordinary[usage];
334 if (criterion == DINFO_STRUCT_FILE_NONE)
335 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
336 if (criterion == DINFO_STRUCT_FILE_ANY)
337 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
339 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
341 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
342 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
344 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
345 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
346 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
349 /* Return a pointer to a copy of the section string name S with all
350 attributes stripped off, and an asterisk prepended (for assemble_name). */
353 stripattributes (const char *s)
355 char *stripped = XNEWVEC (char, strlen (s) + 2);
360 while (*s && *s != ',')
367 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
368 switch to the data section instead, and write out a synthetic start label
369 for collect2 the first time around. */
372 switch_to_eh_frame_section (bool back)
376 #ifdef EH_FRAME_SECTION_NAME
377 if (eh_frame_section == 0)
381 if (EH_TABLES_CAN_BE_READ_ONLY)
387 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
389 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
391 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
394 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
395 && (fde_encoding & 0x70) != DW_EH_PE_aligned
396 && (per_encoding & 0x70) != DW_EH_PE_absptr
397 && (per_encoding & 0x70) != DW_EH_PE_aligned
398 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
399 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
400 ? 0 : SECTION_WRITE);
403 flags = SECTION_WRITE;
404 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
406 #endif /* EH_FRAME_SECTION_NAME */
408 if (eh_frame_section)
409 switch_to_section (eh_frame_section);
412 /* We have no special eh_frame section. Put the information in
413 the data section and emit special labels to guide collect2. */
414 switch_to_section (data_section);
418 label = get_file_function_name ("F");
419 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
420 targetm.asm_out.globalize_label (asm_out_file,
421 IDENTIFIER_POINTER (label));
422 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
427 /* Switch [BACK] to the eh or debug frame table section, depending on
431 switch_to_frame_table_section (int for_eh, bool back)
434 switch_to_eh_frame_section (back);
437 if (!debug_frame_section)
438 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
439 SECTION_DEBUG, NULL);
440 switch_to_section (debug_frame_section);
444 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
446 enum dw_cfi_oprnd_type
447 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
452 case DW_CFA_GNU_window_save:
453 case DW_CFA_remember_state:
454 case DW_CFA_restore_state:
455 return dw_cfi_oprnd_unused;
458 case DW_CFA_advance_loc1:
459 case DW_CFA_advance_loc2:
460 case DW_CFA_advance_loc4:
461 case DW_CFA_MIPS_advance_loc8:
462 return dw_cfi_oprnd_addr;
465 case DW_CFA_offset_extended:
467 case DW_CFA_offset_extended_sf:
468 case DW_CFA_def_cfa_sf:
470 case DW_CFA_restore_extended:
471 case DW_CFA_undefined:
472 case DW_CFA_same_value:
473 case DW_CFA_def_cfa_register:
474 case DW_CFA_register:
475 case DW_CFA_expression:
476 return dw_cfi_oprnd_reg_num;
478 case DW_CFA_def_cfa_offset:
479 case DW_CFA_GNU_args_size:
480 case DW_CFA_def_cfa_offset_sf:
481 return dw_cfi_oprnd_offset;
483 case DW_CFA_def_cfa_expression:
484 return dw_cfi_oprnd_loc;
491 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
493 enum dw_cfi_oprnd_type
494 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
499 case DW_CFA_def_cfa_sf:
501 case DW_CFA_offset_extended_sf:
502 case DW_CFA_offset_extended:
503 return dw_cfi_oprnd_offset;
505 case DW_CFA_register:
506 return dw_cfi_oprnd_reg_num;
508 case DW_CFA_expression:
509 return dw_cfi_oprnd_loc;
512 return dw_cfi_oprnd_unused;
516 /* Output one FDE. */
519 output_fde (dw_fde_ref fde, bool for_eh, bool second,
520 char *section_start_label, int fde_encoding, char *augmentation,
521 bool any_lsda_needed, int lsda_encoding)
523 const char *begin, *end;
524 static unsigned int j;
527 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
529 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
531 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
532 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
533 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
534 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
535 " indicating 64-bit DWARF extension");
536 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
538 ASM_OUTPUT_LABEL (asm_out_file, l1);
541 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
543 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
544 debug_frame_section, "FDE CIE offset");
546 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
547 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
551 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
552 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
553 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
554 "FDE initial location");
555 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
556 end, begin, "FDE address range");
560 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
561 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
568 int size = size_of_encoded_value (lsda_encoding);
570 if (lsda_encoding == DW_EH_PE_aligned)
572 int offset = ( 4 /* Length */
574 + 2 * size_of_encoded_value (fde_encoding)
575 + 1 /* Augmentation size */ );
576 int pad = -offset & (PTR_SIZE - 1);
579 gcc_assert (size_of_uleb128 (size) == 1);
582 dw2_asm_output_data_uleb128 (size, "Augmentation size");
584 if (fde->uses_eh_lsda)
586 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
587 fde->funcdef_number);
588 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
589 gen_rtx_SYMBOL_REF (Pmode, l1),
591 "Language Specific Data Area");
595 if (lsda_encoding == DW_EH_PE_aligned)
596 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
597 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
598 "Language Specific Data Area (none)");
602 dw2_asm_output_data_uleb128 (0, "Augmentation size");
605 /* Loop through the Call Frame Instructions associated with this FDE. */
606 fde->dw_fde_current_label = begin;
608 size_t from, until, i;
611 until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
613 if (fde->dw_fde_second_begin == NULL)
616 until = fde->dw_fde_switch_cfi_index;
618 from = fde->dw_fde_switch_cfi_index;
620 for (i = from; i < until; i++)
621 output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i), fde, for_eh);
624 /* If we are to emit a ref/link from function bodies to their frame tables,
625 do it now. This is typically performed to make sure that tables
626 associated with functions are dragged with them and not discarded in
627 garbage collecting links. We need to do this on a per function basis to
628 cope with -ffunction-sections. */
630 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
631 /* Switch to the function section, emit the ref to the tables, and
632 switch *back* into the table section. */
633 switch_to_section (function_section (fde->decl));
634 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
635 switch_to_frame_table_section (for_eh, true);
638 /* Pad the FDE out to an address sized boundary. */
639 ASM_OUTPUT_ALIGN (asm_out_file,
640 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
641 ASM_OUTPUT_LABEL (asm_out_file, l2);
646 /* Return true if frame description entry FDE is needed for EH. */
649 fde_needed_for_eh_p (dw_fde_ref fde)
651 if (flag_asynchronous_unwind_tables)
654 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
657 if (fde->uses_eh_lsda)
660 /* If exceptions are enabled, we have collected nothrow info. */
661 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
667 /* Output the call frame information used to record information
668 that relates to calculating the frame pointer, and records the
669 location of saved registers. */
672 output_call_frame_info (int for_eh)
677 char l1[20], l2[20], section_start_label[20];
678 bool any_lsda_needed = false;
679 char augmentation[6];
680 int augmentation_size;
681 int fde_encoding = DW_EH_PE_absptr;
682 int per_encoding = DW_EH_PE_absptr;
683 int lsda_encoding = DW_EH_PE_absptr;
685 rtx personality = NULL;
688 /* Don't emit a CIE if there won't be any FDEs. */
692 /* Nothing to do if the assembler's doing it all. */
693 if (dwarf2out_do_cfi_asm ())
696 /* If we don't have any functions we'll want to unwind out of, don't emit
697 any EH unwind information. If we make FDEs linkonce, we may have to
698 emit an empty label for an FDE that wouldn't otherwise be emitted. We
699 want to avoid having an FDE kept around when the function it refers to
700 is discarded. Example where this matters: a primary function template
701 in C++ requires EH information, an explicit specialization doesn't. */
704 bool any_eh_needed = false;
706 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, i, fde)
708 if (fde->uses_eh_lsda)
709 any_eh_needed = any_lsda_needed = true;
710 else if (fde_needed_for_eh_p (fde))
711 any_eh_needed = true;
712 else if (TARGET_USES_WEAK_UNWIND_INFO)
713 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, 1, 1);
720 /* We're going to be generating comments, so turn on app. */
724 /* Switch to the proper frame section, first time. */
725 switch_to_frame_table_section (for_eh, false);
727 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
728 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
730 /* Output the CIE. */
731 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
732 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
733 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
734 dw2_asm_output_data (4, 0xffffffff,
735 "Initial length escape value indicating 64-bit DWARF extension");
736 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
737 "Length of Common Information Entry");
738 ASM_OUTPUT_LABEL (asm_out_file, l1);
740 /* Now that the CIE pointer is PC-relative for EH,
741 use 0 to identify the CIE. */
742 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
743 (for_eh ? 0 : DWARF_CIE_ID),
744 "CIE Identifier Tag");
746 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
747 use CIE version 1, unless that would produce incorrect results
748 due to overflowing the return register column. */
749 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
751 if (return_reg >= 256 || dwarf_version > 2)
753 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
756 augmentation_size = 0;
758 personality = current_unit_personality;
764 z Indicates that a uleb128 is present to size the
765 augmentation section.
766 L Indicates the encoding (and thus presence) of
767 an LSDA pointer in the FDE augmentation.
768 R Indicates a non-default pointer encoding for
770 P Indicates the presence of an encoding + language
771 personality routine in the CIE augmentation. */
773 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
774 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
775 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
777 p = augmentation + 1;
781 augmentation_size += 1 + size_of_encoded_value (per_encoding);
782 assemble_external_libcall (personality);
787 augmentation_size += 1;
789 if (fde_encoding != DW_EH_PE_absptr)
792 augmentation_size += 1;
794 if (p > augmentation + 1)
796 augmentation[0] = 'z';
800 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
801 if (personality && per_encoding == DW_EH_PE_aligned)
803 int offset = ( 4 /* Length */
805 + 1 /* CIE version */
806 + strlen (augmentation) + 1 /* Augmentation */
807 + size_of_uleb128 (1) /* Code alignment */
808 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
810 + 1 /* Augmentation size */
811 + 1 /* Personality encoding */ );
812 int pad = -offset & (PTR_SIZE - 1);
814 augmentation_size += pad;
816 /* Augmentations should be small, so there's scarce need to
817 iterate for a solution. Die if we exceed one uleb128 byte. */
818 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
822 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
823 if (dw_cie_version >= 4)
825 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
826 dw2_asm_output_data (1, 0, "CIE Segment Size");
828 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
829 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
830 "CIE Data Alignment Factor");
832 if (dw_cie_version == 1)
833 dw2_asm_output_data (1, return_reg, "CIE RA Column");
835 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
839 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
842 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
843 eh_data_format_name (per_encoding));
844 dw2_asm_output_encoded_addr_rtx (per_encoding,
850 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
851 eh_data_format_name (lsda_encoding));
853 if (fde_encoding != DW_EH_PE_absptr)
854 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
855 eh_data_format_name (fde_encoding));
858 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, i, cfi)
859 output_cfi (cfi, NULL, for_eh);
861 /* Pad the CIE out to an address sized boundary. */
862 ASM_OUTPUT_ALIGN (asm_out_file,
863 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
864 ASM_OUTPUT_LABEL (asm_out_file, l2);
866 /* Loop through all of the FDE's. */
867 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, i, fde)
871 /* Don't emit EH unwind info for leaf functions that don't need it. */
872 if (for_eh && !fde_needed_for_eh_p (fde))
875 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
876 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
877 augmentation, any_lsda_needed, lsda_encoding);
880 if (for_eh && targetm.terminate_dw2_eh_frame_info)
881 dw2_asm_output_data (4, 0, "End of Table");
882 #ifdef MIPS_DEBUGGING_INFO
883 /* Work around Irix 6 assembler bug whereby labels at the end of a section
884 get a value of 0. Putting .align 0 after the label fixes it. */
885 ASM_OUTPUT_ALIGN (asm_out_file, 0);
888 /* Turn off app to make assembly quicker. */
893 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
896 dwarf2out_do_cfi_startproc (bool second)
900 rtx personality = get_personality_function (current_function_decl);
902 fprintf (asm_out_file, "\t.cfi_startproc\n");
906 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
909 /* ??? The GAS support isn't entirely consistent. We have to
910 handle indirect support ourselves, but PC-relative is done
911 in the assembler. Further, the assembler can't handle any
912 of the weirder relocation types. */
913 if (enc & DW_EH_PE_indirect)
914 ref = dw2_force_const_mem (ref, true);
916 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
917 output_addr_const (asm_out_file, ref);
918 fputc ('\n', asm_out_file);
921 if (crtl->uses_eh_lsda)
925 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
926 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
927 current_function_funcdef_no);
928 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
929 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
931 if (enc & DW_EH_PE_indirect)
932 ref = dw2_force_const_mem (ref, true);
934 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
935 output_addr_const (asm_out_file, ref);
936 fputc ('\n', asm_out_file);
940 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
941 this allocation may be done before pass_final. */
944 dwarf2out_alloc_current_fde (void)
948 fde = ggc_alloc_cleared_dw_fde_node ();
949 fde->decl = current_function_decl;
950 fde->funcdef_number = current_function_funcdef_no;
951 fde->fde_index = VEC_length (dw_fde_ref, fde_vec);
952 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
953 fde->uses_eh_lsda = crtl->uses_eh_lsda;
954 fde->nothrow = crtl->nothrow;
955 fde->drap_reg = INVALID_REGNUM;
956 fde->vdrap_reg = INVALID_REGNUM;
958 /* Record the FDE associated with this function. */
960 VEC_safe_push (dw_fde_ref, gc, fde_vec, fde);
965 /* Output a marker (i.e. a label) for the beginning of a function, before
969 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
970 const char *file ATTRIBUTE_UNUSED)
972 char label[MAX_ARTIFICIAL_LABEL_BYTES];
978 current_function_func_begin_label = NULL;
980 do_frame = dwarf2out_do_frame ();
982 /* ??? current_function_func_begin_label is also used by except.c for
983 call-site information. We must emit this label if it might be used. */
986 || targetm_common.except_unwind_info (&global_options) != UI_TARGET))
989 fnsec = function_section (current_function_decl);
990 switch_to_section (fnsec);
991 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
992 current_function_funcdef_no);
993 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
994 current_function_funcdef_no);
995 dup_label = xstrdup (label);
996 current_function_func_begin_label = dup_label;
998 /* We can elide the fde allocation if we're not emitting debug info. */
1002 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1003 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1004 would include pass_dwarf2_frame. If we've not created the FDE yet,
1008 fde = dwarf2out_alloc_current_fde ();
1010 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1011 fde->dw_fde_begin = dup_label;
1012 fde->dw_fde_current_label = dup_label;
1013 fde->in_std_section = (fnsec == text_section
1014 || (cold_text_section && fnsec == cold_text_section));
1016 /* We only want to output line number information for the genuine dwarf2
1017 prologue case, not the eh frame case. */
1018 #ifdef DWARF2_DEBUGGING_INFO
1020 dwarf2out_source_line (line, file, 0, true);
1023 if (dwarf2out_do_cfi_asm ())
1024 dwarf2out_do_cfi_startproc (false);
1027 rtx personality = get_personality_function (current_function_decl);
1028 if (!current_unit_personality)
1029 current_unit_personality = personality;
1031 /* We cannot keep a current personality per function as without CFI
1032 asm, at the point where we emit the CFI data, there is no current
1033 function anymore. */
1034 if (personality && current_unit_personality != personality)
1035 sorry ("multiple EH personalities are supported only with assemblers "
1036 "supporting .cfi_personality directive");
1040 /* Output a marker (i.e. a label) for the end of the generated code
1041 for a function prologue. This gets called *after* the prologue code has
1045 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
1046 const char *file ATTRIBUTE_UNUSED)
1048 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1050 /* Output a label to mark the endpoint of the code generated for this
1052 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
1053 current_function_funcdef_no);
1054 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
1055 current_function_funcdef_no);
1056 cfun->fde->dw_fde_vms_end_prologue = xstrdup (label);
1059 /* Output a marker (i.e. a label) for the beginning of the generated code
1060 for a function epilogue. This gets called *before* the prologue code has
1064 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1065 const char *file ATTRIBUTE_UNUSED)
1067 dw_fde_ref fde = cfun->fde;
1068 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1070 if (fde->dw_fde_vms_begin_epilogue)
1073 /* Output a label to mark the endpoint of the code generated for this
1075 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
1076 current_function_funcdef_no);
1077 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
1078 current_function_funcdef_no);
1079 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
1082 /* Output a marker (i.e. a label) for the absolute end of the generated code
1083 for a function definition. This gets called *after* the epilogue code has
1087 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1088 const char *file ATTRIBUTE_UNUSED)
1091 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1093 last_var_location_insn = NULL_RTX;
1094 cached_next_real_insn = NULL_RTX;
1096 if (dwarf2out_do_cfi_asm ())
1097 fprintf (asm_out_file, "\t.cfi_endproc\n");
1099 /* Output a label to mark the endpoint of the code generated for this
1101 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1102 current_function_funcdef_no);
1103 ASM_OUTPUT_LABEL (asm_out_file, label);
1105 gcc_assert (fde != NULL);
1106 if (fde->dw_fde_second_begin == NULL)
1107 fde->dw_fde_end = xstrdup (label);
1111 dwarf2out_frame_finish (void)
1113 /* Output call frame information. */
1114 if (targetm.debug_unwind_info () == UI_DWARF2)
1115 output_call_frame_info (0);
1117 /* Output another copy for the unwinder. */
1118 if ((flag_unwind_tables || flag_exceptions)
1119 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
1120 output_call_frame_info (1);
1123 /* Note that the current function section is being used for code. */
1126 dwarf2out_note_section_used (void)
1128 section *sec = current_function_section ();
1129 if (sec == text_section)
1130 text_section_used = true;
1131 else if (sec == cold_text_section)
1132 cold_text_section_used = true;
1135 static void var_location_switch_text_section (void);
1136 static void set_cur_line_info_table (section *);
1139 dwarf2out_switch_text_section (void)
1142 dw_fde_ref fde = cfun->fde;
1144 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1146 if (!in_cold_section_p)
1148 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
1149 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
1150 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
1154 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1155 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
1156 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1158 have_multiple_function_sections = true;
1160 /* There is no need to mark used sections when not debugging. */
1161 if (cold_text_section != NULL)
1162 dwarf2out_note_section_used ();
1164 if (dwarf2out_do_cfi_asm ())
1165 fprintf (asm_out_file, "\t.cfi_endproc\n");
1167 /* Now do the real section switch. */
1168 sect = current_function_section ();
1169 switch_to_section (sect);
1171 fde->second_in_std_section
1172 = (sect == text_section
1173 || (cold_text_section && sect == cold_text_section));
1175 if (dwarf2out_do_cfi_asm ())
1176 dwarf2out_do_cfi_startproc (true);
1178 var_location_switch_text_section ();
1180 set_cur_line_info_table (sect);
1183 /* And now, the subset of the debugging information support code necessary
1184 for emitting location expressions. */
1186 /* Data about a single source file. */
1187 struct GTY(()) dwarf_file_data {
1188 const char * filename;
1192 typedef struct GTY(()) deferred_locations_struct
1196 } deferred_locations;
1198 DEF_VEC_O(deferred_locations);
1199 DEF_VEC_ALLOC_O(deferred_locations,gc);
1201 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
1203 DEF_VEC_P(dw_die_ref);
1204 DEF_VEC_ALLOC_P(dw_die_ref,heap);
1206 /* Location lists are ranges + location descriptions for that range,
1207 so you can track variables that are in different places over
1208 their entire life. */
1209 typedef struct GTY(()) dw_loc_list_struct {
1210 dw_loc_list_ref dw_loc_next;
1211 const char *begin; /* Label for begin address of range */
1212 const char *end; /* Label for end address of range */
1213 char *ll_symbol; /* Label for beginning of location list.
1214 Only on head of list */
1215 const char *section; /* Section this loclist is relative to */
1216 dw_loc_descr_ref expr;
1218 /* True if all addresses in this and subsequent lists are known to be
1221 /* True if this list has been replaced by dw_loc_next. */
1224 /* True if the range should be emitted even if begin and end
1229 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
1231 /* Convert a DWARF stack opcode into its string name. */
1234 dwarf_stack_op_name (unsigned int op)
1239 return "DW_OP_addr";
1241 return "DW_OP_deref";
1243 return "DW_OP_const1u";
1245 return "DW_OP_const1s";
1247 return "DW_OP_const2u";
1249 return "DW_OP_const2s";
1251 return "DW_OP_const4u";
1253 return "DW_OP_const4s";
1255 return "DW_OP_const8u";
1257 return "DW_OP_const8s";
1259 return "DW_OP_constu";
1261 return "DW_OP_consts";
1265 return "DW_OP_drop";
1267 return "DW_OP_over";
1269 return "DW_OP_pick";
1271 return "DW_OP_swap";
1275 return "DW_OP_xderef";
1283 return "DW_OP_minus";
1295 return "DW_OP_plus";
1296 case DW_OP_plus_uconst:
1297 return "DW_OP_plus_uconst";
1303 return "DW_OP_shra";
1321 return "DW_OP_skip";
1323 return "DW_OP_lit0";
1325 return "DW_OP_lit1";
1327 return "DW_OP_lit2";
1329 return "DW_OP_lit3";
1331 return "DW_OP_lit4";
1333 return "DW_OP_lit5";
1335 return "DW_OP_lit6";
1337 return "DW_OP_lit7";
1339 return "DW_OP_lit8";
1341 return "DW_OP_lit9";
1343 return "DW_OP_lit10";
1345 return "DW_OP_lit11";
1347 return "DW_OP_lit12";
1349 return "DW_OP_lit13";
1351 return "DW_OP_lit14";
1353 return "DW_OP_lit15";
1355 return "DW_OP_lit16";
1357 return "DW_OP_lit17";
1359 return "DW_OP_lit18";
1361 return "DW_OP_lit19";
1363 return "DW_OP_lit20";
1365 return "DW_OP_lit21";
1367 return "DW_OP_lit22";
1369 return "DW_OP_lit23";
1371 return "DW_OP_lit24";
1373 return "DW_OP_lit25";
1375 return "DW_OP_lit26";
1377 return "DW_OP_lit27";
1379 return "DW_OP_lit28";
1381 return "DW_OP_lit29";
1383 return "DW_OP_lit30";
1385 return "DW_OP_lit31";
1387 return "DW_OP_reg0";
1389 return "DW_OP_reg1";
1391 return "DW_OP_reg2";
1393 return "DW_OP_reg3";
1395 return "DW_OP_reg4";
1397 return "DW_OP_reg5";
1399 return "DW_OP_reg6";
1401 return "DW_OP_reg7";
1403 return "DW_OP_reg8";
1405 return "DW_OP_reg9";
1407 return "DW_OP_reg10";
1409 return "DW_OP_reg11";
1411 return "DW_OP_reg12";
1413 return "DW_OP_reg13";
1415 return "DW_OP_reg14";
1417 return "DW_OP_reg15";
1419 return "DW_OP_reg16";
1421 return "DW_OP_reg17";
1423 return "DW_OP_reg18";
1425 return "DW_OP_reg19";
1427 return "DW_OP_reg20";
1429 return "DW_OP_reg21";
1431 return "DW_OP_reg22";
1433 return "DW_OP_reg23";
1435 return "DW_OP_reg24";
1437 return "DW_OP_reg25";
1439 return "DW_OP_reg26";
1441 return "DW_OP_reg27";
1443 return "DW_OP_reg28";
1445 return "DW_OP_reg29";
1447 return "DW_OP_reg30";
1449 return "DW_OP_reg31";
1451 return "DW_OP_breg0";
1453 return "DW_OP_breg1";
1455 return "DW_OP_breg2";
1457 return "DW_OP_breg3";
1459 return "DW_OP_breg4";
1461 return "DW_OP_breg5";
1463 return "DW_OP_breg6";
1465 return "DW_OP_breg7";
1467 return "DW_OP_breg8";
1469 return "DW_OP_breg9";
1471 return "DW_OP_breg10";
1473 return "DW_OP_breg11";
1475 return "DW_OP_breg12";
1477 return "DW_OP_breg13";
1479 return "DW_OP_breg14";
1481 return "DW_OP_breg15";
1483 return "DW_OP_breg16";
1485 return "DW_OP_breg17";
1487 return "DW_OP_breg18";
1489 return "DW_OP_breg19";
1491 return "DW_OP_breg20";
1493 return "DW_OP_breg21";
1495 return "DW_OP_breg22";
1497 return "DW_OP_breg23";
1499 return "DW_OP_breg24";
1501 return "DW_OP_breg25";
1503 return "DW_OP_breg26";
1505 return "DW_OP_breg27";
1507 return "DW_OP_breg28";
1509 return "DW_OP_breg29";
1511 return "DW_OP_breg30";
1513 return "DW_OP_breg31";
1515 return "DW_OP_regx";
1517 return "DW_OP_fbreg";
1519 return "DW_OP_bregx";
1521 return "DW_OP_piece";
1522 case DW_OP_deref_size:
1523 return "DW_OP_deref_size";
1524 case DW_OP_xderef_size:
1525 return "DW_OP_xderef_size";
1529 case DW_OP_push_object_address:
1530 return "DW_OP_push_object_address";
1532 return "DW_OP_call2";
1534 return "DW_OP_call4";
1535 case DW_OP_call_ref:
1536 return "DW_OP_call_ref";
1537 case DW_OP_implicit_value:
1538 return "DW_OP_implicit_value";
1539 case DW_OP_stack_value:
1540 return "DW_OP_stack_value";
1541 case DW_OP_form_tls_address:
1542 return "DW_OP_form_tls_address";
1543 case DW_OP_call_frame_cfa:
1544 return "DW_OP_call_frame_cfa";
1545 case DW_OP_bit_piece:
1546 return "DW_OP_bit_piece";
1548 case DW_OP_GNU_push_tls_address:
1549 return "DW_OP_GNU_push_tls_address";
1550 case DW_OP_GNU_uninit:
1551 return "DW_OP_GNU_uninit";
1552 case DW_OP_GNU_encoded_addr:
1553 return "DW_OP_GNU_encoded_addr";
1554 case DW_OP_GNU_implicit_pointer:
1555 return "DW_OP_GNU_implicit_pointer";
1556 case DW_OP_GNU_entry_value:
1557 return "DW_OP_GNU_entry_value";
1558 case DW_OP_GNU_const_type:
1559 return "DW_OP_GNU_const_type";
1560 case DW_OP_GNU_regval_type:
1561 return "DW_OP_GNU_regval_type";
1562 case DW_OP_GNU_deref_type:
1563 return "DW_OP_GNU_deref_type";
1564 case DW_OP_GNU_convert:
1565 return "DW_OP_GNU_convert";
1566 case DW_OP_GNU_reinterpret:
1567 return "DW_OP_GNU_reinterpret";
1568 case DW_OP_GNU_parameter_ref:
1569 return "DW_OP_GNU_parameter_ref";
1572 return "OP_<unknown>";
1576 /* Return a pointer to a newly allocated location description. Location
1577 descriptions are simple expression terms that can be strung
1578 together to form more complicated location (address) descriptions. */
1580 static inline dw_loc_descr_ref
1581 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
1582 unsigned HOST_WIDE_INT oprnd2)
1584 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
1586 descr->dw_loc_opc = op;
1587 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
1588 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
1589 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
1590 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
1595 /* Return a pointer to a newly allocated location description for
1598 static inline dw_loc_descr_ref
1599 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
1602 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
1605 return new_loc_descr (DW_OP_bregx, reg, offset);
1608 /* Add a location description term to a location description expression. */
1611 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
1613 dw_loc_descr_ref *d;
1615 /* Find the end of the chain. */
1616 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
1622 /* Compare two location operands for exact equality. */
1625 dw_val_equal_p (dw_val_node *a, dw_val_node *b)
1627 if (a->val_class != b->val_class)
1629 switch (a->val_class)
1631 case dw_val_class_none:
1633 case dw_val_class_addr:
1634 return rtx_equal_p (a->v.val_addr, b->v.val_addr);
1636 case dw_val_class_offset:
1637 case dw_val_class_unsigned_const:
1638 case dw_val_class_const:
1639 case dw_val_class_range_list:
1640 case dw_val_class_lineptr:
1641 case dw_val_class_macptr:
1642 /* These are all HOST_WIDE_INT, signed or unsigned. */
1643 return a->v.val_unsigned == b->v.val_unsigned;
1645 case dw_val_class_loc:
1646 return a->v.val_loc == b->v.val_loc;
1647 case dw_val_class_loc_list:
1648 return a->v.val_loc_list == b->v.val_loc_list;
1649 case dw_val_class_die_ref:
1650 return a->v.val_die_ref.die == b->v.val_die_ref.die;
1651 case dw_val_class_fde_ref:
1652 return a->v.val_fde_index == b->v.val_fde_index;
1653 case dw_val_class_lbl_id:
1654 return strcmp (a->v.val_lbl_id, b->v.val_lbl_id) == 0;
1655 case dw_val_class_str:
1656 return a->v.val_str == b->v.val_str;
1657 case dw_val_class_flag:
1658 return a->v.val_flag == b->v.val_flag;
1659 case dw_val_class_file:
1660 return a->v.val_file == b->v.val_file;
1661 case dw_val_class_decl_ref:
1662 return a->v.val_decl_ref == b->v.val_decl_ref;
1664 case dw_val_class_const_double:
1665 return (a->v.val_double.high == b->v.val_double.high
1666 && a->v.val_double.low == b->v.val_double.low);
1668 case dw_val_class_vec:
1670 size_t a_len = a->v.val_vec.elt_size * a->v.val_vec.length;
1671 size_t b_len = b->v.val_vec.elt_size * b->v.val_vec.length;
1673 return (a_len == b_len
1674 && !memcmp (a->v.val_vec.array, b->v.val_vec.array, a_len));
1677 case dw_val_class_data8:
1678 return memcmp (a->v.val_data8, b->v.val_data8, 8) == 0;
1680 case dw_val_class_vms_delta:
1681 return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)
1682 && !strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1));
1687 /* Compare two location atoms for exact equality. */
1690 loc_descr_equal_p_1 (dw_loc_descr_ref a, dw_loc_descr_ref b)
1692 if (a->dw_loc_opc != b->dw_loc_opc)
1695 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1696 address size, but since we always allocate cleared storage it
1697 should be zero for other types of locations. */
1698 if (a->dtprel != b->dtprel)
1701 return (dw_val_equal_p (&a->dw_loc_oprnd1, &b->dw_loc_oprnd1)
1702 && dw_val_equal_p (&a->dw_loc_oprnd2, &b->dw_loc_oprnd2));
1705 /* Compare two complete location expressions for exact equality. */
1708 loc_descr_equal_p (dw_loc_descr_ref a, dw_loc_descr_ref b)
1714 if (a == NULL || b == NULL)
1716 if (!loc_descr_equal_p_1 (a, b))
1725 /* Add a constant OFFSET to a location expression. */
1728 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
1730 dw_loc_descr_ref loc;
1733 gcc_assert (*list_head != NULL);
1738 /* Find the end of the chain. */
1739 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
1743 if (loc->dw_loc_opc == DW_OP_fbreg
1744 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
1745 p = &loc->dw_loc_oprnd1.v.val_int;
1746 else if (loc->dw_loc_opc == DW_OP_bregx)
1747 p = &loc->dw_loc_oprnd2.v.val_int;
1749 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1750 offset. Don't optimize if an signed integer overflow would happen. */
1752 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
1753 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
1756 else if (offset > 0)
1757 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
1761 loc->dw_loc_next = int_loc_descriptor (-offset);
1762 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
1766 /* Add a constant OFFSET to a location list. */
1769 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
1772 for (d = list_head; d != NULL; d = d->dw_loc_next)
1773 loc_descr_plus_const (&d->expr, offset);
1776 #define DWARF_REF_SIZE \
1777 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1779 static unsigned long int get_base_type_offset (dw_die_ref);
1781 /* Return the size of a location descriptor. */
1783 static unsigned long
1784 size_of_loc_descr (dw_loc_descr_ref loc)
1786 unsigned long size = 1;
1788 switch (loc->dw_loc_opc)
1791 size += DWARF2_ADDR_SIZE;
1810 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1813 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1818 case DW_OP_plus_uconst:
1819 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1857 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1860 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1863 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1866 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1867 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1870 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1872 case DW_OP_bit_piece:
1873 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1874 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
1876 case DW_OP_deref_size:
1877 case DW_OP_xderef_size:
1886 case DW_OP_call_ref:
1887 size += DWARF_REF_SIZE;
1889 case DW_OP_implicit_value:
1890 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1891 + loc->dw_loc_oprnd1.v.val_unsigned;
1893 case DW_OP_GNU_implicit_pointer:
1894 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1896 case DW_OP_GNU_entry_value:
1898 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
1899 size += size_of_uleb128 (op_size) + op_size;
1902 case DW_OP_GNU_const_type:
1905 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1906 size += size_of_uleb128 (o) + 1;
1907 switch (loc->dw_loc_oprnd2.val_class)
1909 case dw_val_class_vec:
1910 size += loc->dw_loc_oprnd2.v.val_vec.length
1911 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
1913 case dw_val_class_const:
1914 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1916 case dw_val_class_const_double:
1917 size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1924 case DW_OP_GNU_regval_type:
1927 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1928 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1929 + size_of_uleb128 (o);
1932 case DW_OP_GNU_deref_type:
1935 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1936 size += 1 + size_of_uleb128 (o);
1939 case DW_OP_GNU_convert:
1940 case DW_OP_GNU_reinterpret:
1941 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
1942 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1946 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1947 size += size_of_uleb128 (o);
1950 case DW_OP_GNU_parameter_ref:
1960 /* Return the size of a series of location descriptors. */
1963 size_of_locs (dw_loc_descr_ref loc)
1968 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1969 field, to avoid writing to a PCH file. */
1970 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1972 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
1974 size += size_of_loc_descr (l);
1979 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1981 l->dw_loc_addr = size;
1982 size += size_of_loc_descr (l);
1988 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
1989 static void get_ref_die_offset_label (char *, dw_die_ref);
1990 static unsigned long int get_ref_die_offset (dw_die_ref);
1992 /* Output location description stack opcode's operands (if any).
1993 The for_eh_or_skip parameter controls whether register numbers are
1994 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1995 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1996 info). This should be suppressed for the cases that have not been converted
1997 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2000 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
2002 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2003 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2005 switch (loc->dw_loc_opc)
2007 #ifdef DWARF2_DEBUGGING_INFO
2010 dw2_asm_output_data (2, val1->v.val_int, NULL);
2015 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2016 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
2018 fputc ('\n', asm_out_file);
2023 dw2_asm_output_data (4, val1->v.val_int, NULL);
2028 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2029 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
2031 fputc ('\n', asm_out_file);
2036 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2037 dw2_asm_output_data (8, val1->v.val_int, NULL);
2044 gcc_assert (val1->val_class == dw_val_class_loc);
2045 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2047 dw2_asm_output_data (2, offset, NULL);
2050 case DW_OP_implicit_value:
2051 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2052 switch (val2->val_class)
2054 case dw_val_class_const:
2055 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
2057 case dw_val_class_vec:
2059 unsigned int elt_size = val2->v.val_vec.elt_size;
2060 unsigned int len = val2->v.val_vec.length;
2064 if (elt_size > sizeof (HOST_WIDE_INT))
2069 for (i = 0, p = val2->v.val_vec.array;
2072 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2073 "fp or vector constant word %u", i);
2076 case dw_val_class_const_double:
2078 unsigned HOST_WIDE_INT first, second;
2080 if (WORDS_BIG_ENDIAN)
2082 first = val2->v.val_double.high;
2083 second = val2->v.val_double.low;
2087 first = val2->v.val_double.low;
2088 second = val2->v.val_double.high;
2090 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2092 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2096 case dw_val_class_addr:
2097 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
2098 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
2113 case DW_OP_implicit_value:
2114 /* We currently don't make any attempt to make sure these are
2115 aligned properly like we do for the main unwind info, so
2116 don't support emitting things larger than a byte if we're
2117 only doing unwinding. */
2122 dw2_asm_output_data (1, val1->v.val_int, NULL);
2125 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2128 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2131 dw2_asm_output_data (1, val1->v.val_int, NULL);
2133 case DW_OP_plus_uconst:
2134 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2168 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2172 unsigned r = val1->v.val_unsigned;
2173 if (for_eh_or_skip >= 0)
2174 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2175 gcc_assert (size_of_uleb128 (r)
2176 == size_of_uleb128 (val1->v.val_unsigned));
2177 dw2_asm_output_data_uleb128 (r, NULL);
2181 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2185 unsigned r = val1->v.val_unsigned;
2186 if (for_eh_or_skip >= 0)
2187 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2188 gcc_assert (size_of_uleb128 (r)
2189 == size_of_uleb128 (val1->v.val_unsigned));
2190 dw2_asm_output_data_uleb128 (r, NULL);
2191 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2195 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2197 case DW_OP_bit_piece:
2198 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2199 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
2201 case DW_OP_deref_size:
2202 case DW_OP_xderef_size:
2203 dw2_asm_output_data (1, val1->v.val_int, NULL);
2209 if (targetm.asm_out.output_dwarf_dtprel)
2211 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
2214 fputc ('\n', asm_out_file);
2221 #ifdef DWARF2_DEBUGGING_INFO
2222 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2229 case DW_OP_GNU_implicit_pointer:
2231 char label[MAX_ARTIFICIAL_LABEL_BYTES
2232 + HOST_BITS_PER_WIDE_INT / 2 + 2];
2233 gcc_assert (val1->val_class == dw_val_class_die_ref);
2234 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2235 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2236 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2240 case DW_OP_GNU_entry_value:
2241 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2242 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2245 case DW_OP_GNU_const_type:
2247 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2249 dw2_asm_output_data_uleb128 (o, NULL);
2250 switch (val2->val_class)
2252 case dw_val_class_const:
2253 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2254 dw2_asm_output_data (1, l, NULL);
2255 dw2_asm_output_data (l, val2->v.val_int, NULL);
2257 case dw_val_class_vec:
2259 unsigned int elt_size = val2->v.val_vec.elt_size;
2260 unsigned int len = val2->v.val_vec.length;
2265 dw2_asm_output_data (1, l, NULL);
2266 if (elt_size > sizeof (HOST_WIDE_INT))
2271 for (i = 0, p = val2->v.val_vec.array;
2274 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2275 "fp or vector constant word %u", i);
2278 case dw_val_class_const_double:
2280 unsigned HOST_WIDE_INT first, second;
2281 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2283 dw2_asm_output_data (1, 2 * l, NULL);
2284 if (WORDS_BIG_ENDIAN)
2286 first = val2->v.val_double.high;
2287 second = val2->v.val_double.low;
2291 first = val2->v.val_double.low;
2292 second = val2->v.val_double.high;
2294 dw2_asm_output_data (l, first, NULL);
2295 dw2_asm_output_data (l, second, NULL);
2303 case DW_OP_GNU_regval_type:
2305 unsigned r = val1->v.val_unsigned;
2306 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2308 if (for_eh_or_skip >= 0)
2310 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2311 gcc_assert (size_of_uleb128 (r)
2312 == size_of_uleb128 (val1->v.val_unsigned));
2314 dw2_asm_output_data_uleb128 (r, NULL);
2315 dw2_asm_output_data_uleb128 (o, NULL);
2318 case DW_OP_GNU_deref_type:
2320 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2322 dw2_asm_output_data (1, val1->v.val_int, NULL);
2323 dw2_asm_output_data_uleb128 (o, NULL);
2326 case DW_OP_GNU_convert:
2327 case DW_OP_GNU_reinterpret:
2328 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2329 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2332 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2334 dw2_asm_output_data_uleb128 (o, NULL);
2338 case DW_OP_GNU_parameter_ref:
2341 gcc_assert (val1->val_class == dw_val_class_die_ref);
2342 o = get_ref_die_offset (val1->v.val_die_ref.die);
2343 dw2_asm_output_data (4, o, NULL);
2348 /* Other codes have no operands. */
2353 /* Output a sequence of location operations.
2354 The for_eh_or_skip parameter controls whether register numbers are
2355 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2356 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2357 info). This should be suppressed for the cases that have not been converted
2358 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2361 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2363 for (; loc != NULL; loc = loc->dw_loc_next)
2365 enum dwarf_location_atom opc = loc->dw_loc_opc;
2366 /* Output the opcode. */
2367 if (for_eh_or_skip >= 0
2368 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2370 unsigned r = (opc - DW_OP_breg0);
2371 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2372 gcc_assert (r <= 31);
2373 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2375 else if (for_eh_or_skip >= 0
2376 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2378 unsigned r = (opc - DW_OP_reg0);
2379 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2380 gcc_assert (r <= 31);
2381 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2384 dw2_asm_output_data (1, opc,
2385 "%s", dwarf_stack_op_name (opc));
2387 /* Output the operand(s) (if any). */
2388 output_loc_operands (loc, for_eh_or_skip);
2392 /* Output location description stack opcode's operands (if any).
2393 The output is single bytes on a line, suitable for .cfi_escape. */
2396 output_loc_operands_raw (dw_loc_descr_ref loc)
2398 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2399 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2401 switch (loc->dw_loc_opc)
2404 case DW_OP_implicit_value:
2405 /* We cannot output addresses in .cfi_escape, only bytes. */
2411 case DW_OP_deref_size:
2412 case DW_OP_xderef_size:
2413 fputc (',', asm_out_file);
2414 dw2_asm_output_data_raw (1, val1->v.val_int);
2419 fputc (',', asm_out_file);
2420 dw2_asm_output_data_raw (2, val1->v.val_int);
2425 fputc (',', asm_out_file);
2426 dw2_asm_output_data_raw (4, val1->v.val_int);
2431 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2432 fputc (',', asm_out_file);
2433 dw2_asm_output_data_raw (8, val1->v.val_int);
2441 gcc_assert (val1->val_class == dw_val_class_loc);
2442 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2444 fputc (',', asm_out_file);
2445 dw2_asm_output_data_raw (2, offset);
2451 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2452 gcc_assert (size_of_uleb128 (r)
2453 == size_of_uleb128 (val1->v.val_unsigned));
2454 fputc (',', asm_out_file);
2455 dw2_asm_output_data_uleb128_raw (r);
2460 case DW_OP_plus_uconst:
2462 fputc (',', asm_out_file);
2463 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2466 case DW_OP_bit_piece:
2467 fputc (',', asm_out_file);
2468 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2469 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
2506 fputc (',', asm_out_file);
2507 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
2512 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2513 gcc_assert (size_of_uleb128 (r)
2514 == size_of_uleb128 (val1->v.val_unsigned));
2515 fputc (',', asm_out_file);
2516 dw2_asm_output_data_uleb128_raw (r);
2517 fputc (',', asm_out_file);
2518 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
2522 case DW_OP_GNU_implicit_pointer:
2523 case DW_OP_GNU_entry_value:
2524 case DW_OP_GNU_const_type:
2525 case DW_OP_GNU_regval_type:
2526 case DW_OP_GNU_deref_type:
2527 case DW_OP_GNU_convert:
2528 case DW_OP_GNU_reinterpret:
2529 case DW_OP_GNU_parameter_ref:
2534 /* Other codes have no operands. */
2540 output_loc_sequence_raw (dw_loc_descr_ref loc)
2544 enum dwarf_location_atom opc = loc->dw_loc_opc;
2545 /* Output the opcode. */
2546 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2548 unsigned r = (opc - DW_OP_breg0);
2549 r = DWARF2_FRAME_REG_OUT (r, 1);
2550 gcc_assert (r <= 31);
2551 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2553 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2555 unsigned r = (opc - DW_OP_reg0);
2556 r = DWARF2_FRAME_REG_OUT (r, 1);
2557 gcc_assert (r <= 31);
2558 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2560 /* Output the opcode. */
2561 fprintf (asm_out_file, "%#x", opc);
2562 output_loc_operands_raw (loc);
2564 if (!loc->dw_loc_next)
2566 loc = loc->dw_loc_next;
2568 fputc (',', asm_out_file);
2572 /* This function builds a dwarf location descriptor sequence from a
2573 dw_cfa_location, adding the given OFFSET to the result of the
2576 struct dw_loc_descr_struct *
2577 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
2579 struct dw_loc_descr_struct *head, *tmp;
2581 offset += cfa->offset;
2585 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
2586 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2587 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2588 add_loc_descr (&head, tmp);
2591 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
2592 add_loc_descr (&head, tmp);
2596 head = new_reg_loc_descr (cfa->reg, offset);
2601 /* This function builds a dwarf location descriptor sequence for
2602 the address at OFFSET from the CFA when stack is aligned to
2605 struct dw_loc_descr_struct *
2606 build_cfa_aligned_loc (dw_cfa_location *cfa,
2607 HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
2609 struct dw_loc_descr_struct *head;
2610 unsigned int dwarf_fp
2611 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
2613 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2614 if (cfa->reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
2616 head = new_reg_loc_descr (dwarf_fp, 0);
2617 add_loc_descr (&head, int_loc_descriptor (alignment));
2618 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
2619 loc_descr_plus_const (&head, offset);
2622 head = new_reg_loc_descr (dwarf_fp, offset);
2626 /* And now, the support for symbolic debugging information. */
2628 /* .debug_str support. */
2629 static int output_indirect_string (void **, void *);
2631 static void dwarf2out_init (const char *);
2632 static void dwarf2out_finish (const char *);
2633 static void dwarf2out_assembly_start (void);
2634 static void dwarf2out_define (unsigned int, const char *);
2635 static void dwarf2out_undef (unsigned int, const char *);
2636 static void dwarf2out_start_source_file (unsigned, const char *);
2637 static void dwarf2out_end_source_file (unsigned);
2638 static void dwarf2out_function_decl (tree);
2639 static void dwarf2out_begin_block (unsigned, unsigned);
2640 static void dwarf2out_end_block (unsigned, unsigned);
2641 static bool dwarf2out_ignore_block (const_tree);
2642 static void dwarf2out_global_decl (tree);
2643 static void dwarf2out_type_decl (tree, int);
2644 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
2645 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
2647 static void dwarf2out_abstract_function (tree);
2648 static void dwarf2out_var_location (rtx);
2649 static void dwarf2out_begin_function (tree);
2650 static void dwarf2out_set_name (tree, tree);
2652 /* The debug hooks structure. */
2654 const struct gcc_debug_hooks dwarf2_debug_hooks =
2658 dwarf2out_assembly_start,
2661 dwarf2out_start_source_file,
2662 dwarf2out_end_source_file,
2663 dwarf2out_begin_block,
2664 dwarf2out_end_block,
2665 dwarf2out_ignore_block,
2666 dwarf2out_source_line,
2667 dwarf2out_begin_prologue,
2668 #if VMS_DEBUGGING_INFO
2669 dwarf2out_vms_end_prologue,
2670 dwarf2out_vms_begin_epilogue,
2672 debug_nothing_int_charstar,
2673 debug_nothing_int_charstar,
2675 dwarf2out_end_epilogue,
2676 dwarf2out_begin_function,
2677 debug_nothing_int, /* end_function */
2678 dwarf2out_function_decl, /* function_decl */
2679 dwarf2out_global_decl,
2680 dwarf2out_type_decl, /* type_decl */
2681 dwarf2out_imported_module_or_decl,
2682 debug_nothing_tree, /* deferred_inline_function */
2683 /* The DWARF 2 backend tries to reduce debugging bloat by not
2684 emitting the abstract description of inline functions until
2685 something tries to reference them. */
2686 dwarf2out_abstract_function, /* outlining_inline_function */
2687 debug_nothing_rtx, /* label */
2688 debug_nothing_int, /* handle_pch */
2689 dwarf2out_var_location,
2690 dwarf2out_switch_text_section,
2692 1, /* start_end_main_source_file */
2693 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
2696 /* NOTE: In the comments in this file, many references are made to
2697 "Debugging Information Entries". This term is abbreviated as `DIE'
2698 throughout the remainder of this file. */
2700 /* An internal representation of the DWARF output is built, and then
2701 walked to generate the DWARF debugging info. The walk of the internal
2702 representation is done after the entire program has been compiled.
2703 The types below are used to describe the internal representation. */
2705 /* Whether to put type DIEs into their own section .debug_types instead
2706 of making them part of the .debug_info section. Only supported for
2707 Dwarf V4 or higher and the user didn't disable them through
2708 -fno-debug-types-section. It is more efficient to put them in a
2709 separate comdat sections since the linker will then be able to
2710 remove duplicates. But not all tools support .debug_types sections
2713 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2715 /* Various DIE's use offsets relative to the beginning of the
2716 .debug_info section to refer to each other. */
2718 typedef long int dw_offset;
2720 /* Define typedefs here to avoid circular dependencies. */
2722 typedef struct dw_attr_struct *dw_attr_ref;
2723 typedef struct dw_line_info_struct *dw_line_info_ref;
2724 typedef struct pubname_struct *pubname_ref;
2725 typedef struct dw_ranges_struct *dw_ranges_ref;
2726 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
2727 typedef struct comdat_type_struct *comdat_type_node_ref;
2729 /* The entries in the line_info table more-or-less mirror the opcodes
2730 that are used in the real dwarf line table. Arrays of these entries
2731 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2734 enum dw_line_info_opcode {
2735 /* Emit DW_LNE_set_address; the operand is the label index. */
2738 /* Emit a row to the matrix with the given line. This may be done
2739 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2743 /* Emit a DW_LNS_set_file. */
2746 /* Emit a DW_LNS_set_column. */
2749 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2752 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2753 LI_set_prologue_end,
2754 LI_set_epilogue_begin,
2756 /* Emit a DW_LNE_set_discriminator. */
2757 LI_set_discriminator
2760 typedef struct GTY(()) dw_line_info_struct {
2761 enum dw_line_info_opcode opcode;
2763 } dw_line_info_entry;
2765 DEF_VEC_O(dw_line_info_entry);
2766 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
2768 typedef struct GTY(()) dw_line_info_table_struct {
2769 /* The label that marks the end of this section. */
2770 const char *end_label;
2772 /* The values for the last row of the matrix, as collected in the table.
2773 These are used to minimize the changes to the next row. */
2774 unsigned int file_num;
2775 unsigned int line_num;
2776 unsigned int column_num;
2781 VEC(dw_line_info_entry, gc) *entries;
2782 } dw_line_info_table;
2784 typedef dw_line_info_table *dw_line_info_table_p;
2786 DEF_VEC_P(dw_line_info_table_p);
2787 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
2789 /* Each DIE attribute has a field specifying the attribute kind,
2790 a link to the next attribute in the chain, and an attribute value.
2791 Attributes are typically linked below the DIE they modify. */
2793 typedef struct GTY(()) dw_attr_struct {
2794 enum dwarf_attribute dw_attr;
2795 dw_val_node dw_attr_val;
2799 DEF_VEC_O(dw_attr_node);
2800 DEF_VEC_ALLOC_O(dw_attr_node,gc);
2802 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2803 The children of each node form a circular list linked by
2804 die_sib. die_child points to the node *before* the "first" child node. */
2806 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
2807 union die_symbol_or_type_node
2809 char * GTY ((tag ("0"))) die_symbol;
2810 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
2812 GTY ((desc ("use_debug_types"))) die_id;
2813 VEC(dw_attr_node,gc) * die_attr;
2814 dw_die_ref die_parent;
2815 dw_die_ref die_child;
2817 dw_die_ref die_definition; /* ref from a specification to its definition */
2818 dw_offset die_offset;
2819 unsigned long die_abbrev;
2821 /* Die is used and must not be pruned as unused. */
2822 int die_perennial_p;
2823 unsigned int decl_id;
2824 enum dwarf_tag die_tag;
2828 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2829 #define FOR_EACH_CHILD(die, c, expr) do { \
2830 c = die->die_child; \
2834 } while (c != die->die_child); \
2837 /* The pubname structure */
2839 typedef struct GTY(()) pubname_struct {
2845 DEF_VEC_O(pubname_entry);
2846 DEF_VEC_ALLOC_O(pubname_entry, gc);
2848 struct GTY(()) dw_ranges_struct {
2849 /* If this is positive, it's a block number, otherwise it's a
2850 bitwise-negated index into dw_ranges_by_label. */
2854 /* A structure to hold a macinfo entry. */
2856 typedef struct GTY(()) macinfo_struct {
2858 unsigned HOST_WIDE_INT lineno;
2863 DEF_VEC_O(macinfo_entry);
2864 DEF_VEC_ALLOC_O(macinfo_entry, gc);
2866 struct GTY(()) dw_ranges_by_label_struct {
2871 /* The comdat type node structure. */
2872 typedef struct GTY(()) comdat_type_struct
2874 dw_die_ref root_die;
2875 dw_die_ref type_die;
2876 char signature[DWARF_TYPE_SIGNATURE_SIZE];
2877 struct comdat_type_struct *next;
2881 /* The limbo die list structure. */
2882 typedef struct GTY(()) limbo_die_struct {
2885 struct limbo_die_struct *next;
2889 typedef struct skeleton_chain_struct
2893 struct skeleton_chain_struct *parent;
2895 skeleton_chain_node;
2897 /* Define a macro which returns nonzero for a TYPE_DECL which was
2898 implicitly generated for a type.
2900 Note that, unlike the C front-end (which generates a NULL named
2901 TYPE_DECL node for each complete tagged type, each array type,
2902 and each function type node created) the C++ front-end generates
2903 a _named_ TYPE_DECL node for each tagged type node created.
2904 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2905 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2906 front-end, but for each type, tagged or not. */
2908 #define TYPE_DECL_IS_STUB(decl) \
2909 (DECL_NAME (decl) == NULL_TREE \
2910 || (DECL_ARTIFICIAL (decl) \
2911 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2912 /* This is necessary for stub decls that \
2913 appear in nested inline functions. */ \
2914 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2915 && (decl_ultimate_origin (decl) \
2916 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2918 /* Information concerning the compilation unit's programming
2919 language, and compiler version. */
2921 /* Fixed size portion of the DWARF compilation unit header. */
2922 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2923 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2925 /* Fixed size portion of the DWARF comdat type unit header. */
2926 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2927 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2928 + DWARF_OFFSET_SIZE)
2930 /* Fixed size portion of public names info. */
2931 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2933 /* Fixed size portion of the address range info. */
2934 #define DWARF_ARANGES_HEADER_SIZE \
2935 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2936 DWARF2_ADDR_SIZE * 2) \
2937 - DWARF_INITIAL_LENGTH_SIZE)
2939 /* Size of padding portion in the address range info. It must be
2940 aligned to twice the pointer size. */
2941 #define DWARF_ARANGES_PAD_SIZE \
2942 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2943 DWARF2_ADDR_SIZE * 2) \
2944 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2946 /* Use assembler line directives if available. */
2947 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2948 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2949 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2951 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2955 /* Minimum line offset in a special line info. opcode.
2956 This value was chosen to give a reasonable range of values. */
2957 #define DWARF_LINE_BASE -10
2959 /* First special line opcode - leave room for the standard opcodes. */
2960 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2962 /* Range of line offsets in a special line info. opcode. */
2963 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2965 /* Flag that indicates the initial value of the is_stmt_start flag.
2966 In the present implementation, we do not mark any lines as
2967 the beginning of a source statement, because that information
2968 is not made available by the GCC front-end. */
2969 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2971 /* Maximum number of operations per instruction bundle. */
2972 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2973 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2976 /* This location is used by calc_die_sizes() to keep track
2977 the offset of each DIE within the .debug_info section. */
2978 static unsigned long next_die_offset;
2980 /* Record the root of the DIE's built for the current compilation unit. */
2981 static GTY(()) dw_die_ref single_comp_unit_die;
2983 /* A list of type DIEs that have been separated into comdat sections. */
2984 static GTY(()) comdat_type_node *comdat_type_list;
2986 /* A list of DIEs with a NULL parent waiting to be relocated. */
2987 static GTY(()) limbo_die_node *limbo_die_list;
2989 /* A list of DIEs for which we may have to generate
2990 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2991 static GTY(()) limbo_die_node *deferred_asm_name;
2993 /* Filenames referenced by this compilation unit. */
2994 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
2996 /* A hash table of references to DIE's that describe declarations.
2997 The key is a DECL_UID() which is a unique number identifying each decl. */
2998 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3000 /* A hash table of references to DIE's that describe COMMON blocks.
3001 The key is DECL_UID() ^ die_parent. */
3002 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
3004 typedef struct GTY(()) die_arg_entry_struct {
3009 DEF_VEC_O(die_arg_entry);
3010 DEF_VEC_ALLOC_O(die_arg_entry,gc);
3012 /* Node of the variable location list. */
3013 struct GTY ((chain_next ("%h.next"))) var_loc_node {
3014 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3015 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3016 in mode of the EXPR_LIST node and first EXPR_LIST operand
3017 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3018 location or NULL for padding. For larger bitsizes,
3019 mode is 0 and first operand is a CONCAT with bitsize
3020 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3021 NULL as second operand. */
3023 const char * GTY (()) label;
3024 struct var_loc_node * GTY (()) next;
3027 /* Variable location list. */
3028 struct GTY (()) var_loc_list_def {
3029 struct var_loc_node * GTY (()) first;
3031 /* Pointer to the last but one or last element of the
3032 chained list. If the list is empty, both first and
3033 last are NULL, if the list contains just one node
3034 or the last node certainly is not redundant, it points
3035 to the last node, otherwise points to the last but one.
3036 Do not mark it for GC because it is marked through the chain. */
3037 struct var_loc_node * GTY ((skip ("%h"))) last;
3039 /* Pointer to the last element before section switch,
3040 if NULL, either sections weren't switched or first
3041 is after section switch. */
3042 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
3044 /* DECL_UID of the variable decl. */
3045 unsigned int decl_id;
3047 typedef struct var_loc_list_def var_loc_list;
3049 /* Call argument location list. */
3050 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
3051 rtx GTY (()) call_arg_loc_note;
3052 const char * GTY (()) label;
3053 tree GTY (()) block;
3055 rtx GTY (()) symbol_ref;
3056 struct call_arg_loc_node * GTY (()) next;
3060 /* Table of decl location linked lists. */
3061 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3063 /* Head and tail of call_arg_loc chain. */
3064 static GTY (()) struct call_arg_loc_node *call_arg_locations;
3065 static struct call_arg_loc_node *call_arg_loc_last;
3067 /* Number of call sites in the current function. */
3068 static int call_site_count = -1;
3069 /* Number of tail call sites in the current function. */
3070 static int tail_call_site_count = -1;
3072 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
3074 static VEC (dw_die_ref, heap) *block_map;
3076 /* A cached location list. */
3077 struct GTY (()) cached_dw_loc_list_def {
3078 /* The DECL_UID of the decl that this entry describes. */
3079 unsigned int decl_id;
3081 /* The cached location list. */
3082 dw_loc_list_ref loc_list;
3084 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
3086 /* Table of cached location lists. */
3087 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
3089 /* A pointer to the base of a list of references to DIE's that
3090 are uniquely identified by their tag, presence/absence of
3091 children DIE's, and list of attribute/value pairs. */
3092 static GTY((length ("abbrev_die_table_allocated")))
3093 dw_die_ref *abbrev_die_table;
3095 /* Number of elements currently allocated for abbrev_die_table. */
3096 static GTY(()) unsigned abbrev_die_table_allocated;
3098 /* Number of elements in type_die_table currently in use. */
3099 static GTY(()) unsigned abbrev_die_table_in_use;
3101 /* Size (in elements) of increments by which we may expand the
3102 abbrev_die_table. */
3103 #define ABBREV_DIE_TABLE_INCREMENT 256
3105 /* A global counter for generating labels for line number data. */
3106 static unsigned int line_info_label_num;
3108 /* The current table to which we should emit line number information
3109 for the current function. This will be set up at the beginning of
3110 assembly for the function. */
3111 static dw_line_info_table *cur_line_info_table;
3113 /* The two default tables of line number info. */
3114 static GTY(()) dw_line_info_table *text_section_line_info;
3115 static GTY(()) dw_line_info_table *cold_text_section_line_info;
3117 /* The set of all non-default tables of line number info. */
3118 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
3120 /* A flag to tell pubnames/types export if there is an info section to
3122 static bool info_section_emitted;
3124 /* A pointer to the base of a table that contains a list of publicly
3125 accessible names. */
3126 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
3128 /* A pointer to the base of a table that contains a list of publicly
3129 accessible types. */
3130 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
3132 /* A pointer to the base of a table that contains a list of macro
3133 defines/undefines (and file start/end markers). */
3134 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
3136 /* Array of dies for which we should generate .debug_ranges info. */
3137 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3139 /* Number of elements currently allocated for ranges_table. */
3140 static GTY(()) unsigned ranges_table_allocated;
3142 /* Number of elements in ranges_table currently in use. */
3143 static GTY(()) unsigned ranges_table_in_use;
3145 /* Array of pairs of labels referenced in ranges_table. */
3146 static GTY ((length ("ranges_by_label_allocated")))
3147 dw_ranges_by_label_ref ranges_by_label;
3149 /* Number of elements currently allocated for ranges_by_label. */
3150 static GTY(()) unsigned ranges_by_label_allocated;
3152 /* Number of elements in ranges_by_label currently in use. */
3153 static GTY(()) unsigned ranges_by_label_in_use;
3155 /* Size (in elements) of increments by which we may expand the
3157 #define RANGES_TABLE_INCREMENT 64
3159 /* Whether we have location lists that need outputting */
3160 static GTY(()) bool have_location_lists;
3162 /* Unique label counter. */
3163 static GTY(()) unsigned int loclabel_num;
3165 /* Unique label counter for point-of-call tables. */
3166 static GTY(()) unsigned int poc_label_num;
3168 /* Record whether the function being analyzed contains inlined functions. */
3169 static int current_function_has_inlines;
3171 /* The last file entry emitted by maybe_emit_file(). */
3172 static GTY(()) struct dwarf_file_data * last_emitted_file;
3174 /* Number of internal labels generated by gen_internal_sym(). */
3175 static GTY(()) int label_num;
3177 /* Cached result of previous call to lookup_filename. */
3178 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
3180 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
3182 /* Instances of generic types for which we need to generate debug
3183 info that describe their generic parameters and arguments. That
3184 generation needs to happen once all types are properly laid out so
3185 we do it at the end of compilation. */
3186 static GTY(()) VEC(tree,gc) *generic_type_instances;
3188 /* Offset from the "steady-state frame pointer" to the frame base,
3189 within the current function. */
3190 static HOST_WIDE_INT frame_pointer_fb_offset;
3191 static bool frame_pointer_fb_offset_valid;
3193 static VEC (dw_die_ref, heap) *base_types;
3195 /* Forward declarations for functions defined in this file. */
3197 static int is_pseudo_reg (const_rtx);
3198 static tree type_main_variant (tree);
3199 static int is_tagged_type (const_tree);
3200 static const char *dwarf_tag_name (unsigned);
3201 static const char *dwarf_attr_name (unsigned);
3202 static const char *dwarf_form_name (unsigned);
3203 static tree decl_ultimate_origin (const_tree);
3204 static tree decl_class_context (tree);
3205 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3206 static inline enum dw_val_class AT_class (dw_attr_ref);
3207 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3208 static inline unsigned AT_flag (dw_attr_ref);
3209 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3210 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3211 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3212 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3213 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3214 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3215 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3216 unsigned int, unsigned char *);
3217 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3218 static hashval_t debug_str_do_hash (const void *);
3219 static int debug_str_eq (const void *, const void *);
3220 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3221 static inline const char *AT_string (dw_attr_ref);
3222 static enum dwarf_form AT_string_form (dw_attr_ref);
3223 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3224 static void add_AT_specification (dw_die_ref, dw_die_ref);
3225 static inline dw_die_ref AT_ref (dw_attr_ref);
3226 static inline int AT_ref_external (dw_attr_ref);
3227 static inline void set_AT_ref_external (dw_attr_ref, int);
3228 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3229 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3230 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3231 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3233 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3234 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3235 static inline rtx AT_addr (dw_attr_ref);
3236 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3237 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3238 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3239 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3240 unsigned HOST_WIDE_INT);
3241 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3243 static inline const char *AT_lbl (dw_attr_ref);
3244 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3245 static const char *get_AT_low_pc (dw_die_ref);
3246 static const char *get_AT_hi_pc (dw_die_ref);
3247 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3248 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3249 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3250 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3251 static bool is_cxx (void);
3252 static bool is_fortran (void);
3253 static bool is_ada (void);
3254 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3255 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3256 static void add_child_die (dw_die_ref, dw_die_ref);
3257 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3258 static dw_die_ref lookup_type_die (tree);
3259 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3260 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3261 static void equate_type_number_to_die (tree, dw_die_ref);
3262 static hashval_t decl_die_table_hash (const void *);
3263 static int decl_die_table_eq (const void *, const void *);
3264 static dw_die_ref lookup_decl_die (tree);
3265 static hashval_t common_block_die_table_hash (const void *);
3266 static int common_block_die_table_eq (const void *, const void *);
3267 static hashval_t decl_loc_table_hash (const void *);
3268 static int decl_loc_table_eq (const void *, const void *);
3269 static var_loc_list *lookup_decl_loc (const_tree);
3270 static void equate_decl_number_to_die (tree, dw_die_ref);
3271 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
3272 static void print_spaces (FILE *);
3273 static void print_die (dw_die_ref, FILE *);
3274 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3275 static dw_die_ref pop_compile_unit (dw_die_ref);
3276 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3277 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3278 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3279 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3280 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3281 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3282 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
3283 struct md5_ctx *, int *);
3284 struct checksum_attributes;
3285 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3286 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3287 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3288 static void generate_type_signature (dw_die_ref, comdat_type_node *);
3289 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3290 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3291 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3292 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3293 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3294 static void compute_section_prefix (dw_die_ref);
3295 static int is_type_die (dw_die_ref);
3296 static int is_comdat_die (dw_die_ref);
3297 static int is_symbol_die (dw_die_ref);
3298 static void assign_symbol_names (dw_die_ref);
3299 static void break_out_includes (dw_die_ref);
3300 static int is_declaration_die (dw_die_ref);
3301 static int should_move_die_to_comdat (dw_die_ref);
3302 static dw_die_ref clone_as_declaration (dw_die_ref);
3303 static dw_die_ref clone_die (dw_die_ref);
3304 static dw_die_ref clone_tree (dw_die_ref);
3305 static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref);
3306 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3307 static void generate_skeleton_bottom_up (skeleton_chain_node *);
3308 static dw_die_ref generate_skeleton (dw_die_ref);
3309 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3312 static void break_out_comdat_types (dw_die_ref);
3313 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
3314 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
3315 static void copy_decls_for_unworthy_types (dw_die_ref);
3317 static hashval_t htab_cu_hash (const void *);
3318 static int htab_cu_eq (const void *, const void *);
3319 static void htab_cu_del (void *);
3320 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3321 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3322 static void add_sibling_attributes (dw_die_ref);
3323 static void build_abbrev_table (dw_die_ref);
3324 static void output_location_lists (dw_die_ref);
3325 static int constant_size (unsigned HOST_WIDE_INT);
3326 static unsigned long size_of_die (dw_die_ref);
3327 static void calc_die_sizes (dw_die_ref);
3328 static void calc_base_type_die_sizes (void);
3329 static void mark_dies (dw_die_ref);
3330 static void unmark_dies (dw_die_ref);
3331 static void unmark_all_dies (dw_die_ref);
3332 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
3333 static unsigned long size_of_aranges (void);
3334 static enum dwarf_form value_format (dw_attr_ref);
3335 static void output_value_format (dw_attr_ref);
3336 static void output_abbrev_section (void);
3337 static void output_die_symbol (dw_die_ref);
3338 static void output_die (dw_die_ref);
3339 static void output_compilation_unit_header (void);
3340 static void output_comp_unit (dw_die_ref, int);
3341 static void output_comdat_type_unit (comdat_type_node *);
3342 static const char *dwarf2_name (tree, int);
3343 static void add_pubname (tree, dw_die_ref);
3344 static void add_pubname_string (const char *, dw_die_ref);
3345 static void add_pubtype (tree, dw_die_ref);
3346 static void output_pubnames (VEC (pubname_entry,gc) *);
3347 static void output_aranges (unsigned long);
3348 static unsigned int add_ranges_num (int);
3349 static unsigned int add_ranges (const_tree);
3350 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3352 static void output_ranges (void);
3353 static dw_line_info_table *new_line_info_table (void);
3354 static void output_line_info (void);
3355 static void output_file_names (void);
3356 static dw_die_ref base_type_die (tree);
3357 static int is_base_type (tree);
3358 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
3359 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3360 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3361 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3362 static int type_is_enum (const_tree);
3363 static unsigned int dbx_reg_number (const_rtx);
3364 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3365 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3366 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3367 enum var_init_status);
3368 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3369 enum var_init_status);
3370 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
3371 enum var_init_status);
3372 static int is_based_loc (const_rtx);
3373 static int resolve_one_addr (rtx *, void *);
3374 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3375 enum var_init_status);
3376 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
3377 enum var_init_status);
3378 static dw_loc_list_ref loc_list_from_tree (tree, int);
3379 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3380 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3381 static tree field_type (const_tree);
3382 static unsigned int simple_type_align_in_bits (const_tree);
3383 static unsigned int simple_decl_align_in_bits (const_tree);
3384 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3385 static HOST_WIDE_INT field_byte_offset (const_tree);
3386 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3388 static void add_data_member_location_attribute (dw_die_ref, tree);
3389 static bool add_const_value_attribute (dw_die_ref, rtx);
3390 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3391 static void insert_double (double_int, unsigned char *);
3392 static void insert_float (const_rtx, unsigned char *);
3393 static rtx rtl_for_decl_location (tree);
3394 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
3395 enum dwarf_attribute);
3396 static bool tree_add_const_value_attribute (dw_die_ref, tree);
3397 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3398 static void add_name_attribute (dw_die_ref, const char *);
3399 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3400 static void add_comp_dir_attribute (dw_die_ref);
3401 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3402 static void add_subscript_info (dw_die_ref, tree, bool);
3403 static void add_byte_size_attribute (dw_die_ref, tree);
3404 static void add_bit_offset_attribute (dw_die_ref, tree);
3405 static void add_bit_size_attribute (dw_die_ref, tree);
3406 static void add_prototyped_attribute (dw_die_ref, tree);
3407 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
3408 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3409 static void add_src_coords_attributes (dw_die_ref, tree);
3410 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3411 static void push_decl_scope (tree);
3412 static void pop_decl_scope (void);
3413 static dw_die_ref scope_die_for (tree, dw_die_ref);
3414 static inline int local_scope_p (dw_die_ref);
3415 static inline int class_scope_p (dw_die_ref);
3416 static inline int class_or_namespace_scope_p (dw_die_ref);
3417 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3418 static void add_calling_convention_attribute (dw_die_ref, tree);
3419 static const char *type_tag (const_tree);
3420 static tree member_declared_type (const_tree);
3422 static const char *decl_start_label (tree);
3424 static void gen_array_type_die (tree, dw_die_ref);
3425 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
3427 static void gen_entry_point_die (tree, dw_die_ref);
3429 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3430 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
3431 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
3432 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3433 static void gen_formal_types_die (tree, dw_die_ref);
3434 static void gen_subprogram_die (tree, dw_die_ref);
3435 static void gen_variable_die (tree, tree, dw_die_ref);
3436 static void gen_const_die (tree, dw_die_ref);
3437 static void gen_label_die (tree, dw_die_ref);
3438 static void gen_lexical_block_die (tree, dw_die_ref, int);
3439 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3440 static void gen_field_die (tree, dw_die_ref);
3441 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3442 static dw_die_ref gen_compile_unit_die (const char *);
3443 static void gen_inheritance_die (tree, tree, dw_die_ref);
3444 static void gen_member_die (tree, dw_die_ref);
3445 static void gen_struct_or_union_type_die (tree, dw_die_ref,
3446 enum debug_info_usage);
3447 static void gen_subroutine_type_die (tree, dw_die_ref);
3448 static void gen_typedef_die (tree, dw_die_ref);
3449 static void gen_type_die (tree, dw_die_ref);
3450 static void gen_block_die (tree, dw_die_ref, int);
3451 static void decls_for_scope (tree, dw_die_ref, int);
3452 static inline int is_redundant_typedef (const_tree);
3453 static bool is_naming_typedef_decl (const_tree);
3454 static inline dw_die_ref get_context_die (tree);
3455 static void gen_namespace_die (tree, dw_die_ref);
3456 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
3457 static dw_die_ref force_decl_die (tree);
3458 static dw_die_ref force_type_die (tree);
3459 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3460 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
3461 static struct dwarf_file_data * lookup_filename (const char *);
3462 static void retry_incomplete_types (void);
3463 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3464 static void gen_generic_params_dies (tree);
3465 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
3466 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
3467 static void splice_child_die (dw_die_ref, dw_die_ref);
3468 static int file_info_cmp (const void *, const void *);
3469 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3470 const char *, const char *);
3471 static void output_loc_list (dw_loc_list_ref);
3472 static char *gen_internal_sym (const char *);
3474 static void prune_unmark_dies (dw_die_ref);
3475 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
3476 static void prune_unused_types_mark (dw_die_ref, int);
3477 static void prune_unused_types_walk (dw_die_ref);
3478 static void prune_unused_types_walk_attribs (dw_die_ref);
3479 static void prune_unused_types_prune (dw_die_ref);
3480 static void prune_unused_types (void);
3481 static int maybe_emit_file (struct dwarf_file_data *fd);
3482 static inline const char *AT_vms_delta1 (dw_attr_ref);
3483 static inline const char *AT_vms_delta2 (dw_attr_ref);
3484 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
3485 const char *, const char *);
3486 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
3487 static void gen_remaining_tmpl_value_param_die_attribute (void);
3488 static bool generic_type_p (tree);
3489 static void schedule_generic_params_dies_gen (tree t);
3490 static void gen_scheduled_generic_parms_dies (void);
3492 /* Section names used to hold DWARF debugging information. */
3493 #ifndef DEBUG_INFO_SECTION
3494 #define DEBUG_INFO_SECTION ".debug_info"
3496 #ifndef DEBUG_ABBREV_SECTION
3497 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3499 #ifndef DEBUG_ARANGES_SECTION
3500 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3502 #ifndef DEBUG_MACINFO_SECTION
3503 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3505 #ifndef DEBUG_MACRO_SECTION
3506 #define DEBUG_MACRO_SECTION ".debug_macro"
3508 #ifndef DEBUG_LINE_SECTION
3509 #define DEBUG_LINE_SECTION ".debug_line"
3511 #ifndef DEBUG_LOC_SECTION
3512 #define DEBUG_LOC_SECTION ".debug_loc"
3514 #ifndef DEBUG_PUBNAMES_SECTION
3515 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3517 #ifndef DEBUG_PUBTYPES_SECTION
3518 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3520 #ifndef DEBUG_STR_SECTION
3521 #define DEBUG_STR_SECTION ".debug_str"
3523 #ifndef DEBUG_RANGES_SECTION
3524 #define DEBUG_RANGES_SECTION ".debug_ranges"
3527 /* Standard ELF section names for compiled code and data. */
3528 #ifndef TEXT_SECTION_NAME
3529 #define TEXT_SECTION_NAME ".text"
3532 /* Section flags for .debug_str section. */
3533 #define DEBUG_STR_SECTION_FLAGS \
3534 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3535 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3538 /* Labels we insert at beginning sections we can reference instead of
3539 the section names themselves. */
3541 #ifndef TEXT_SECTION_LABEL
3542 #define TEXT_SECTION_LABEL "Ltext"
3544 #ifndef COLD_TEXT_SECTION_LABEL
3545 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3547 #ifndef DEBUG_LINE_SECTION_LABEL
3548 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3550 #ifndef DEBUG_INFO_SECTION_LABEL
3551 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3553 #ifndef DEBUG_ABBREV_SECTION_LABEL
3554 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3556 #ifndef DEBUG_LOC_SECTION_LABEL
3557 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3559 #ifndef DEBUG_RANGES_SECTION_LABEL
3560 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3562 #ifndef DEBUG_MACINFO_SECTION_LABEL
3563 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3565 #ifndef DEBUG_MACRO_SECTION_LABEL
3566 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3570 /* Definitions of defaults for formats and names of various special
3571 (artificial) labels which may be generated within this file (when the -g
3572 options is used and DWARF2_DEBUGGING_INFO is in effect.
3573 If necessary, these may be overridden from within the tm.h file, but
3574 typically, overriding these defaults is unnecessary. */
3576 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3577 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3578 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3579 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3580 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3581 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3582 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3583 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3584 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3585 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3587 #ifndef TEXT_END_LABEL
3588 #define TEXT_END_LABEL "Letext"
3590 #ifndef COLD_END_LABEL
3591 #define COLD_END_LABEL "Letext_cold"
3593 #ifndef BLOCK_BEGIN_LABEL
3594 #define BLOCK_BEGIN_LABEL "LBB"
3596 #ifndef BLOCK_END_LABEL
3597 #define BLOCK_END_LABEL "LBE"
3599 #ifndef LINE_CODE_LABEL
3600 #define LINE_CODE_LABEL "LM"
3604 /* Return the root of the DIE's built for the current compilation unit. */
3606 comp_unit_die (void)
3608 if (!single_comp_unit_die)
3609 single_comp_unit_die = gen_compile_unit_die (NULL);
3610 return single_comp_unit_die;
3613 /* We allow a language front-end to designate a function that is to be
3614 called to "demangle" any name before it is put into a DIE. */
3616 static const char *(*demangle_name_func) (const char *);
3619 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3621 demangle_name_func = func;
3624 /* Test if rtl node points to a pseudo register. */
3627 is_pseudo_reg (const_rtx rtl)
3629 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3630 || (GET_CODE (rtl) == SUBREG
3631 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3634 /* Return a reference to a type, with its const and volatile qualifiers
3638 type_main_variant (tree type)
3640 type = TYPE_MAIN_VARIANT (type);
3642 /* ??? There really should be only one main variant among any group of
3643 variants of a given type (and all of the MAIN_VARIANT values for all
3644 members of the group should point to that one type) but sometimes the C
3645 front-end messes this up for array types, so we work around that bug
3647 if (TREE_CODE (type) == ARRAY_TYPE)
3648 while (type != TYPE_MAIN_VARIANT (type))
3649 type = TYPE_MAIN_VARIANT (type);
3654 /* Return nonzero if the given type node represents a tagged type. */
3657 is_tagged_type (const_tree type)
3659 enum tree_code code = TREE_CODE (type);
3661 return (code == RECORD_TYPE || code == UNION_TYPE
3662 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3665 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3668 get_ref_die_offset_label (char *label, dw_die_ref ref)
3670 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
3673 /* Return die_offset of a DIE reference to a base type. */
3675 static unsigned long int
3676 get_base_type_offset (dw_die_ref ref)
3678 if (ref->die_offset)
3679 return ref->die_offset;
3680 if (comp_unit_die ()->die_abbrev)
3682 calc_base_type_die_sizes ();
3683 gcc_assert (ref->die_offset);
3685 return ref->die_offset;
3688 /* Return die_offset of a DIE reference other than base type. */
3690 static unsigned long int
3691 get_ref_die_offset (dw_die_ref ref)
3693 gcc_assert (ref->die_offset);
3694 return ref->die_offset;
3697 /* Convert a DIE tag into its string name. */
3700 dwarf_tag_name (unsigned int tag)
3704 case DW_TAG_padding:
3705 return "DW_TAG_padding";
3706 case DW_TAG_array_type:
3707 return "DW_TAG_array_type";
3708 case DW_TAG_class_type:
3709 return "DW_TAG_class_type";
3710 case DW_TAG_entry_point:
3711 return "DW_TAG_entry_point";
3712 case DW_TAG_enumeration_type:
3713 return "DW_TAG_enumeration_type";
3714 case DW_TAG_formal_parameter:
3715 return "DW_TAG_formal_parameter";
3716 case DW_TAG_imported_declaration:
3717 return "DW_TAG_imported_declaration";
3719 return "DW_TAG_label";
3720 case DW_TAG_lexical_block:
3721 return "DW_TAG_lexical_block";
3723 return "DW_TAG_member";
3724 case DW_TAG_pointer_type:
3725 return "DW_TAG_pointer_type";
3726 case DW_TAG_reference_type:
3727 return "DW_TAG_reference_type";
3728 case DW_TAG_compile_unit:
3729 return "DW_TAG_compile_unit";
3730 case DW_TAG_string_type:
3731 return "DW_TAG_string_type";
3732 case DW_TAG_structure_type:
3733 return "DW_TAG_structure_type";
3734 case DW_TAG_subroutine_type:
3735 return "DW_TAG_subroutine_type";
3736 case DW_TAG_typedef:
3737 return "DW_TAG_typedef";
3738 case DW_TAG_union_type:
3739 return "DW_TAG_union_type";
3740 case DW_TAG_unspecified_parameters:
3741 return "DW_TAG_unspecified_parameters";
3742 case DW_TAG_variant:
3743 return "DW_TAG_variant";
3744 case DW_TAG_common_block:
3745 return "DW_TAG_common_block";
3746 case DW_TAG_common_inclusion:
3747 return "DW_TAG_common_inclusion";
3748 case DW_TAG_inheritance:
3749 return "DW_TAG_inheritance";
3750 case DW_TAG_inlined_subroutine:
3751 return "DW_TAG_inlined_subroutine";
3753 return "DW_TAG_module";
3754 case DW_TAG_ptr_to_member_type:
3755 return "DW_TAG_ptr_to_member_type";
3756 case DW_TAG_set_type:
3757 return "DW_TAG_set_type";
3758 case DW_TAG_subrange_type:
3759 return "DW_TAG_subrange_type";
3760 case DW_TAG_with_stmt:
3761 return "DW_TAG_with_stmt";
3762 case DW_TAG_access_declaration:
3763 return "DW_TAG_access_declaration";
3764 case DW_TAG_base_type:
3765 return "DW_TAG_base_type";
3766 case DW_TAG_catch_block:
3767 return "DW_TAG_catch_block";
3768 case DW_TAG_const_type:
3769 return "DW_TAG_const_type";
3770 case DW_TAG_constant:
3771 return "DW_TAG_constant";
3772 case DW_TAG_enumerator:
3773 return "DW_TAG_enumerator";
3774 case DW_TAG_file_type:
3775 return "DW_TAG_file_type";
3777 return "DW_TAG_friend";
3778 case DW_TAG_namelist:
3779 return "DW_TAG_namelist";
3780 case DW_TAG_namelist_item:
3781 return "DW_TAG_namelist_item";
3782 case DW_TAG_packed_type:
3783 return "DW_TAG_packed_type";
3784 case DW_TAG_subprogram:
3785 return "DW_TAG_subprogram";
3786 case DW_TAG_template_type_param:
3787 return "DW_TAG_template_type_param";
3788 case DW_TAG_template_value_param:
3789 return "DW_TAG_template_value_param";
3790 case DW_TAG_thrown_type:
3791 return "DW_TAG_thrown_type";
3792 case DW_TAG_try_block:
3793 return "DW_TAG_try_block";
3794 case DW_TAG_variant_part:
3795 return "DW_TAG_variant_part";
3796 case DW_TAG_variable:
3797 return "DW_TAG_variable";
3798 case DW_TAG_volatile_type:
3799 return "DW_TAG_volatile_type";
3800 case DW_TAG_dwarf_procedure:
3801 return "DW_TAG_dwarf_procedure";
3802 case DW_TAG_restrict_type:
3803 return "DW_TAG_restrict_type";
3804 case DW_TAG_interface_type:
3805 return "DW_TAG_interface_type";
3806 case DW_TAG_namespace:
3807 return "DW_TAG_namespace";
3808 case DW_TAG_imported_module:
3809 return "DW_TAG_imported_module";
3810 case DW_TAG_unspecified_type:
3811 return "DW_TAG_unspecified_type";
3812 case DW_TAG_partial_unit:
3813 return "DW_TAG_partial_unit";
3814 case DW_TAG_imported_unit:
3815 return "DW_TAG_imported_unit";
3816 case DW_TAG_condition:
3817 return "DW_TAG_condition";
3818 case DW_TAG_shared_type:
3819 return "DW_TAG_shared_type";
3820 case DW_TAG_type_unit:
3821 return "DW_TAG_type_unit";
3822 case DW_TAG_rvalue_reference_type:
3823 return "DW_TAG_rvalue_reference_type";
3824 case DW_TAG_template_alias:
3825 return "DW_TAG_template_alias";
3826 case DW_TAG_GNU_template_parameter_pack:
3827 return "DW_TAG_GNU_template_parameter_pack";
3828 case DW_TAG_GNU_formal_parameter_pack:
3829 return "DW_TAG_GNU_formal_parameter_pack";
3830 case DW_TAG_MIPS_loop:
3831 return "DW_TAG_MIPS_loop";
3832 case DW_TAG_format_label:
3833 return "DW_TAG_format_label";
3834 case DW_TAG_function_template:
3835 return "DW_TAG_function_template";
3836 case DW_TAG_class_template:
3837 return "DW_TAG_class_template";
3838 case DW_TAG_GNU_BINCL:
3839 return "DW_TAG_GNU_BINCL";
3840 case DW_TAG_GNU_EINCL:
3841 return "DW_TAG_GNU_EINCL";
3842 case DW_TAG_GNU_template_template_param:
3843 return "DW_TAG_GNU_template_template_param";
3844 case DW_TAG_GNU_call_site:
3845 return "DW_TAG_GNU_call_site";
3846 case DW_TAG_GNU_call_site_parameter:
3847 return "DW_TAG_GNU_call_site_parameter";
3849 return "DW_TAG_<unknown>";
3853 /* Convert a DWARF attribute code into its string name. */
3856 dwarf_attr_name (unsigned int attr)
3861 return "DW_AT_sibling";
3862 case DW_AT_location:
3863 return "DW_AT_location";
3865 return "DW_AT_name";
3866 case DW_AT_ordering:
3867 return "DW_AT_ordering";
3868 case DW_AT_subscr_data:
3869 return "DW_AT_subscr_data";
3870 case DW_AT_byte_size:
3871 return "DW_AT_byte_size";
3872 case DW_AT_bit_offset:
3873 return "DW_AT_bit_offset";
3874 case DW_AT_bit_size:
3875 return "DW_AT_bit_size";
3876 case DW_AT_element_list:
3877 return "DW_AT_element_list";
3878 case DW_AT_stmt_list:
3879 return "DW_AT_stmt_list";
3881 return "DW_AT_low_pc";
3883 return "DW_AT_high_pc";
3884 case DW_AT_language:
3885 return "DW_AT_language";
3887 return "DW_AT_member";
3889 return "DW_AT_discr";
3890 case DW_AT_discr_value:
3891 return "DW_AT_discr_value";
3892 case DW_AT_visibility:
3893 return "DW_AT_visibility";
3895 return "DW_AT_import";
3896 case DW_AT_string_length:
3897 return "DW_AT_string_length";
3898 case DW_AT_common_reference:
3899 return "DW_AT_common_reference";
3900 case DW_AT_comp_dir:
3901 return "DW_AT_comp_dir";
3902 case DW_AT_const_value:
3903 return "DW_AT_const_value";
3904 case DW_AT_containing_type:
3905 return "DW_AT_containing_type";
3906 case DW_AT_default_value:
3907 return "DW_AT_default_value";
3909 return "DW_AT_inline";
3910 case DW_AT_is_optional:
3911 return "DW_AT_is_optional";
3912 case DW_AT_lower_bound:
3913 return "DW_AT_lower_bound";
3914 case DW_AT_producer:
3915 return "DW_AT_producer";
3916 case DW_AT_prototyped:
3917 return "DW_AT_prototyped";
3918 case DW_AT_return_addr:
3919 return "DW_AT_return_addr";
3920 case DW_AT_start_scope:
3921 return "DW_AT_start_scope";
3922 case DW_AT_bit_stride:
3923 return "DW_AT_bit_stride";
3924 case DW_AT_upper_bound:
3925 return "DW_AT_upper_bound";
3926 case DW_AT_abstract_origin:
3927 return "DW_AT_abstract_origin";
3928 case DW_AT_accessibility:
3929 return "DW_AT_accessibility";
3930 case DW_AT_address_class:
3931 return "DW_AT_address_class";
3932 case DW_AT_artificial:
3933 return "DW_AT_artificial";
3934 case DW_AT_base_types:
3935 return "DW_AT_base_types";
3936 case DW_AT_calling_convention:
3937 return "DW_AT_calling_convention";
3939 return "DW_AT_count";
3940 case DW_AT_data_member_location:
3941 return "DW_AT_data_member_location";
3942 case DW_AT_decl_column:
3943 return "DW_AT_decl_column";
3944 case DW_AT_decl_file:
3945 return "DW_AT_decl_file";
3946 case DW_AT_decl_line:
3947 return "DW_AT_decl_line";
3948 case DW_AT_declaration:
3949 return "DW_AT_declaration";
3950 case DW_AT_discr_list:
3951 return "DW_AT_discr_list";
3952 case DW_AT_encoding:
3953 return "DW_AT_encoding";
3954 case DW_AT_external:
3955 return "DW_AT_external";
3956 case DW_AT_explicit:
3957 return "DW_AT_explicit";
3958 case DW_AT_frame_base:
3959 return "DW_AT_frame_base";
3961 return "DW_AT_friend";
3962 case DW_AT_identifier_case:
3963 return "DW_AT_identifier_case";
3964 case DW_AT_macro_info:
3965 return "DW_AT_macro_info";
3966 case DW_AT_namelist_items:
3967 return "DW_AT_namelist_items";
3968 case DW_AT_priority:
3969 return "DW_AT_priority";
3971 return "DW_AT_segment";
3972 case DW_AT_specification:
3973 return "DW_AT_specification";
3974 case DW_AT_static_link:
3975 return "DW_AT_static_link";
3977 return "DW_AT_type";
3978 case DW_AT_use_location:
3979 return "DW_AT_use_location";
3980 case DW_AT_variable_parameter:
3981 return "DW_AT_variable_parameter";
3982 case DW_AT_virtuality:
3983 return "DW_AT_virtuality";
3984 case DW_AT_vtable_elem_location:
3985 return "DW_AT_vtable_elem_location";
3987 case DW_AT_allocated:
3988 return "DW_AT_allocated";
3989 case DW_AT_associated:
3990 return "DW_AT_associated";
3991 case DW_AT_data_location:
3992 return "DW_AT_data_location";
3993 case DW_AT_byte_stride:
3994 return "DW_AT_byte_stride";
3995 case DW_AT_entry_pc:
3996 return "DW_AT_entry_pc";
3997 case DW_AT_use_UTF8:
3998 return "DW_AT_use_UTF8";
3999 case DW_AT_extension:
4000 return "DW_AT_extension";
4002 return "DW_AT_ranges";
4003 case DW_AT_trampoline:
4004 return "DW_AT_trampoline";
4005 case DW_AT_call_column:
4006 return "DW_AT_call_column";
4007 case DW_AT_call_file:
4008 return "DW_AT_call_file";
4009 case DW_AT_call_line:
4010 return "DW_AT_call_line";
4011 case DW_AT_object_pointer:
4012 return "DW_AT_object_pointer";
4014 case DW_AT_signature:
4015 return "DW_AT_signature";
4016 case DW_AT_main_subprogram:
4017 return "DW_AT_main_subprogram";
4018 case DW_AT_data_bit_offset:
4019 return "DW_AT_data_bit_offset";
4020 case DW_AT_const_expr:
4021 return "DW_AT_const_expr";
4022 case DW_AT_enum_class:
4023 return "DW_AT_enum_class";
4024 case DW_AT_linkage_name:
4025 return "DW_AT_linkage_name";
4027 case DW_AT_MIPS_fde:
4028 return "DW_AT_MIPS_fde";
4029 case DW_AT_MIPS_loop_begin:
4030 return "DW_AT_MIPS_loop_begin";
4031 case DW_AT_MIPS_tail_loop_begin:
4032 return "DW_AT_MIPS_tail_loop_begin";
4033 case DW_AT_MIPS_epilog_begin:
4034 return "DW_AT_MIPS_epilog_begin";
4035 #if VMS_DEBUGGING_INFO
4036 case DW_AT_HP_prologue:
4037 return "DW_AT_HP_prologue";
4039 case DW_AT_MIPS_loop_unroll_factor:
4040 return "DW_AT_MIPS_loop_unroll_factor";
4042 case DW_AT_MIPS_software_pipeline_depth:
4043 return "DW_AT_MIPS_software_pipeline_depth";
4044 case DW_AT_MIPS_linkage_name:
4045 return "DW_AT_MIPS_linkage_name";
4046 #if VMS_DEBUGGING_INFO
4047 case DW_AT_HP_epilogue:
4048 return "DW_AT_HP_epilogue";
4050 case DW_AT_MIPS_stride:
4051 return "DW_AT_MIPS_stride";
4053 case DW_AT_MIPS_abstract_name:
4054 return "DW_AT_MIPS_abstract_name";
4055 case DW_AT_MIPS_clone_origin:
4056 return "DW_AT_MIPS_clone_origin";
4057 case DW_AT_MIPS_has_inlines:
4058 return "DW_AT_MIPS_has_inlines";
4060 case DW_AT_sf_names:
4061 return "DW_AT_sf_names";
4062 case DW_AT_src_info:
4063 return "DW_AT_src_info";
4064 case DW_AT_mac_info:
4065 return "DW_AT_mac_info";
4066 case DW_AT_src_coords:
4067 return "DW_AT_src_coords";
4068 case DW_AT_body_begin:
4069 return "DW_AT_body_begin";
4070 case DW_AT_body_end:
4071 return "DW_AT_body_end";
4073 case DW_AT_GNU_vector:
4074 return "DW_AT_GNU_vector";
4075 case DW_AT_GNU_guarded_by:
4076 return "DW_AT_GNU_guarded_by";
4077 case DW_AT_GNU_pt_guarded_by:
4078 return "DW_AT_GNU_pt_guarded_by";
4079 case DW_AT_GNU_guarded:
4080 return "DW_AT_GNU_guarded";
4081 case DW_AT_GNU_pt_guarded:
4082 return "DW_AT_GNU_pt_guarded";
4083 case DW_AT_GNU_locks_excluded:
4084 return "DW_AT_GNU_locks_excluded";
4085 case DW_AT_GNU_exclusive_locks_required:
4086 return "DW_AT_GNU_exclusive_locks_required";
4087 case DW_AT_GNU_shared_locks_required:
4088 return "DW_AT_GNU_shared_locks_required";
4089 case DW_AT_GNU_odr_signature:
4090 return "DW_AT_GNU_odr_signature";
4091 case DW_AT_GNU_template_name:
4092 return "DW_AT_GNU_template_name";
4093 case DW_AT_GNU_call_site_value:
4094 return "DW_AT_GNU_call_site_value";
4095 case DW_AT_GNU_call_site_data_value:
4096 return "DW_AT_GNU_call_site_data_value";
4097 case DW_AT_GNU_call_site_target:
4098 return "DW_AT_GNU_call_site_target";
4099 case DW_AT_GNU_call_site_target_clobbered:
4100 return "DW_AT_GNU_call_site_target_clobbered";
4101 case DW_AT_GNU_tail_call:
4102 return "DW_AT_GNU_tail_call";
4103 case DW_AT_GNU_all_tail_call_sites:
4104 return "DW_AT_GNU_all_tail_call_sites";
4105 case DW_AT_GNU_all_call_sites:
4106 return "DW_AT_GNU_all_call_sites";
4107 case DW_AT_GNU_all_source_call_sites:
4108 return "DW_AT_GNU_all_source_call_sites";
4109 case DW_AT_GNU_macros:
4110 return "DW_AT_GNU_macros";
4112 case DW_AT_GNAT_descriptive_type:
4113 return "DW_AT_GNAT_descriptive_type";
4115 case DW_AT_VMS_rtnbeg_pd_address:
4116 return "DW_AT_VMS_rtnbeg_pd_address";
4119 return "DW_AT_<unknown>";
4123 /* Convert a DWARF value form code into its string name. */
4126 dwarf_form_name (unsigned int form)
4131 return "DW_FORM_addr";
4132 case DW_FORM_block2:
4133 return "DW_FORM_block2";
4134 case DW_FORM_block4:
4135 return "DW_FORM_block4";
4137 return "DW_FORM_data2";
4139 return "DW_FORM_data4";
4141 return "DW_FORM_data8";
4142 case DW_FORM_string:
4143 return "DW_FORM_string";
4145 return "DW_FORM_block";
4146 case DW_FORM_block1:
4147 return "DW_FORM_block1";
4149 return "DW_FORM_data1";
4151 return "DW_FORM_flag";
4153 return "DW_FORM_sdata";
4155 return "DW_FORM_strp";
4157 return "DW_FORM_udata";
4158 case DW_FORM_ref_addr:
4159 return "DW_FORM_ref_addr";
4161 return "DW_FORM_ref1";
4163 return "DW_FORM_ref2";
4165 return "DW_FORM_ref4";
4167 return "DW_FORM_ref8";
4168 case DW_FORM_ref_udata:
4169 return "DW_FORM_ref_udata";
4170 case DW_FORM_indirect:
4171 return "DW_FORM_indirect";
4172 case DW_FORM_sec_offset:
4173 return "DW_FORM_sec_offset";
4174 case DW_FORM_exprloc:
4175 return "DW_FORM_exprloc";
4176 case DW_FORM_flag_present:
4177 return "DW_FORM_flag_present";
4178 case DW_FORM_ref_sig8:
4179 return "DW_FORM_ref_sig8";
4181 return "DW_FORM_<unknown>";
4185 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4186 instance of an inlined instance of a decl which is local to an inline
4187 function, so we have to trace all of the way back through the origin chain
4188 to find out what sort of node actually served as the original seed for the
4192 decl_ultimate_origin (const_tree decl)
4194 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4197 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4198 nodes in the function to point to themselves; ignore that if
4199 we're trying to output the abstract instance of this function. */
4200 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4203 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4204 most distant ancestor, this should never happen. */
4205 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4207 return DECL_ABSTRACT_ORIGIN (decl);
4210 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4211 of a virtual function may refer to a base class, so we check the 'this'
4215 decl_class_context (tree decl)
4217 tree context = NULL_TREE;
4219 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4220 context = DECL_CONTEXT (decl);
4222 context = TYPE_MAIN_VARIANT
4223 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4225 if (context && !TYPE_P (context))
4226 context = NULL_TREE;
4231 /* Add an attribute/value pair to a DIE. */
4234 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4236 /* Maybe this should be an assert? */
4240 if (die->die_attr == NULL)
4241 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4242 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4245 static inline enum dw_val_class
4246 AT_class (dw_attr_ref a)
4248 return a->dw_attr_val.val_class;
4251 /* Add a flag value attribute to a DIE. */
4254 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4258 attr.dw_attr = attr_kind;
4259 attr.dw_attr_val.val_class = dw_val_class_flag;
4260 attr.dw_attr_val.v.val_flag = flag;
4261 add_dwarf_attr (die, &attr);
4264 static inline unsigned
4265 AT_flag (dw_attr_ref a)
4267 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4268 return a->dw_attr_val.v.val_flag;
4271 /* Add a signed integer attribute value to a DIE. */
4274 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4278 attr.dw_attr = attr_kind;
4279 attr.dw_attr_val.val_class = dw_val_class_const;
4280 attr.dw_attr_val.v.val_int = int_val;
4281 add_dwarf_attr (die, &attr);
4284 static inline HOST_WIDE_INT
4285 AT_int (dw_attr_ref a)
4287 gcc_assert (a && AT_class (a) == dw_val_class_const);
4288 return a->dw_attr_val.v.val_int;
4291 /* Add an unsigned integer attribute value to a DIE. */
4294 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4295 unsigned HOST_WIDE_INT unsigned_val)
4299 attr.dw_attr = attr_kind;
4300 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4301 attr.dw_attr_val.v.val_unsigned = unsigned_val;
4302 add_dwarf_attr (die, &attr);
4305 static inline unsigned HOST_WIDE_INT
4306 AT_unsigned (dw_attr_ref a)
4308 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4309 return a->dw_attr_val.v.val_unsigned;
4312 /* Add an unsigned double integer attribute value to a DIE. */
4315 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
4316 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
4320 attr.dw_attr = attr_kind;
4321 attr.dw_attr_val.val_class = dw_val_class_const_double;
4322 attr.dw_attr_val.v.val_double.high = high;
4323 attr.dw_attr_val.v.val_double.low = low;
4324 add_dwarf_attr (die, &attr);
4327 /* Add a floating point attribute value to a DIE and return it. */
4330 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4331 unsigned int length, unsigned int elt_size, unsigned char *array)
4335 attr.dw_attr = attr_kind;
4336 attr.dw_attr_val.val_class = dw_val_class_vec;
4337 attr.dw_attr_val.v.val_vec.length = length;
4338 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4339 attr.dw_attr_val.v.val_vec.array = array;
4340 add_dwarf_attr (die, &attr);
4343 /* Add an 8-byte data attribute value to a DIE. */
4346 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
4347 unsigned char data8[8])
4351 attr.dw_attr = attr_kind;
4352 attr.dw_attr_val.val_class = dw_val_class_data8;
4353 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
4354 add_dwarf_attr (die, &attr);
4357 /* Hash and equality functions for debug_str_hash. */
4360 debug_str_do_hash (const void *x)
4362 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4366 debug_str_eq (const void *x1, const void *x2)
4368 return strcmp ((((const struct indirect_string_node *)x1)->str),
4369 (const char *)x2) == 0;
4372 /* Add STR to the indirect string hash table. */
4374 static struct indirect_string_node *
4375 find_AT_string (const char *str)
4377 struct indirect_string_node *node;
4380 if (! debug_str_hash)
4381 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4382 debug_str_eq, NULL);
4384 slot = htab_find_slot_with_hash (debug_str_hash, str,
4385 htab_hash_string (str), INSERT);
4388 node = ggc_alloc_cleared_indirect_string_node ();
4389 node->str = ggc_strdup (str);
4393 node = (struct indirect_string_node *) *slot;
4399 /* Add a string attribute value to a DIE. */
4402 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4405 struct indirect_string_node *node;
4407 node = find_AT_string (str);
4409 attr.dw_attr = attr_kind;
4410 attr.dw_attr_val.val_class = dw_val_class_str;
4411 attr.dw_attr_val.v.val_str = node;
4412 add_dwarf_attr (die, &attr);
4415 static inline const char *
4416 AT_string (dw_attr_ref a)
4418 gcc_assert (a && AT_class (a) == dw_val_class_str);
4419 return a->dw_attr_val.v.val_str->str;
4422 /* Find out whether a string should be output inline in DIE
4423 or out-of-line in .debug_str section. */
4425 static enum dwarf_form
4426 AT_string_form (dw_attr_ref a)
4428 struct indirect_string_node *node;
4432 gcc_assert (a && AT_class (a) == dw_val_class_str);
4434 node = a->dw_attr_val.v.val_str;
4438 len = strlen (node->str) + 1;
4440 /* If the string is shorter or equal to the size of the reference, it is
4441 always better to put it inline. */
4442 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4443 return node->form = DW_FORM_string;
4445 /* If we cannot expect the linker to merge strings in .debug_str
4446 section, only put it into .debug_str if it is worth even in this
4448 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4449 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
4450 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
4451 return node->form = DW_FORM_string;
4453 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4454 ++dw2_string_counter;
4455 node->label = xstrdup (label);
4457 return node->form = DW_FORM_strp;
4460 /* Add a DIE reference attribute value to a DIE. */
4463 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4467 #ifdef ENABLE_CHECKING
4468 gcc_assert (targ_die != NULL);
4470 /* With LTO we can end up trying to reference something we didn't create
4471 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4472 if (targ_die == NULL)
4476 attr.dw_attr = attr_kind;
4477 attr.dw_attr_val.val_class = dw_val_class_die_ref;
4478 attr.dw_attr_val.v.val_die_ref.die = targ_die;
4479 attr.dw_attr_val.v.val_die_ref.external = 0;
4480 add_dwarf_attr (die, &attr);
4483 /* Add an AT_specification attribute to a DIE, and also make the back
4484 pointer from the specification to the definition. */
4487 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4489 add_AT_die_ref (die, DW_AT_specification, targ_die);
4490 gcc_assert (!targ_die->die_definition);
4491 targ_die->die_definition = die;
4494 static inline dw_die_ref
4495 AT_ref (dw_attr_ref a)
4497 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4498 return a->dw_attr_val.v.val_die_ref.die;
4502 AT_ref_external (dw_attr_ref a)
4504 if (a && AT_class (a) == dw_val_class_die_ref)
4505 return a->dw_attr_val.v.val_die_ref.external;
4511 set_AT_ref_external (dw_attr_ref a, int i)
4513 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4514 a->dw_attr_val.v.val_die_ref.external = i;
4517 /* Add an FDE reference attribute value to a DIE. */
4520 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4524 attr.dw_attr = attr_kind;
4525 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
4526 attr.dw_attr_val.v.val_fde_index = targ_fde;
4527 add_dwarf_attr (die, &attr);
4530 /* Add a location description attribute value to a DIE. */
4533 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4537 attr.dw_attr = attr_kind;
4538 attr.dw_attr_val.val_class = dw_val_class_loc;
4539 attr.dw_attr_val.v.val_loc = loc;
4540 add_dwarf_attr (die, &attr);
4543 static inline dw_loc_descr_ref
4544 AT_loc (dw_attr_ref a)
4546 gcc_assert (a && AT_class (a) == dw_val_class_loc);
4547 return a->dw_attr_val.v.val_loc;
4551 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4555 attr.dw_attr = attr_kind;
4556 attr.dw_attr_val.val_class = dw_val_class_loc_list;
4557 attr.dw_attr_val.v.val_loc_list = loc_list;
4558 add_dwarf_attr (die, &attr);
4559 have_location_lists = true;
4562 static inline dw_loc_list_ref
4563 AT_loc_list (dw_attr_ref a)
4565 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4566 return a->dw_attr_val.v.val_loc_list;
4569 static inline dw_loc_list_ref *
4570 AT_loc_list_ptr (dw_attr_ref a)
4572 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4573 return &a->dw_attr_val.v.val_loc_list;
4576 /* Add an address constant attribute value to a DIE. */
4579 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
4583 attr.dw_attr = attr_kind;
4584 attr.dw_attr_val.val_class = dw_val_class_addr;
4585 attr.dw_attr_val.v.val_addr = addr;
4586 add_dwarf_attr (die, &attr);
4589 /* Get the RTX from to an address DIE attribute. */
4592 AT_addr (dw_attr_ref a)
4594 gcc_assert (a && AT_class (a) == dw_val_class_addr);
4595 return a->dw_attr_val.v.val_addr;
4598 /* Add a file attribute value to a DIE. */
4601 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
4602 struct dwarf_file_data *fd)
4606 attr.dw_attr = attr_kind;
4607 attr.dw_attr_val.val_class = dw_val_class_file;
4608 attr.dw_attr_val.v.val_file = fd;
4609 add_dwarf_attr (die, &attr);
4612 /* Get the dwarf_file_data from a file DIE attribute. */
4614 static inline struct dwarf_file_data *
4615 AT_file (dw_attr_ref a)
4617 gcc_assert (a && AT_class (a) == dw_val_class_file);
4618 return a->dw_attr_val.v.val_file;
4621 /* Add a vms delta attribute value to a DIE. */
4624 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
4625 const char *lbl1, const char *lbl2)
4629 attr.dw_attr = attr_kind;
4630 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
4631 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
4632 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
4633 add_dwarf_attr (die, &attr);
4636 /* Add a label identifier attribute value to a DIE. */
4639 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
4643 attr.dw_attr = attr_kind;
4644 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4645 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4646 add_dwarf_attr (die, &attr);
4649 /* Add a section offset attribute value to a DIE, an offset into the
4650 debug_line section. */
4653 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4658 attr.dw_attr = attr_kind;
4659 attr.dw_attr_val.val_class = dw_val_class_lineptr;
4660 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4661 add_dwarf_attr (die, &attr);
4664 /* Add a section offset attribute value to a DIE, an offset into the
4665 debug_macinfo section. */
4668 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4673 attr.dw_attr = attr_kind;
4674 attr.dw_attr_val.val_class = dw_val_class_macptr;
4675 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4676 add_dwarf_attr (die, &attr);
4679 /* Add an offset attribute value to a DIE. */
4682 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
4683 unsigned HOST_WIDE_INT offset)
4687 attr.dw_attr = attr_kind;
4688 attr.dw_attr_val.val_class = dw_val_class_offset;
4689 attr.dw_attr_val.v.val_offset = offset;
4690 add_dwarf_attr (die, &attr);
4693 /* Add an range_list attribute value to a DIE. */
4696 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4697 long unsigned int offset)
4701 attr.dw_attr = attr_kind;
4702 attr.dw_attr_val.val_class = dw_val_class_range_list;
4703 attr.dw_attr_val.v.val_offset = offset;
4704 add_dwarf_attr (die, &attr);
4707 /* Return the start label of a delta attribute. */
4709 static inline const char *
4710 AT_vms_delta1 (dw_attr_ref a)
4712 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4713 return a->dw_attr_val.v.val_vms_delta.lbl1;
4716 /* Return the end label of a delta attribute. */
4718 static inline const char *
4719 AT_vms_delta2 (dw_attr_ref a)
4721 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4722 return a->dw_attr_val.v.val_vms_delta.lbl2;
4725 static inline const char *
4726 AT_lbl (dw_attr_ref a)
4728 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
4729 || AT_class (a) == dw_val_class_lineptr
4730 || AT_class (a) == dw_val_class_macptr));
4731 return a->dw_attr_val.v.val_lbl_id;
4734 /* Get the attribute of type attr_kind. */
4737 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4741 dw_die_ref spec = NULL;
4746 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
4747 if (a->dw_attr == attr_kind)
4749 else if (a->dw_attr == DW_AT_specification
4750 || a->dw_attr == DW_AT_abstract_origin)
4754 return get_AT (spec, attr_kind);
4759 /* Return the "low pc" attribute value, typically associated with a subprogram
4760 DIE. Return null if the "low pc" attribute is either not present, or if it
4761 cannot be represented as an assembler label identifier. */
4763 static inline const char *
4764 get_AT_low_pc (dw_die_ref die)
4766 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4768 return a ? AT_lbl (a) : NULL;
4771 /* Return the "high pc" attribute value, typically associated with a subprogram
4772 DIE. Return null if the "high pc" attribute is either not present, or if it
4773 cannot be represented as an assembler label identifier. */
4775 static inline const char *
4776 get_AT_hi_pc (dw_die_ref die)
4778 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4780 return a ? AT_lbl (a) : NULL;
4783 /* Return the value of the string attribute designated by ATTR_KIND, or
4784 NULL if it is not present. */
4786 static inline const char *
4787 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4789 dw_attr_ref a = get_AT (die, attr_kind);
4791 return a ? AT_string (a) : NULL;
4794 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4795 if it is not present. */
4798 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4800 dw_attr_ref a = get_AT (die, attr_kind);
4802 return a ? AT_flag (a) : 0;
4805 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4806 if it is not present. */
4808 static inline unsigned
4809 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4811 dw_attr_ref a = get_AT (die, attr_kind);
4813 return a ? AT_unsigned (a) : 0;
4816 static inline dw_die_ref
4817 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4819 dw_attr_ref a = get_AT (die, attr_kind);
4821 return a ? AT_ref (a) : NULL;
4824 static inline struct dwarf_file_data *
4825 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
4827 dw_attr_ref a = get_AT (die, attr_kind);
4829 return a ? AT_file (a) : NULL;
4832 /* Return TRUE if the language is C++. */
4837 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4839 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
4842 /* Return TRUE if the language is Fortran. */
4847 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4849 return (lang == DW_LANG_Fortran77
4850 || lang == DW_LANG_Fortran90
4851 || lang == DW_LANG_Fortran95);
4854 /* Return TRUE if the language is Ada. */
4859 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4861 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4864 /* Remove the specified attribute if present. */
4867 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4875 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
4876 if (a->dw_attr == attr_kind)
4878 if (AT_class (a) == dw_val_class_str)
4879 if (a->dw_attr_val.v.val_str->refcount)
4880 a->dw_attr_val.v.val_str->refcount--;
4882 /* VEC_ordered_remove should help reduce the number of abbrevs
4884 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
4889 /* Remove CHILD from its parent. PREV must have the property that
4890 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4893 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
4895 gcc_assert (child->die_parent == prev->die_parent);
4896 gcc_assert (prev->die_sib == child);
4899 gcc_assert (child->die_parent->die_child == child);
4903 prev->die_sib = child->die_sib;
4904 if (child->die_parent->die_child == child)
4905 child->die_parent->die_child = prev;
4908 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4909 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4912 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
4914 dw_die_ref parent = old_child->die_parent;
4916 gcc_assert (parent == prev->die_parent);
4917 gcc_assert (prev->die_sib == old_child);
4919 new_child->die_parent = parent;
4920 if (prev == old_child)
4922 gcc_assert (parent->die_child == old_child);
4923 new_child->die_sib = new_child;
4927 prev->die_sib = new_child;
4928 new_child->die_sib = old_child->die_sib;
4930 if (old_child->die_parent->die_child == old_child)
4931 old_child->die_parent->die_child = new_child;
4934 /* Move all children from OLD_PARENT to NEW_PARENT. */
4937 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
4940 new_parent->die_child = old_parent->die_child;
4941 old_parent->die_child = NULL;
4942 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
4945 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4949 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
4955 dw_die_ref prev = c;
4957 while (c->die_tag == tag)
4959 remove_child_with_prev (c, prev);
4960 /* Might have removed every child. */
4961 if (c == c->die_sib)
4965 } while (c != die->die_child);
4968 /* Add a CHILD_DIE as the last child of DIE. */
4971 add_child_die (dw_die_ref die, dw_die_ref child_die)
4973 /* FIXME this should probably be an assert. */
4974 if (! die || ! child_die)
4976 gcc_assert (die != child_die);
4978 child_die->die_parent = die;
4981 child_die->die_sib = die->die_child->die_sib;
4982 die->die_child->die_sib = child_die;
4985 child_die->die_sib = child_die;
4986 die->die_child = child_die;
4989 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4990 is the specification, to the end of PARENT's list of children.
4991 This is done by removing and re-adding it. */
4994 splice_child_die (dw_die_ref parent, dw_die_ref child)
4998 /* We want the declaration DIE from inside the class, not the
4999 specification DIE at toplevel. */
5000 if (child->die_parent != parent)
5002 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5008 gcc_assert (child->die_parent == parent
5009 || (child->die_parent
5010 == get_AT_ref (parent, DW_AT_specification)));
5012 for (p = child->die_parent->die_child; ; p = p->die_sib)
5013 if (p->die_sib == child)
5015 remove_child_with_prev (child, p);
5019 add_child_die (parent, child);
5022 /* Return a pointer to a newly created DIE node. */
5024 static inline dw_die_ref
5025 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5027 dw_die_ref die = ggc_alloc_cleared_die_node ();
5029 die->die_tag = tag_value;
5031 if (parent_die != NULL)
5032 add_child_die (parent_die, die);
5035 limbo_die_node *limbo_node;
5037 limbo_node = ggc_alloc_cleared_limbo_die_node ();
5038 limbo_node->die = die;
5039 limbo_node->created_for = t;
5040 limbo_node->next = limbo_die_list;
5041 limbo_die_list = limbo_node;
5047 /* Return the DIE associated with the given type specifier. */
5049 static inline dw_die_ref
5050 lookup_type_die (tree type)
5052 return TYPE_SYMTAB_DIE (type);
5055 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5056 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5057 anonymous type instead the one of the naming typedef. */
5059 static inline dw_die_ref
5060 strip_naming_typedef (tree type, dw_die_ref type_die)
5063 && TREE_CODE (type) == RECORD_TYPE
5065 && type_die->die_tag == DW_TAG_typedef
5066 && is_naming_typedef_decl (TYPE_NAME (type)))
5067 type_die = get_AT_ref (type_die, DW_AT_type);
5071 /* Like lookup_type_die, but if type is an anonymous type named by a
5072 typedef[1], return the DIE of the anonymous type instead the one of
5073 the naming typedef. This is because in gen_typedef_die, we did
5074 equate the anonymous struct named by the typedef with the DIE of
5075 the naming typedef. So by default, lookup_type_die on an anonymous
5076 struct yields the DIE of the naming typedef.
5078 [1]: Read the comment of is_naming_typedef_decl to learn about what
5079 a naming typedef is. */
5081 static inline dw_die_ref
5082 lookup_type_die_strip_naming_typedef (tree type)
5084 dw_die_ref die = lookup_type_die (type);
5085 return strip_naming_typedef (type, die);
5088 /* Equate a DIE to a given type specifier. */
5091 equate_type_number_to_die (tree type, dw_die_ref type_die)
5093 TYPE_SYMTAB_DIE (type) = type_die;
5096 /* Returns a hash value for X (which really is a die_struct). */
5099 decl_die_table_hash (const void *x)
5101 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5104 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5107 decl_die_table_eq (const void *x, const void *y)
5109 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5112 /* Return the DIE associated with a given declaration. */
5114 static inline dw_die_ref
5115 lookup_decl_die (tree decl)
5117 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5120 /* Returns a hash value for X (which really is a var_loc_list). */
5123 decl_loc_table_hash (const void *x)
5125 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5128 /* Return nonzero if decl_id of var_loc_list X is the same as
5132 decl_loc_table_eq (const void *x, const void *y)
5134 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5137 /* Return the var_loc list associated with a given declaration. */
5139 static inline var_loc_list *
5140 lookup_decl_loc (const_tree decl)
5142 if (!decl_loc_table)
5144 return (var_loc_list *)
5145 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5148 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5151 cached_dw_loc_list_table_hash (const void *x)
5153 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
5156 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5160 cached_dw_loc_list_table_eq (const void *x, const void *y)
5162 return (((const cached_dw_loc_list *) x)->decl_id
5163 == DECL_UID ((const_tree) y));
5166 /* Equate a DIE to a particular declaration. */
5169 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5171 unsigned int decl_id = DECL_UID (decl);
5174 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5176 decl_die->decl_id = decl_id;
5179 /* Return how many bits covers PIECE EXPR_LIST. */
5182 decl_piece_bitsize (rtx piece)
5184 int ret = (int) GET_MODE (piece);
5187 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
5188 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
5189 return INTVAL (XEXP (XEXP (piece, 0), 0));
5192 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5195 decl_piece_varloc_ptr (rtx piece)
5197 if ((int) GET_MODE (piece))
5198 return &XEXP (piece, 0);
5200 return &XEXP (XEXP (piece, 0), 1);
5203 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5204 Next is the chain of following piece nodes. */
5207 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
5209 if (bitsize <= (int) MAX_MACHINE_MODE)
5210 return alloc_EXPR_LIST (bitsize, loc_note, next);
5212 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
5217 /* Return rtx that should be stored into loc field for
5218 LOC_NOTE and BITPOS/BITSIZE. */
5221 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
5222 HOST_WIDE_INT bitsize)
5226 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
5228 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
5233 /* This function either modifies location piece list *DEST in
5234 place (if SRC and INNER is NULL), or copies location piece list
5235 *SRC to *DEST while modifying it. Location BITPOS is modified
5236 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5237 not copied and if needed some padding around it is added.
5238 When modifying in place, DEST should point to EXPR_LIST where
5239 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5240 to the start of the whole list and INNER points to the EXPR_LIST
5241 where earlier pieces cover PIECE_BITPOS bits. */
5244 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
5245 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
5246 HOST_WIDE_INT bitsize, rtx loc_note)
5249 bool copy = inner != NULL;
5253 /* First copy all nodes preceeding the current bitpos. */
5254 while (src != inner)
5256 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5257 decl_piece_bitsize (*src), NULL_RTX);
5258 dest = &XEXP (*dest, 1);
5259 src = &XEXP (*src, 1);
5262 /* Add padding if needed. */
5263 if (bitpos != piece_bitpos)
5265 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
5266 copy ? NULL_RTX : *dest);
5267 dest = &XEXP (*dest, 1);
5269 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
5272 /* A piece with correct bitpos and bitsize already exist,
5273 just update the location for it and return. */
5274 *decl_piece_varloc_ptr (*dest) = loc_note;
5277 /* Add the piece that changed. */
5278 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
5279 dest = &XEXP (*dest, 1);
5280 /* Skip over pieces that overlap it. */
5281 diff = bitpos - piece_bitpos + bitsize;
5284 while (diff > 0 && *src)
5287 diff -= decl_piece_bitsize (piece);
5289 src = &XEXP (piece, 1);
5292 *src = XEXP (piece, 1);
5293 free_EXPR_LIST_node (piece);
5296 /* Add padding if needed. */
5297 if (diff < 0 && *src)
5301 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
5302 dest = &XEXP (*dest, 1);
5306 /* Finally copy all nodes following it. */
5309 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5310 decl_piece_bitsize (*src), NULL_RTX);
5311 dest = &XEXP (*dest, 1);
5312 src = &XEXP (*src, 1);
5316 /* Add a variable location node to the linked list for DECL. */
5318 static struct var_loc_node *
5319 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
5321 unsigned int decl_id;
5324 struct var_loc_node *loc = NULL;
5325 HOST_WIDE_INT bitsize = -1, bitpos = -1;
5327 if (DECL_DEBUG_EXPR_IS_FROM (decl))
5329 tree realdecl = DECL_DEBUG_EXPR (decl);
5330 if (realdecl && handled_component_p (realdecl))
5332 HOST_WIDE_INT maxsize;
5335 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
5336 if (!DECL_P (innerdecl)
5337 || DECL_IGNORED_P (innerdecl)
5338 || TREE_STATIC (innerdecl)
5340 || bitpos + bitsize > 256
5341 || bitsize != maxsize)
5347 decl_id = DECL_UID (decl);
5348 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5351 temp = ggc_alloc_cleared_var_loc_list ();
5352 temp->decl_id = decl_id;
5356 temp = (var_loc_list *) *slot;
5358 /* For PARM_DECLs try to keep around the original incoming value,
5359 even if that means we'll emit a zero-range .debug_loc entry. */
5361 && temp->first == temp->last
5362 && TREE_CODE (decl) == PARM_DECL
5363 && GET_CODE (temp->first->loc) == NOTE
5364 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
5365 && DECL_INCOMING_RTL (decl)
5366 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
5367 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
5368 == GET_CODE (DECL_INCOMING_RTL (decl))
5369 && prev_real_insn (temp->first->loc) == NULL_RTX
5371 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
5372 NOTE_VAR_LOCATION_LOC (loc_note))
5373 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
5374 != NOTE_VAR_LOCATION_STATUS (loc_note))))
5376 loc = ggc_alloc_cleared_var_loc_node ();
5377 temp->first->next = loc;
5379 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5381 else if (temp->last)
5383 struct var_loc_node *last = temp->last, *unused = NULL;
5384 rtx *piece_loc = NULL, last_loc_note;
5385 int piece_bitpos = 0;
5389 gcc_assert (last->next == NULL);
5391 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
5393 piece_loc = &last->loc;
5396 int cur_bitsize = decl_piece_bitsize (*piece_loc);
5397 if (piece_bitpos + cur_bitsize > bitpos)
5399 piece_bitpos += cur_bitsize;
5400 piece_loc = &XEXP (*piece_loc, 1);
5404 /* TEMP->LAST here is either pointer to the last but one or
5405 last element in the chained list, LAST is pointer to the
5407 if (label && strcmp (last->label, label) == 0)
5409 /* For SRA optimized variables if there weren't any real
5410 insns since last note, just modify the last node. */
5411 if (piece_loc != NULL)
5413 adjust_piece_list (piece_loc, NULL, NULL,
5414 bitpos, piece_bitpos, bitsize, loc_note);
5417 /* If the last note doesn't cover any instructions, remove it. */
5418 if (temp->last != last)
5420 temp->last->next = NULL;
5423 gcc_assert (strcmp (last->label, label) != 0);
5427 gcc_assert (temp->first == temp->last
5428 || (temp->first->next == temp->last
5429 && TREE_CODE (decl) == PARM_DECL));
5430 memset (temp->last, '\0', sizeof (*temp->last));
5431 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
5435 if (bitsize == -1 && NOTE_P (last->loc))
5436 last_loc_note = last->loc;
5437 else if (piece_loc != NULL
5438 && *piece_loc != NULL_RTX
5439 && piece_bitpos == bitpos
5440 && decl_piece_bitsize (*piece_loc) == bitsize)
5441 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
5443 last_loc_note = NULL_RTX;
5444 /* If the current location is the same as the end of the list,
5445 and either both or neither of the locations is uninitialized,
5446 we have nothing to do. */
5447 if (last_loc_note == NULL_RTX
5448 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
5449 NOTE_VAR_LOCATION_LOC (loc_note)))
5450 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5451 != NOTE_VAR_LOCATION_STATUS (loc_note))
5452 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5453 == VAR_INIT_STATUS_UNINITIALIZED)
5454 || (NOTE_VAR_LOCATION_STATUS (loc_note)
5455 == VAR_INIT_STATUS_UNINITIALIZED))))
5457 /* Add LOC to the end of list and update LAST. If the last
5458 element of the list has been removed above, reuse its
5459 memory for the new node, otherwise allocate a new one. */
5463 memset (loc, '\0', sizeof (*loc));
5466 loc = ggc_alloc_cleared_var_loc_node ();
5467 if (bitsize == -1 || piece_loc == NULL)
5468 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5470 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
5471 bitpos, piece_bitpos, bitsize, loc_note);
5473 /* Ensure TEMP->LAST will point either to the new last but one
5474 element of the chain, or to the last element in it. */
5475 if (last != temp->last)
5483 loc = ggc_alloc_cleared_var_loc_node ();
5486 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5491 /* Keep track of the number of spaces used to indent the
5492 output of the debugging routines that print the structure of
5493 the DIE internal representation. */
5494 static int print_indent;
5496 /* Indent the line the number of spaces given by print_indent. */
5499 print_spaces (FILE *outfile)
5501 fprintf (outfile, "%*s", print_indent, "");
5504 /* Print a type signature in hex. */
5507 print_signature (FILE *outfile, char *sig)
5511 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
5512 fprintf (outfile, "%02x", sig[i] & 0xff);
5515 /* Print the information associated with a given DIE, and its children.
5516 This routine is a debugging aid only. */
5519 print_die (dw_die_ref die, FILE *outfile)
5525 print_spaces (outfile);
5526 fprintf (outfile, "DIE %4ld: %s (%p)\n",
5527 die->die_offset, dwarf_tag_name (die->die_tag),
5529 print_spaces (outfile);
5530 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5531 fprintf (outfile, " offset: %ld", die->die_offset);
5532 fprintf (outfile, " mark: %d\n", die->die_mark);
5534 if (use_debug_types && die->die_id.die_type_node)
5536 print_spaces (outfile);
5537 fprintf (outfile, " signature: ");
5538 print_signature (outfile, die->die_id.die_type_node->signature);
5539 fprintf (outfile, "\n");
5542 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5544 print_spaces (outfile);
5545 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5547 switch (AT_class (a))
5549 case dw_val_class_addr:
5550 fprintf (outfile, "address");
5552 case dw_val_class_offset:
5553 fprintf (outfile, "offset");
5555 case dw_val_class_loc:
5556 fprintf (outfile, "location descriptor");
5558 case dw_val_class_loc_list:
5559 fprintf (outfile, "location list -> label:%s",
5560 AT_loc_list (a)->ll_symbol);
5562 case dw_val_class_range_list:
5563 fprintf (outfile, "range list");
5565 case dw_val_class_const:
5566 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5568 case dw_val_class_unsigned_const:
5569 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5571 case dw_val_class_const_double:
5572 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
5573 HOST_WIDE_INT_PRINT_UNSIGNED")",
5574 a->dw_attr_val.v.val_double.high,
5575 a->dw_attr_val.v.val_double.low);
5577 case dw_val_class_vec:
5578 fprintf (outfile, "floating-point or vector constant");
5580 case dw_val_class_flag:
5581 fprintf (outfile, "%u", AT_flag (a));
5583 case dw_val_class_die_ref:
5584 if (AT_ref (a) != NULL)
5586 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
5588 fprintf (outfile, "die -> signature: ");
5589 print_signature (outfile,
5590 AT_ref (a)->die_id.die_type_node->signature);
5592 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
5593 fprintf (outfile, "die -> label: %s",
5594 AT_ref (a)->die_id.die_symbol);
5596 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5597 fprintf (outfile, " (%p)", (void *) AT_ref (a));
5600 fprintf (outfile, "die -> <null>");
5602 case dw_val_class_vms_delta:
5603 fprintf (outfile, "delta: @slotcount(%s-%s)",
5604 AT_vms_delta2 (a), AT_vms_delta1 (a));
5606 case dw_val_class_lbl_id:
5607 case dw_val_class_lineptr:
5608 case dw_val_class_macptr:
5609 fprintf (outfile, "label: %s", AT_lbl (a));
5611 case dw_val_class_str:
5612 if (AT_string (a) != NULL)
5613 fprintf (outfile, "\"%s\"", AT_string (a));
5615 fprintf (outfile, "<null>");
5617 case dw_val_class_file:
5618 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
5619 AT_file (a)->emitted_number);
5621 case dw_val_class_data8:
5625 for (i = 0; i < 8; i++)
5626 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
5633 fprintf (outfile, "\n");
5636 if (die->die_child != NULL)
5639 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5642 if (print_indent == 0)
5643 fprintf (outfile, "\n");
5646 /* Print the information collected for a given DIE. */
5649 debug_dwarf_die (dw_die_ref die)
5651 print_die (die, stderr);
5654 /* Print all DWARF information collected for the compilation unit.
5655 This routine is a debugging aid only. */
5661 print_die (comp_unit_die (), stderr);
5664 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5665 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5666 DIE that marks the start of the DIEs for this include file. */
5669 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5671 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5672 dw_die_ref new_unit = gen_compile_unit_die (filename);
5674 new_unit->die_sib = old_unit;
5678 /* Close an include-file CU and reopen the enclosing one. */
5681 pop_compile_unit (dw_die_ref old_unit)
5683 dw_die_ref new_unit = old_unit->die_sib;
5685 old_unit->die_sib = NULL;
5689 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5690 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5692 /* Calculate the checksum of a location expression. */
5695 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5699 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
5701 CHECKSUM (loc->dw_loc_oprnd1);
5702 CHECKSUM (loc->dw_loc_oprnd2);
5705 /* Calculate the checksum of an attribute. */
5708 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5710 dw_loc_descr_ref loc;
5713 CHECKSUM (at->dw_attr);
5715 /* We don't care that this was compiled with a different compiler
5716 snapshot; if the output is the same, that's what matters. */
5717 if (at->dw_attr == DW_AT_producer)
5720 switch (AT_class (at))
5722 case dw_val_class_const:
5723 CHECKSUM (at->dw_attr_val.v.val_int);
5725 case dw_val_class_unsigned_const:
5726 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5728 case dw_val_class_const_double:
5729 CHECKSUM (at->dw_attr_val.v.val_double);
5731 case dw_val_class_vec:
5732 CHECKSUM (at->dw_attr_val.v.val_vec);
5734 case dw_val_class_flag:
5735 CHECKSUM (at->dw_attr_val.v.val_flag);
5737 case dw_val_class_str:
5738 CHECKSUM_STRING (AT_string (at));
5741 case dw_val_class_addr:
5743 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5744 CHECKSUM_STRING (XSTR (r, 0));
5747 case dw_val_class_offset:
5748 CHECKSUM (at->dw_attr_val.v.val_offset);
5751 case dw_val_class_loc:
5752 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5753 loc_checksum (loc, ctx);
5756 case dw_val_class_die_ref:
5757 die_checksum (AT_ref (at), ctx, mark);
5760 case dw_val_class_fde_ref:
5761 case dw_val_class_vms_delta:
5762 case dw_val_class_lbl_id:
5763 case dw_val_class_lineptr:
5764 case dw_val_class_macptr:
5767 case dw_val_class_file:
5768 CHECKSUM_STRING (AT_file (at)->filename);
5771 case dw_val_class_data8:
5772 CHECKSUM (at->dw_attr_val.v.val_data8);
5780 /* Calculate the checksum of a DIE. */
5783 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5789 /* To avoid infinite recursion. */
5792 CHECKSUM (die->die_mark);
5795 die->die_mark = ++(*mark);
5797 CHECKSUM (die->die_tag);
5799 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5800 attr_checksum (a, ctx, mark);
5802 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
5806 #undef CHECKSUM_STRING
5808 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5809 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5810 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5811 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5812 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5813 #define CHECKSUM_ATTR(FOO) \
5814 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5816 /* Calculate the checksum of a number in signed LEB128 format. */
5819 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
5826 byte = (value & 0x7f);
5828 more = !((value == 0 && (byte & 0x40) == 0)
5829 || (value == -1 && (byte & 0x40) != 0));
5838 /* Calculate the checksum of a number in unsigned LEB128 format. */
5841 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
5845 unsigned char byte = (value & 0x7f);
5848 /* More bytes to follow. */
5856 /* Checksum the context of the DIE. This adds the names of any
5857 surrounding namespaces or structures to the checksum. */
5860 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
5864 int tag = die->die_tag;
5866 if (tag != DW_TAG_namespace
5867 && tag != DW_TAG_structure_type
5868 && tag != DW_TAG_class_type)
5871 name = get_AT_string (die, DW_AT_name);
5873 spec = get_AT_ref (die, DW_AT_specification);
5877 if (die->die_parent != NULL)
5878 checksum_die_context (die->die_parent, ctx);
5880 CHECKSUM_ULEB128 ('C');
5881 CHECKSUM_ULEB128 (tag);
5883 CHECKSUM_STRING (name);
5886 /* Calculate the checksum of a location expression. */
5889 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5891 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5892 were emitted as a DW_FORM_sdata instead of a location expression. */
5893 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
5895 CHECKSUM_ULEB128 (DW_FORM_sdata);
5896 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
5900 /* Otherwise, just checksum the raw location expression. */
5903 CHECKSUM_ULEB128 (loc->dw_loc_opc);
5904 CHECKSUM (loc->dw_loc_oprnd1);
5905 CHECKSUM (loc->dw_loc_oprnd2);
5906 loc = loc->dw_loc_next;
5910 /* Calculate the checksum of an attribute. */
5913 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
5914 struct md5_ctx *ctx, int *mark)
5916 dw_loc_descr_ref loc;
5919 if (AT_class (at) == dw_val_class_die_ref)
5921 dw_die_ref target_die = AT_ref (at);
5923 /* For pointer and reference types, we checksum only the (qualified)
5924 name of the target type (if there is a name). For friend entries,
5925 we checksum only the (qualified) name of the target type or function.
5926 This allows the checksum to remain the same whether the target type
5927 is complete or not. */
5928 if ((at->dw_attr == DW_AT_type
5929 && (tag == DW_TAG_pointer_type
5930 || tag == DW_TAG_reference_type
5931 || tag == DW_TAG_rvalue_reference_type
5932 || tag == DW_TAG_ptr_to_member_type))
5933 || (at->dw_attr == DW_AT_friend
5934 && tag == DW_TAG_friend))
5936 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
5938 if (name_attr != NULL)
5940 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
5944 CHECKSUM_ULEB128 ('N');
5945 CHECKSUM_ULEB128 (at->dw_attr);
5946 if (decl->die_parent != NULL)
5947 checksum_die_context (decl->die_parent, ctx);
5948 CHECKSUM_ULEB128 ('E');
5949 CHECKSUM_STRING (AT_string (name_attr));
5954 /* For all other references to another DIE, we check to see if the
5955 target DIE has already been visited. If it has, we emit a
5956 backward reference; if not, we descend recursively. */
5957 if (target_die->die_mark > 0)
5959 CHECKSUM_ULEB128 ('R');
5960 CHECKSUM_ULEB128 (at->dw_attr);
5961 CHECKSUM_ULEB128 (target_die->die_mark);
5965 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
5969 target_die->die_mark = ++(*mark);
5970 CHECKSUM_ULEB128 ('T');
5971 CHECKSUM_ULEB128 (at->dw_attr);
5972 if (decl->die_parent != NULL)
5973 checksum_die_context (decl->die_parent, ctx);
5974 die_checksum_ordered (target_die, ctx, mark);
5979 CHECKSUM_ULEB128 ('A');
5980 CHECKSUM_ULEB128 (at->dw_attr);
5982 switch (AT_class (at))
5984 case dw_val_class_const:
5985 CHECKSUM_ULEB128 (DW_FORM_sdata);
5986 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
5989 case dw_val_class_unsigned_const:
5990 CHECKSUM_ULEB128 (DW_FORM_sdata);
5991 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
5994 case dw_val_class_const_double:
5995 CHECKSUM_ULEB128 (DW_FORM_block);
5996 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
5997 CHECKSUM (at->dw_attr_val.v.val_double);
6000 case dw_val_class_vec:
6001 CHECKSUM_ULEB128 (DW_FORM_block);
6002 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
6003 CHECKSUM (at->dw_attr_val.v.val_vec);
6006 case dw_val_class_flag:
6007 CHECKSUM_ULEB128 (DW_FORM_flag);
6008 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
6011 case dw_val_class_str:
6012 CHECKSUM_ULEB128 (DW_FORM_string);
6013 CHECKSUM_STRING (AT_string (at));
6016 case dw_val_class_addr:
6018 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6019 CHECKSUM_ULEB128 (DW_FORM_string);
6020 CHECKSUM_STRING (XSTR (r, 0));
6023 case dw_val_class_offset:
6024 CHECKSUM_ULEB128 (DW_FORM_sdata);
6025 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
6028 case dw_val_class_loc:
6029 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6030 loc_checksum_ordered (loc, ctx);
6033 case dw_val_class_fde_ref:
6034 case dw_val_class_lbl_id:
6035 case dw_val_class_lineptr:
6036 case dw_val_class_macptr:
6039 case dw_val_class_file:
6040 CHECKSUM_ULEB128 (DW_FORM_string);
6041 CHECKSUM_STRING (AT_file (at)->filename);
6044 case dw_val_class_data8:
6045 CHECKSUM (at->dw_attr_val.v.val_data8);
6053 struct checksum_attributes
6055 dw_attr_ref at_name;
6056 dw_attr_ref at_type;
6057 dw_attr_ref at_friend;
6058 dw_attr_ref at_accessibility;
6059 dw_attr_ref at_address_class;
6060 dw_attr_ref at_allocated;
6061 dw_attr_ref at_artificial;
6062 dw_attr_ref at_associated;
6063 dw_attr_ref at_binary_scale;
6064 dw_attr_ref at_bit_offset;
6065 dw_attr_ref at_bit_size;
6066 dw_attr_ref at_bit_stride;
6067 dw_attr_ref at_byte_size;
6068 dw_attr_ref at_byte_stride;
6069 dw_attr_ref at_const_value;
6070 dw_attr_ref at_containing_type;
6071 dw_attr_ref at_count;
6072 dw_attr_ref at_data_location;
6073 dw_attr_ref at_data_member_location;
6074 dw_attr_ref at_decimal_scale;
6075 dw_attr_ref at_decimal_sign;
6076 dw_attr_ref at_default_value;
6077 dw_attr_ref at_digit_count;
6078 dw_attr_ref at_discr;
6079 dw_attr_ref at_discr_list;
6080 dw_attr_ref at_discr_value;
6081 dw_attr_ref at_encoding;
6082 dw_attr_ref at_endianity;
6083 dw_attr_ref at_explicit;
6084 dw_attr_ref at_is_optional;
6085 dw_attr_ref at_location;
6086 dw_attr_ref at_lower_bound;
6087 dw_attr_ref at_mutable;
6088 dw_attr_ref at_ordering;
6089 dw_attr_ref at_picture_string;
6090 dw_attr_ref at_prototyped;
6091 dw_attr_ref at_small;
6092 dw_attr_ref at_segment;
6093 dw_attr_ref at_string_length;
6094 dw_attr_ref at_threads_scaled;
6095 dw_attr_ref at_upper_bound;
6096 dw_attr_ref at_use_location;
6097 dw_attr_ref at_use_UTF8;
6098 dw_attr_ref at_variable_parameter;
6099 dw_attr_ref at_virtuality;
6100 dw_attr_ref at_visibility;
6101 dw_attr_ref at_vtable_elem_location;
6104 /* Collect the attributes that we will want to use for the checksum. */
6107 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
6112 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6123 attrs->at_friend = a;
6125 case DW_AT_accessibility:
6126 attrs->at_accessibility = a;
6128 case DW_AT_address_class:
6129 attrs->at_address_class = a;
6131 case DW_AT_allocated:
6132 attrs->at_allocated = a;
6134 case DW_AT_artificial:
6135 attrs->at_artificial = a;
6137 case DW_AT_associated:
6138 attrs->at_associated = a;
6140 case DW_AT_binary_scale:
6141 attrs->at_binary_scale = a;
6143 case DW_AT_bit_offset:
6144 attrs->at_bit_offset = a;
6146 case DW_AT_bit_size:
6147 attrs->at_bit_size = a;
6149 case DW_AT_bit_stride:
6150 attrs->at_bit_stride = a;
6152 case DW_AT_byte_size:
6153 attrs->at_byte_size = a;
6155 case DW_AT_byte_stride:
6156 attrs->at_byte_stride = a;
6158 case DW_AT_const_value:
6159 attrs->at_const_value = a;
6161 case DW_AT_containing_type:
6162 attrs->at_containing_type = a;
6165 attrs->at_count = a;
6167 case DW_AT_data_location:
6168 attrs->at_data_location = a;
6170 case DW_AT_data_member_location:
6171 attrs->at_data_member_location = a;
6173 case DW_AT_decimal_scale:
6174 attrs->at_decimal_scale = a;
6176 case DW_AT_decimal_sign:
6177 attrs->at_decimal_sign = a;
6179 case DW_AT_default_value:
6180 attrs->at_default_value = a;
6182 case DW_AT_digit_count:
6183 attrs->at_digit_count = a;
6186 attrs->at_discr = a;
6188 case DW_AT_discr_list:
6189 attrs->at_discr_list = a;
6191 case DW_AT_discr_value:
6192 attrs->at_discr_value = a;
6194 case DW_AT_encoding:
6195 attrs->at_encoding = a;
6197 case DW_AT_endianity:
6198 attrs->at_endianity = a;
6200 case DW_AT_explicit:
6201 attrs->at_explicit = a;
6203 case DW_AT_is_optional:
6204 attrs->at_is_optional = a;
6206 case DW_AT_location:
6207 attrs->at_location = a;
6209 case DW_AT_lower_bound:
6210 attrs->at_lower_bound = a;
6213 attrs->at_mutable = a;
6215 case DW_AT_ordering:
6216 attrs->at_ordering = a;
6218 case DW_AT_picture_string:
6219 attrs->at_picture_string = a;
6221 case DW_AT_prototyped:
6222 attrs->at_prototyped = a;
6225 attrs->at_small = a;
6228 attrs->at_segment = a;
6230 case DW_AT_string_length:
6231 attrs->at_string_length = a;
6233 case DW_AT_threads_scaled:
6234 attrs->at_threads_scaled = a;
6236 case DW_AT_upper_bound:
6237 attrs->at_upper_bound = a;
6239 case DW_AT_use_location:
6240 attrs->at_use_location = a;
6242 case DW_AT_use_UTF8:
6243 attrs->at_use_UTF8 = a;
6245 case DW_AT_variable_parameter:
6246 attrs->at_variable_parameter = a;
6248 case DW_AT_virtuality:
6249 attrs->at_virtuality = a;
6251 case DW_AT_visibility:
6252 attrs->at_visibility = a;
6254 case DW_AT_vtable_elem_location:
6255 attrs->at_vtable_elem_location = a;
6263 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6266 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6270 struct checksum_attributes attrs;
6272 CHECKSUM_ULEB128 ('D');
6273 CHECKSUM_ULEB128 (die->die_tag);
6275 memset (&attrs, 0, sizeof (attrs));
6277 decl = get_AT_ref (die, DW_AT_specification);
6279 collect_checksum_attributes (&attrs, decl);
6280 collect_checksum_attributes (&attrs, die);
6282 CHECKSUM_ATTR (attrs.at_name);
6283 CHECKSUM_ATTR (attrs.at_accessibility);
6284 CHECKSUM_ATTR (attrs.at_address_class);
6285 CHECKSUM_ATTR (attrs.at_allocated);
6286 CHECKSUM_ATTR (attrs.at_artificial);
6287 CHECKSUM_ATTR (attrs.at_associated);
6288 CHECKSUM_ATTR (attrs.at_binary_scale);
6289 CHECKSUM_ATTR (attrs.at_bit_offset);
6290 CHECKSUM_ATTR (attrs.at_bit_size);
6291 CHECKSUM_ATTR (attrs.at_bit_stride);
6292 CHECKSUM_ATTR (attrs.at_byte_size);
6293 CHECKSUM_ATTR (attrs.at_byte_stride);
6294 CHECKSUM_ATTR (attrs.at_const_value);
6295 CHECKSUM_ATTR (attrs.at_containing_type);
6296 CHECKSUM_ATTR (attrs.at_count);
6297 CHECKSUM_ATTR (attrs.at_data_location);
6298 CHECKSUM_ATTR (attrs.at_data_member_location);
6299 CHECKSUM_ATTR (attrs.at_decimal_scale);
6300 CHECKSUM_ATTR (attrs.at_decimal_sign);
6301 CHECKSUM_ATTR (attrs.at_default_value);
6302 CHECKSUM_ATTR (attrs.at_digit_count);
6303 CHECKSUM_ATTR (attrs.at_discr);
6304 CHECKSUM_ATTR (attrs.at_discr_list);
6305 CHECKSUM_ATTR (attrs.at_discr_value);
6306 CHECKSUM_ATTR (attrs.at_encoding);
6307 CHECKSUM_ATTR (attrs.at_endianity);
6308 CHECKSUM_ATTR (attrs.at_explicit);
6309 CHECKSUM_ATTR (attrs.at_is_optional);
6310 CHECKSUM_ATTR (attrs.at_location);
6311 CHECKSUM_ATTR (attrs.at_lower_bound);
6312 CHECKSUM_ATTR (attrs.at_mutable);
6313 CHECKSUM_ATTR (attrs.at_ordering);
6314 CHECKSUM_ATTR (attrs.at_picture_string);
6315 CHECKSUM_ATTR (attrs.at_prototyped);
6316 CHECKSUM_ATTR (attrs.at_small);
6317 CHECKSUM_ATTR (attrs.at_segment);
6318 CHECKSUM_ATTR (attrs.at_string_length);
6319 CHECKSUM_ATTR (attrs.at_threads_scaled);
6320 CHECKSUM_ATTR (attrs.at_upper_bound);
6321 CHECKSUM_ATTR (attrs.at_use_location);
6322 CHECKSUM_ATTR (attrs.at_use_UTF8);
6323 CHECKSUM_ATTR (attrs.at_variable_parameter);
6324 CHECKSUM_ATTR (attrs.at_virtuality);
6325 CHECKSUM_ATTR (attrs.at_visibility);
6326 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
6327 CHECKSUM_ATTR (attrs.at_type);
6328 CHECKSUM_ATTR (attrs.at_friend);
6330 /* Checksum the child DIEs, except for nested types and member functions. */
6333 dw_attr_ref name_attr;
6336 name_attr = get_AT (c, DW_AT_name);
6337 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
6338 && name_attr != NULL)
6340 CHECKSUM_ULEB128 ('S');
6341 CHECKSUM_ULEB128 (c->die_tag);
6342 CHECKSUM_STRING (AT_string (name_attr));
6346 /* Mark this DIE so it gets processed when unmarking. */
6347 if (c->die_mark == 0)
6349 die_checksum_ordered (c, ctx, mark);
6351 } while (c != die->die_child);
6353 CHECKSUM_ULEB128 (0);
6357 #undef CHECKSUM_STRING
6358 #undef CHECKSUM_ATTR
6359 #undef CHECKSUM_LEB128
6360 #undef CHECKSUM_ULEB128
6362 /* Generate the type signature for DIE. This is computed by generating an
6363 MD5 checksum over the DIE's tag, its relevant attributes, and its
6364 children. Attributes that are references to other DIEs are processed
6365 by recursion, using the MARK field to prevent infinite recursion.
6366 If the DIE is nested inside a namespace or another type, we also
6367 need to include that context in the signature. The lower 64 bits
6368 of the resulting MD5 checksum comprise the signature. */
6371 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
6375 unsigned char checksum[16];
6379 name = get_AT_string (die, DW_AT_name);
6380 decl = get_AT_ref (die, DW_AT_specification);
6382 /* First, compute a signature for just the type name (and its surrounding
6383 context, if any. This is stored in the type unit DIE for link-time
6384 ODR (one-definition rule) checking. */
6386 if (is_cxx() && name != NULL)
6388 md5_init_ctx (&ctx);
6390 /* Checksum the names of surrounding namespaces and structures. */
6391 if (decl != NULL && decl->die_parent != NULL)
6392 checksum_die_context (decl->die_parent, &ctx);
6394 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
6395 md5_process_bytes (name, strlen (name) + 1, &ctx);
6396 md5_finish_ctx (&ctx, checksum);
6398 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
6401 /* Next, compute the complete type signature. */
6403 md5_init_ctx (&ctx);
6405 die->die_mark = mark;
6407 /* Checksum the names of surrounding namespaces and structures. */
6408 if (decl != NULL && decl->die_parent != NULL)
6409 checksum_die_context (decl->die_parent, &ctx);
6411 /* Checksum the DIE and its children. */
6412 die_checksum_ordered (die, &ctx, &mark);
6413 unmark_all_dies (die);
6414 md5_finish_ctx (&ctx, checksum);
6416 /* Store the signature in the type node and link the type DIE and the
6417 type node together. */
6418 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
6419 DWARF_TYPE_SIGNATURE_SIZE);
6420 die->die_id.die_type_node = type_node;
6421 type_node->type_die = die;
6423 /* If the DIE is a specification, link its declaration to the type node
6426 decl->die_id.die_type_node = type_node;
6429 /* Do the location expressions look same? */
6431 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6433 return loc1->dw_loc_opc == loc2->dw_loc_opc
6434 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6435 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6438 /* Do the values look the same? */
6440 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6442 dw_loc_descr_ref loc1, loc2;
6445 if (v1->val_class != v2->val_class)
6448 switch (v1->val_class)
6450 case dw_val_class_const:
6451 return v1->v.val_int == v2->v.val_int;
6452 case dw_val_class_unsigned_const:
6453 return v1->v.val_unsigned == v2->v.val_unsigned;
6454 case dw_val_class_const_double:
6455 return v1->v.val_double.high == v2->v.val_double.high
6456 && v1->v.val_double.low == v2->v.val_double.low;
6457 case dw_val_class_vec:
6458 if (v1->v.val_vec.length != v2->v.val_vec.length
6459 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6461 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6462 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6465 case dw_val_class_flag:
6466 return v1->v.val_flag == v2->v.val_flag;
6467 case dw_val_class_str:
6468 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6470 case dw_val_class_addr:
6471 r1 = v1->v.val_addr;
6472 r2 = v2->v.val_addr;
6473 if (GET_CODE (r1) != GET_CODE (r2))
6475 return !rtx_equal_p (r1, r2);
6477 case dw_val_class_offset:
6478 return v1->v.val_offset == v2->v.val_offset;
6480 case dw_val_class_loc:
6481 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6483 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6484 if (!same_loc_p (loc1, loc2, mark))
6486 return !loc1 && !loc2;
6488 case dw_val_class_die_ref:
6489 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6491 case dw_val_class_fde_ref:
6492 case dw_val_class_vms_delta:
6493 case dw_val_class_lbl_id:
6494 case dw_val_class_lineptr:
6495 case dw_val_class_macptr:
6498 case dw_val_class_file:
6499 return v1->v.val_file == v2->v.val_file;
6501 case dw_val_class_data8:
6502 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
6509 /* Do the attributes look the same? */
6512 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6514 if (at1->dw_attr != at2->dw_attr)
6517 /* We don't care that this was compiled with a different compiler
6518 snapshot; if the output is the same, that's what matters. */
6519 if (at1->dw_attr == DW_AT_producer)
6522 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6525 /* Do the dies look the same? */
6528 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6534 /* To avoid infinite recursion. */
6536 return die1->die_mark == die2->die_mark;
6537 die1->die_mark = die2->die_mark = ++(*mark);
6539 if (die1->die_tag != die2->die_tag)
6542 if (VEC_length (dw_attr_node, die1->die_attr)
6543 != VEC_length (dw_attr_node, die2->die_attr))
6546 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
6547 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6550 c1 = die1->die_child;
6551 c2 = die2->die_child;
6560 if (!same_die_p (c1, c2, mark))
6564 if (c1 == die1->die_child)
6566 if (c2 == die2->die_child)
6576 /* Do the dies look the same? Wrapper around same_die_p. */
6579 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6582 int ret = same_die_p (die1, die2, &mark);
6584 unmark_all_dies (die1);
6585 unmark_all_dies (die2);
6590 /* The prefix to attach to symbols on DIEs in the current comdat debug
6592 static char *comdat_symbol_id;
6594 /* The index of the current symbol within the current comdat CU. */
6595 static unsigned int comdat_symbol_number;
6597 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6598 children, and set comdat_symbol_id accordingly. */
6601 compute_section_prefix (dw_die_ref unit_die)
6603 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6604 const char *base = die_name ? lbasename (die_name) : "anonymous";
6605 char *name = XALLOCAVEC (char, strlen (base) + 64);
6608 unsigned char checksum[16];
6611 /* Compute the checksum of the DIE, then append part of it as hex digits to
6612 the name filename of the unit. */
6614 md5_init_ctx (&ctx);
6616 die_checksum (unit_die, &ctx, &mark);
6617 unmark_all_dies (unit_die);
6618 md5_finish_ctx (&ctx, checksum);
6620 sprintf (name, "%s.", base);
6621 clean_symbol_name (name);
6623 p = name + strlen (name);
6624 for (i = 0; i < 4; i++)
6626 sprintf (p, "%.2x", checksum[i]);
6630 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
6631 comdat_symbol_number = 0;
6634 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6637 is_type_die (dw_die_ref die)
6639 switch (die->die_tag)
6641 case DW_TAG_array_type:
6642 case DW_TAG_class_type:
6643 case DW_TAG_interface_type:
6644 case DW_TAG_enumeration_type:
6645 case DW_TAG_pointer_type:
6646 case DW_TAG_reference_type:
6647 case DW_TAG_rvalue_reference_type:
6648 case DW_TAG_string_type:
6649 case DW_TAG_structure_type:
6650 case DW_TAG_subroutine_type:
6651 case DW_TAG_union_type:
6652 case DW_TAG_ptr_to_member_type:
6653 case DW_TAG_set_type:
6654 case DW_TAG_subrange_type:
6655 case DW_TAG_base_type:
6656 case DW_TAG_const_type:
6657 case DW_TAG_file_type:
6658 case DW_TAG_packed_type:
6659 case DW_TAG_volatile_type:
6660 case DW_TAG_typedef:
6667 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6668 Basically, we want to choose the bits that are likely to be shared between
6669 compilations (types) and leave out the bits that are specific to individual
6670 compilations (functions). */
6673 is_comdat_die (dw_die_ref c)
6675 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6676 we do for stabs. The advantage is a greater likelihood of sharing between
6677 objects that don't include headers in the same order (and therefore would
6678 put the base types in a different comdat). jason 8/28/00 */
6680 if (c->die_tag == DW_TAG_base_type)
6683 if (c->die_tag == DW_TAG_pointer_type
6684 || c->die_tag == DW_TAG_reference_type
6685 || c->die_tag == DW_TAG_rvalue_reference_type
6686 || c->die_tag == DW_TAG_const_type
6687 || c->die_tag == DW_TAG_volatile_type)
6689 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6691 return t ? is_comdat_die (t) : 0;
6694 return is_type_die (c);
6697 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6698 compilation unit. */
6701 is_symbol_die (dw_die_ref c)
6703 return (is_type_die (c)
6704 || is_declaration_die (c)
6705 || c->die_tag == DW_TAG_namespace
6706 || c->die_tag == DW_TAG_module);
6709 /* Returns true iff C is a compile-unit DIE. */
6712 is_cu_die (dw_die_ref c)
6714 return c && c->die_tag == DW_TAG_compile_unit;
6718 gen_internal_sym (const char *prefix)
6722 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6723 return xstrdup (buf);
6726 /* Assign symbols to all worthy DIEs under DIE. */
6729 assign_symbol_names (dw_die_ref die)
6733 if (is_symbol_die (die))
6735 if (comdat_symbol_id)
6737 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
6739 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6740 comdat_symbol_id, comdat_symbol_number++);
6741 die->die_id.die_symbol = xstrdup (p);
6744 die->die_id.die_symbol = gen_internal_sym ("LDIE");
6747 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6750 struct cu_hash_table_entry
6753 unsigned min_comdat_num, max_comdat_num;
6754 struct cu_hash_table_entry *next;
6757 /* Routines to manipulate hash table of CUs. */
6759 htab_cu_hash (const void *of)
6761 const struct cu_hash_table_entry *const entry =
6762 (const struct cu_hash_table_entry *) of;
6764 return htab_hash_string (entry->cu->die_id.die_symbol);
6768 htab_cu_eq (const void *of1, const void *of2)
6770 const struct cu_hash_table_entry *const entry1 =
6771 (const struct cu_hash_table_entry *) of1;
6772 const struct die_struct *const entry2 = (const struct die_struct *) of2;
6774 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
6778 htab_cu_del (void *what)
6780 struct cu_hash_table_entry *next,
6781 *entry = (struct cu_hash_table_entry *) what;
6791 /* Check whether we have already seen this CU and set up SYM_NUM
6794 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6796 struct cu_hash_table_entry dummy;
6797 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6799 dummy.max_comdat_num = 0;
6801 slot = (struct cu_hash_table_entry **)
6802 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
6806 for (; entry; last = entry, entry = entry->next)
6808 if (same_die_p_wrap (cu, entry->cu))
6814 *sym_num = entry->min_comdat_num;
6818 entry = XCNEW (struct cu_hash_table_entry);
6820 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6821 entry->next = *slot;
6827 /* Record SYM_NUM to record of CU in HTABLE. */
6829 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6831 struct cu_hash_table_entry **slot, *entry;
6833 slot = (struct cu_hash_table_entry **)
6834 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
6838 entry->max_comdat_num = sym_num;
6841 /* Traverse the DIE (which is always comp_unit_die), and set up
6842 additional compilation units for each of the include files we see
6843 bracketed by BINCL/EINCL. */
6846 break_out_includes (dw_die_ref die)
6849 dw_die_ref unit = NULL;
6850 limbo_die_node *node, **pnode;
6851 htab_t cu_hash_table;
6855 dw_die_ref prev = c;
6857 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6858 || (unit && is_comdat_die (c)))
6860 dw_die_ref next = c->die_sib;
6862 /* This DIE is for a secondary CU; remove it from the main one. */
6863 remove_child_with_prev (c, prev);
6865 if (c->die_tag == DW_TAG_GNU_BINCL)
6866 unit = push_new_compile_unit (unit, c);
6867 else if (c->die_tag == DW_TAG_GNU_EINCL)
6868 unit = pop_compile_unit (unit);
6870 add_child_die (unit, c);
6872 if (c == die->die_child)
6875 } while (c != die->die_child);
6878 /* We can only use this in debugging, since the frontend doesn't check
6879 to make sure that we leave every include file we enter. */
6883 assign_symbol_names (die);
6884 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6885 for (node = limbo_die_list, pnode = &limbo_die_list;
6891 compute_section_prefix (node->die);
6892 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6893 &comdat_symbol_number);
6894 assign_symbol_names (node->die);
6896 *pnode = node->next;
6899 pnode = &node->next;
6900 record_comdat_symbol_number (node->die, cu_hash_table,
6901 comdat_symbol_number);
6904 htab_delete (cu_hash_table);
6907 /* Return non-zero if this DIE is a declaration. */
6910 is_declaration_die (dw_die_ref die)
6915 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6916 if (a->dw_attr == DW_AT_declaration)
6922 /* Return non-zero if this DIE is nested inside a subprogram. */
6925 is_nested_in_subprogram (dw_die_ref die)
6927 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
6931 return local_scope_p (decl);
6934 /* Return non-zero if this DIE contains a defining declaration of a
6938 contains_subprogram_definition (dw_die_ref die)
6942 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
6944 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
6948 /* Return non-zero if this is a type DIE that should be moved to a
6949 COMDAT .debug_types section. */
6952 should_move_die_to_comdat (dw_die_ref die)
6954 switch (die->die_tag)
6956 case DW_TAG_class_type:
6957 case DW_TAG_structure_type:
6958 case DW_TAG_enumeration_type:
6959 case DW_TAG_union_type:
6960 /* Don't move declarations, inlined instances, or types nested in a
6962 if (is_declaration_die (die)
6963 || get_AT (die, DW_AT_abstract_origin)
6964 || is_nested_in_subprogram (die))
6966 /* A type definition should never contain a subprogram definition. */
6967 gcc_assert (!contains_subprogram_definition (die));
6969 case DW_TAG_array_type:
6970 case DW_TAG_interface_type:
6971 case DW_TAG_pointer_type:
6972 case DW_TAG_reference_type:
6973 case DW_TAG_rvalue_reference_type:
6974 case DW_TAG_string_type:
6975 case DW_TAG_subroutine_type:
6976 case DW_TAG_ptr_to_member_type:
6977 case DW_TAG_set_type:
6978 case DW_TAG_subrange_type:
6979 case DW_TAG_base_type:
6980 case DW_TAG_const_type:
6981 case DW_TAG_file_type:
6982 case DW_TAG_packed_type:
6983 case DW_TAG_volatile_type:
6984 case DW_TAG_typedef:
6990 /* Make a clone of DIE. */
6993 clone_die (dw_die_ref die)
6999 clone = ggc_alloc_cleared_die_node ();
7000 clone->die_tag = die->die_tag;
7002 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7003 add_dwarf_attr (clone, a);
7008 /* Make a clone of the tree rooted at DIE. */
7011 clone_tree (dw_die_ref die)
7014 dw_die_ref clone = clone_die (die);
7016 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
7021 /* Make a clone of DIE as a declaration. */
7024 clone_as_declaration (dw_die_ref die)
7031 /* If the DIE is already a declaration, just clone it. */
7032 if (is_declaration_die (die))
7033 return clone_die (die);
7035 /* If the DIE is a specification, just clone its declaration DIE. */
7036 decl = get_AT_ref (die, DW_AT_specification);
7038 return clone_die (decl);
7040 clone = ggc_alloc_cleared_die_node ();
7041 clone->die_tag = die->die_tag;
7043 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7045 /* We don't want to copy over all attributes.
7046 For example we don't want DW_AT_byte_size because otherwise we will no
7047 longer have a declaration and GDB will treat it as a definition. */
7051 case DW_AT_artificial:
7052 case DW_AT_containing_type:
7053 case DW_AT_external:
7056 case DW_AT_virtuality:
7057 case DW_AT_linkage_name:
7058 case DW_AT_MIPS_linkage_name:
7059 add_dwarf_attr (clone, a);
7061 case DW_AT_byte_size:
7067 if (die->die_id.die_type_node)
7068 add_AT_die_ref (clone, DW_AT_signature, die);
7070 add_AT_flag (clone, DW_AT_declaration, 1);
7074 /* Copy the declaration context to the new type unit DIE. This includes
7075 any surrounding namespace or type declarations. If the DIE has an
7076 AT_specification attribute, it also includes attributes and children
7077 attached to the specification, and returns a pointer to the original
7078 parent of the declaration DIE. Returns NULL otherwise. */
7081 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
7084 dw_die_ref new_decl;
7085 dw_die_ref orig_parent = NULL;
7087 decl = get_AT_ref (die, DW_AT_specification);
7096 /* The original DIE will be changed to a declaration, and must
7097 be moved to be a child of the original declaration DIE. */
7098 orig_parent = decl->die_parent;
7100 /* Copy the type node pointer from the new DIE to the original
7101 declaration DIE so we can forward references later. */
7102 decl->die_id.die_type_node = die->die_id.die_type_node;
7104 remove_AT (die, DW_AT_specification);
7106 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
7108 if (a->dw_attr != DW_AT_name
7109 && a->dw_attr != DW_AT_declaration
7110 && a->dw_attr != DW_AT_external)
7111 add_dwarf_attr (die, a);
7114 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
7117 if (decl->die_parent != NULL
7118 && decl->die_parent->die_tag != DW_TAG_compile_unit
7119 && decl->die_parent->die_tag != DW_TAG_type_unit)
7121 new_decl = copy_ancestor_tree (unit, decl, NULL);
7122 if (new_decl != NULL)
7124 remove_AT (new_decl, DW_AT_signature);
7125 add_AT_specification (die, new_decl);
7132 /* Generate the skeleton ancestor tree for the given NODE, then clone
7133 the DIE and add the clone into the tree. */
7136 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
7138 if (node->new_die != NULL)
7141 node->new_die = clone_as_declaration (node->old_die);
7143 if (node->parent != NULL)
7145 generate_skeleton_ancestor_tree (node->parent);
7146 add_child_die (node->parent->new_die, node->new_die);
7150 /* Generate a skeleton tree of DIEs containing any declarations that are
7151 found in the original tree. We traverse the tree looking for declaration
7152 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7155 generate_skeleton_bottom_up (skeleton_chain_node *parent)
7157 skeleton_chain_node node;
7160 dw_die_ref prev = NULL;
7161 dw_die_ref next = NULL;
7163 node.parent = parent;
7165 first = c = parent->old_die->die_child;
7169 if (prev == NULL || prev->die_sib == c)
7172 next = (c == first ? NULL : c->die_sib);
7174 node.new_die = NULL;
7175 if (is_declaration_die (c))
7177 /* Clone the existing DIE, move the original to the skeleton
7178 tree (which is in the main CU), and put the clone, with
7179 all the original's children, where the original came from. */
7180 dw_die_ref clone = clone_die (c);
7181 move_all_children (c, clone);
7183 replace_child (c, clone, prev);
7184 generate_skeleton_ancestor_tree (parent);
7185 add_child_die (parent->new_die, c);
7189 generate_skeleton_bottom_up (&node);
7190 } while (next != NULL);
7193 /* Wrapper function for generate_skeleton_bottom_up. */
7196 generate_skeleton (dw_die_ref die)
7198 skeleton_chain_node node;
7201 node.new_die = NULL;
7204 /* If this type definition is nested inside another type,
7205 always leave at least a declaration in its place. */
7206 if (die->die_parent != NULL && is_type_die (die->die_parent))
7207 node.new_die = clone_as_declaration (die);
7209 generate_skeleton_bottom_up (&node);
7210 return node.new_die;
7213 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7214 declaration. The original DIE is moved to a new compile unit so that
7215 existing references to it follow it to the new location. If any of the
7216 original DIE's descendants is a declaration, we need to replace the
7217 original DIE with a skeleton tree and move the declarations back into the
7221 remove_child_or_replace_with_skeleton (dw_die_ref unit, dw_die_ref child,
7224 dw_die_ref skeleton, orig_parent;
7226 /* Copy the declaration context to the type unit DIE. If the returned
7227 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7229 orig_parent = copy_declaration_context (unit, child);
7231 skeleton = generate_skeleton (child);
7232 if (skeleton == NULL)
7233 remove_child_with_prev (child, prev);
7236 skeleton->die_id.die_type_node = child->die_id.die_type_node;
7238 /* If the original DIE was a specification, we need to put
7239 the skeleton under the parent DIE of the declaration.
7240 This leaves the original declaration in the tree, but
7241 it will be pruned later since there are no longer any
7242 references to it. */
7243 if (orig_parent != NULL)
7245 remove_child_with_prev (child, prev);
7246 add_child_die (orig_parent, skeleton);
7249 replace_child (child, skeleton, prev);
7255 /* Traverse the DIE and set up additional .debug_types sections for each
7256 type worthy of being placed in a COMDAT section. */
7259 break_out_comdat_types (dw_die_ref die)
7263 dw_die_ref prev = NULL;
7264 dw_die_ref next = NULL;
7265 dw_die_ref unit = NULL;
7267 first = c = die->die_child;
7271 if (prev == NULL || prev->die_sib == c)
7274 next = (c == first ? NULL : c->die_sib);
7275 if (should_move_die_to_comdat (c))
7277 dw_die_ref replacement;
7278 comdat_type_node_ref type_node;
7280 /* Create a new type unit DIE as the root for the new tree, and
7281 add it to the list of comdat types. */
7282 unit = new_die (DW_TAG_type_unit, NULL, NULL);
7283 add_AT_unsigned (unit, DW_AT_language,
7284 get_AT_unsigned (comp_unit_die (), DW_AT_language));
7285 type_node = ggc_alloc_cleared_comdat_type_node ();
7286 type_node->root_die = unit;
7287 type_node->next = comdat_type_list;
7288 comdat_type_list = type_node;
7290 /* Generate the type signature. */
7291 generate_type_signature (c, type_node);
7293 /* Copy the declaration context, attributes, and children of the
7294 declaration into the new type unit DIE, then remove this DIE
7295 from the main CU (or replace it with a skeleton if necessary). */
7296 replacement = remove_child_or_replace_with_skeleton (unit, c, prev);
7298 /* Break out nested types into their own type units. */
7299 break_out_comdat_types (c);
7301 /* Add the DIE to the new compunit. */
7302 add_child_die (unit, c);
7304 if (replacement != NULL)
7307 else if (c->die_tag == DW_TAG_namespace
7308 || c->die_tag == DW_TAG_class_type
7309 || c->die_tag == DW_TAG_structure_type
7310 || c->die_tag == DW_TAG_union_type)
7312 /* Look for nested types that can be broken out. */
7313 break_out_comdat_types (c);
7315 } while (next != NULL);
7318 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7320 struct decl_table_entry
7326 /* Routines to manipulate hash table of copied declarations. */
7329 htab_decl_hash (const void *of)
7331 const struct decl_table_entry *const entry =
7332 (const struct decl_table_entry *) of;
7334 return htab_hash_pointer (entry->orig);
7338 htab_decl_eq (const void *of1, const void *of2)
7340 const struct decl_table_entry *const entry1 =
7341 (const struct decl_table_entry *) of1;
7342 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7344 return entry1->orig == entry2;
7348 htab_decl_del (void *what)
7350 struct decl_table_entry *entry = (struct decl_table_entry *) what;
7355 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7356 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7357 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7358 to check if the ancestor has already been copied into UNIT. */
7361 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7363 dw_die_ref parent = die->die_parent;
7364 dw_die_ref new_parent = unit;
7367 struct decl_table_entry *entry = NULL;
7371 /* Check if the entry has already been copied to UNIT. */
7372 slot = htab_find_slot_with_hash (decl_table, die,
7373 htab_hash_pointer (die), INSERT);
7374 if (*slot != HTAB_EMPTY_ENTRY)
7376 entry = (struct decl_table_entry *) *slot;
7380 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7381 entry = XCNEW (struct decl_table_entry);
7389 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
7392 if (parent->die_tag != DW_TAG_compile_unit
7393 && parent->die_tag != DW_TAG_type_unit)
7394 new_parent = copy_ancestor_tree (unit, parent, decl_table);
7397 copy = clone_as_declaration (die);
7398 add_child_die (new_parent, copy);
7400 if (decl_table != NULL)
7402 /* Record the pointer to the copy. */
7409 /* Walk the DIE and its children, looking for references to incomplete
7410 or trivial types that are unmarked (i.e., that are not in the current
7414 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7420 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7422 if (AT_class (a) == dw_val_class_die_ref)
7424 dw_die_ref targ = AT_ref (a);
7425 comdat_type_node_ref type_node = targ->die_id.die_type_node;
7427 struct decl_table_entry *entry;
7429 if (targ->die_mark != 0 || type_node != NULL)
7432 slot = htab_find_slot_with_hash (decl_table, targ,
7433 htab_hash_pointer (targ), INSERT);
7435 if (*slot != HTAB_EMPTY_ENTRY)
7437 /* TARG has already been copied, so we just need to
7438 modify the reference to point to the copy. */
7439 entry = (struct decl_table_entry *) *slot;
7440 a->dw_attr_val.v.val_die_ref.die = entry->copy;
7444 dw_die_ref parent = unit;
7445 dw_die_ref copy = clone_tree (targ);
7447 /* Make sure the cloned tree is marked as part of the
7451 /* Record in DECL_TABLE that TARG has been copied.
7452 Need to do this now, before the recursive call,
7453 because DECL_TABLE may be expanded and SLOT
7454 would no longer be a valid pointer. */
7455 entry = XCNEW (struct decl_table_entry);
7460 /* If TARG has surrounding context, copy its ancestor tree
7461 into the new type unit. */
7462 if (targ->die_parent != NULL
7463 && targ->die_parent->die_tag != DW_TAG_compile_unit
7464 && targ->die_parent->die_tag != DW_TAG_type_unit)
7465 parent = copy_ancestor_tree (unit, targ->die_parent,
7468 add_child_die (parent, copy);
7469 a->dw_attr_val.v.val_die_ref.die = copy;
7471 /* Make sure the newly-copied DIE is walked. If it was
7472 installed in a previously-added context, it won't
7473 get visited otherwise. */
7476 /* Find the highest point of the newly-added tree,
7477 mark each node along the way, and walk from there. */
7478 parent->die_mark = 1;
7479 while (parent->die_parent
7480 && parent->die_parent->die_mark == 0)
7482 parent = parent->die_parent;
7483 parent->die_mark = 1;
7485 copy_decls_walk (unit, parent, decl_table);
7491 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
7494 /* Copy declarations for "unworthy" types into the new comdat section.
7495 Incomplete types, modified types, and certain other types aren't broken
7496 out into comdat sections of their own, so they don't have a signature,
7497 and we need to copy the declaration into the same section so that we
7498 don't have an external reference. */
7501 copy_decls_for_unworthy_types (dw_die_ref unit)
7506 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
7507 copy_decls_walk (unit, unit, decl_table);
7508 htab_delete (decl_table);
7512 /* Traverse the DIE and add a sibling attribute if it may have the
7513 effect of speeding up access to siblings. To save some space,
7514 avoid generating sibling attributes for DIE's without children. */
7517 add_sibling_attributes (dw_die_ref die)
7521 if (! die->die_child)
7524 if (die->die_parent && die != die->die_parent->die_child)
7525 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7527 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7530 /* Output all location lists for the DIE and its children. */
7533 output_location_lists (dw_die_ref die)
7539 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7540 if (AT_class (a) == dw_val_class_loc_list)
7541 output_loc_list (AT_loc_list (a));
7543 FOR_EACH_CHILD (die, c, output_location_lists (c));
7546 /* The format of each DIE (and its attribute value pairs) is encoded in an
7547 abbreviation table. This routine builds the abbreviation table and assigns
7548 a unique abbreviation id for each abbreviation entry. The children of each
7549 die are visited recursively. */
7552 build_abbrev_table (dw_die_ref die)
7554 unsigned long abbrev_id;
7555 unsigned int n_alloc;
7560 /* Scan the DIE references, and mark as external any that refer to
7561 DIEs from other CUs (i.e. those which are not marked). */
7562 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7563 if (AT_class (a) == dw_val_class_die_ref
7564 && AT_ref (a)->die_mark == 0)
7566 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
7567 set_AT_ref_external (a, 1);
7570 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7572 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7573 dw_attr_ref die_a, abbrev_a;
7577 if (abbrev->die_tag != die->die_tag)
7579 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7582 if (VEC_length (dw_attr_node, abbrev->die_attr)
7583 != VEC_length (dw_attr_node, die->die_attr))
7586 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
7588 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7589 if ((abbrev_a->dw_attr != die_a->dw_attr)
7590 || (value_format (abbrev_a) != value_format (die_a)))
7600 if (abbrev_id >= abbrev_die_table_in_use)
7602 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7604 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7605 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7608 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7609 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7610 abbrev_die_table_allocated = n_alloc;
7613 ++abbrev_die_table_in_use;
7614 abbrev_die_table[abbrev_id] = die;
7617 die->die_abbrev = abbrev_id;
7618 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7621 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7624 constant_size (unsigned HOST_WIDE_INT value)
7631 log = floor_log2 (value);
7634 log = 1 << (floor_log2 (log) + 1);
7639 /* Return the size of a DIE as it is represented in the
7640 .debug_info section. */
7642 static unsigned long
7643 size_of_die (dw_die_ref die)
7645 unsigned long size = 0;
7649 size += size_of_uleb128 (die->die_abbrev);
7650 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7652 switch (AT_class (a))
7654 case dw_val_class_addr:
7655 size += DWARF2_ADDR_SIZE;
7657 case dw_val_class_offset:
7658 size += DWARF_OFFSET_SIZE;
7660 case dw_val_class_loc:
7662 unsigned long lsize = size_of_locs (AT_loc (a));
7665 if (dwarf_version >= 4)
7666 size += size_of_uleb128 (lsize);
7668 size += constant_size (lsize);
7672 case dw_val_class_loc_list:
7673 size += DWARF_OFFSET_SIZE;
7675 case dw_val_class_range_list:
7676 size += DWARF_OFFSET_SIZE;
7678 case dw_val_class_const:
7679 size += size_of_sleb128 (AT_int (a));
7681 case dw_val_class_unsigned_const:
7683 int csize = constant_size (AT_unsigned (a));
7684 if (dwarf_version == 3
7685 && a->dw_attr == DW_AT_data_member_location
7687 size += size_of_uleb128 (AT_unsigned (a));
7692 case dw_val_class_const_double:
7693 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
7694 if (HOST_BITS_PER_WIDE_INT >= 64)
7697 case dw_val_class_vec:
7698 size += constant_size (a->dw_attr_val.v.val_vec.length
7699 * a->dw_attr_val.v.val_vec.elt_size)
7700 + a->dw_attr_val.v.val_vec.length
7701 * a->dw_attr_val.v.val_vec.elt_size; /* block */
7703 case dw_val_class_flag:
7704 if (dwarf_version >= 4)
7705 /* Currently all add_AT_flag calls pass in 1 as last argument,
7706 so DW_FORM_flag_present can be used. If that ever changes,
7707 we'll need to use DW_FORM_flag and have some optimization
7708 in build_abbrev_table that will change those to
7709 DW_FORM_flag_present if it is set to 1 in all DIEs using
7710 the same abbrev entry. */
7711 gcc_assert (a->dw_attr_val.v.val_flag == 1);
7715 case dw_val_class_die_ref:
7716 if (AT_ref_external (a))
7718 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7719 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7720 is sized by target address length, whereas in DWARF3
7721 it's always sized as an offset. */
7722 if (use_debug_types)
7723 size += DWARF_TYPE_SIGNATURE_SIZE;
7724 else if (dwarf_version == 2)
7725 size += DWARF2_ADDR_SIZE;
7727 size += DWARF_OFFSET_SIZE;
7730 size += DWARF_OFFSET_SIZE;
7732 case dw_val_class_fde_ref:
7733 size += DWARF_OFFSET_SIZE;
7735 case dw_val_class_lbl_id:
7736 size += DWARF2_ADDR_SIZE;
7738 case dw_val_class_lineptr:
7739 case dw_val_class_macptr:
7740 size += DWARF_OFFSET_SIZE;
7742 case dw_val_class_str:
7743 if (AT_string_form (a) == DW_FORM_strp)
7744 size += DWARF_OFFSET_SIZE;
7746 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7748 case dw_val_class_file:
7749 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7751 case dw_val_class_data8:
7754 case dw_val_class_vms_delta:
7755 size += DWARF_OFFSET_SIZE;
7765 /* Size the debugging information associated with a given DIE. Visits the
7766 DIE's children recursively. Updates the global variable next_die_offset, on
7767 each time through. Uses the current value of next_die_offset to update the
7768 die_offset field in each DIE. */
7771 calc_die_sizes (dw_die_ref die)
7775 gcc_assert (die->die_offset == 0
7776 || (unsigned long int) die->die_offset == next_die_offset);
7777 die->die_offset = next_die_offset;
7778 next_die_offset += size_of_die (die);
7780 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7782 if (die->die_child != NULL)
7783 /* Count the null byte used to terminate sibling lists. */
7784 next_die_offset += 1;
7787 /* Size just the base type children at the start of the CU.
7788 This is needed because build_abbrev needs to size locs
7789 and sizing of type based stack ops needs to know die_offset
7790 values for the base types. */
7793 calc_base_type_die_sizes (void)
7795 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7797 dw_die_ref base_type;
7798 #if ENABLE_ASSERT_CHECKING
7799 dw_die_ref prev = comp_unit_die ()->die_child;
7802 die_offset += size_of_die (comp_unit_die ());
7803 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
7805 #if ENABLE_ASSERT_CHECKING
7806 gcc_assert (base_type->die_offset == 0
7807 && prev->die_sib == base_type
7808 && base_type->die_child == NULL
7809 && base_type->die_abbrev);
7812 base_type->die_offset = die_offset;
7813 die_offset += size_of_die (base_type);
7817 /* Set the marks for a die and its children. We do this so
7818 that we know whether or not a reference needs to use FORM_ref_addr; only
7819 DIEs in the same CU will be marked. We used to clear out the offset
7820 and use that as the flag, but ran into ordering problems. */
7823 mark_dies (dw_die_ref die)
7827 gcc_assert (!die->die_mark);
7830 FOR_EACH_CHILD (die, c, mark_dies (c));
7833 /* Clear the marks for a die and its children. */
7836 unmark_dies (dw_die_ref die)
7840 if (! use_debug_types)
7841 gcc_assert (die->die_mark);
7844 FOR_EACH_CHILD (die, c, unmark_dies (c));
7847 /* Clear the marks for a die, its children and referred dies. */
7850 unmark_all_dies (dw_die_ref die)
7860 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7862 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7863 if (AT_class (a) == dw_val_class_die_ref)
7864 unmark_all_dies (AT_ref (a));
7867 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7868 generated for the compilation unit. */
7870 static unsigned long
7871 size_of_pubnames (VEC (pubname_entry, gc) * names)
7877 size = DWARF_PUBNAMES_HEADER_SIZE;
7878 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
7879 if (names != pubtype_table
7880 || p->die->die_offset != 0
7881 || !flag_eliminate_unused_debug_types)
7882 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7884 size += DWARF_OFFSET_SIZE;
7888 /* Return the size of the information in the .debug_aranges section. */
7890 static unsigned long
7891 size_of_aranges (void)
7895 size = DWARF_ARANGES_HEADER_SIZE;
7897 /* Count the address/length pair for this compilation unit. */
7898 if (text_section_used)
7899 size += 2 * DWARF2_ADDR_SIZE;
7900 if (cold_text_section_used)
7901 size += 2 * DWARF2_ADDR_SIZE;
7902 if (have_multiple_function_sections)
7907 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
7909 if (!fde->in_std_section)
7910 size += 2 * DWARF2_ADDR_SIZE;
7911 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
7912 size += 2 * DWARF2_ADDR_SIZE;
7916 /* Count the two zero words used to terminated the address range table. */
7917 size += 2 * DWARF2_ADDR_SIZE;
7921 /* Select the encoding of an attribute value. */
7923 static enum dwarf_form
7924 value_format (dw_attr_ref a)
7926 switch (a->dw_attr_val.val_class)
7928 case dw_val_class_addr:
7929 /* Only very few attributes allow DW_FORM_addr. */
7934 case DW_AT_entry_pc:
7935 case DW_AT_trampoline:
7936 return DW_FORM_addr;
7940 switch (DWARF2_ADDR_SIZE)
7943 return DW_FORM_data1;
7945 return DW_FORM_data2;
7947 return DW_FORM_data4;
7949 return DW_FORM_data8;
7953 case dw_val_class_range_list:
7954 case dw_val_class_loc_list:
7955 if (dwarf_version >= 4)
7956 return DW_FORM_sec_offset;
7958 case dw_val_class_vms_delta:
7959 case dw_val_class_offset:
7960 switch (DWARF_OFFSET_SIZE)
7963 return DW_FORM_data4;
7965 return DW_FORM_data8;
7969 case dw_val_class_loc:
7970 if (dwarf_version >= 4)
7971 return DW_FORM_exprloc;
7972 switch (constant_size (size_of_locs (AT_loc (a))))
7975 return DW_FORM_block1;
7977 return DW_FORM_block2;
7981 case dw_val_class_const:
7982 return DW_FORM_sdata;
7983 case dw_val_class_unsigned_const:
7984 switch (constant_size (AT_unsigned (a)))
7987 return DW_FORM_data1;
7989 return DW_FORM_data2;
7991 /* In DWARF3 DW_AT_data_member_location with
7992 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
7993 constant, so we need to use DW_FORM_udata if we need
7994 a large constant. */
7995 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
7996 return DW_FORM_udata;
7997 return DW_FORM_data4;
7999 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
8000 return DW_FORM_udata;
8001 return DW_FORM_data8;
8005 case dw_val_class_const_double:
8006 switch (HOST_BITS_PER_WIDE_INT)
8009 return DW_FORM_data2;
8011 return DW_FORM_data4;
8013 return DW_FORM_data8;
8016 return DW_FORM_block1;
8018 case dw_val_class_vec:
8019 switch (constant_size (a->dw_attr_val.v.val_vec.length
8020 * a->dw_attr_val.v.val_vec.elt_size))
8023 return DW_FORM_block1;
8025 return DW_FORM_block2;
8027 return DW_FORM_block4;
8031 case dw_val_class_flag:
8032 if (dwarf_version >= 4)
8034 /* Currently all add_AT_flag calls pass in 1 as last argument,
8035 so DW_FORM_flag_present can be used. If that ever changes,
8036 we'll need to use DW_FORM_flag and have some optimization
8037 in build_abbrev_table that will change those to
8038 DW_FORM_flag_present if it is set to 1 in all DIEs using
8039 the same abbrev entry. */
8040 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8041 return DW_FORM_flag_present;
8043 return DW_FORM_flag;
8044 case dw_val_class_die_ref:
8045 if (AT_ref_external (a))
8046 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
8049 case dw_val_class_fde_ref:
8050 return DW_FORM_data;
8051 case dw_val_class_lbl_id:
8052 return DW_FORM_addr;
8053 case dw_val_class_lineptr:
8054 case dw_val_class_macptr:
8055 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
8056 case dw_val_class_str:
8057 return AT_string_form (a);
8058 case dw_val_class_file:
8059 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8062 return DW_FORM_data1;
8064 return DW_FORM_data2;
8066 return DW_FORM_data4;
8071 case dw_val_class_data8:
8072 return DW_FORM_data8;
8079 /* Output the encoding of an attribute value. */
8082 output_value_format (dw_attr_ref a)
8084 enum dwarf_form form = value_format (a);
8086 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8089 /* Output the .debug_abbrev section which defines the DIE abbreviation
8093 output_abbrev_section (void)
8095 unsigned long abbrev_id;
8097 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8099 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8103 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8104 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8105 dwarf_tag_name (abbrev->die_tag));
8107 if (abbrev->die_child != NULL)
8108 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8110 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8112 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8115 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8116 dwarf_attr_name (a_attr->dw_attr));
8117 output_value_format (a_attr);
8120 dw2_asm_output_data (1, 0, NULL);
8121 dw2_asm_output_data (1, 0, NULL);
8124 /* Terminate the table. */
8125 dw2_asm_output_data (1, 0, NULL);
8128 /* Output a symbol we can use to refer to this DIE from another CU. */
8131 output_die_symbol (dw_die_ref die)
8133 char *sym = die->die_id.die_symbol;
8138 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8139 /* We make these global, not weak; if the target doesn't support
8140 .linkonce, it doesn't support combining the sections, so debugging
8142 targetm.asm_out.globalize_label (asm_out_file, sym);
8144 ASM_OUTPUT_LABEL (asm_out_file, sym);
8147 /* Return a new location list, given the begin and end range, and the
8150 static inline dw_loc_list_ref
8151 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8152 const char *section)
8154 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
8156 retlist->begin = begin;
8158 retlist->expr = expr;
8159 retlist->section = section;
8164 /* Generate a new internal symbol for this location list node, if it
8165 hasn't got one yet. */
8168 gen_llsym (dw_loc_list_ref list)
8170 gcc_assert (!list->ll_symbol);
8171 list->ll_symbol = gen_internal_sym ("LLST");
8174 /* Output the location list given to us. */
8177 output_loc_list (dw_loc_list_ref list_head)
8179 dw_loc_list_ref curr = list_head;
8181 if (list_head->emitted)
8183 list_head->emitted = true;
8185 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8187 /* Walk the location list, and output each range + expression. */
8188 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8191 /* Don't output an entry that starts and ends at the same address. */
8192 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
8194 size = size_of_locs (curr->expr);
8195 /* If the expression is too large, drop it on the floor. We could
8196 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8197 in the expression, but >= 64KB expressions for a single value
8198 in a single range are unlikely very useful. */
8201 if (!have_multiple_function_sections)
8203 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8204 "Location list begin address (%s)",
8205 list_head->ll_symbol);
8206 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8207 "Location list end address (%s)",
8208 list_head->ll_symbol);
8212 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8213 "Location list begin address (%s)",
8214 list_head->ll_symbol);
8215 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8216 "Location list end address (%s)",
8217 list_head->ll_symbol);
8220 /* Output the block length for this list of location operations. */
8221 gcc_assert (size <= 0xffff);
8222 dw2_asm_output_data (2, size, "%s", "Location expression size");
8224 output_loc_sequence (curr->expr, -1);
8227 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8228 "Location list terminator begin (%s)",
8229 list_head->ll_symbol);
8230 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8231 "Location list terminator end (%s)",
8232 list_head->ll_symbol);
8235 /* Output a type signature. */
8238 output_signature (const char *sig, const char *name)
8242 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8243 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
8246 /* Output the DIE and its attributes. Called recursively to generate
8247 the definitions of each child DIE. */
8250 output_die (dw_die_ref die)
8257 /* If someone in another CU might refer to us, set up a symbol for
8258 them to point to. */
8259 if (! use_debug_types && die->die_id.die_symbol)
8260 output_die_symbol (die);
8262 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
8263 (unsigned long)die->die_offset,
8264 dwarf_tag_name (die->die_tag));
8266 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8268 const char *name = dwarf_attr_name (a->dw_attr);
8270 switch (AT_class (a))
8272 case dw_val_class_addr:
8273 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8276 case dw_val_class_offset:
8277 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8281 case dw_val_class_range_list:
8283 char *p = strchr (ranges_section_label, '\0');
8285 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8286 a->dw_attr_val.v.val_offset);
8287 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8288 debug_ranges_section, "%s", name);
8293 case dw_val_class_loc:
8294 size = size_of_locs (AT_loc (a));
8296 /* Output the block length for this list of location operations. */
8297 if (dwarf_version >= 4)
8298 dw2_asm_output_data_uleb128 (size, "%s", name);
8300 dw2_asm_output_data (constant_size (size), size, "%s", name);
8302 output_loc_sequence (AT_loc (a), -1);
8305 case dw_val_class_const:
8306 /* ??? It would be slightly more efficient to use a scheme like is
8307 used for unsigned constants below, but gdb 4.x does not sign
8308 extend. Gdb 5.x does sign extend. */
8309 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8312 case dw_val_class_unsigned_const:
8314 int csize = constant_size (AT_unsigned (a));
8315 if (dwarf_version == 3
8316 && a->dw_attr == DW_AT_data_member_location
8318 dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name);
8320 dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
8324 case dw_val_class_const_double:
8326 unsigned HOST_WIDE_INT first, second;
8328 if (HOST_BITS_PER_WIDE_INT >= 64)
8329 dw2_asm_output_data (1,
8330 2 * HOST_BITS_PER_WIDE_INT
8331 / HOST_BITS_PER_CHAR,
8334 if (WORDS_BIG_ENDIAN)
8336 first = a->dw_attr_val.v.val_double.high;
8337 second = a->dw_attr_val.v.val_double.low;
8341 first = a->dw_attr_val.v.val_double.low;
8342 second = a->dw_attr_val.v.val_double.high;
8345 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8347 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8352 case dw_val_class_vec:
8354 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8355 unsigned int len = a->dw_attr_val.v.val_vec.length;
8359 dw2_asm_output_data (constant_size (len * elt_size),
8360 len * elt_size, "%s", name);
8361 if (elt_size > sizeof (HOST_WIDE_INT))
8366 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8369 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8370 "fp or vector constant word %u", i);
8374 case dw_val_class_flag:
8375 if (dwarf_version >= 4)
8377 /* Currently all add_AT_flag calls pass in 1 as last argument,
8378 so DW_FORM_flag_present can be used. If that ever changes,
8379 we'll need to use DW_FORM_flag and have some optimization
8380 in build_abbrev_table that will change those to
8381 DW_FORM_flag_present if it is set to 1 in all DIEs using
8382 the same abbrev entry. */
8383 gcc_assert (AT_flag (a) == 1);
8385 fprintf (asm_out_file, "\t\t\t%s %s\n",
8386 ASM_COMMENT_START, name);
8389 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8392 case dw_val_class_loc_list:
8394 char *sym = AT_loc_list (a)->ll_symbol;
8397 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8402 case dw_val_class_die_ref:
8403 if (AT_ref_external (a))
8405 if (use_debug_types)
8407 comdat_type_node_ref type_node =
8408 AT_ref (a)->die_id.die_type_node;
8410 gcc_assert (type_node);
8411 output_signature (type_node->signature, name);
8415 char *sym = AT_ref (a)->die_id.die_symbol;
8419 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8420 length, whereas in DWARF3 it's always sized as an
8422 if (dwarf_version == 2)
8423 size = DWARF2_ADDR_SIZE;
8425 size = DWARF_OFFSET_SIZE;
8426 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
8432 gcc_assert (AT_ref (a)->die_offset);
8433 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8438 case dw_val_class_fde_ref:
8442 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8443 a->dw_attr_val.v.val_fde_index * 2);
8444 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8449 case dw_val_class_vms_delta:
8450 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
8451 AT_vms_delta2 (a), AT_vms_delta1 (a),
8455 case dw_val_class_lbl_id:
8456 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8459 case dw_val_class_lineptr:
8460 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8461 debug_line_section, "%s", name);
8464 case dw_val_class_macptr:
8465 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8466 debug_macinfo_section, "%s", name);
8469 case dw_val_class_str:
8470 if (AT_string_form (a) == DW_FORM_strp)
8471 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8472 a->dw_attr_val.v.val_str->label,
8474 "%s: \"%s\"", name, AT_string (a));
8476 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8479 case dw_val_class_file:
8481 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8483 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8484 a->dw_attr_val.v.val_file->filename);
8488 case dw_val_class_data8:
8492 for (i = 0; i < 8; i++)
8493 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
8494 i == 0 ? "%s" : NULL, name);
8503 FOR_EACH_CHILD (die, c, output_die (c));
8505 /* Add null byte to terminate sibling list. */
8506 if (die->die_child != NULL)
8507 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8508 (unsigned long) die->die_offset);
8511 /* Output the compilation unit that appears at the beginning of the
8512 .debug_info section, and precedes the DIE descriptions. */
8515 output_compilation_unit_header (void)
8517 int ver = dwarf_version;
8519 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8520 dw2_asm_output_data (4, 0xffffffff,
8521 "Initial length escape value indicating 64-bit DWARF extension");
8522 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8523 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8524 "Length of Compilation Unit Info");
8525 dw2_asm_output_data (2, ver, "DWARF version number");
8526 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8527 debug_abbrev_section,
8528 "Offset Into Abbrev. Section");
8529 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8532 /* Output the compilation unit DIE and its children. */
8535 output_comp_unit (dw_die_ref die, int output_if_empty)
8537 const char *secname;
8540 /* Unless we are outputting main CU, we may throw away empty ones. */
8541 if (!output_if_empty && die->die_child == NULL)
8544 /* Even if there are no children of this DIE, we must output the information
8545 about the compilation unit. Otherwise, on an empty translation unit, we
8546 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8547 will then complain when examining the file. First mark all the DIEs in
8548 this CU so we know which get local refs. */
8551 build_abbrev_table (die);
8553 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8554 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8555 calc_die_sizes (die);
8557 oldsym = die->die_id.die_symbol;
8560 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8562 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8564 die->die_id.die_symbol = NULL;
8565 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8569 switch_to_section (debug_info_section);
8570 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
8571 info_section_emitted = true;
8574 /* Output debugging information. */
8575 output_compilation_unit_header ();
8578 /* Leave the marks on the main CU, so we can check them in
8583 die->die_id.die_symbol = oldsym;
8587 /* Output a comdat type unit DIE and its children. */
8590 output_comdat_type_unit (comdat_type_node *node)
8592 const char *secname;
8595 #if defined (OBJECT_FORMAT_ELF)
8599 /* First mark all the DIEs in this CU so we know which get local refs. */
8600 mark_dies (node->root_die);
8602 build_abbrev_table (node->root_die);
8604 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8605 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
8606 calc_die_sizes (node->root_die);
8608 #if defined (OBJECT_FORMAT_ELF)
8609 secname = ".debug_types";
8610 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
8611 sprintf (tmp, "wt.");
8612 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8613 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
8614 comdat_key = get_identifier (tmp);
8615 targetm.asm_out.named_section (secname,
8616 SECTION_DEBUG | SECTION_LINKONCE,
8619 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
8620 sprintf (tmp, ".gnu.linkonce.wt.");
8621 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8622 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
8624 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8627 /* Output debugging information. */
8628 output_compilation_unit_header ();
8629 output_signature (node->signature, "Type Signature");
8630 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
8631 "Offset to Type DIE");
8632 output_die (node->root_die);
8634 unmark_dies (node->root_die);
8637 /* Return the DWARF2/3 pubname associated with a decl. */
8640 dwarf2_name (tree decl, int scope)
8642 if (DECL_NAMELESS (decl))
8644 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8647 /* Add a new entry to .debug_pubnames if appropriate. */
8650 add_pubname_string (const char *str, dw_die_ref die)
8652 if (targetm.want_debug_pub_sections)
8657 e.name = xstrdup (str);
8658 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8663 add_pubname (tree decl, dw_die_ref die)
8665 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
8667 const char *name = dwarf2_name (decl, 1);
8669 add_pubname_string (name, die);
8673 /* Add a new entry to .debug_pubtypes if appropriate. */
8676 add_pubtype (tree decl, dw_die_ref die)
8680 if (!targetm.want_debug_pub_sections)
8684 if ((TREE_PUBLIC (decl)
8685 || is_cu_die (die->die_parent))
8686 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8691 if (TYPE_NAME (decl))
8693 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8694 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8695 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8696 && DECL_NAME (TYPE_NAME (decl)))
8697 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8699 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8704 e.name = dwarf2_name (decl, 1);
8706 e.name = xstrdup (e.name);
8709 /* If we don't have a name for the type, there's no point in adding
8711 if (e.name && e.name[0] != '\0')
8712 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8716 /* Output the public names table used to speed up access to externally
8717 visible names; or the public types table used to find type definitions. */
8720 output_pubnames (VEC (pubname_entry, gc) * names)
8723 unsigned long pubnames_length = size_of_pubnames (names);
8726 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8727 dw2_asm_output_data (4, 0xffffffff,
8728 "Initial length escape value indicating 64-bit DWARF extension");
8729 if (names == pubname_table)
8730 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8731 "Length of Public Names Info");
8733 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8734 "Length of Public Type Names Info");
8735 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8736 dw2_asm_output_data (2, 2, "DWARF Version");
8737 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8739 "Offset of Compilation Unit Info");
8740 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8741 "Compilation Unit Length");
8743 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
8745 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8746 if (names == pubname_table)
8747 gcc_assert (pub->die->die_mark);
8749 if (names != pubtype_table
8750 || pub->die->die_offset != 0
8751 || !flag_eliminate_unused_debug_types)
8753 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8756 dw2_asm_output_nstring (pub->name, -1, "external name");
8760 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8763 /* Output the information that goes into the .debug_aranges table.
8764 Namely, define the beginning and ending address range of the
8765 text section generated for this compilation unit. */
8768 output_aranges (unsigned long aranges_length)
8772 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8773 dw2_asm_output_data (4, 0xffffffff,
8774 "Initial length escape value indicating 64-bit DWARF extension");
8775 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8776 "Length of Address Ranges Info");
8777 /* Version number for aranges is still 2, even in DWARF3. */
8778 dw2_asm_output_data (2, 2, "DWARF Version");
8779 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8781 "Offset of Compilation Unit Info");
8782 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8783 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8785 /* We need to align to twice the pointer size here. */
8786 if (DWARF_ARANGES_PAD_SIZE)
8788 /* Pad using a 2 byte words so that padding is correct for any
8790 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8791 2 * DWARF2_ADDR_SIZE);
8792 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8793 dw2_asm_output_data (2, 0, NULL);
8796 /* It is necessary not to output these entries if the sections were
8797 not used; if the sections were not used, the length will be 0 and
8798 the address may end up as 0 if the section is discarded by ld
8799 --gc-sections, leaving an invalid (0, 0) entry that can be
8800 confused with the terminator. */
8801 if (text_section_used)
8803 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8804 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8805 text_section_label, "Length");
8807 if (cold_text_section_used)
8809 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8811 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8812 cold_text_section_label, "Length");
8815 if (have_multiple_function_sections)
8820 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
8822 if (!fde->in_std_section)
8824 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
8826 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
8827 fde->dw_fde_begin, "Length");
8829 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
8831 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
8833 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
8834 fde->dw_fde_second_begin, "Length");
8839 /* Output the terminator words. */
8840 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8841 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8844 /* Add a new entry to .debug_ranges. Return the offset at which it
8848 add_ranges_num (int num)
8850 unsigned int in_use = ranges_table_in_use;
8852 if (in_use == ranges_table_allocated)
8854 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8855 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8856 ranges_table_allocated);
8857 memset (ranges_table + ranges_table_in_use, 0,
8858 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8861 ranges_table[in_use].num = num;
8862 ranges_table_in_use = in_use + 1;
8864 return in_use * 2 * DWARF2_ADDR_SIZE;
8867 /* Add a new entry to .debug_ranges corresponding to a block, or a
8868 range terminator if BLOCK is NULL. */
8871 add_ranges (const_tree block)
8873 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8876 /* Add a new entry to .debug_ranges corresponding to a pair of
8880 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
8883 unsigned int in_use = ranges_by_label_in_use;
8884 unsigned int offset;
8886 if (in_use == ranges_by_label_allocated)
8888 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8889 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8891 ranges_by_label_allocated);
8892 memset (ranges_by_label + ranges_by_label_in_use, 0,
8893 RANGES_TABLE_INCREMENT
8894 * sizeof (struct dw_ranges_by_label_struct));
8897 ranges_by_label[in_use].begin = begin;
8898 ranges_by_label[in_use].end = end;
8899 ranges_by_label_in_use = in_use + 1;
8901 offset = add_ranges_num (-(int)in_use - 1);
8904 add_AT_range_list (die, DW_AT_ranges, offset);
8910 output_ranges (void)
8913 static const char *const start_fmt = "Offset %#x";
8914 const char *fmt = start_fmt;
8916 for (i = 0; i < ranges_table_in_use; i++)
8918 int block_num = ranges_table[i].num;
8922 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8923 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8925 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8926 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8928 /* If all code is in the text section, then the compilation
8929 unit base address defaults to DW_AT_low_pc, which is the
8930 base of the text section. */
8931 if (!have_multiple_function_sections)
8933 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8935 fmt, i * 2 * DWARF2_ADDR_SIZE);
8936 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8937 text_section_label, NULL);
8940 /* Otherwise, the compilation unit base address is zero,
8941 which allows us to use absolute addresses, and not worry
8942 about whether the target supports cross-section
8946 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8947 fmt, i * 2 * DWARF2_ADDR_SIZE);
8948 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8954 /* Negative block_num stands for an index into ranges_by_label. */
8955 else if (block_num < 0)
8957 int lab_idx = - block_num - 1;
8959 if (!have_multiple_function_sections)
8963 /* If we ever use add_ranges_by_labels () for a single
8964 function section, all we have to do is to take out
8966 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8967 ranges_by_label[lab_idx].begin,
8969 fmt, i * 2 * DWARF2_ADDR_SIZE);
8970 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8971 ranges_by_label[lab_idx].end,
8972 text_section_label, NULL);
8977 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8978 ranges_by_label[lab_idx].begin,
8979 fmt, i * 2 * DWARF2_ADDR_SIZE);
8980 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8981 ranges_by_label[lab_idx].end,
8987 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8988 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8994 /* Data structure containing information about input files. */
8997 const char *path; /* Complete file name. */
8998 const char *fname; /* File name part. */
8999 int length; /* Length of entire string. */
9000 struct dwarf_file_data * file_idx; /* Index in input file table. */
9001 int dir_idx; /* Index in directory table. */
9004 /* Data structure containing information about directories with source
9008 const char *path; /* Path including directory name. */
9009 int length; /* Path length. */
9010 int prefix; /* Index of directory entry which is a prefix. */
9011 int count; /* Number of files in this directory. */
9012 int dir_idx; /* Index of directory used as base. */
9015 /* Callback function for file_info comparison. We sort by looking at
9016 the directories in the path. */
9019 file_info_cmp (const void *p1, const void *p2)
9021 const struct file_info *const s1 = (const struct file_info *) p1;
9022 const struct file_info *const s2 = (const struct file_info *) p2;
9023 const unsigned char *cp1;
9024 const unsigned char *cp2;
9026 /* Take care of file names without directories. We need to make sure that
9027 we return consistent values to qsort since some will get confused if
9028 we return the same value when identical operands are passed in opposite
9029 orders. So if neither has a directory, return 0 and otherwise return
9030 1 or -1 depending on which one has the directory. */
9031 if ((s1->path == s1->fname || s2->path == s2->fname))
9032 return (s2->path == s2->fname) - (s1->path == s1->fname);
9034 cp1 = (const unsigned char *) s1->path;
9035 cp2 = (const unsigned char *) s2->path;
9041 /* Reached the end of the first path? If so, handle like above. */
9042 if ((cp1 == (const unsigned char *) s1->fname)
9043 || (cp2 == (const unsigned char *) s2->fname))
9044 return ((cp2 == (const unsigned char *) s2->fname)
9045 - (cp1 == (const unsigned char *) s1->fname));
9047 /* Character of current path component the same? */
9048 else if (*cp1 != *cp2)
9053 struct file_name_acquire_data
9055 struct file_info *files;
9060 /* Traversal function for the hash table. */
9063 file_name_acquire (void ** slot, void *data)
9065 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9066 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9067 struct file_info *fi;
9070 gcc_assert (fnad->max_files >= d->emitted_number);
9072 if (! d->emitted_number)
9075 gcc_assert (fnad->max_files != fnad->used_files);
9077 fi = fnad->files + fnad->used_files++;
9079 /* Skip all leading "./". */
9081 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9084 /* Create a new array entry. */
9086 fi->length = strlen (f);
9089 /* Search for the file name part. */
9090 f = strrchr (f, DIR_SEPARATOR);
9091 #if defined (DIR_SEPARATOR_2)
9093 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9097 if (f == NULL || f < g)
9103 fi->fname = f == NULL ? fi->path : f + 1;
9107 /* Output the directory table and the file name table. We try to minimize
9108 the total amount of memory needed. A heuristic is used to avoid large
9109 slowdowns with many input files. */
9112 output_file_names (void)
9114 struct file_name_acquire_data fnad;
9116 struct file_info *files;
9117 struct dir_info *dirs;
9125 if (!last_emitted_file)
9127 dw2_asm_output_data (1, 0, "End directory table");
9128 dw2_asm_output_data (1, 0, "End file name table");
9132 numfiles = last_emitted_file->emitted_number;
9134 /* Allocate the various arrays we need. */
9135 files = XALLOCAVEC (struct file_info, numfiles);
9136 dirs = XALLOCAVEC (struct dir_info, numfiles);
9139 fnad.used_files = 0;
9140 fnad.max_files = numfiles;
9141 htab_traverse (file_table, file_name_acquire, &fnad);
9142 gcc_assert (fnad.used_files == fnad.max_files);
9144 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9146 /* Find all the different directories used. */
9147 dirs[0].path = files[0].path;
9148 dirs[0].length = files[0].fname - files[0].path;
9149 dirs[0].prefix = -1;
9151 dirs[0].dir_idx = 0;
9152 files[0].dir_idx = 0;
9155 for (i = 1; i < numfiles; i++)
9156 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9157 && memcmp (dirs[ndirs - 1].path, files[i].path,
9158 dirs[ndirs - 1].length) == 0)
9160 /* Same directory as last entry. */
9161 files[i].dir_idx = ndirs - 1;
9162 ++dirs[ndirs - 1].count;
9168 /* This is a new directory. */
9169 dirs[ndirs].path = files[i].path;
9170 dirs[ndirs].length = files[i].fname - files[i].path;
9171 dirs[ndirs].count = 1;
9172 dirs[ndirs].dir_idx = ndirs;
9173 files[i].dir_idx = ndirs;
9175 /* Search for a prefix. */
9176 dirs[ndirs].prefix = -1;
9177 for (j = 0; j < ndirs; j++)
9178 if (dirs[j].length < dirs[ndirs].length
9179 && dirs[j].length > 1
9180 && (dirs[ndirs].prefix == -1
9181 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9182 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9183 dirs[ndirs].prefix = j;
9188 /* Now to the actual work. We have to find a subset of the directories which
9189 allow expressing the file name using references to the directory table
9190 with the least amount of characters. We do not do an exhaustive search
9191 where we would have to check out every combination of every single
9192 possible prefix. Instead we use a heuristic which provides nearly optimal
9193 results in most cases and never is much off. */
9194 saved = XALLOCAVEC (int, ndirs);
9195 savehere = XALLOCAVEC (int, ndirs);
9197 memset (saved, '\0', ndirs * sizeof (saved[0]));
9198 for (i = 0; i < ndirs; i++)
9203 /* We can always save some space for the current directory. But this
9204 does not mean it will be enough to justify adding the directory. */
9205 savehere[i] = dirs[i].length;
9206 total = (savehere[i] - saved[i]) * dirs[i].count;
9208 for (j = i + 1; j < ndirs; j++)
9211 if (saved[j] < dirs[i].length)
9213 /* Determine whether the dirs[i] path is a prefix of the
9218 while (k != -1 && k != (int) i)
9223 /* Yes it is. We can possibly save some memory by
9224 writing the filenames in dirs[j] relative to
9226 savehere[j] = dirs[i].length;
9227 total += (savehere[j] - saved[j]) * dirs[j].count;
9232 /* Check whether we can save enough to justify adding the dirs[i]
9234 if (total > dirs[i].length + 1)
9236 /* It's worthwhile adding. */
9237 for (j = i; j < ndirs; j++)
9238 if (savehere[j] > 0)
9240 /* Remember how much we saved for this directory so far. */
9241 saved[j] = savehere[j];
9243 /* Remember the prefix directory. */
9244 dirs[j].dir_idx = i;
9249 /* Emit the directory name table. */
9250 idx_offset = dirs[0].length > 0 ? 1 : 0;
9251 for (i = 1 - idx_offset; i < ndirs; i++)
9252 dw2_asm_output_nstring (dirs[i].path,
9254 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9255 "Directory Entry: %#x", i + idx_offset);
9257 dw2_asm_output_data (1, 0, "End directory table");
9259 /* We have to emit them in the order of emitted_number since that's
9260 used in the debug info generation. To do this efficiently we
9261 generate a back-mapping of the indices first. */
9262 backmap = XALLOCAVEC (int, numfiles);
9263 for (i = 0; i < numfiles; i++)
9264 backmap[files[i].file_idx->emitted_number - 1] = i;
9266 /* Now write all the file names. */
9267 for (i = 0; i < numfiles; i++)
9269 int file_idx = backmap[i];
9270 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9272 #ifdef VMS_DEBUGGING_INFO
9273 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9275 /* Setting these fields can lead to debugger miscomparisons,
9276 but VMS Debug requires them to be set correctly. */
9281 int maxfilelen = strlen (files[file_idx].path)
9282 + dirs[dir_idx].length
9283 + MAX_VMS_VERSION_LEN + 1;
9284 char *filebuf = XALLOCAVEC (char, maxfilelen);
9286 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9287 snprintf (filebuf, maxfilelen, "%s;%d",
9288 files[file_idx].path + dirs[dir_idx].length, ver);
9290 dw2_asm_output_nstring
9291 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
9293 /* Include directory index. */
9294 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9296 /* Modification time. */
9297 dw2_asm_output_data_uleb128
9298 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9302 /* File length in bytes. */
9303 dw2_asm_output_data_uleb128
9304 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9308 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9309 "File Entry: %#x", (unsigned) i + 1);
9311 /* Include directory index. */
9312 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9314 /* Modification time. */
9315 dw2_asm_output_data_uleb128 (0, NULL);
9317 /* File length in bytes. */
9318 dw2_asm_output_data_uleb128 (0, NULL);
9319 #endif /* VMS_DEBUGGING_INFO */
9322 dw2_asm_output_data (1, 0, "End file name table");
9326 /* Output one line number table into the .debug_line section. */
9329 output_one_line_info_table (dw_line_info_table *table)
9331 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9332 unsigned int current_line = 1;
9333 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
9334 dw_line_info_entry *ent;
9337 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
9339 switch (ent->opcode)
9341 case LI_set_address:
9342 /* ??? Unfortunately, we have little choice here currently, and
9343 must always use the most general form. GCC does not know the
9344 address delta itself, so we can't use DW_LNS_advance_pc. Many
9345 ports do have length attributes which will give an upper bound
9346 on the address range. We could perhaps use length attributes
9347 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9348 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
9350 /* This can handle any delta. This takes
9351 4+DWARF2_ADDR_SIZE bytes. */
9352 dw2_asm_output_data (1, 0, "set address %s", line_label);
9353 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9354 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9355 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9359 if (ent->val == current_line)
9361 /* We still need to start a new row, so output a copy insn. */
9362 dw2_asm_output_data (1, DW_LNS_copy,
9363 "copy line %u", current_line);
9367 int line_offset = ent->val - current_line;
9368 int line_delta = line_offset - DWARF_LINE_BASE;
9370 current_line = ent->val;
9371 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9373 /* This can handle deltas from -10 to 234, using the current
9374 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9375 This takes 1 byte. */
9376 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9377 "line %u", current_line);
9381 /* This can handle any delta. This takes at least 4 bytes,
9382 depending on the value being encoded. */
9383 dw2_asm_output_data (1, DW_LNS_advance_line,
9384 "advance to line %u", current_line);
9385 dw2_asm_output_data_sleb128 (line_offset, NULL);
9386 dw2_asm_output_data (1, DW_LNS_copy, NULL);
9392 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
9393 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9397 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
9398 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9401 case LI_negate_stmt:
9402 current_is_stmt = !current_is_stmt;
9403 dw2_asm_output_data (1, DW_LNS_negate_stmt,
9404 "is_stmt %d", current_is_stmt);
9407 case LI_set_prologue_end:
9408 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
9409 "set prologue end");
9412 case LI_set_epilogue_begin:
9413 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
9414 "set epilogue begin");
9417 case LI_set_discriminator:
9418 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
9419 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
9420 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
9421 dw2_asm_output_data_uleb128 (ent->val, NULL);
9426 /* Emit debug info for the address of the end of the table. */
9427 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
9428 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9429 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9430 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
9432 dw2_asm_output_data (1, 0, "end sequence");
9433 dw2_asm_output_data_uleb128 (1, NULL);
9434 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9437 /* Output the source line number correspondence information. This
9438 information goes into the .debug_line section. */
9441 output_line_info (void)
9443 char l1[20], l2[20], p1[20], p2[20];
9444 int ver = dwarf_version;
9445 bool saw_one = false;
9448 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9449 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9450 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9451 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9453 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9454 dw2_asm_output_data (4, 0xffffffff,
9455 "Initial length escape value indicating 64-bit DWARF extension");
9456 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9457 "Length of Source Line Info");
9458 ASM_OUTPUT_LABEL (asm_out_file, l1);
9460 dw2_asm_output_data (2, ver, "DWARF Version");
9461 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9462 ASM_OUTPUT_LABEL (asm_out_file, p1);
9464 /* Define the architecture-dependent minimum instruction length (in bytes).
9465 In this implementation of DWARF, this field is used for information
9466 purposes only. Since GCC generates assembly language, we have no
9467 a priori knowledge of how many instruction bytes are generated for each
9468 source line, and therefore can use only the DW_LNE_set_address and
9469 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9470 this as '1', which is "correct enough" for all architectures,
9471 and don't let the target override. */
9472 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9475 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
9476 "Maximum Operations Per Instruction");
9477 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9478 "Default is_stmt_start flag");
9479 dw2_asm_output_data (1, DWARF_LINE_BASE,
9480 "Line Base Value (Special Opcodes)");
9481 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9482 "Line Range Value (Special Opcodes)");
9483 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9484 "Special Opcode Base");
9486 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9491 case DW_LNS_advance_pc:
9492 case DW_LNS_advance_line:
9493 case DW_LNS_set_file:
9494 case DW_LNS_set_column:
9495 case DW_LNS_fixed_advance_pc:
9496 case DW_LNS_set_isa:
9504 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
9508 /* Write out the information about the files we use. */
9509 output_file_names ();
9510 ASM_OUTPUT_LABEL (asm_out_file, p2);
9512 if (separate_line_info)
9514 dw_line_info_table *table;
9517 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
9520 output_one_line_info_table (table);
9524 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
9526 output_one_line_info_table (cold_text_section_line_info);
9530 /* ??? Some Darwin linkers crash on a .debug_line section with no
9531 sequences. Further, merely a DW_LNE_end_sequence entry is not
9532 sufficient -- the address column must also be initialized.
9533 Make sure to output at least one set_address/end_sequence pair,
9534 choosing .text since that section is always present. */
9535 if (text_section_line_info->in_use || !saw_one)
9536 output_one_line_info_table (text_section_line_info);
9538 /* Output the marker for the end of the line number info. */
9539 ASM_OUTPUT_LABEL (asm_out_file, l2);
9542 /* Given a pointer to a tree node for some base type, return a pointer to
9543 a DIE that describes the given type.
9545 This routine must only be called for GCC type nodes that correspond to
9546 Dwarf base (fundamental) types. */
9549 base_type_die (tree type)
9551 dw_die_ref base_type_result;
9552 enum dwarf_type encoding;
9554 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9557 /* If this is a subtype that should not be emitted as a subrange type,
9558 use the base type. See subrange_type_for_debug_p. */
9559 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
9560 type = TREE_TYPE (type);
9562 switch (TREE_CODE (type))
9565 if ((dwarf_version >= 4 || !dwarf_strict)
9567 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9568 && DECL_IS_BUILTIN (TYPE_NAME (type))
9569 && DECL_NAME (TYPE_NAME (type)))
9571 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
9572 if (strcmp (name, "char16_t") == 0
9573 || strcmp (name, "char32_t") == 0)
9575 encoding = DW_ATE_UTF;
9579 if (TYPE_STRING_FLAG (type))
9581 if (TYPE_UNSIGNED (type))
9582 encoding = DW_ATE_unsigned_char;
9584 encoding = DW_ATE_signed_char;
9586 else if (TYPE_UNSIGNED (type))
9587 encoding = DW_ATE_unsigned;
9589 encoding = DW_ATE_signed;
9593 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9595 if (dwarf_version >= 3 || !dwarf_strict)
9596 encoding = DW_ATE_decimal_float;
9598 encoding = DW_ATE_lo_user;
9601 encoding = DW_ATE_float;
9604 case FIXED_POINT_TYPE:
9605 if (!(dwarf_version >= 3 || !dwarf_strict))
9606 encoding = DW_ATE_lo_user;
9607 else if (TYPE_UNSIGNED (type))
9608 encoding = DW_ATE_unsigned_fixed;
9610 encoding = DW_ATE_signed_fixed;
9613 /* Dwarf2 doesn't know anything about complex ints, so use
9614 a user defined type for it. */
9616 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9617 encoding = DW_ATE_complex_float;
9619 encoding = DW_ATE_lo_user;
9623 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9624 encoding = DW_ATE_boolean;
9628 /* No other TREE_CODEs are Dwarf fundamental types. */
9632 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
9634 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9635 int_size_in_bytes (type));
9636 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9638 return base_type_result;
9641 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9642 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9645 is_base_type (tree type)
9647 switch (TREE_CODE (type))
9653 case FIXED_POINT_TYPE:
9661 case QUAL_UNION_TYPE:
9666 case REFERENCE_TYPE:
9680 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9681 node, return the size in bits for the type if it is a constant, or else
9682 return the alignment for the type if the type's size is not constant, or
9683 else return BITS_PER_WORD if the type actually turns out to be an
9686 static inline unsigned HOST_WIDE_INT
9687 simple_type_size_in_bits (const_tree type)
9689 if (TREE_CODE (type) == ERROR_MARK)
9690 return BITS_PER_WORD;
9691 else if (TYPE_SIZE (type) == NULL_TREE)
9693 else if (host_integerp (TYPE_SIZE (type), 1))
9694 return tree_low_cst (TYPE_SIZE (type), 1);
9696 return TYPE_ALIGN (type);
9699 /* Similarly, but return a double_int instead of UHWI. */
9701 static inline double_int
9702 double_int_type_size_in_bits (const_tree type)
9704 if (TREE_CODE (type) == ERROR_MARK)
9705 return uhwi_to_double_int (BITS_PER_WORD);
9706 else if (TYPE_SIZE (type) == NULL_TREE)
9707 return double_int_zero;
9708 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
9709 return tree_to_double_int (TYPE_SIZE (type));
9711 return uhwi_to_double_int (TYPE_ALIGN (type));
9714 /* Given a pointer to a tree node for a subrange type, return a pointer
9715 to a DIE that describes the given type. */
9718 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
9720 dw_die_ref subrange_die;
9721 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9723 if (context_die == NULL)
9724 context_die = comp_unit_die ();
9726 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9728 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9730 /* The size of the subrange type and its base type do not match,
9731 so we need to generate a size attribute for the subrange type. */
9732 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9736 add_bound_info (subrange_die, DW_AT_lower_bound, low);
9738 add_bound_info (subrange_die, DW_AT_upper_bound, high);
9740 return subrange_die;
9743 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9744 entry that chains various modifiers in front of the given type. */
9747 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9748 dw_die_ref context_die)
9750 enum tree_code code = TREE_CODE (type);
9751 dw_die_ref mod_type_die;
9752 dw_die_ref sub_die = NULL;
9753 tree item_type = NULL;
9754 tree qualified_type;
9755 tree name, low, high;
9757 if (code == ERROR_MARK)
9760 /* See if we already have the appropriately qualified variant of
9763 = get_qualified_type (type,
9764 ((is_const_type ? TYPE_QUAL_CONST : 0)
9765 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9767 if (qualified_type == sizetype
9768 && TYPE_NAME (qualified_type)
9769 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
9771 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
9773 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
9774 && TYPE_PRECISION (t)
9775 == TYPE_PRECISION (qualified_type)
9776 && TYPE_UNSIGNED (t)
9777 == TYPE_UNSIGNED (qualified_type));
9781 /* If we do, then we can just use its DIE, if it exists. */
9784 mod_type_die = lookup_type_die (qualified_type);
9786 return mod_type_die;
9789 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9791 /* Handle C typedef types. */
9792 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
9793 && !DECL_ARTIFICIAL (name))
9795 tree dtype = TREE_TYPE (name);
9797 if (qualified_type == dtype)
9799 /* For a named type, use the typedef. */
9800 gen_type_die (qualified_type, context_die);
9801 return lookup_type_die (qualified_type);
9803 else if (is_const_type < TYPE_READONLY (dtype)
9804 || is_volatile_type < TYPE_VOLATILE (dtype)
9805 || (is_const_type <= TYPE_READONLY (dtype)
9806 && is_volatile_type <= TYPE_VOLATILE (dtype)
9807 && DECL_ORIGINAL_TYPE (name) != type))
9808 /* cv-unqualified version of named type. Just use the unnamed
9809 type to which it refers. */
9810 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9811 is_const_type, is_volatile_type,
9813 /* Else cv-qualified version of named type; fall through. */
9817 /* If both is_const_type and is_volatile_type, prefer the path
9818 which leads to a qualified type. */
9819 && (!is_volatile_type
9820 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
9821 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
9823 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
9824 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9826 else if (is_volatile_type)
9828 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
9829 sub_die = modified_type_die (type, is_const_type, 0, context_die);
9831 else if (code == POINTER_TYPE)
9833 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
9834 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9835 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9836 item_type = TREE_TYPE (type);
9837 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
9838 add_AT_unsigned (mod_type_die, DW_AT_address_class,
9839 TYPE_ADDR_SPACE (item_type));
9841 else if (code == REFERENCE_TYPE)
9843 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
9844 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
9847 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
9848 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9849 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9850 item_type = TREE_TYPE (type);
9851 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
9852 add_AT_unsigned (mod_type_die, DW_AT_address_class,
9853 TYPE_ADDR_SPACE (item_type));
9855 else if (code == INTEGER_TYPE
9856 && TREE_TYPE (type) != NULL_TREE
9857 && subrange_type_for_debug_p (type, &low, &high))
9859 mod_type_die = subrange_type_die (type, low, high, context_die);
9860 item_type = TREE_TYPE (type);
9862 else if (is_base_type (type))
9863 mod_type_die = base_type_die (type);
9866 gen_type_die (type, context_die);
9868 /* We have to get the type_main_variant here (and pass that to the
9869 `lookup_type_die' routine) because the ..._TYPE node we have
9870 might simply be a *copy* of some original type node (where the
9871 copy was created to help us keep track of typedef names) and
9872 that copy might have a different TYPE_UID from the original
9874 if (TREE_CODE (type) != VECTOR_TYPE)
9875 return lookup_type_die (type_main_variant (type));
9877 /* Vectors have the debugging information in the type,
9878 not the main variant. */
9879 return lookup_type_die (type);
9882 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9883 don't output a DW_TAG_typedef, since there isn't one in the
9884 user's program; just attach a DW_AT_name to the type.
9885 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
9886 if the base type already has the same name. */
9888 && ((TREE_CODE (name) != TYPE_DECL
9889 && (qualified_type == TYPE_MAIN_VARIANT (type)
9890 || (!is_const_type && !is_volatile_type)))
9891 || (TREE_CODE (name) == TYPE_DECL
9892 && TREE_TYPE (name) == qualified_type
9893 && DECL_NAME (name))))
9895 if (TREE_CODE (name) == TYPE_DECL)
9896 /* Could just call add_name_and_src_coords_attributes here,
9897 but since this is a builtin type it doesn't have any
9898 useful source coordinates anyway. */
9899 name = DECL_NAME (name);
9900 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9901 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
9902 if (TYPE_ARTIFICIAL (type))
9903 add_AT_flag (mod_type_die, DW_AT_artificial, 1);
9905 /* This probably indicates a bug. */
9906 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
9908 name = TYPE_NAME (type);
9910 && TREE_CODE (name) == TYPE_DECL)
9911 name = DECL_NAME (name);
9912 add_name_attribute (mod_type_die,
9913 name ? IDENTIFIER_POINTER (name) : "__unknown__");
9917 equate_type_number_to_die (qualified_type, mod_type_die);
9920 /* We must do this after the equate_type_number_to_die call, in case
9921 this is a recursive type. This ensures that the modified_type_die
9922 recursion will terminate even if the type is recursive. Recursive
9923 types are possible in Ada. */
9924 sub_die = modified_type_die (item_type,
9925 TYPE_READONLY (item_type),
9926 TYPE_VOLATILE (item_type),
9929 if (sub_die != NULL)
9930 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9932 return mod_type_die;
9935 /* Generate DIEs for the generic parameters of T.
9936 T must be either a generic type or a generic function.
9937 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
9940 gen_generic_params_dies (tree t)
9944 dw_die_ref die = NULL;
9946 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
9950 die = lookup_type_die (t);
9951 else if (DECL_P (t))
9952 die = lookup_decl_die (t);
9956 parms = lang_hooks.get_innermost_generic_parms (t);
9958 /* T has no generic parameter. It means T is neither a generic type
9959 or function. End of story. */
9962 parms_num = TREE_VEC_LENGTH (parms);
9963 args = lang_hooks.get_innermost_generic_args (t);
9964 for (i = 0; i < parms_num; i++)
9966 tree parm, arg, arg_pack_elems;
9968 parm = TREE_VEC_ELT (parms, i);
9969 arg = TREE_VEC_ELT (args, i);
9970 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
9971 gcc_assert (parm && TREE_VALUE (parm) && arg);
9973 if (parm && TREE_VALUE (parm) && arg)
9975 /* If PARM represents a template parameter pack,
9976 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
9977 by DW_TAG_template_*_parameter DIEs for the argument
9978 pack elements of ARG. Note that ARG would then be
9979 an argument pack. */
9981 template_parameter_pack_die (TREE_VALUE (parm),
9985 generic_parameter_die (TREE_VALUE (parm), arg,
9986 true /* Emit DW_AT_name */, die);
9991 /* Create and return a DIE for PARM which should be
9992 the representation of a generic type parameter.
9993 For instance, in the C++ front end, PARM would be a template parameter.
9994 ARG is the argument to PARM.
9995 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
9997 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10001 generic_parameter_die (tree parm, tree arg,
10003 dw_die_ref parent_die)
10005 dw_die_ref tmpl_die = NULL;
10006 const char *name = NULL;
10008 if (!parm || !DECL_NAME (parm) || !arg)
10011 /* We support non-type generic parameters and arguments,
10012 type generic parameters and arguments, as well as
10013 generic generic parameters (a.k.a. template template parameters in C++)
10015 if (TREE_CODE (parm) == PARM_DECL)
10016 /* PARM is a nontype generic parameter */
10017 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
10018 else if (TREE_CODE (parm) == TYPE_DECL)
10019 /* PARM is a type generic parameter. */
10020 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
10021 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10022 /* PARM is a generic generic parameter.
10023 Its DIE is a GNU extension. It shall have a
10024 DW_AT_name attribute to represent the name of the template template
10025 parameter, and a DW_AT_GNU_template_name attribute to represent the
10026 name of the template template argument. */
10027 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
10030 gcc_unreachable ();
10036 /* If PARM is a generic parameter pack, it means we are
10037 emitting debug info for a template argument pack element.
10038 In other terms, ARG is a template argument pack element.
10039 In that case, we don't emit any DW_AT_name attribute for
10043 name = IDENTIFIER_POINTER (DECL_NAME (parm));
10045 add_AT_string (tmpl_die, DW_AT_name, name);
10048 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10050 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10051 TMPL_DIE should have a child DW_AT_type attribute that is set
10052 to the type of the argument to PARM, which is ARG.
10053 If PARM is a type generic parameter, TMPL_DIE should have a
10054 child DW_AT_type that is set to ARG. */
10055 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
10056 add_type_attribute (tmpl_die, tmpl_type, 0,
10057 TREE_THIS_VOLATILE (tmpl_type),
10062 /* So TMPL_DIE is a DIE representing a
10063 a generic generic template parameter, a.k.a template template
10064 parameter in C++ and arg is a template. */
10066 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10067 to the name of the argument. */
10068 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
10070 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
10073 if (TREE_CODE (parm) == PARM_DECL)
10074 /* So PARM is a non-type generic parameter.
10075 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10076 attribute of TMPL_DIE which value represents the value
10078 We must be careful here:
10079 The value of ARG might reference some function decls.
10080 We might currently be emitting debug info for a generic
10081 type and types are emitted before function decls, we don't
10082 know if the function decls referenced by ARG will actually be
10083 emitted after cgraph computations.
10084 So must defer the generation of the DW_AT_const_value to
10085 after cgraph is ready. */
10086 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
10092 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10093 PARM_PACK must be a template parameter pack. The returned DIE
10094 will be child DIE of PARENT_DIE. */
10097 template_parameter_pack_die (tree parm_pack,
10098 tree parm_pack_args,
10099 dw_die_ref parent_die)
10104 gcc_assert (parent_die && parm_pack);
10106 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
10107 add_name_and_src_coords_attributes (die, parm_pack);
10108 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
10109 generic_parameter_die (parm_pack,
10110 TREE_VEC_ELT (parm_pack_args, j),
10111 false /* Don't emit DW_AT_name */,
10116 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10117 an enumerated type. */
10120 type_is_enum (const_tree type)
10122 return TREE_CODE (type) == ENUMERAL_TYPE;
10125 /* Return the DBX register number described by a given RTL node. */
10127 static unsigned int
10128 dbx_reg_number (const_rtx rtl)
10130 unsigned regno = REGNO (rtl);
10132 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10134 #ifdef LEAF_REG_REMAP
10135 if (current_function_uses_only_leaf_regs)
10137 int leaf_reg = LEAF_REG_REMAP (regno);
10138 if (leaf_reg != -1)
10139 regno = (unsigned) leaf_reg;
10143 return DBX_REGISTER_NUMBER (regno);
10146 /* Optionally add a DW_OP_piece term to a location description expression.
10147 DW_OP_piece is only added if the location description expression already
10148 doesn't end with DW_OP_piece. */
10151 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10153 dw_loc_descr_ref loc;
10155 if (*list_head != NULL)
10157 /* Find the end of the chain. */
10158 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10161 if (loc->dw_loc_opc != DW_OP_piece)
10162 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10166 /* Return a location descriptor that designates a machine register or
10167 zero if there is none. */
10169 static dw_loc_descr_ref
10170 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10174 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10177 /* We only use "frame base" when we're sure we're talking about the
10178 post-prologue local stack frame. We do this by *not* running
10179 register elimination until this point, and recognizing the special
10180 argument pointer and soft frame pointer rtx's.
10181 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10182 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
10183 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
10185 dw_loc_descr_ref result = NULL;
10187 if (dwarf_version >= 4 || !dwarf_strict)
10189 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
10192 add_loc_descr (&result,
10193 new_loc_descr (DW_OP_stack_value, 0, 0));
10198 regs = targetm.dwarf_register_span (rtl);
10200 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10201 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10203 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10206 /* Return a location descriptor that designates a machine register for
10207 a given hard register number. */
10209 static dw_loc_descr_ref
10210 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10212 dw_loc_descr_ref reg_loc_descr;
10216 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10218 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10220 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10221 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10223 return reg_loc_descr;
10226 /* Given an RTL of a register, return a location descriptor that
10227 designates a value that spans more than one register. */
10229 static dw_loc_descr_ref
10230 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10231 enum var_init_status initialized)
10233 int nregs, size, i;
10235 dw_loc_descr_ref loc_result = NULL;
10238 #ifdef LEAF_REG_REMAP
10239 if (current_function_uses_only_leaf_regs)
10241 int leaf_reg = LEAF_REG_REMAP (reg);
10242 if (leaf_reg != -1)
10243 reg = (unsigned) leaf_reg;
10246 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10247 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10249 /* Simple, contiguous registers. */
10250 if (regs == NULL_RTX)
10252 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10257 dw_loc_descr_ref t;
10259 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10260 VAR_INIT_STATUS_INITIALIZED);
10261 add_loc_descr (&loc_result, t);
10262 add_loc_descr_op_piece (&loc_result, size);
10268 /* Now onto stupid register sets in non contiguous locations. */
10270 gcc_assert (GET_CODE (regs) == PARALLEL);
10272 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10275 for (i = 0; i < XVECLEN (regs, 0); ++i)
10277 dw_loc_descr_ref t;
10279 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10280 VAR_INIT_STATUS_INITIALIZED);
10281 add_loc_descr (&loc_result, t);
10282 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10283 add_loc_descr_op_piece (&loc_result, size);
10286 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10287 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10291 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
10293 /* Return a location descriptor that designates a constant i,
10294 as a compound operation from constant (i >> shift), constant shift
10297 static dw_loc_descr_ref
10298 int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
10300 dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
10301 add_loc_descr (&ret, int_loc_descriptor (shift));
10302 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
10306 /* Return a location descriptor that designates a constant. */
10308 static dw_loc_descr_ref
10309 int_loc_descriptor (HOST_WIDE_INT i)
10311 enum dwarf_location_atom op;
10313 /* Pick the smallest representation of a constant, rather than just
10314 defaulting to the LEB encoding. */
10317 int clz = clz_hwi (i);
10318 int ctz = ctz_hwi (i);
10320 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10321 else if (i <= 0xff)
10322 op = DW_OP_const1u;
10323 else if (i <= 0xffff)
10324 op = DW_OP_const2u;
10325 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
10326 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
10327 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10328 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10329 while DW_OP_const4u is 5 bytes. */
10330 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
10331 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10332 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
10333 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10334 while DW_OP_const4u is 5 bytes. */
10335 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
10336 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
10337 op = DW_OP_const4u;
10338 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10339 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
10340 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10341 while DW_OP_constu of constant >= 0x100000000 takes at least
10343 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
10344 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
10345 && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
10346 >= HOST_BITS_PER_WIDE_INT)
10347 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10348 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10349 while DW_OP_constu takes in this case at least 6 bytes. */
10350 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
10351 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
10352 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
10353 && size_of_uleb128 (i) > 6)
10354 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10355 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
10362 op = DW_OP_const1s;
10363 else if (i >= -0x8000)
10364 op = DW_OP_const2s;
10365 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
10367 if (size_of_int_loc_descriptor (i) < 5)
10369 dw_loc_descr_ref ret = int_loc_descriptor (-i);
10370 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
10373 op = DW_OP_const4s;
10377 if (size_of_int_loc_descriptor (i)
10378 < (unsigned long) 1 + size_of_sleb128 (i))
10380 dw_loc_descr_ref ret = int_loc_descriptor (-i);
10381 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
10388 return new_loc_descr (op, i, 0);
10391 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10392 without actually allocating it. */
10394 static unsigned long
10395 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
10397 return size_of_int_loc_descriptor (i >> shift)
10398 + size_of_int_loc_descriptor (shift)
10402 /* Return size_of_locs (int_loc_descriptor (i)) without
10403 actually allocating it. */
10405 static unsigned long
10406 size_of_int_loc_descriptor (HOST_WIDE_INT i)
10415 else if (i <= 0xff)
10417 else if (i <= 0xffff)
10421 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
10422 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
10423 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10425 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10426 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
10427 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10429 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
10431 s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
10432 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10433 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
10434 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10436 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
10437 && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
10438 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10440 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
10441 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
10443 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10452 else if (i >= -0x8000)
10454 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
10456 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
10458 s = size_of_int_loc_descriptor (-i) + 1;
10466 unsigned long r = 1 + size_of_sleb128 (i);
10467 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
10469 s = size_of_int_loc_descriptor (-i) + 1;
10478 /* Return loc description representing "address" of integer value.
10479 This can appear only as toplevel expression. */
10481 static dw_loc_descr_ref
10482 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
10485 dw_loc_descr_ref loc_result = NULL;
10487 if (!(dwarf_version >= 4 || !dwarf_strict))
10490 litsize = size_of_int_loc_descriptor (i);
10491 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10492 is more compact. For DW_OP_stack_value we need:
10493 litsize + 1 (DW_OP_stack_value)
10494 and for DW_OP_implicit_value:
10495 1 (DW_OP_implicit_value) + 1 (length) + size. */
10496 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
10498 loc_result = int_loc_descriptor (i);
10499 add_loc_descr (&loc_result,
10500 new_loc_descr (DW_OP_stack_value, 0, 0));
10504 loc_result = new_loc_descr (DW_OP_implicit_value,
10506 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
10507 loc_result->dw_loc_oprnd2.v.val_int = i;
10511 /* Return a location descriptor that designates a base+offset location. */
10513 static dw_loc_descr_ref
10514 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10515 enum var_init_status initialized)
10517 unsigned int regno;
10518 dw_loc_descr_ref result;
10519 dw_fde_ref fde = cfun->fde;
10521 /* We only use "frame base" when we're sure we're talking about the
10522 post-prologue local stack frame. We do this by *not* running
10523 register elimination until this point, and recognizing the special
10524 argument pointer and soft frame pointer rtx's. */
10525 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10527 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10531 if (GET_CODE (elim) == PLUS)
10533 offset += INTVAL (XEXP (elim, 1));
10534 elim = XEXP (elim, 0);
10536 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10537 && (elim == hard_frame_pointer_rtx
10538 || elim == stack_pointer_rtx))
10539 || elim == (frame_pointer_needed
10540 ? hard_frame_pointer_rtx
10541 : stack_pointer_rtx));
10543 /* If drap register is used to align stack, use frame
10544 pointer + offset to access stack variables. If stack
10545 is aligned without drap, use stack pointer + offset to
10546 access stack variables. */
10547 if (crtl->stack_realign_tried
10548 && reg == frame_pointer_rtx)
10551 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10552 ? HARD_FRAME_POINTER_REGNUM
10554 return new_reg_loc_descr (base_reg, offset);
10557 gcc_assert (frame_pointer_fb_offset_valid);
10558 offset += frame_pointer_fb_offset;
10559 return new_loc_descr (DW_OP_fbreg, offset, 0);
10563 regno = DWARF_FRAME_REGNUM (REGNO (reg));
10565 if (!optimize && fde
10566 && (fde->drap_reg == regno || fde->vdrap_reg == regno))
10568 /* Use cfa+offset to represent the location of arguments passed
10569 on the stack when drap is used to align stack.
10570 Only do this when not optimizing, for optimized code var-tracking
10571 is supposed to track where the arguments live and the register
10572 used as vdrap or drap in some spot might be used for something
10573 else in other part of the routine. */
10574 return new_loc_descr (DW_OP_fbreg, offset, 0);
10578 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10581 result = new_loc_descr (DW_OP_bregx, regno, offset);
10583 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10584 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10589 /* Return true if this RTL expression describes a base+offset calculation. */
10592 is_based_loc (const_rtx rtl)
10594 return (GET_CODE (rtl) == PLUS
10595 && ((REG_P (XEXP (rtl, 0))
10596 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10597 && CONST_INT_P (XEXP (rtl, 1)))));
10600 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10603 static dw_loc_descr_ref
10604 tls_mem_loc_descriptor (rtx mem)
10607 dw_loc_descr_ref loc_result;
10609 if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
10612 base = get_base_address (MEM_EXPR (mem));
10614 || TREE_CODE (base) != VAR_DECL
10615 || !DECL_THREAD_LOCAL_P (base))
10618 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
10619 if (loc_result == NULL)
10622 if (MEM_OFFSET (mem))
10623 loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
10628 /* Output debug info about reason why we failed to expand expression as dwarf
10632 expansion_failed (tree expr, rtx rtl, char const *reason)
10634 if (dump_file && (dump_flags & TDF_DETAILS))
10636 fprintf (dump_file, "Failed to expand as dwarf: ");
10638 print_generic_expr (dump_file, expr, dump_flags);
10641 fprintf (dump_file, "\n");
10642 print_rtl (dump_file, rtl);
10644 fprintf (dump_file, "\nReason: %s\n", reason);
10648 /* Helper function for const_ok_for_output, called either directly
10649 or via for_each_rtx. */
10652 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
10656 if (GET_CODE (rtl) == UNSPEC)
10658 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10659 we can't express it in the debug info. */
10660 #ifdef ENABLE_CHECKING
10661 /* Don't complain about TLS UNSPECs, those are just too hard to
10663 if (XVECLEN (rtl, 0) != 1
10664 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
10665 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
10666 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
10667 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
10668 inform (current_function_decl
10669 ? DECL_SOURCE_LOCATION (current_function_decl)
10670 : UNKNOWN_LOCATION,
10671 #if NUM_UNSPEC_VALUES > 0
10672 "non-delegitimized UNSPEC %s (%d) found in variable location",
10673 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
10674 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
10677 "non-delegitimized UNSPEC %d found in variable location",
10681 expansion_failed (NULL_TREE, rtl,
10682 "UNSPEC hasn't been delegitimized.\n");
10686 if (GET_CODE (rtl) != SYMBOL_REF)
10689 if (CONSTANT_POOL_ADDRESS_P (rtl))
10692 get_pool_constant_mark (rtl, &marked);
10693 /* If all references to this pool constant were optimized away,
10694 it was not output and thus we can't represent it. */
10697 expansion_failed (NULL_TREE, rtl,
10698 "Constant was removed from constant pool.\n");
10703 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
10706 /* Avoid references to external symbols in debug info, on several targets
10707 the linker might even refuse to link when linking a shared library,
10708 and in many other cases the relocations for .debug_info/.debug_loc are
10709 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
10710 to be defined within the same shared library or executable are fine. */
10711 if (SYMBOL_REF_EXTERNAL_P (rtl))
10713 tree decl = SYMBOL_REF_DECL (rtl);
10715 if (decl == NULL || !targetm.binds_local_p (decl))
10717 expansion_failed (NULL_TREE, rtl,
10718 "Symbol not defined in current TU.\n");
10726 /* Return true if constant RTL can be emitted in DW_OP_addr or
10727 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
10728 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
10731 const_ok_for_output (rtx rtl)
10733 if (GET_CODE (rtl) == SYMBOL_REF)
10734 return const_ok_for_output_1 (&rtl, NULL) == 0;
10736 if (GET_CODE (rtl) == CONST)
10737 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
10742 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
10743 if possible, NULL otherwise. */
10746 base_type_for_mode (enum machine_mode mode, bool unsignedp)
10748 dw_die_ref type_die;
10749 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
10753 switch (TREE_CODE (type))
10761 type_die = lookup_type_die (type);
10763 type_die = modified_type_die (type, false, false, comp_unit_die ());
10764 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
10769 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
10770 type matching MODE, or, if MODE is narrower than or as wide as
10771 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
10774 static dw_loc_descr_ref
10775 convert_descriptor_to_mode (enum machine_mode mode, dw_loc_descr_ref op)
10777 enum machine_mode outer_mode = mode;
10778 dw_die_ref type_die;
10779 dw_loc_descr_ref cvt;
10781 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
10783 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
10786 type_die = base_type_for_mode (outer_mode, 1);
10787 if (type_die == NULL)
10789 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10790 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10791 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10792 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10793 add_loc_descr (&op, cvt);
10797 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
10799 static dw_loc_descr_ref
10800 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
10801 dw_loc_descr_ref op1)
10803 dw_loc_descr_ref ret = op0;
10804 add_loc_descr (&ret, op1);
10805 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10806 if (STORE_FLAG_VALUE != 1)
10808 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
10809 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
10814 /* Return location descriptor for signed comparison OP RTL. */
10816 static dw_loc_descr_ref
10817 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
10818 enum machine_mode mem_mode)
10820 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
10821 dw_loc_descr_ref op0, op1;
10824 if (op_mode == VOIDmode)
10825 op_mode = GET_MODE (XEXP (rtl, 1));
10826 if (op_mode == VOIDmode)
10830 && (GET_MODE_CLASS (op_mode) != MODE_INT
10831 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
10834 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
10835 VAR_INIT_STATUS_INITIALIZED);
10836 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
10837 VAR_INIT_STATUS_INITIALIZED);
10839 if (op0 == NULL || op1 == NULL)
10842 if (GET_MODE_CLASS (op_mode) != MODE_INT
10843 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
10844 return compare_loc_descriptor (op, op0, op1);
10846 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
10848 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
10849 dw_loc_descr_ref cvt;
10851 if (type_die == NULL)
10853 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10854 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10855 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10856 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10857 add_loc_descr (&op0, cvt);
10858 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10859 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10860 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10861 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10862 add_loc_descr (&op1, cvt);
10863 return compare_loc_descriptor (op, op0, op1);
10866 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
10867 /* For eq/ne, if the operands are known to be zero-extended,
10868 there is no need to do the fancy shifting up. */
10869 if (op == DW_OP_eq || op == DW_OP_ne)
10871 dw_loc_descr_ref last0, last1;
10872 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
10874 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
10876 /* deref_size zero extends, and for constants we can check
10877 whether they are zero extended or not. */
10878 if (((last0->dw_loc_opc == DW_OP_deref_size
10879 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
10880 || (CONST_INT_P (XEXP (rtl, 0))
10881 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
10882 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
10883 && ((last1->dw_loc_opc == DW_OP_deref_size
10884 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
10885 || (CONST_INT_P (XEXP (rtl, 1))
10886 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
10887 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
10888 return compare_loc_descriptor (op, op0, op1);
10890 /* EQ/NE comparison against constant in narrower type than
10891 DWARF2_ADDR_SIZE can be performed either as
10892 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
10895 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
10896 DW_OP_{eq,ne}. Pick whatever is shorter. */
10897 if (CONST_INT_P (XEXP (rtl, 1))
10898 && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
10899 && (size_of_int_loc_descriptor (shift) + 1
10900 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift)
10901 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
10902 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
10903 & GET_MODE_MASK (op_mode))))
10905 add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
10906 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10907 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
10908 & GET_MODE_MASK (op_mode));
10909 return compare_loc_descriptor (op, op0, op1);
10912 add_loc_descr (&op0, int_loc_descriptor (shift));
10913 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
10914 if (CONST_INT_P (XEXP (rtl, 1)))
10915 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
10918 add_loc_descr (&op1, int_loc_descriptor (shift));
10919 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
10921 return compare_loc_descriptor (op, op0, op1);
10924 /* Return location descriptor for unsigned comparison OP RTL. */
10926 static dw_loc_descr_ref
10927 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
10928 enum machine_mode mem_mode)
10930 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
10931 dw_loc_descr_ref op0, op1;
10933 if (op_mode == VOIDmode)
10934 op_mode = GET_MODE (XEXP (rtl, 1));
10935 if (op_mode == VOIDmode)
10937 if (GET_MODE_CLASS (op_mode) != MODE_INT)
10940 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
10943 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
10944 VAR_INIT_STATUS_INITIALIZED);
10945 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
10946 VAR_INIT_STATUS_INITIALIZED);
10948 if (op0 == NULL || op1 == NULL)
10951 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
10953 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
10954 dw_loc_descr_ref last0, last1;
10955 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
10957 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
10959 if (CONST_INT_P (XEXP (rtl, 0)))
10960 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
10961 /* deref_size zero extends, so no need to mask it again. */
10962 else if (last0->dw_loc_opc != DW_OP_deref_size
10963 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
10965 add_loc_descr (&op0, int_loc_descriptor (mask));
10966 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10968 if (CONST_INT_P (XEXP (rtl, 1)))
10969 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
10970 /* deref_size zero extends, so no need to mask it again. */
10971 else if (last1->dw_loc_opc != DW_OP_deref_size
10972 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
10974 add_loc_descr (&op1, int_loc_descriptor (mask));
10975 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
10978 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
10980 HOST_WIDE_INT bias = 1;
10981 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
10982 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
10983 if (CONST_INT_P (XEXP (rtl, 1)))
10984 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
10985 + INTVAL (XEXP (rtl, 1)));
10987 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
10990 return compare_loc_descriptor (op, op0, op1);
10993 /* Return location descriptor for {U,S}{MIN,MAX}. */
10995 static dw_loc_descr_ref
10996 minmax_loc_descriptor (rtx rtl, enum machine_mode mode,
10997 enum machine_mode mem_mode)
10999 enum dwarf_location_atom op;
11000 dw_loc_descr_ref op0, op1, ret;
11001 dw_loc_descr_ref bra_node, drop_node;
11004 && (GET_MODE_CLASS (mode) != MODE_INT
11005 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
11008 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11009 VAR_INIT_STATUS_INITIALIZED);
11010 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11011 VAR_INIT_STATUS_INITIALIZED);
11013 if (op0 == NULL || op1 == NULL)
11016 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
11017 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
11018 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
11019 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
11021 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11023 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
11024 add_loc_descr (&op0, int_loc_descriptor (mask));
11025 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11026 add_loc_descr (&op1, int_loc_descriptor (mask));
11027 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11029 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
11031 HOST_WIDE_INT bias = 1;
11032 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11033 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11034 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11037 else if (GET_MODE_CLASS (mode) == MODE_INT
11038 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11040 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
11041 add_loc_descr (&op0, int_loc_descriptor (shift));
11042 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11043 add_loc_descr (&op1, int_loc_descriptor (shift));
11044 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11046 else if (GET_MODE_CLASS (mode) == MODE_INT
11047 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11049 dw_die_ref type_die = base_type_for_mode (mode, 0);
11050 dw_loc_descr_ref cvt;
11051 if (type_die == NULL)
11053 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11054 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11055 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11056 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11057 add_loc_descr (&op0, cvt);
11058 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11059 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11060 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11061 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11062 add_loc_descr (&op1, cvt);
11065 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
11070 add_loc_descr (&ret, op1);
11071 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11072 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11073 add_loc_descr (&ret, bra_node);
11074 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11075 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
11076 add_loc_descr (&ret, drop_node);
11077 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11078 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
11079 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
11080 && GET_MODE_CLASS (mode) == MODE_INT
11081 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11082 ret = convert_descriptor_to_mode (mode, ret);
11086 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11087 but after converting arguments to type_die, afterwards
11088 convert back to unsigned. */
11090 static dw_loc_descr_ref
11091 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
11092 enum machine_mode mode, enum machine_mode mem_mode)
11094 dw_loc_descr_ref cvt, op0, op1;
11096 if (type_die == NULL)
11098 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11099 VAR_INIT_STATUS_INITIALIZED);
11100 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11101 VAR_INIT_STATUS_INITIALIZED);
11102 if (op0 == NULL || op1 == NULL)
11104 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11105 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11106 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11107 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11108 add_loc_descr (&op0, cvt);
11109 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11110 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11111 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11112 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11113 add_loc_descr (&op1, cvt);
11114 add_loc_descr (&op0, op1);
11115 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
11116 return convert_descriptor_to_mode (mode, op0);
11119 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11120 const0 is DW_OP_lit0 or corresponding typed constant,
11121 const1 is DW_OP_lit1 or corresponding typed constant
11122 and constMSB is constant with just the MSB bit set
11124 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11125 L1: const0 DW_OP_swap
11126 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11127 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11132 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11133 L1: const0 DW_OP_swap
11134 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11135 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11140 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11141 L1: const1 DW_OP_swap
11142 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11143 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11147 static dw_loc_descr_ref
11148 clz_loc_descriptor (rtx rtl, enum machine_mode mode,
11149 enum machine_mode mem_mode)
11151 dw_loc_descr_ref op0, ret, tmp;
11152 HOST_WIDE_INT valv;
11153 dw_loc_descr_ref l1jump, l1label;
11154 dw_loc_descr_ref l2jump, l2label;
11155 dw_loc_descr_ref l3jump, l3label;
11156 dw_loc_descr_ref l4jump, l4label;
11159 if (GET_MODE_CLASS (mode) != MODE_INT
11160 || GET_MODE (XEXP (rtl, 0)) != mode
11161 || (GET_CODE (rtl) == CLZ
11162 && GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT))
11165 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11166 VAR_INIT_STATUS_INITIALIZED);
11170 if (GET_CODE (rtl) == CLZ)
11172 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11173 valv = GET_MODE_BITSIZE (mode);
11175 else if (GET_CODE (rtl) == FFS)
11177 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11178 valv = GET_MODE_BITSIZE (mode);
11179 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11180 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
11181 add_loc_descr (&ret, l1jump);
11182 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11183 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
11184 VAR_INIT_STATUS_INITIALIZED);
11187 add_loc_descr (&ret, tmp);
11188 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
11189 add_loc_descr (&ret, l4jump);
11190 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
11191 ? const1_rtx : const0_rtx,
11193 VAR_INIT_STATUS_INITIALIZED);
11194 if (l1label == NULL)
11196 add_loc_descr (&ret, l1label);
11197 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11198 l2label = new_loc_descr (DW_OP_dup, 0, 0);
11199 add_loc_descr (&ret, l2label);
11200 if (GET_CODE (rtl) != CLZ)
11202 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
11203 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
11204 << (GET_MODE_BITSIZE (mode) - 1));
11206 msb = immed_double_const (0, (unsigned HOST_WIDE_INT) 1
11207 << (GET_MODE_BITSIZE (mode)
11208 - HOST_BITS_PER_WIDE_INT - 1), mode);
11209 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
11210 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11211 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
11212 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
11214 tmp = mem_loc_descriptor (msb, mode, mem_mode,
11215 VAR_INIT_STATUS_INITIALIZED);
11218 add_loc_descr (&ret, tmp);
11219 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11220 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
11221 add_loc_descr (&ret, l3jump);
11222 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11223 VAR_INIT_STATUS_INITIALIZED);
11226 add_loc_descr (&ret, tmp);
11227 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
11228 ? DW_OP_shl : DW_OP_shr, 0, 0));
11229 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11230 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
11231 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11232 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
11233 add_loc_descr (&ret, l2jump);
11234 l3label = new_loc_descr (DW_OP_drop, 0, 0);
11235 add_loc_descr (&ret, l3label);
11236 l4label = new_loc_descr (DW_OP_nop, 0, 0);
11237 add_loc_descr (&ret, l4label);
11238 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11239 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11240 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11241 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11242 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11243 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
11244 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11245 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
11249 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11250 const1 is DW_OP_lit1 or corresponding typed constant):
11252 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11253 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11257 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11258 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11261 static dw_loc_descr_ref
11262 popcount_loc_descriptor (rtx rtl, enum machine_mode mode,
11263 enum machine_mode mem_mode)
11265 dw_loc_descr_ref op0, ret, tmp;
11266 dw_loc_descr_ref l1jump, l1label;
11267 dw_loc_descr_ref l2jump, l2label;
11269 if (GET_MODE_CLASS (mode) != MODE_INT
11270 || GET_MODE (XEXP (rtl, 0)) != mode)
11273 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11274 VAR_INIT_STATUS_INITIALIZED);
11278 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11279 VAR_INIT_STATUS_INITIALIZED);
11282 add_loc_descr (&ret, tmp);
11283 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11284 l1label = new_loc_descr (DW_OP_dup, 0, 0);
11285 add_loc_descr (&ret, l1label);
11286 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11287 add_loc_descr (&ret, l2jump);
11288 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11289 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11290 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11291 VAR_INIT_STATUS_INITIALIZED);
11294 add_loc_descr (&ret, tmp);
11295 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11296 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
11297 ? DW_OP_plus : DW_OP_xor, 0, 0));
11298 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11299 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11300 VAR_INIT_STATUS_INITIALIZED);
11301 add_loc_descr (&ret, tmp);
11302 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11303 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11304 add_loc_descr (&ret, l1jump);
11305 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11306 add_loc_descr (&ret, l2label);
11307 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11308 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11309 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11310 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11314 /* BSWAP (constS is initial shift count, either 56 or 24):
11316 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11317 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11318 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11319 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11320 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11322 static dw_loc_descr_ref
11323 bswap_loc_descriptor (rtx rtl, enum machine_mode mode,
11324 enum machine_mode mem_mode)
11326 dw_loc_descr_ref op0, ret, tmp;
11327 dw_loc_descr_ref l1jump, l1label;
11328 dw_loc_descr_ref l2jump, l2label;
11330 if (GET_MODE_CLASS (mode) != MODE_INT
11331 || BITS_PER_UNIT != 8
11332 || (GET_MODE_BITSIZE (mode) != 32
11333 && GET_MODE_BITSIZE (mode) != 64))
11336 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11337 VAR_INIT_STATUS_INITIALIZED);
11342 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11344 VAR_INIT_STATUS_INITIALIZED);
11347 add_loc_descr (&ret, tmp);
11348 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11349 VAR_INIT_STATUS_INITIALIZED);
11352 add_loc_descr (&ret, tmp);
11353 l1label = new_loc_descr (DW_OP_pick, 2, 0);
11354 add_loc_descr (&ret, l1label);
11355 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11357 VAR_INIT_STATUS_INITIALIZED);
11358 add_loc_descr (&ret, tmp);
11359 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
11360 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11361 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11362 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
11363 VAR_INIT_STATUS_INITIALIZED);
11366 add_loc_descr (&ret, tmp);
11367 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11368 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
11369 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11370 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11371 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11372 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11373 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11374 VAR_INIT_STATUS_INITIALIZED);
11375 add_loc_descr (&ret, tmp);
11376 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
11377 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11378 add_loc_descr (&ret, l2jump);
11379 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
11380 VAR_INIT_STATUS_INITIALIZED);
11381 add_loc_descr (&ret, tmp);
11382 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11383 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11384 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11385 add_loc_descr (&ret, l1jump);
11386 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11387 add_loc_descr (&ret, l2label);
11388 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11389 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11390 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11391 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11392 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11393 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11397 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11398 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11399 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11400 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11402 ROTATERT is similar:
11403 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11404 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11405 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11407 static dw_loc_descr_ref
11408 rotate_loc_descriptor (rtx rtl, enum machine_mode mode,
11409 enum machine_mode mem_mode)
11411 rtx rtlop1 = XEXP (rtl, 1);
11412 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
11415 if (GET_MODE_CLASS (mode) != MODE_INT)
11418 if (GET_MODE (rtlop1) != VOIDmode
11419 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
11420 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11421 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11422 VAR_INIT_STATUS_INITIALIZED);
11423 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11424 VAR_INIT_STATUS_INITIALIZED);
11425 if (op0 == NULL || op1 == NULL)
11427 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11428 for (i = 0; i < 2; i++)
11430 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
11431 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
11433 VAR_INIT_STATUS_INITIALIZED);
11434 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
11435 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11437 : HOST_BITS_PER_WIDE_INT == 64
11438 ? DW_OP_const8u : DW_OP_constu,
11439 GET_MODE_MASK (mode), 0);
11442 if (mask[i] == NULL)
11444 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
11447 add_loc_descr (&ret, op1);
11448 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11449 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11450 if (GET_CODE (rtl) == ROTATERT)
11452 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11453 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11454 GET_MODE_BITSIZE (mode), 0));
11456 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11457 if (mask[0] != NULL)
11458 add_loc_descr (&ret, mask[0]);
11459 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11460 if (mask[1] != NULL)
11462 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11463 add_loc_descr (&ret, mask[1]);
11464 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11466 if (GET_CODE (rtl) == ROTATE)
11468 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11469 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11470 GET_MODE_BITSIZE (mode), 0));
11472 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11473 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11477 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11478 for DEBUG_PARAMETER_REF RTL. */
11480 static dw_loc_descr_ref
11481 parameter_ref_descriptor (rtx rtl)
11483 dw_loc_descr_ref ret;
11488 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
11489 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
11490 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
11493 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11494 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
11495 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
11499 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
11500 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
11505 /* Helper function to get mode of MEM's address. */
11508 get_address_mode (rtx mem)
11510 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
11511 if (mode != VOIDmode)
11513 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
11516 /* The following routine converts the RTL for a variable or parameter
11517 (resident in memory) into an equivalent Dwarf representation of a
11518 mechanism for getting the address of that same variable onto the top of a
11519 hypothetical "address evaluation" stack.
11521 When creating memory location descriptors, we are effectively transforming
11522 the RTL for a memory-resident object into its Dwarf postfix expression
11523 equivalent. This routine recursively descends an RTL tree, turning
11524 it into Dwarf postfix code as it goes.
11526 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11528 MEM_MODE is the mode of the memory reference, needed to handle some
11529 autoincrement addressing modes.
11531 Return 0 if we can't represent the location. */
11534 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11535 enum machine_mode mem_mode,
11536 enum var_init_status initialized)
11538 dw_loc_descr_ref mem_loc_result = NULL;
11539 enum dwarf_location_atom op;
11540 dw_loc_descr_ref op0, op1;
11542 if (mode == VOIDmode)
11543 mode = GET_MODE (rtl);
11545 /* Note that for a dynamically sized array, the location we will generate a
11546 description of here will be the lowest numbered location which is
11547 actually within the array. That's *not* necessarily the same as the
11548 zeroth element of the array. */
11550 rtl = targetm.delegitimize_address (rtl);
11552 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
11555 switch (GET_CODE (rtl))
11560 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
11563 /* The case of a subreg may arise when we have a local (register)
11564 variable or a formal (register) parameter which doesn't quite fill
11565 up an entire register. For now, just assume that it is
11566 legitimate to make the Dwarf info refer to the whole register which
11567 contains the given subreg. */
11568 if (!subreg_lowpart_p (rtl))
11570 if (GET_MODE_CLASS (mode) == MODE_INT
11571 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
11572 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11573 #ifdef POINTERS_EXTEND_UNSIGNED
11574 || (mode == Pmode && mem_mode != VOIDmode)
11577 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
11579 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11580 GET_MODE (SUBREG_REG (rtl)),
11581 mem_mode, initialized);
11586 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11588 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
11589 && (GET_MODE_CLASS (mode) != MODE_INT
11590 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
11594 dw_die_ref type_die;
11595 dw_loc_descr_ref cvt;
11597 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11598 GET_MODE (SUBREG_REG (rtl)),
11599 mem_mode, initialized);
11600 if (mem_loc_result == NULL)
11602 type_die = base_type_for_mode (mode,
11603 GET_MODE_CLASS (mode) == MODE_INT);
11604 if (type_die == NULL)
11606 mem_loc_result = NULL;
11609 if (GET_MODE_SIZE (mode)
11610 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11611 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11613 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
11614 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11615 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11616 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11617 add_loc_descr (&mem_loc_result, cvt);
11622 if (GET_MODE_CLASS (mode) != MODE_INT
11623 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11624 #ifdef POINTERS_EXTEND_UNSIGNED
11625 && (mode != Pmode || mem_mode == VOIDmode)
11629 dw_die_ref type_die;
11633 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
11635 type_die = base_type_for_mode (mode,
11636 GET_MODE_CLASS (mode) == MODE_INT);
11637 if (type_die == NULL)
11639 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
11640 dbx_reg_number (rtl), 0);
11641 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
11642 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
11643 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
11646 /* Whenever a register number forms a part of the description of the
11647 method for calculating the (dynamic) address of a memory resident
11648 object, DWARF rules require the register number be referred to as
11649 a "base register". This distinction is not based in any way upon
11650 what category of register the hardware believes the given register
11651 belongs to. This is strictly DWARF terminology we're dealing with
11652 here. Note that in cases where the location of a memory-resident
11653 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11654 OP_CONST (0)) the actual DWARF location descriptor that we generate
11655 may just be OP_BASEREG (basereg). This may look deceptively like
11656 the object in question was allocated to a register (rather than in
11657 memory) so DWARF consumers need to be aware of the subtle
11658 distinction between OP_REG and OP_BASEREG. */
11659 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
11660 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
11661 else if (stack_realign_drap
11663 && crtl->args.internal_arg_pointer == rtl
11664 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
11666 /* If RTL is internal_arg_pointer, which has been optimized
11667 out, use DRAP instead. */
11668 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
11669 VAR_INIT_STATUS_INITIALIZED);
11675 if (GET_MODE_CLASS (mode) != MODE_INT)
11677 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
11678 mem_mode, VAR_INIT_STATUS_INITIALIZED);
11681 else if (GET_CODE (rtl) == ZERO_EXTEND
11682 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11683 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
11684 < HOST_BITS_PER_WIDE_INT
11685 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11686 to expand zero extend as two shifts instead of
11688 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
11690 enum machine_mode imode = GET_MODE (XEXP (rtl, 0));
11691 mem_loc_result = op0;
11692 add_loc_descr (&mem_loc_result,
11693 int_loc_descriptor (GET_MODE_MASK (imode)));
11694 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
11696 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11698 int shift = DWARF2_ADDR_SIZE
11699 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11700 shift *= BITS_PER_UNIT;
11701 if (GET_CODE (rtl) == SIGN_EXTEND)
11705 mem_loc_result = op0;
11706 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11707 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11708 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11709 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11711 else if (!dwarf_strict)
11713 dw_die_ref type_die1, type_die2;
11714 dw_loc_descr_ref cvt;
11716 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
11717 GET_CODE (rtl) == ZERO_EXTEND);
11718 if (type_die1 == NULL)
11720 type_die2 = base_type_for_mode (mode, 1);
11721 if (type_die2 == NULL)
11723 mem_loc_result = op0;
11724 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11725 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11726 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
11727 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11728 add_loc_descr (&mem_loc_result, cvt);
11729 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11730 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11731 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
11732 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11733 add_loc_descr (&mem_loc_result, cvt);
11739 rtx new_rtl = avoid_constant_pool_reference (rtl);
11740 if (new_rtl != rtl)
11742 mem_loc_result = mem_loc_descriptor (new_rtl, mode, mem_mode,
11744 if (mem_loc_result != NULL)
11745 return mem_loc_result;
11748 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
11749 get_address_mode (rtl), mode,
11750 VAR_INIT_STATUS_INITIALIZED);
11751 if (mem_loc_result == NULL)
11752 mem_loc_result = tls_mem_loc_descriptor (rtl);
11753 if (mem_loc_result != NULL)
11755 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11756 || GET_MODE_CLASS (mode) != MODE_INT)
11758 dw_die_ref type_die;
11759 dw_loc_descr_ref deref;
11764 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
11765 if (type_die == NULL)
11767 deref = new_loc_descr (DW_OP_GNU_deref_type,
11768 GET_MODE_SIZE (mode), 0);
11769 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
11770 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
11771 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
11772 add_loc_descr (&mem_loc_result, deref);
11774 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
11775 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
11777 add_loc_descr (&mem_loc_result,
11778 new_loc_descr (DW_OP_deref_size,
11779 GET_MODE_SIZE (mode), 0));
11784 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
11787 /* Some ports can transform a symbol ref into a label ref, because
11788 the symbol ref is too far away and has to be dumped into a constant
11792 if (GET_MODE_CLASS (mode) != MODE_INT
11793 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11794 #ifdef POINTERS_EXTEND_UNSIGNED
11795 && (mode != Pmode || mem_mode == VOIDmode)
11799 if (GET_CODE (rtl) == SYMBOL_REF
11800 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11802 dw_loc_descr_ref temp;
11804 /* If this is not defined, we have no way to emit the data. */
11805 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
11808 /* We used to emit DW_OP_addr here, but that's wrong, since
11809 DW_OP_addr should be relocated by the debug info consumer,
11810 while DW_OP_GNU_push_tls_address operand should not. */
11811 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
11812 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
11813 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
11814 temp->dw_loc_oprnd1.v.val_addr = rtl;
11815 temp->dtprel = true;
11817 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
11818 add_loc_descr (&mem_loc_result, temp);
11823 if (!const_ok_for_output (rtl))
11827 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
11828 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
11829 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
11830 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11836 case DEBUG_IMPLICIT_PTR:
11837 expansion_failed (NULL_TREE, rtl,
11838 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11844 if (REG_P (ENTRY_VALUE_EXP (rtl)))
11846 if (GET_MODE_CLASS (mode) != MODE_INT
11847 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11848 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
11849 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11852 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
11853 VAR_INIT_STATUS_INITIALIZED);
11855 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
11856 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
11858 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
11859 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11860 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
11864 gcc_unreachable ();
11867 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
11868 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
11869 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
11872 case DEBUG_PARAMETER_REF:
11873 mem_loc_result = parameter_ref_descriptor (rtl);
11877 /* Extract the PLUS expression nested inside and fall into
11878 PLUS code below. */
11879 rtl = XEXP (rtl, 1);
11884 /* Turn these into a PLUS expression and fall into the PLUS code
11886 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
11887 GEN_INT (GET_CODE (rtl) == PRE_INC
11888 ? GET_MODE_UNIT_SIZE (mem_mode)
11889 : -GET_MODE_UNIT_SIZE (mem_mode)));
11891 /* ... fall through ... */
11895 if (is_based_loc (rtl)
11896 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11897 && GET_MODE_CLASS (mode) == MODE_INT)
11898 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
11899 INTVAL (XEXP (rtl, 1)),
11900 VAR_INIT_STATUS_INITIALIZED);
11903 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11904 VAR_INIT_STATUS_INITIALIZED);
11905 if (mem_loc_result == 0)
11908 if (CONST_INT_P (XEXP (rtl, 1))
11909 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11910 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
11913 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11914 VAR_INIT_STATUS_INITIALIZED);
11917 add_loc_descr (&mem_loc_result, op1);
11918 add_loc_descr (&mem_loc_result,
11919 new_loc_descr (DW_OP_plus, 0, 0));
11924 /* If a pseudo-reg is optimized away, it is possible for it to
11925 be replaced with a MEM containing a multiply or shift. */
11936 && GET_MODE_CLASS (mode) == MODE_INT
11937 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11939 mem_loc_result = typed_binop (DW_OP_div, rtl,
11940 base_type_for_mode (mode, 0),
11964 if (GET_MODE_CLASS (mode) != MODE_INT)
11966 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11967 VAR_INIT_STATUS_INITIALIZED);
11969 rtx rtlop1 = XEXP (rtl, 1);
11970 if (GET_MODE (rtlop1) != VOIDmode
11971 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
11972 < GET_MODE_BITSIZE (mode))
11973 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11974 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11975 VAR_INIT_STATUS_INITIALIZED);
11978 if (op0 == 0 || op1 == 0)
11981 mem_loc_result = op0;
11982 add_loc_descr (&mem_loc_result, op1);
11983 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11999 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12000 VAR_INIT_STATUS_INITIALIZED);
12001 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12002 VAR_INIT_STATUS_INITIALIZED);
12004 if (op0 == 0 || op1 == 0)
12007 mem_loc_result = op0;
12008 add_loc_descr (&mem_loc_result, op1);
12009 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12013 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
12015 mem_loc_result = typed_binop (DW_OP_mod, rtl,
12016 base_type_for_mode (mode, 0),
12021 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12022 VAR_INIT_STATUS_INITIALIZED);
12023 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12024 VAR_INIT_STATUS_INITIALIZED);
12026 if (op0 == 0 || op1 == 0)
12029 mem_loc_result = op0;
12030 add_loc_descr (&mem_loc_result, op1);
12031 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
12032 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
12033 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
12034 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
12035 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
12039 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
12041 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
12046 mem_loc_result = typed_binop (DW_OP_div, rtl,
12047 base_type_for_mode (mode, 1),
12065 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12066 VAR_INIT_STATUS_INITIALIZED);
12071 mem_loc_result = op0;
12072 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12076 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12077 #ifdef POINTERS_EXTEND_UNSIGNED
12079 && mem_mode != VOIDmode
12080 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
12084 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
12088 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
12089 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
12091 dw_die_ref type_die = base_type_for_mode (mode, 1);
12092 enum machine_mode amode;
12093 if (type_die == NULL)
12095 amode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
12097 if (INTVAL (rtl) >= 0
12098 && amode != BLKmode
12099 && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
12100 /* const DW_OP_GNU_convert <XXX> vs.
12101 DW_OP_GNU_const_type <XXX, 1, const>. */
12102 && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
12103 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode))
12105 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
12106 op0 = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12107 op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12108 op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12109 op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
12110 add_loc_descr (&mem_loc_result, op0);
12111 return mem_loc_result;
12113 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
12115 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12116 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12117 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
12118 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
12119 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
12122 mem_loc_result->dw_loc_oprnd2.val_class
12123 = dw_val_class_const_double;
12124 mem_loc_result->dw_loc_oprnd2.v.val_double
12125 = shwi_to_double_int (INTVAL (rtl));
12133 dw_die_ref type_die;
12135 /* Note that a CONST_DOUBLE rtx could represent either an integer
12136 or a floating-point constant. A CONST_DOUBLE is used whenever
12137 the constant requires more than one word in order to be
12138 adequately represented. We output CONST_DOUBLEs as blocks. */
12139 if (mode == VOIDmode
12140 || (GET_MODE (rtl) == VOIDmode
12141 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
12143 type_die = base_type_for_mode (mode,
12144 GET_MODE_CLASS (mode) == MODE_INT);
12145 if (type_die == NULL)
12147 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
12148 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12149 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12150 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
12151 if (SCALAR_FLOAT_MODE_P (mode))
12153 unsigned int length = GET_MODE_SIZE (mode);
12154 unsigned char *array
12155 = (unsigned char*) ggc_alloc_atomic (length);
12157 insert_float (rtl, array);
12158 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12159 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12160 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12161 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12165 mem_loc_result->dw_loc_oprnd2.val_class
12166 = dw_val_class_const_double;
12167 mem_loc_result->dw_loc_oprnd2.v.val_double
12168 = rtx_to_double_int (rtl);
12174 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
12178 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12182 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12186 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12190 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12194 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
12198 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12202 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12206 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12210 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12215 if (GET_MODE_CLASS (mode) != MODE_INT)
12220 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
12225 if (CONST_INT_P (XEXP (rtl, 1))
12226 && CONST_INT_P (XEXP (rtl, 2))
12227 && ((unsigned) INTVAL (XEXP (rtl, 1))
12228 + (unsigned) INTVAL (XEXP (rtl, 2))
12229 <= GET_MODE_BITSIZE (mode))
12230 && GET_MODE_CLASS (mode) == MODE_INT
12231 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12232 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
12235 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12236 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12239 if (GET_CODE (rtl) == SIGN_EXTRACT)
12243 mem_loc_result = op0;
12244 size = INTVAL (XEXP (rtl, 1));
12245 shift = INTVAL (XEXP (rtl, 2));
12246 if (BITS_BIG_ENDIAN)
12247 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
12249 if (shift + size != (int) DWARF2_ADDR_SIZE)
12251 add_loc_descr (&mem_loc_result,
12252 int_loc_descriptor (DWARF2_ADDR_SIZE
12254 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
12256 if (size != (int) DWARF2_ADDR_SIZE)
12258 add_loc_descr (&mem_loc_result,
12259 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
12260 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12267 dw_loc_descr_ref op2, bra_node, drop_node;
12268 op0 = mem_loc_descriptor (XEXP (rtl, 0),
12269 GET_MODE (XEXP (rtl, 0)) == VOIDmode
12270 ? word_mode : GET_MODE (XEXP (rtl, 0)),
12271 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12272 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12273 VAR_INIT_STATUS_INITIALIZED);
12274 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
12275 VAR_INIT_STATUS_INITIALIZED);
12276 if (op0 == NULL || op1 == NULL || op2 == NULL)
12279 mem_loc_result = op1;
12280 add_loc_descr (&mem_loc_result, op2);
12281 add_loc_descr (&mem_loc_result, op0);
12282 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12283 add_loc_descr (&mem_loc_result, bra_node);
12284 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
12285 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
12286 add_loc_descr (&mem_loc_result, drop_node);
12287 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12288 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
12293 case FLOAT_TRUNCATE:
12295 case UNSIGNED_FLOAT:
12300 dw_die_ref type_die;
12301 dw_loc_descr_ref cvt;
12303 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12304 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12307 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
12308 && (GET_CODE (rtl) == FLOAT
12309 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
12310 <= DWARF2_ADDR_SIZE))
12312 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12313 GET_CODE (rtl) == UNSIGNED_FLOAT);
12314 if (type_die == NULL)
12316 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12317 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12318 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12319 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12320 add_loc_descr (&op0, cvt);
12322 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
12323 if (type_die == NULL)
12325 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12326 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12327 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12328 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12329 add_loc_descr (&op0, cvt);
12330 if (GET_MODE_CLASS (mode) == MODE_INT
12331 && (GET_CODE (rtl) == FIX
12332 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
12334 op0 = convert_descriptor_to_mode (mode, op0);
12338 mem_loc_result = op0;
12345 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
12350 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
12354 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
12359 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
12364 /* In theory, we could implement the above. */
12365 /* DWARF cannot represent the unsigned compare operations
12390 case FRACT_CONVERT:
12391 case UNSIGNED_FRACT_CONVERT:
12393 case UNSIGNED_SAT_FRACT:
12399 case VEC_DUPLICATE:
12403 case STRICT_LOW_PART:
12407 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12408 can't express it in the debug info. This can happen e.g. with some
12413 resolve_one_addr (&rtl, NULL);
12417 #ifdef ENABLE_CHECKING
12418 print_rtl (stderr, rtl);
12419 gcc_unreachable ();
12425 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12426 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12428 return mem_loc_result;
12431 /* Return a descriptor that describes the concatenation of two locations.
12432 This is typically a complex variable. */
12434 static dw_loc_descr_ref
12435 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
12437 dw_loc_descr_ref cc_loc_result = NULL;
12438 dw_loc_descr_ref x0_ref
12439 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12440 dw_loc_descr_ref x1_ref
12441 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12443 if (x0_ref == 0 || x1_ref == 0)
12446 cc_loc_result = x0_ref;
12447 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
12449 add_loc_descr (&cc_loc_result, x1_ref);
12450 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
12452 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
12453 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12455 return cc_loc_result;
12458 /* Return a descriptor that describes the concatenation of N
12461 static dw_loc_descr_ref
12462 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
12465 dw_loc_descr_ref cc_loc_result = NULL;
12466 unsigned int n = XVECLEN (concatn, 0);
12468 for (i = 0; i < n; ++i)
12470 dw_loc_descr_ref ref;
12471 rtx x = XVECEXP (concatn, 0, i);
12473 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12477 add_loc_descr (&cc_loc_result, ref);
12478 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
12481 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12482 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12484 return cc_loc_result;
12487 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12488 for DEBUG_IMPLICIT_PTR RTL. */
12490 static dw_loc_descr_ref
12491 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
12493 dw_loc_descr_ref ret;
12498 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
12499 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
12500 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
12501 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
12502 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
12503 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
12506 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12507 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
12508 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
12512 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
12513 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
12518 /* Output a proper Dwarf location descriptor for a variable or parameter
12519 which is either allocated in a register or in a memory location. For a
12520 register, we just generate an OP_REG and the register number. For a
12521 memory location we provide a Dwarf postfix expression describing how to
12522 generate the (dynamic) address of the object onto the address stack.
12524 MODE is mode of the decl if this loc_descriptor is going to be used in
12525 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12526 allowed, VOIDmode otherwise.
12528 If we don't know how to describe it, return 0. */
12530 static dw_loc_descr_ref
12531 loc_descriptor (rtx rtl, enum machine_mode mode,
12532 enum var_init_status initialized)
12534 dw_loc_descr_ref loc_result = NULL;
12536 switch (GET_CODE (rtl))
12539 /* The case of a subreg may arise when we have a local (register)
12540 variable or a formal (register) parameter which doesn't quite fill
12541 up an entire register. For now, just assume that it is
12542 legitimate to make the Dwarf info refer to the whole register which
12543 contains the given subreg. */
12544 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
12545 loc_result = loc_descriptor (SUBREG_REG (rtl),
12546 GET_MODE (SUBREG_REG (rtl)), initialized);
12552 loc_result = reg_loc_descriptor (rtl, initialized);
12556 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
12557 GET_MODE (rtl), initialized);
12558 if (loc_result == NULL)
12559 loc_result = tls_mem_loc_descriptor (rtl);
12560 if (loc_result == NULL)
12562 rtx new_rtl = avoid_constant_pool_reference (rtl);
12563 if (new_rtl != rtl)
12564 loc_result = loc_descriptor (new_rtl, mode, initialized);
12569 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
12574 loc_result = concatn_loc_descriptor (rtl, initialized);
12579 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
12581 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
12582 if (GET_CODE (loc) == EXPR_LIST)
12583 loc = XEXP (loc, 0);
12584 loc_result = loc_descriptor (loc, mode, initialized);
12588 rtl = XEXP (rtl, 1);
12593 rtvec par_elems = XVEC (rtl, 0);
12594 int num_elem = GET_NUM_ELEM (par_elems);
12595 enum machine_mode mode;
12598 /* Create the first one, so we have something to add to. */
12599 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
12600 VOIDmode, initialized);
12601 if (loc_result == NULL)
12603 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
12604 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12605 for (i = 1; i < num_elem; i++)
12607 dw_loc_descr_ref temp;
12609 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
12610 VOIDmode, initialized);
12613 add_loc_descr (&loc_result, temp);
12614 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
12615 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12621 if (mode != VOIDmode && mode != BLKmode)
12622 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
12627 if (mode == VOIDmode)
12628 mode = GET_MODE (rtl);
12630 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12632 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12634 /* Note that a CONST_DOUBLE rtx could represent either an integer
12635 or a floating-point constant. A CONST_DOUBLE is used whenever
12636 the constant requires more than one word in order to be
12637 adequately represented. We output CONST_DOUBLEs as blocks. */
12638 loc_result = new_loc_descr (DW_OP_implicit_value,
12639 GET_MODE_SIZE (mode), 0);
12640 if (SCALAR_FLOAT_MODE_P (mode))
12642 unsigned int length = GET_MODE_SIZE (mode);
12643 unsigned char *array
12644 = (unsigned char*) ggc_alloc_atomic (length);
12646 insert_float (rtl, array);
12647 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12648 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12649 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12650 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12654 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
12655 loc_result->dw_loc_oprnd2.v.val_double
12656 = rtx_to_double_int (rtl);
12662 if (mode == VOIDmode)
12663 mode = GET_MODE (rtl);
12665 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12667 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
12668 unsigned int length = CONST_VECTOR_NUNITS (rtl);
12669 unsigned char *array = (unsigned char *)
12670 ggc_alloc_atomic (length * elt_size);
12674 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12675 switch (GET_MODE_CLASS (mode))
12677 case MODE_VECTOR_INT:
12678 for (i = 0, p = array; i < length; i++, p += elt_size)
12680 rtx elt = CONST_VECTOR_ELT (rtl, i);
12681 double_int val = rtx_to_double_int (elt);
12683 if (elt_size <= sizeof (HOST_WIDE_INT))
12684 insert_int (double_int_to_shwi (val), elt_size, p);
12687 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
12688 insert_double (val, p);
12693 case MODE_VECTOR_FLOAT:
12694 for (i = 0, p = array; i < length; i++, p += elt_size)
12696 rtx elt = CONST_VECTOR_ELT (rtl, i);
12697 insert_float (elt, p);
12702 gcc_unreachable ();
12705 loc_result = new_loc_descr (DW_OP_implicit_value,
12706 length * elt_size, 0);
12707 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12708 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
12709 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
12710 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12715 if (mode == VOIDmode
12716 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
12717 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
12718 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
12720 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
12725 if (!const_ok_for_output (rtl))
12728 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
12729 && (dwarf_version >= 4 || !dwarf_strict))
12731 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
12732 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
12733 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
12734 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
12735 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12739 case DEBUG_IMPLICIT_PTR:
12740 loc_result = implicit_ptr_descriptor (rtl, 0);
12744 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
12745 && CONST_INT_P (XEXP (rtl, 1)))
12748 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
12754 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
12755 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
12756 && dwarf_version >= 4)
12757 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
12759 /* Value expression. */
12760 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
12762 add_loc_descr (&loc_result,
12763 new_loc_descr (DW_OP_stack_value, 0, 0));
12771 /* We need to figure out what section we should use as the base for the
12772 address ranges where a given location is valid.
12773 1. If this particular DECL has a section associated with it, use that.
12774 2. If this function has a section associated with it, use that.
12775 3. Otherwise, use the text section.
12776 XXX: If you split a variable across multiple sections, we won't notice. */
12778 static const char *
12779 secname_for_decl (const_tree decl)
12781 const char *secname;
12783 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
12785 tree sectree = DECL_SECTION_NAME (decl);
12786 secname = TREE_STRING_POINTER (sectree);
12788 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
12790 tree sectree = DECL_SECTION_NAME (current_function_decl);
12791 secname = TREE_STRING_POINTER (sectree);
12793 else if (cfun && in_cold_section_p)
12794 secname = crtl->subsections.cold_section_label;
12796 secname = text_section_label;
12801 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12804 decl_by_reference_p (tree decl)
12806 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
12807 || TREE_CODE (decl) == VAR_DECL)
12808 && DECL_BY_REFERENCE (decl));
12811 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12814 static dw_loc_descr_ref
12815 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
12816 enum var_init_status initialized)
12818 int have_address = 0;
12819 dw_loc_descr_ref descr;
12820 enum machine_mode mode;
12822 if (want_address != 2)
12824 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12826 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
12828 varloc = PAT_VAR_LOCATION_LOC (varloc);
12829 if (GET_CODE (varloc) == EXPR_LIST)
12830 varloc = XEXP (varloc, 0);
12831 mode = GET_MODE (varloc);
12832 if (MEM_P (varloc))
12834 rtx addr = XEXP (varloc, 0);
12835 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
12836 mode, initialized);
12841 rtx x = avoid_constant_pool_reference (varloc);
12843 descr = mem_loc_descriptor (x, mode, VOIDmode,
12848 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
12855 if (GET_CODE (varloc) == VAR_LOCATION)
12856 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
12858 mode = DECL_MODE (loc);
12859 descr = loc_descriptor (varloc, mode, initialized);
12866 if (want_address == 2 && !have_address
12867 && (dwarf_version >= 4 || !dwarf_strict))
12869 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
12871 expansion_failed (loc, NULL_RTX,
12872 "DWARF address size mismatch");
12875 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
12878 /* Show if we can't fill the request for an address. */
12879 if (want_address && !have_address)
12881 expansion_failed (loc, NULL_RTX,
12882 "Want address and only have value");
12886 /* If we've got an address and don't want one, dereference. */
12887 if (!want_address && have_address)
12889 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
12890 enum dwarf_location_atom op;
12892 if (size > DWARF2_ADDR_SIZE || size == -1)
12894 expansion_failed (loc, NULL_RTX,
12895 "DWARF address size mismatch");
12898 else if (size == DWARF2_ADDR_SIZE)
12901 op = DW_OP_deref_size;
12903 add_loc_descr (&descr, new_loc_descr (op, size, 0));
12909 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
12910 if it is not possible. */
12912 static dw_loc_descr_ref
12913 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
12915 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
12916 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
12917 else if (dwarf_version >= 3 || !dwarf_strict)
12918 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
12923 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12924 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
12926 static dw_loc_descr_ref
12927 dw_sra_loc_expr (tree decl, rtx loc)
12930 unsigned int padsize = 0;
12931 dw_loc_descr_ref descr, *descr_tail;
12932 unsigned HOST_WIDE_INT decl_size;
12934 enum var_init_status initialized;
12936 if (DECL_SIZE (decl) == NULL
12937 || !host_integerp (DECL_SIZE (decl), 1))
12940 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
12942 descr_tail = &descr;
12944 for (p = loc; p; p = XEXP (p, 1))
12946 unsigned int bitsize = decl_piece_bitsize (p);
12947 rtx loc_note = *decl_piece_varloc_ptr (p);
12948 dw_loc_descr_ref cur_descr;
12949 dw_loc_descr_ref *tail, last = NULL;
12950 unsigned int opsize = 0;
12952 if (loc_note == NULL_RTX
12953 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
12955 padsize += bitsize;
12958 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
12959 varloc = NOTE_VAR_LOCATION (loc_note);
12960 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
12961 if (cur_descr == NULL)
12963 padsize += bitsize;
12967 /* Check that cur_descr either doesn't use
12968 DW_OP_*piece operations, or their sum is equal
12969 to bitsize. Otherwise we can't embed it. */
12970 for (tail = &cur_descr; *tail != NULL;
12971 tail = &(*tail)->dw_loc_next)
12972 if ((*tail)->dw_loc_opc == DW_OP_piece)
12974 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
12978 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
12980 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
12984 if (last != NULL && opsize != bitsize)
12986 padsize += bitsize;
12990 /* If there is a hole, add DW_OP_*piece after empty DWARF
12991 expression, which means that those bits are optimized out. */
12994 if (padsize > decl_size)
12996 decl_size -= padsize;
12997 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
12998 if (*descr_tail == NULL)
13000 descr_tail = &(*descr_tail)->dw_loc_next;
13003 *descr_tail = cur_descr;
13005 if (bitsize > decl_size)
13007 decl_size -= bitsize;
13010 HOST_WIDE_INT offset = 0;
13011 if (GET_CODE (varloc) == VAR_LOCATION
13012 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
13014 varloc = PAT_VAR_LOCATION_LOC (varloc);
13015 if (GET_CODE (varloc) == EXPR_LIST)
13016 varloc = XEXP (varloc, 0);
13020 if (GET_CODE (varloc) == CONST
13021 || GET_CODE (varloc) == SIGN_EXTEND
13022 || GET_CODE (varloc) == ZERO_EXTEND)
13023 varloc = XEXP (varloc, 0);
13024 else if (GET_CODE (varloc) == SUBREG)
13025 varloc = SUBREG_REG (varloc);
13030 /* DW_OP_bit_size offset should be zero for register
13031 or implicit location descriptions and empty location
13032 descriptions, but for memory addresses needs big endian
13034 if (MEM_P (varloc))
13036 unsigned HOST_WIDE_INT memsize
13037 = MEM_SIZE (varloc) * BITS_PER_UNIT;
13038 if (memsize != bitsize)
13040 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
13041 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
13043 if (memsize < bitsize)
13045 if (BITS_BIG_ENDIAN)
13046 offset = memsize - bitsize;
13050 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
13051 if (*descr_tail == NULL)
13053 descr_tail = &(*descr_tail)->dw_loc_next;
13057 /* If there were any non-empty expressions, add padding till the end of
13059 if (descr != NULL && decl_size != 0)
13061 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
13062 if (*descr_tail == NULL)
13068 /* Return the dwarf representation of the location list LOC_LIST of
13069 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13072 static dw_loc_list_ref
13073 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
13075 const char *endname, *secname;
13077 enum var_init_status initialized;
13078 struct var_loc_node *node;
13079 dw_loc_descr_ref descr;
13080 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13081 dw_loc_list_ref list = NULL;
13082 dw_loc_list_ref *listp = &list;
13084 /* Now that we know what section we are using for a base,
13085 actually construct the list of locations.
13086 The first location information is what is passed to the
13087 function that creates the location list, and the remaining
13088 locations just get added on to that list.
13089 Note that we only know the start address for a location
13090 (IE location changes), so to build the range, we use
13091 the range [current location start, next location start].
13092 This means we have to special case the last node, and generate
13093 a range of [last location start, end of function label]. */
13095 secname = secname_for_decl (decl);
13097 for (node = loc_list->first; node; node = node->next)
13098 if (GET_CODE (node->loc) == EXPR_LIST
13099 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
13101 if (GET_CODE (node->loc) == EXPR_LIST)
13103 /* This requires DW_OP_{,bit_}piece, which is not usable
13104 inside DWARF expressions. */
13105 if (want_address != 2)
13107 descr = dw_sra_loc_expr (decl, node->loc);
13113 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
13114 varloc = NOTE_VAR_LOCATION (node->loc);
13115 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
13119 bool range_across_switch = false;
13120 /* If section switch happens in between node->label
13121 and node->next->label (or end of function) and
13122 we can't emit it as a single entry list,
13123 emit two ranges, first one ending at the end
13124 of first partition and second one starting at the
13125 beginning of second partition. */
13126 if (node == loc_list->last_before_switch
13127 && (node != loc_list->first || loc_list->first->next)
13128 && current_function_decl)
13130 endname = cfun->fde->dw_fde_end;
13131 range_across_switch = true;
13133 /* The variable has a location between NODE->LABEL and
13134 NODE->NEXT->LABEL. */
13135 else if (node->next)
13136 endname = node->next->label;
13137 /* If the variable has a location at the last label
13138 it keeps its location until the end of function. */
13139 else if (!current_function_decl)
13140 endname = text_end_label;
13143 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13144 current_function_funcdef_no);
13145 endname = ggc_strdup (label_id);
13148 *listp = new_loc_list (descr, node->label, endname, secname);
13149 if (TREE_CODE (decl) == PARM_DECL
13150 && node == loc_list->first
13151 && GET_CODE (node->loc) == NOTE
13152 && strcmp (node->label, endname) == 0)
13153 (*listp)->force = true;
13154 listp = &(*listp)->dw_loc_next;
13156 if (range_across_switch)
13158 if (GET_CODE (node->loc) == EXPR_LIST)
13159 descr = dw_sra_loc_expr (decl, node->loc);
13162 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
13163 varloc = NOTE_VAR_LOCATION (node->loc);
13164 descr = dw_loc_list_1 (decl, varloc, want_address,
13167 gcc_assert (descr);
13168 /* The variable has a location between NODE->LABEL and
13169 NODE->NEXT->LABEL. */
13171 endname = node->next->label;
13173 endname = cfun->fde->dw_fde_second_end;
13174 *listp = new_loc_list (descr,
13175 cfun->fde->dw_fde_second_begin,
13177 listp = &(*listp)->dw_loc_next;
13182 /* Try to avoid the overhead of a location list emitting a location
13183 expression instead, but only if we didn't have more than one
13184 location entry in the first place. If some entries were not
13185 representable, we don't want to pretend a single entry that was
13186 applies to the entire scope in which the variable is
13188 if (list && loc_list->first->next)
13194 /* Return if the loc_list has only single element and thus can be represented
13195 as location description. */
13198 single_element_loc_list_p (dw_loc_list_ref list)
13200 gcc_assert (!list->dw_loc_next || list->ll_symbol);
13201 return !list->ll_symbol;
13204 /* To each location in list LIST add loc descr REF. */
13207 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
13209 dw_loc_descr_ref copy;
13210 add_loc_descr (&list->expr, ref);
13211 list = list->dw_loc_next;
13214 copy = ggc_alloc_dw_loc_descr_node ();
13215 memcpy (copy, ref, sizeof (dw_loc_descr_node));
13216 add_loc_descr (&list->expr, copy);
13217 while (copy->dw_loc_next)
13219 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
13220 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
13221 copy->dw_loc_next = new_copy;
13224 list = list->dw_loc_next;
13228 /* Given two lists RET and LIST
13229 produce location list that is result of adding expression in LIST
13230 to expression in RET on each possition in program.
13231 Might be destructive on both RET and LIST.
13233 TODO: We handle only simple cases of RET or LIST having at most one
13234 element. General case would inolve sorting the lists in program order
13235 and merging them that will need some additional work.
13236 Adding that will improve quality of debug info especially for SRA-ed
13240 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
13249 if (!list->dw_loc_next)
13251 add_loc_descr_to_each (*ret, list->expr);
13254 if (!(*ret)->dw_loc_next)
13256 add_loc_descr_to_each (list, (*ret)->expr);
13260 expansion_failed (NULL_TREE, NULL_RTX,
13261 "Don't know how to merge two non-trivial"
13262 " location lists.\n");
13267 /* LOC is constant expression. Try a luck, look it up in constant
13268 pool and return its loc_descr of its address. */
13270 static dw_loc_descr_ref
13271 cst_pool_loc_descr (tree loc)
13273 /* Get an RTL for this, if something has been emitted. */
13274 rtx rtl = lookup_constant_def (loc);
13276 if (!rtl || !MEM_P (rtl))
13281 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
13283 /* TODO: We might get more coverage if we was actually delaying expansion
13284 of all expressions till end of compilation when constant pools are fully
13286 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
13288 expansion_failed (loc, NULL_RTX,
13289 "CST value in contant pool but not marked.");
13292 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
13293 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
13296 /* Return dw_loc_list representing address of addr_expr LOC
13297 by looking for innder INDIRECT_REF expression and turing it
13298 into simple arithmetics. */
13300 static dw_loc_list_ref
13301 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
13304 HOST_WIDE_INT bitsize, bitpos, bytepos;
13305 enum machine_mode mode;
13307 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13308 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13310 obj = get_inner_reference (TREE_OPERAND (loc, 0),
13311 &bitsize, &bitpos, &offset, &mode,
13312 &unsignedp, &volatilep, false);
13314 if (bitpos % BITS_PER_UNIT)
13316 expansion_failed (loc, NULL_RTX, "bitfield access");
13319 if (!INDIRECT_REF_P (obj))
13321 expansion_failed (obj,
13322 NULL_RTX, "no indirect ref in inner refrence");
13325 if (!offset && !bitpos)
13326 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
13328 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
13329 && (dwarf_version >= 4 || !dwarf_strict))
13331 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
13336 /* Variable offset. */
13337 list_ret1 = loc_list_from_tree (offset, 0);
13338 if (list_ret1 == 0)
13340 add_loc_list (&list_ret, list_ret1);
13343 add_loc_descr_to_each (list_ret,
13344 new_loc_descr (DW_OP_plus, 0, 0));
13346 bytepos = bitpos / BITS_PER_UNIT;
13348 add_loc_descr_to_each (list_ret,
13349 new_loc_descr (DW_OP_plus_uconst,
13351 else if (bytepos < 0)
13352 loc_list_plus_const (list_ret, bytepos);
13353 add_loc_descr_to_each (list_ret,
13354 new_loc_descr (DW_OP_stack_value, 0, 0));
13360 /* Generate Dwarf location list representing LOC.
13361 If WANT_ADDRESS is false, expression computing LOC will be computed
13362 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13363 if WANT_ADDRESS is 2, expression computing address useable in location
13364 will be returned (i.e. DW_OP_reg can be used
13365 to refer to register values). */
13367 static dw_loc_list_ref
13368 loc_list_from_tree (tree loc, int want_address)
13370 dw_loc_descr_ref ret = NULL, ret1 = NULL;
13371 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13372 int have_address = 0;
13373 enum dwarf_location_atom op;
13375 /* ??? Most of the time we do not take proper care for sign/zero
13376 extending the values properly. Hopefully this won't be a real
13379 switch (TREE_CODE (loc))
13382 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
13385 case PLACEHOLDER_EXPR:
13386 /* This case involves extracting fields from an object to determine the
13387 position of other fields. We don't try to encode this here. The
13388 only user of this is Ada, which encodes the needed information using
13389 the names of types. */
13390 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
13394 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
13395 /* There are no opcodes for these operations. */
13398 case PREINCREMENT_EXPR:
13399 case PREDECREMENT_EXPR:
13400 case POSTINCREMENT_EXPR:
13401 case POSTDECREMENT_EXPR:
13402 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
13403 /* There are no opcodes for these operations. */
13407 /* If we already want an address, see if there is INDIRECT_REF inside
13408 e.g. for &this->field. */
13411 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
13412 (loc, want_address == 2);
13415 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
13416 && (ret = cst_pool_loc_descr (loc)))
13419 /* Otherwise, process the argument and look for the address. */
13420 if (!list_ret && !ret)
13421 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
13425 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
13431 if (DECL_THREAD_LOCAL_P (loc))
13434 enum dwarf_location_atom first_op;
13435 enum dwarf_location_atom second_op;
13436 bool dtprel = false;
13438 if (targetm.have_tls)
13440 /* If this is not defined, we have no way to emit the
13442 if (!targetm.asm_out.output_dwarf_dtprel)
13445 /* The way DW_OP_GNU_push_tls_address is specified, we
13446 can only look up addresses of objects in the current
13447 module. We used DW_OP_addr as first op, but that's
13448 wrong, because DW_OP_addr is relocated by the debug
13449 info consumer, while DW_OP_GNU_push_tls_address
13450 operand shouldn't be. */
13451 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
13453 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
13455 second_op = DW_OP_GNU_push_tls_address;
13459 if (!targetm.emutls.debug_form_tls_address
13460 || !(dwarf_version >= 3 || !dwarf_strict))
13462 /* We stuffed the control variable into the DECL_VALUE_EXPR
13463 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13464 no longer appear in gimple code. We used the control
13465 variable in specific so that we could pick it up here. */
13466 loc = DECL_VALUE_EXPR (loc);
13467 first_op = DW_OP_addr;
13468 second_op = DW_OP_form_tls_address;
13471 rtl = rtl_for_decl_location (loc);
13472 if (rtl == NULL_RTX)
13477 rtl = XEXP (rtl, 0);
13478 if (! CONSTANT_P (rtl))
13481 ret = new_loc_descr (first_op, 0, 0);
13482 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13483 ret->dw_loc_oprnd1.v.val_addr = rtl;
13484 ret->dtprel = dtprel;
13486 ret1 = new_loc_descr (second_op, 0, 0);
13487 add_loc_descr (&ret, ret1);
13496 if (DECL_HAS_VALUE_EXPR_P (loc))
13497 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
13501 case FUNCTION_DECL:
13504 var_loc_list *loc_list = lookup_decl_loc (loc);
13506 if (loc_list && loc_list->first)
13508 list_ret = dw_loc_list (loc_list, loc, want_address);
13509 have_address = want_address != 0;
13512 rtl = rtl_for_decl_location (loc);
13513 if (rtl == NULL_RTX)
13515 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
13518 else if (CONST_INT_P (rtl))
13520 HOST_WIDE_INT val = INTVAL (rtl);
13521 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13522 val &= GET_MODE_MASK (DECL_MODE (loc));
13523 ret = int_loc_descriptor (val);
13525 else if (GET_CODE (rtl) == CONST_STRING)
13527 expansion_failed (loc, NULL_RTX, "CONST_STRING");
13530 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
13532 ret = new_loc_descr (DW_OP_addr, 0, 0);
13533 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13534 ret->dw_loc_oprnd1.v.val_addr = rtl;
13538 enum machine_mode mode, mem_mode;
13540 /* Certain constructs can only be represented at top-level. */
13541 if (want_address == 2)
13543 ret = loc_descriptor (rtl, VOIDmode,
13544 VAR_INIT_STATUS_INITIALIZED);
13549 mode = GET_MODE (rtl);
13550 mem_mode = VOIDmode;
13554 mode = get_address_mode (rtl);
13555 rtl = XEXP (rtl, 0);
13558 ret = mem_loc_descriptor (rtl, mode, mem_mode,
13559 VAR_INIT_STATUS_INITIALIZED);
13562 expansion_failed (loc, rtl,
13563 "failed to produce loc descriptor for rtl");
13570 if (!integer_zerop (TREE_OPERAND (loc, 1)))
13574 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13578 case COMPOUND_EXPR:
13579 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
13582 case VIEW_CONVERT_EXPR:
13585 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
13587 case COMPONENT_REF:
13588 case BIT_FIELD_REF:
13590 case ARRAY_RANGE_REF:
13591 case REALPART_EXPR:
13592 case IMAGPART_EXPR:
13595 HOST_WIDE_INT bitsize, bitpos, bytepos;
13596 enum machine_mode mode;
13598 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13600 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
13601 &unsignedp, &volatilep, false);
13603 gcc_assert (obj != loc);
13605 list_ret = loc_list_from_tree (obj,
13607 && !bitpos && !offset ? 2 : 1);
13608 /* TODO: We can extract value of the small expression via shifting even
13609 for nonzero bitpos. */
13612 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
13614 expansion_failed (loc, NULL_RTX,
13615 "bitfield access");
13619 if (offset != NULL_TREE)
13621 /* Variable offset. */
13622 list_ret1 = loc_list_from_tree (offset, 0);
13623 if (list_ret1 == 0)
13625 add_loc_list (&list_ret, list_ret1);
13628 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
13631 bytepos = bitpos / BITS_PER_UNIT;
13633 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
13634 else if (bytepos < 0)
13635 loc_list_plus_const (list_ret, bytepos);
13642 if ((want_address || !host_integerp (loc, 0))
13643 && (ret = cst_pool_loc_descr (loc)))
13645 else if (want_address == 2
13646 && host_integerp (loc, 0)
13647 && (ret = address_of_int_loc_descriptor
13648 (int_size_in_bytes (TREE_TYPE (loc)),
13649 tree_low_cst (loc, 0))))
13651 else if (host_integerp (loc, 0))
13652 ret = int_loc_descriptor (tree_low_cst (loc, 0));
13655 expansion_failed (loc, NULL_RTX,
13656 "Integer operand is not host integer");
13665 if ((ret = cst_pool_loc_descr (loc)))
13668 /* We can construct small constants here using int_loc_descriptor. */
13669 expansion_failed (loc, NULL_RTX,
13670 "constructor or constant not in constant pool");
13673 case TRUTH_AND_EXPR:
13674 case TRUTH_ANDIF_EXPR:
13679 case TRUTH_XOR_EXPR:
13684 case TRUTH_OR_EXPR:
13685 case TRUTH_ORIF_EXPR:
13690 case FLOOR_DIV_EXPR:
13691 case CEIL_DIV_EXPR:
13692 case ROUND_DIV_EXPR:
13693 case TRUNC_DIV_EXPR:
13694 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13703 case FLOOR_MOD_EXPR:
13704 case CEIL_MOD_EXPR:
13705 case ROUND_MOD_EXPR:
13706 case TRUNC_MOD_EXPR:
13707 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13712 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13713 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
13714 if (list_ret == 0 || list_ret1 == 0)
13717 add_loc_list (&list_ret, list_ret1);
13720 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
13721 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
13722 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
13723 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
13724 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
13736 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
13739 case POINTER_PLUS_EXPR:
13741 if (host_integerp (TREE_OPERAND (loc, 1), 0))
13743 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13747 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
13755 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13762 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13769 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13776 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13791 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13792 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
13793 if (list_ret == 0 || list_ret1 == 0)
13796 add_loc_list (&list_ret, list_ret1);
13799 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
13802 case TRUTH_NOT_EXPR:
13816 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13820 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
13826 const enum tree_code code =
13827 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
13829 loc = build3 (COND_EXPR, TREE_TYPE (loc),
13830 build2 (code, integer_type_node,
13831 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
13832 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
13835 /* ... fall through ... */
13839 dw_loc_descr_ref lhs
13840 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
13841 dw_loc_list_ref rhs
13842 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
13843 dw_loc_descr_ref bra_node, jump_node, tmp;
13845 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13846 if (list_ret == 0 || lhs == 0 || rhs == 0)
13849 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
13850 add_loc_descr_to_each (list_ret, bra_node);
13852 add_loc_list (&list_ret, rhs);
13853 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
13854 add_loc_descr_to_each (list_ret, jump_node);
13856 add_loc_descr_to_each (list_ret, lhs);
13857 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13858 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
13860 /* ??? Need a node to point the skip at. Use a nop. */
13861 tmp = new_loc_descr (DW_OP_nop, 0, 0);
13862 add_loc_descr_to_each (list_ret, tmp);
13863 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13864 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
13868 case FIX_TRUNC_EXPR:
13872 /* Leave front-end specific codes as simply unknown. This comes
13873 up, for instance, with the C STMT_EXPR. */
13874 if ((unsigned int) TREE_CODE (loc)
13875 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
13877 expansion_failed (loc, NULL_RTX,
13878 "language specific tree node");
13882 #ifdef ENABLE_CHECKING
13883 /* Otherwise this is a generic code; we should just lists all of
13884 these explicitly. We forgot one. */
13885 gcc_unreachable ();
13887 /* In a release build, we want to degrade gracefully: better to
13888 generate incomplete debugging information than to crash. */
13893 if (!ret && !list_ret)
13896 if (want_address == 2 && !have_address
13897 && (dwarf_version >= 4 || !dwarf_strict))
13899 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
13901 expansion_failed (loc, NULL_RTX,
13902 "DWARF address size mismatch");
13906 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
13908 add_loc_descr_to_each (list_ret,
13909 new_loc_descr (DW_OP_stack_value, 0, 0));
13912 /* Show if we can't fill the request for an address. */
13913 if (want_address && !have_address)
13915 expansion_failed (loc, NULL_RTX,
13916 "Want address and only have value");
13920 gcc_assert (!ret || !list_ret);
13922 /* If we've got an address and don't want one, dereference. */
13923 if (!want_address && have_address)
13925 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
13927 if (size > DWARF2_ADDR_SIZE || size == -1)
13929 expansion_failed (loc, NULL_RTX,
13930 "DWARF address size mismatch");
13933 else if (size == DWARF2_ADDR_SIZE)
13936 op = DW_OP_deref_size;
13939 add_loc_descr (&ret, new_loc_descr (op, size, 0));
13941 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
13944 list_ret = new_loc_list (ret, NULL, NULL, NULL);
13949 /* Same as above but return only single location expression. */
13950 static dw_loc_descr_ref
13951 loc_descriptor_from_tree (tree loc, int want_address)
13953 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
13956 if (ret->dw_loc_next)
13958 expansion_failed (loc, NULL_RTX,
13959 "Location list where only loc descriptor needed");
13965 /* Given a value, round it up to the lowest multiple of `boundary'
13966 which is not less than the value itself. */
13968 static inline HOST_WIDE_INT
13969 ceiling (HOST_WIDE_INT value, unsigned int boundary)
13971 return (((value + boundary - 1) / boundary) * boundary);
13974 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
13975 pointer to the declared type for the relevant field variable, or return
13976 `integer_type_node' if the given node turns out to be an
13977 ERROR_MARK node. */
13980 field_type (const_tree decl)
13984 if (TREE_CODE (decl) == ERROR_MARK)
13985 return integer_type_node;
13987 type = DECL_BIT_FIELD_TYPE (decl);
13988 if (type == NULL_TREE)
13989 type = TREE_TYPE (decl);
13994 /* Given a pointer to a tree node, return the alignment in bits for
13995 it, or else return BITS_PER_WORD if the node actually turns out to
13996 be an ERROR_MARK node. */
13998 static inline unsigned
13999 simple_type_align_in_bits (const_tree type)
14001 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
14004 static inline unsigned
14005 simple_decl_align_in_bits (const_tree decl)
14007 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
14010 /* Return the result of rounding T up to ALIGN. */
14012 static inline double_int
14013 round_up_to_align (double_int t, unsigned int align)
14015 double_int alignd = uhwi_to_double_int (align);
14016 t = double_int_add (t, alignd);
14017 t = double_int_add (t, double_int_minus_one);
14018 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
14019 t = double_int_mul (t, alignd);
14023 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14024 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14025 or return 0 if we are unable to determine what that offset is, either
14026 because the argument turns out to be a pointer to an ERROR_MARK node, or
14027 because the offset is actually variable. (We can't handle the latter case
14030 static HOST_WIDE_INT
14031 field_byte_offset (const_tree decl)
14033 double_int object_offset_in_bits;
14034 double_int object_offset_in_bytes;
14035 double_int bitpos_int;
14037 if (TREE_CODE (decl) == ERROR_MARK)
14040 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
14042 /* We cannot yet cope with fields whose positions are variable, so
14043 for now, when we see such things, we simply return 0. Someday, we may
14044 be able to handle such cases, but it will be damn difficult. */
14045 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
14048 bitpos_int = tree_to_double_int (bit_position (decl));
14050 #ifdef PCC_BITFIELD_TYPE_MATTERS
14051 if (PCC_BITFIELD_TYPE_MATTERS)
14054 tree field_size_tree;
14055 double_int deepest_bitpos;
14056 double_int field_size_in_bits;
14057 unsigned int type_align_in_bits;
14058 unsigned int decl_align_in_bits;
14059 double_int type_size_in_bits;
14061 type = field_type (decl);
14062 type_size_in_bits = double_int_type_size_in_bits (type);
14063 type_align_in_bits = simple_type_align_in_bits (type);
14065 field_size_tree = DECL_SIZE (decl);
14067 /* The size could be unspecified if there was an error, or for
14068 a flexible array member. */
14069 if (!field_size_tree)
14070 field_size_tree = bitsize_zero_node;
14072 /* If the size of the field is not constant, use the type size. */
14073 if (TREE_CODE (field_size_tree) == INTEGER_CST)
14074 field_size_in_bits = tree_to_double_int (field_size_tree);
14076 field_size_in_bits = type_size_in_bits;
14078 decl_align_in_bits = simple_decl_align_in_bits (decl);
14080 /* The GCC front-end doesn't make any attempt to keep track of the
14081 starting bit offset (relative to the start of the containing
14082 structure type) of the hypothetical "containing object" for a
14083 bit-field. Thus, when computing the byte offset value for the
14084 start of the "containing object" of a bit-field, we must deduce
14085 this information on our own. This can be rather tricky to do in
14086 some cases. For example, handling the following structure type
14087 definition when compiling for an i386/i486 target (which only
14088 aligns long long's to 32-bit boundaries) can be very tricky:
14090 struct S { int field1; long long field2:31; };
14092 Fortunately, there is a simple rule-of-thumb which can be used
14093 in such cases. When compiling for an i386/i486, GCC will
14094 allocate 8 bytes for the structure shown above. It decides to
14095 do this based upon one simple rule for bit-field allocation.
14096 GCC allocates each "containing object" for each bit-field at
14097 the first (i.e. lowest addressed) legitimate alignment boundary
14098 (based upon the required minimum alignment for the declared
14099 type of the field) which it can possibly use, subject to the
14100 condition that there is still enough available space remaining
14101 in the containing object (when allocated at the selected point)
14102 to fully accommodate all of the bits of the bit-field itself.
14104 This simple rule makes it obvious why GCC allocates 8 bytes for
14105 each object of the structure type shown above. When looking
14106 for a place to allocate the "containing object" for `field2',
14107 the compiler simply tries to allocate a 64-bit "containing
14108 object" at each successive 32-bit boundary (starting at zero)
14109 until it finds a place to allocate that 64- bit field such that
14110 at least 31 contiguous (and previously unallocated) bits remain
14111 within that selected 64 bit field. (As it turns out, for the
14112 example above, the compiler finds it is OK to allocate the
14113 "containing object" 64-bit field at bit-offset zero within the
14116 Here we attempt to work backwards from the limited set of facts
14117 we're given, and we try to deduce from those facts, where GCC
14118 must have believed that the containing object started (within
14119 the structure type). The value we deduce is then used (by the
14120 callers of this routine) to generate DW_AT_location and
14121 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14122 the case of DW_AT_location, regular fields as well). */
14124 /* Figure out the bit-distance from the start of the structure to
14125 the "deepest" bit of the bit-field. */
14126 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
14128 /* This is the tricky part. Use some fancy footwork to deduce
14129 where the lowest addressed bit of the containing object must
14131 object_offset_in_bits
14132 = double_int_sub (deepest_bitpos, type_size_in_bits);
14134 /* Round up to type_align by default. This works best for
14136 object_offset_in_bits
14137 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
14139 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
14141 object_offset_in_bits
14142 = double_int_sub (deepest_bitpos, type_size_in_bits);
14144 /* Round up to decl_align instead. */
14145 object_offset_in_bits
14146 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
14150 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14151 object_offset_in_bits = bitpos_int;
14153 object_offset_in_bytes
14154 = double_int_div (object_offset_in_bits,
14155 uhwi_to_double_int (BITS_PER_UNIT), true,
14157 return double_int_to_shwi (object_offset_in_bytes);
14160 /* The following routines define various Dwarf attributes and any data
14161 associated with them. */
14163 /* Add a location description attribute value to a DIE.
14165 This emits location attributes suitable for whole variables and
14166 whole parameters. Note that the location attributes for struct fields are
14167 generated by the routine `data_member_location_attribute' below. */
14170 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
14171 dw_loc_list_ref descr)
14175 if (single_element_loc_list_p (descr))
14176 add_AT_loc (die, attr_kind, descr->expr);
14178 add_AT_loc_list (die, attr_kind, descr);
14181 /* Add DW_AT_accessibility attribute to DIE if needed. */
14184 add_accessibility_attribute (dw_die_ref die, tree decl)
14186 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14187 children, otherwise the default is DW_ACCESS_public. In DWARF2
14188 the default has always been DW_ACCESS_public. */
14189 if (TREE_PROTECTED (decl))
14190 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14191 else if (TREE_PRIVATE (decl))
14193 if (dwarf_version == 2
14194 || die->die_parent == NULL
14195 || die->die_parent->die_tag != DW_TAG_class_type)
14196 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
14198 else if (dwarf_version > 2
14200 && die->die_parent->die_tag == DW_TAG_class_type)
14201 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14204 /* Attach the specialized form of location attribute used for data members of
14205 struct and union types. In the special case of a FIELD_DECL node which
14206 represents a bit-field, the "offset" part of this special location
14207 descriptor must indicate the distance in bytes from the lowest-addressed
14208 byte of the containing struct or union type to the lowest-addressed byte of
14209 the "containing object" for the bit-field. (See the `field_byte_offset'
14212 For any given bit-field, the "containing object" is a hypothetical object
14213 (of some integral or enum type) within which the given bit-field lives. The
14214 type of this hypothetical "containing object" is always the same as the
14215 declared type of the individual bit-field itself (for GCC anyway... the
14216 DWARF spec doesn't actually mandate this). Note that it is the size (in
14217 bytes) of the hypothetical "containing object" which will be given in the
14218 DW_AT_byte_size attribute for this bit-field. (See the
14219 `byte_size_attribute' function below.) It is also used when calculating the
14220 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14221 function below.) */
14224 add_data_member_location_attribute (dw_die_ref die, tree decl)
14226 HOST_WIDE_INT offset;
14227 dw_loc_descr_ref loc_descr = 0;
14229 if (TREE_CODE (decl) == TREE_BINFO)
14231 /* We're working on the TAG_inheritance for a base class. */
14232 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
14234 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14235 aren't at a fixed offset from all (sub)objects of the same
14236 type. We need to extract the appropriate offset from our
14237 vtable. The following dwarf expression means
14239 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14241 This is specific to the V3 ABI, of course. */
14243 dw_loc_descr_ref tmp;
14245 /* Make a copy of the object address. */
14246 tmp = new_loc_descr (DW_OP_dup, 0, 0);
14247 add_loc_descr (&loc_descr, tmp);
14249 /* Extract the vtable address. */
14250 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14251 add_loc_descr (&loc_descr, tmp);
14253 /* Calculate the address of the offset. */
14254 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
14255 gcc_assert (offset < 0);
14257 tmp = int_loc_descriptor (-offset);
14258 add_loc_descr (&loc_descr, tmp);
14259 tmp = new_loc_descr (DW_OP_minus, 0, 0);
14260 add_loc_descr (&loc_descr, tmp);
14262 /* Extract the offset. */
14263 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14264 add_loc_descr (&loc_descr, tmp);
14266 /* Add it to the object address. */
14267 tmp = new_loc_descr (DW_OP_plus, 0, 0);
14268 add_loc_descr (&loc_descr, tmp);
14271 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
14274 offset = field_byte_offset (decl);
14278 if (dwarf_version > 2)
14280 /* Don't need to output a location expression, just the constant. */
14282 add_AT_int (die, DW_AT_data_member_location, offset);
14284 add_AT_unsigned (die, DW_AT_data_member_location, offset);
14289 enum dwarf_location_atom op;
14291 /* The DWARF2 standard says that we should assume that the structure
14292 address is already on the stack, so we can specify a structure
14293 field address by using DW_OP_plus_uconst. */
14295 #ifdef MIPS_DEBUGGING_INFO
14296 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
14297 operator correctly. It works only if we leave the offset on the
14301 op = DW_OP_plus_uconst;
14304 loc_descr = new_loc_descr (op, offset, 0);
14308 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
14311 /* Writes integer values to dw_vec_const array. */
14314 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
14318 *dest++ = val & 0xff;
14324 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14326 static HOST_WIDE_INT
14327 extract_int (const unsigned char *src, unsigned int size)
14329 HOST_WIDE_INT val = 0;
14335 val |= *--src & 0xff;
14341 /* Writes double_int values to dw_vec_const array. */
14344 insert_double (double_int val, unsigned char *dest)
14346 unsigned char *p0 = dest;
14347 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
14349 if (WORDS_BIG_ENDIAN)
14355 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
14356 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
14359 /* Writes floating point values to dw_vec_const array. */
14362 insert_float (const_rtx rtl, unsigned char *array)
14364 REAL_VALUE_TYPE rv;
14368 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
14369 real_to_target (val, &rv, GET_MODE (rtl));
14371 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14372 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
14374 insert_int (val[i], 4, array);
14379 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14380 does not have a "location" either in memory or in a register. These
14381 things can arise in GNU C when a constant is passed as an actual parameter
14382 to an inlined function. They can also arise in C++ where declared
14383 constants do not necessarily get memory "homes". */
14386 add_const_value_attribute (dw_die_ref die, rtx rtl)
14388 switch (GET_CODE (rtl))
14392 HOST_WIDE_INT val = INTVAL (rtl);
14395 add_AT_int (die, DW_AT_const_value, val);
14397 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
14402 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14403 floating-point constant. A CONST_DOUBLE is used whenever the
14404 constant requires more than one word in order to be adequately
14407 enum machine_mode mode = GET_MODE (rtl);
14409 if (SCALAR_FLOAT_MODE_P (mode))
14411 unsigned int length = GET_MODE_SIZE (mode);
14412 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
14414 insert_float (rtl, array);
14415 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
14418 add_AT_double (die, DW_AT_const_value,
14419 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
14425 enum machine_mode mode = GET_MODE (rtl);
14426 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
14427 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14428 unsigned char *array = (unsigned char *) ggc_alloc_atomic
14429 (length * elt_size);
14433 switch (GET_MODE_CLASS (mode))
14435 case MODE_VECTOR_INT:
14436 for (i = 0, p = array; i < length; i++, p += elt_size)
14438 rtx elt = CONST_VECTOR_ELT (rtl, i);
14439 double_int val = rtx_to_double_int (elt);
14441 if (elt_size <= sizeof (HOST_WIDE_INT))
14442 insert_int (double_int_to_shwi (val), elt_size, p);
14445 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14446 insert_double (val, p);
14451 case MODE_VECTOR_FLOAT:
14452 for (i = 0, p = array; i < length; i++, p += elt_size)
14454 rtx elt = CONST_VECTOR_ELT (rtl, i);
14455 insert_float (elt, p);
14460 gcc_unreachable ();
14463 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
14468 if (dwarf_version >= 4 || !dwarf_strict)
14470 dw_loc_descr_ref loc_result;
14471 resolve_one_addr (&rtl, NULL);
14473 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14474 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14475 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14476 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14477 add_AT_loc (die, DW_AT_location, loc_result);
14478 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14484 if (CONSTANT_P (XEXP (rtl, 0)))
14485 return add_const_value_attribute (die, XEXP (rtl, 0));
14488 if (!const_ok_for_output (rtl))
14491 if (dwarf_version >= 4 || !dwarf_strict)
14496 /* In cases where an inlined instance of an inline function is passed
14497 the address of an `auto' variable (which is local to the caller) we
14498 can get a situation where the DECL_RTL of the artificial local
14499 variable (for the inlining) which acts as a stand-in for the
14500 corresponding formal parameter (of the inline function) will look
14501 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14502 exactly a compile-time constant expression, but it isn't the address
14503 of the (artificial) local variable either. Rather, it represents the
14504 *value* which the artificial local variable always has during its
14505 lifetime. We currently have no way to represent such quasi-constant
14506 values in Dwarf, so for now we just punt and generate nothing. */
14514 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
14515 && MEM_READONLY_P (rtl)
14516 && GET_MODE (rtl) == BLKmode)
14518 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
14524 /* No other kinds of rtx should be possible here. */
14525 gcc_unreachable ();
14530 /* Determine whether the evaluation of EXPR references any variables
14531 or functions which aren't otherwise used (and therefore may not be
14534 reference_to_unused (tree * tp, int * walk_subtrees,
14535 void * data ATTRIBUTE_UNUSED)
14537 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
14538 *walk_subtrees = 0;
14540 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
14541 && ! TREE_ASM_WRITTEN (*tp))
14543 /* ??? The C++ FE emits debug information for using decls, so
14544 putting gcc_unreachable here falls over. See PR31899. For now
14545 be conservative. */
14546 else if (!cgraph_global_info_ready
14547 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
14549 else if (TREE_CODE (*tp) == VAR_DECL)
14551 struct varpool_node *node = varpool_get_node (*tp);
14552 if (!node || !node->needed)
14555 else if (TREE_CODE (*tp) == FUNCTION_DECL
14556 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
14558 /* The call graph machinery must have finished analyzing,
14559 optimizing and gimplifying the CU by now.
14560 So if *TP has no call graph node associated
14561 to it, it means *TP will not be emitted. */
14562 if (!cgraph_get_node (*tp))
14565 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
14571 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14572 for use in a later add_const_value_attribute call. */
14575 rtl_for_decl_init (tree init, tree type)
14577 rtx rtl = NULL_RTX;
14581 /* If a variable is initialized with a string constant without embedded
14582 zeros, build CONST_STRING. */
14583 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
14585 tree enttype = TREE_TYPE (type);
14586 tree domain = TYPE_DOMAIN (type);
14587 enum machine_mode mode = TYPE_MODE (enttype);
14589 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
14591 && integer_zerop (TYPE_MIN_VALUE (domain))
14592 && compare_tree_int (TYPE_MAX_VALUE (domain),
14593 TREE_STRING_LENGTH (init) - 1) == 0
14594 && ((size_t) TREE_STRING_LENGTH (init)
14595 == strlen (TREE_STRING_POINTER (init)) + 1))
14597 rtl = gen_rtx_CONST_STRING (VOIDmode,
14598 ggc_strdup (TREE_STRING_POINTER (init)));
14599 rtl = gen_rtx_MEM (BLKmode, rtl);
14600 MEM_READONLY_P (rtl) = 1;
14603 /* Other aggregates, and complex values, could be represented using
14605 else if (AGGREGATE_TYPE_P (type)
14606 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
14607 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
14608 || TREE_CODE (type) == COMPLEX_TYPE)
14610 /* Vectors only work if their mode is supported by the target.
14611 FIXME: generic vectors ought to work too. */
14612 else if (TREE_CODE (type) == VECTOR_TYPE
14613 && !VECTOR_MODE_P (TYPE_MODE (type)))
14615 /* If the initializer is something that we know will expand into an
14616 immediate RTL constant, expand it now. We must be careful not to
14617 reference variables which won't be output. */
14618 else if (initializer_constant_valid_p (init, type)
14619 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
14621 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14623 if (TREE_CODE (type) == VECTOR_TYPE)
14624 switch (TREE_CODE (init))
14629 if (TREE_CONSTANT (init))
14631 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
14632 bool constant_p = true;
14634 unsigned HOST_WIDE_INT ix;
14636 /* Even when ctor is constant, it might contain non-*_CST
14637 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14638 belong into VECTOR_CST nodes. */
14639 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
14640 if (!CONSTANT_CLASS_P (value))
14642 constant_p = false;
14648 init = build_vector_from_ctor (type, elts);
14658 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
14660 /* If expand_expr returns a MEM, it wasn't immediate. */
14661 gcc_assert (!rtl || !MEM_P (rtl));
14667 /* Generate RTL for the variable DECL to represent its location. */
14670 rtl_for_decl_location (tree decl)
14674 /* Here we have to decide where we are going to say the parameter "lives"
14675 (as far as the debugger is concerned). We only have a couple of
14676 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14678 DECL_RTL normally indicates where the parameter lives during most of the
14679 activation of the function. If optimization is enabled however, this
14680 could be either NULL or else a pseudo-reg. Both of those cases indicate
14681 that the parameter doesn't really live anywhere (as far as the code
14682 generation parts of GCC are concerned) during most of the function's
14683 activation. That will happen (for example) if the parameter is never
14684 referenced within the function.
14686 We could just generate a location descriptor here for all non-NULL
14687 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14688 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14689 where DECL_RTL is NULL or is a pseudo-reg.
14691 Note however that we can only get away with using DECL_INCOMING_RTL as
14692 a backup substitute for DECL_RTL in certain limited cases. In cases
14693 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14694 we can be sure that the parameter was passed using the same type as it is
14695 declared to have within the function, and that its DECL_INCOMING_RTL
14696 points us to a place where a value of that type is passed.
14698 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14699 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14700 because in these cases DECL_INCOMING_RTL points us to a value of some
14701 type which is *different* from the type of the parameter itself. Thus,
14702 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14703 such cases, the debugger would end up (for example) trying to fetch a
14704 `float' from a place which actually contains the first part of a
14705 `double'. That would lead to really incorrect and confusing
14706 output at debug-time.
14708 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14709 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14710 are a couple of exceptions however. On little-endian machines we can
14711 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14712 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14713 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14714 when (on a little-endian machine) a non-prototyped function has a
14715 parameter declared to be of type `short' or `char'. In such cases,
14716 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14717 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14718 passed `int' value. If the debugger then uses that address to fetch
14719 a `short' or a `char' (on a little-endian machine) the result will be
14720 the correct data, so we allow for such exceptional cases below.
14722 Note that our goal here is to describe the place where the given formal
14723 parameter lives during most of the function's activation (i.e. between the
14724 end of the prologue and the start of the epilogue). We'll do that as best
14725 as we can. Note however that if the given formal parameter is modified
14726 sometime during the execution of the function, then a stack backtrace (at
14727 debug-time) will show the function as having been called with the *new*
14728 value rather than the value which was originally passed in. This happens
14729 rarely enough that it is not a major problem, but it *is* a problem, and
14730 I'd like to fix it.
14732 A future version of dwarf2out.c may generate two additional attributes for
14733 any given DW_TAG_formal_parameter DIE which will describe the "passed
14734 type" and the "passed location" for the given formal parameter in addition
14735 to the attributes we now generate to indicate the "declared type" and the
14736 "active location" for each parameter. This additional set of attributes
14737 could be used by debuggers for stack backtraces. Separately, note that
14738 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
14739 This happens (for example) for inlined-instances of inline function formal
14740 parameters which are never referenced. This really shouldn't be
14741 happening. All PARM_DECL nodes should get valid non-NULL
14742 DECL_INCOMING_RTL values. FIXME. */
14744 /* Use DECL_RTL as the "location" unless we find something better. */
14745 rtl = DECL_RTL_IF_SET (decl);
14747 /* When generating abstract instances, ignore everything except
14748 constants, symbols living in memory, and symbols living in
14749 fixed registers. */
14750 if (! reload_completed)
14753 && (CONSTANT_P (rtl)
14755 && CONSTANT_P (XEXP (rtl, 0)))
14757 && TREE_CODE (decl) == VAR_DECL
14758 && TREE_STATIC (decl))))
14760 rtl = targetm.delegitimize_address (rtl);
14765 else if (TREE_CODE (decl) == PARM_DECL)
14767 if (rtl == NULL_RTX
14768 || is_pseudo_reg (rtl)
14770 && is_pseudo_reg (XEXP (rtl, 0))
14771 && DECL_INCOMING_RTL (decl)
14772 && MEM_P (DECL_INCOMING_RTL (decl))
14773 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
14775 tree declared_type = TREE_TYPE (decl);
14776 tree passed_type = DECL_ARG_TYPE (decl);
14777 enum machine_mode dmode = TYPE_MODE (declared_type);
14778 enum machine_mode pmode = TYPE_MODE (passed_type);
14780 /* This decl represents a formal parameter which was optimized out.
14781 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
14782 all cases where (rtl == NULL_RTX) just below. */
14783 if (dmode == pmode)
14784 rtl = DECL_INCOMING_RTL (decl);
14785 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
14786 && SCALAR_INT_MODE_P (dmode)
14787 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
14788 && DECL_INCOMING_RTL (decl))
14790 rtx inc = DECL_INCOMING_RTL (decl);
14793 else if (MEM_P (inc))
14795 if (BYTES_BIG_ENDIAN)
14796 rtl = adjust_address_nv (inc, dmode,
14797 GET_MODE_SIZE (pmode)
14798 - GET_MODE_SIZE (dmode));
14805 /* If the parm was passed in registers, but lives on the stack, then
14806 make a big endian correction if the mode of the type of the
14807 parameter is not the same as the mode of the rtl. */
14808 /* ??? This is the same series of checks that are made in dbxout.c before
14809 we reach the big endian correction code there. It isn't clear if all
14810 of these checks are necessary here, but keeping them all is the safe
14812 else if (MEM_P (rtl)
14813 && XEXP (rtl, 0) != const0_rtx
14814 && ! CONSTANT_P (XEXP (rtl, 0))
14815 /* Not passed in memory. */
14816 && !MEM_P (DECL_INCOMING_RTL (decl))
14817 /* Not passed by invisible reference. */
14818 && (!REG_P (XEXP (rtl, 0))
14819 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
14820 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
14821 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
14822 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
14825 /* Big endian correction check. */
14826 && BYTES_BIG_ENDIAN
14827 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
14828 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
14831 int offset = (UNITS_PER_WORD
14832 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
14834 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
14835 plus_constant (XEXP (rtl, 0), offset));
14838 else if (TREE_CODE (decl) == VAR_DECL
14841 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
14842 && BYTES_BIG_ENDIAN)
14844 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
14845 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
14847 /* If a variable is declared "register" yet is smaller than
14848 a register, then if we store the variable to memory, it
14849 looks like we're storing a register-sized value, when in
14850 fact we are not. We need to adjust the offset of the
14851 storage location to reflect the actual value's bytes,
14852 else gdb will not be able to display it. */
14854 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
14855 plus_constant (XEXP (rtl, 0), rsize-dsize));
14858 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
14859 and will have been substituted directly into all expressions that use it.
14860 C does not have such a concept, but C++ and other languages do. */
14861 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
14862 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
14865 rtl = targetm.delegitimize_address (rtl);
14867 /* If we don't look past the constant pool, we risk emitting a
14868 reference to a constant pool entry that isn't referenced from
14869 code, and thus is not emitted. */
14871 rtl = avoid_constant_pool_reference (rtl);
14873 /* Try harder to get a rtl. If this symbol ends up not being emitted
14874 in the current CU, resolve_addr will remove the expression referencing
14876 if (rtl == NULL_RTX
14877 && TREE_CODE (decl) == VAR_DECL
14878 && !DECL_EXTERNAL (decl)
14879 && TREE_STATIC (decl)
14880 && DECL_NAME (decl)
14881 && !DECL_HARD_REGISTER (decl)
14882 && DECL_MODE (decl) != VOIDmode)
14884 rtl = make_decl_rtl_for_debug (decl);
14886 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
14887 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
14894 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
14895 returned. If so, the decl for the COMMON block is returned, and the
14896 value is the offset into the common block for the symbol. */
14899 fortran_common (tree decl, HOST_WIDE_INT *value)
14901 tree val_expr, cvar;
14902 enum machine_mode mode;
14903 HOST_WIDE_INT bitsize, bitpos;
14905 int volatilep = 0, unsignedp = 0;
14907 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
14908 it does not have a value (the offset into the common area), or if it
14909 is thread local (as opposed to global) then it isn't common, and shouldn't
14910 be handled as such. */
14911 if (TREE_CODE (decl) != VAR_DECL
14912 || !TREE_STATIC (decl)
14913 || !DECL_HAS_VALUE_EXPR_P (decl)
14917 val_expr = DECL_VALUE_EXPR (decl);
14918 if (TREE_CODE (val_expr) != COMPONENT_REF)
14921 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
14922 &mode, &unsignedp, &volatilep, true);
14924 if (cvar == NULL_TREE
14925 || TREE_CODE (cvar) != VAR_DECL
14926 || DECL_ARTIFICIAL (cvar)
14927 || !TREE_PUBLIC (cvar))
14931 if (offset != NULL)
14933 if (!host_integerp (offset, 0))
14935 *value = tree_low_cst (offset, 0);
14938 *value += bitpos / BITS_PER_UNIT;
14943 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
14944 data attribute for a variable or a parameter. We generate the
14945 DW_AT_const_value attribute only in those cases where the given variable
14946 or parameter does not have a true "location" either in memory or in a
14947 register. This can happen (for example) when a constant is passed as an
14948 actual argument in a call to an inline function. (It's possible that
14949 these things can crop up in other ways also.) Note that one type of
14950 constant value which can be passed into an inlined function is a constant
14951 pointer. This can happen for example if an actual argument in an inlined
14952 function call evaluates to a compile-time constant address.
14954 CACHE_P is true if it is worth caching the location list for DECL,
14955 so that future calls can reuse it rather than regenerate it from scratch.
14956 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
14957 since we will need to refer to them each time the function is inlined. */
14960 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
14961 enum dwarf_attribute attr)
14964 dw_loc_list_ref list;
14965 var_loc_list *loc_list;
14966 cached_dw_loc_list *cache;
14969 if (TREE_CODE (decl) == ERROR_MARK)
14972 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
14973 || TREE_CODE (decl) == RESULT_DECL);
14975 /* Try to get some constant RTL for this decl, and use that as the value of
14978 rtl = rtl_for_decl_location (decl);
14979 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
14980 && add_const_value_attribute (die, rtl))
14983 /* See if we have single element location list that is equivalent to
14984 a constant value. That way we are better to use add_const_value_attribute
14985 rather than expanding constant value equivalent. */
14986 loc_list = lookup_decl_loc (decl);
14989 && loc_list->first->next == NULL
14990 && NOTE_P (loc_list->first->loc)
14991 && NOTE_VAR_LOCATION (loc_list->first->loc)
14992 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
14994 struct var_loc_node *node;
14996 node = loc_list->first;
14997 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
14998 if (GET_CODE (rtl) == EXPR_LIST)
14999 rtl = XEXP (rtl, 0);
15000 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
15001 && add_const_value_attribute (die, rtl))
15004 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15005 list several times. See if we've already cached the contents. */
15007 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
15011 cache = (cached_dw_loc_list *)
15012 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
15014 list = cache->loc_list;
15018 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
15019 /* It is usually worth caching this result if the decl is from
15020 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15021 if (cache_p && list && list->dw_loc_next)
15023 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
15024 DECL_UID (decl), INSERT);
15025 cache = ggc_alloc_cleared_cached_dw_loc_list ();
15026 cache->decl_id = DECL_UID (decl);
15027 cache->loc_list = list;
15033 add_AT_location_description (die, attr, list);
15036 /* None of that worked, so it must not really have a location;
15037 try adding a constant value attribute from the DECL_INITIAL. */
15038 return tree_add_const_value_attribute_for_decl (die, decl);
15041 /* Add VARIABLE and DIE into deferred locations list. */
15044 defer_location (tree variable, dw_die_ref die)
15046 deferred_locations entry;
15047 entry.variable = variable;
15049 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
15052 /* Helper function for tree_add_const_value_attribute. Natively encode
15053 initializer INIT into an array. Return true if successful. */
15056 native_encode_initializer (tree init, unsigned char *array, int size)
15060 if (init == NULL_TREE)
15064 switch (TREE_CODE (init))
15067 type = TREE_TYPE (init);
15068 if (TREE_CODE (type) == ARRAY_TYPE)
15070 tree enttype = TREE_TYPE (type);
15071 enum machine_mode mode = TYPE_MODE (enttype);
15073 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
15075 if (int_size_in_bytes (type) != size)
15077 if (size > TREE_STRING_LENGTH (init))
15079 memcpy (array, TREE_STRING_POINTER (init),
15080 TREE_STRING_LENGTH (init));
15081 memset (array + TREE_STRING_LENGTH (init),
15082 '\0', size - TREE_STRING_LENGTH (init));
15085 memcpy (array, TREE_STRING_POINTER (init), size);
15090 type = TREE_TYPE (init);
15091 if (int_size_in_bytes (type) != size)
15093 if (TREE_CODE (type) == ARRAY_TYPE)
15095 HOST_WIDE_INT min_index;
15096 unsigned HOST_WIDE_INT cnt;
15097 int curpos = 0, fieldsize;
15098 constructor_elt *ce;
15100 if (TYPE_DOMAIN (type) == NULL_TREE
15101 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
15104 fieldsize = int_size_in_bytes (TREE_TYPE (type));
15105 if (fieldsize <= 0)
15108 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
15109 memset (array, '\0', size);
15110 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
15112 tree val = ce->value;
15113 tree index = ce->index;
15115 if (index && TREE_CODE (index) == RANGE_EXPR)
15116 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
15119 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
15124 if (!native_encode_initializer (val, array + pos, fieldsize))
15127 curpos = pos + fieldsize;
15128 if (index && TREE_CODE (index) == RANGE_EXPR)
15130 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
15131 - tree_low_cst (TREE_OPERAND (index, 0), 0);
15132 while (count-- > 0)
15135 memcpy (array + curpos, array + pos, fieldsize);
15136 curpos += fieldsize;
15139 gcc_assert (curpos <= size);
15143 else if (TREE_CODE (type) == RECORD_TYPE
15144 || TREE_CODE (type) == UNION_TYPE)
15146 tree field = NULL_TREE;
15147 unsigned HOST_WIDE_INT cnt;
15148 constructor_elt *ce;
15150 if (int_size_in_bytes (type) != size)
15153 if (TREE_CODE (type) == RECORD_TYPE)
15154 field = TYPE_FIELDS (type);
15156 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
15158 tree val = ce->value;
15159 int pos, fieldsize;
15161 if (ce->index != 0)
15167 if (field == NULL_TREE || DECL_BIT_FIELD (field))
15170 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
15171 && TYPE_DOMAIN (TREE_TYPE (field))
15172 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
15174 else if (DECL_SIZE_UNIT (field) == NULL_TREE
15175 || !host_integerp (DECL_SIZE_UNIT (field), 0))
15177 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
15178 pos = int_byte_position (field);
15179 gcc_assert (pos + fieldsize <= size);
15181 && !native_encode_initializer (val, array + pos, fieldsize))
15187 case VIEW_CONVERT_EXPR:
15188 case NON_LVALUE_EXPR:
15189 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
15191 return native_encode_expr (init, array, size) == size;
15195 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15196 attribute is the const value T. */
15199 tree_add_const_value_attribute (dw_die_ref die, tree t)
15202 tree type = TREE_TYPE (t);
15205 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
15209 gcc_assert (!DECL_P (init));
15211 rtl = rtl_for_decl_init (init, type);
15213 return add_const_value_attribute (die, rtl);
15214 /* If the host and target are sane, try harder. */
15215 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
15216 && initializer_constant_valid_p (init, type))
15218 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
15219 if (size > 0 && (int) size == size)
15221 unsigned char *array = (unsigned char *)
15222 ggc_alloc_cleared_atomic (size);
15224 if (native_encode_initializer (init, array, size))
15226 add_AT_vec (die, DW_AT_const_value, size, 1, array);
15234 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15235 attribute is the const value of T, where T is an integral constant
15236 variable with static storage duration
15237 (so it can't be a PARM_DECL or a RESULT_DECL). */
15240 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
15244 || (TREE_CODE (decl) != VAR_DECL
15245 && TREE_CODE (decl) != CONST_DECL)
15246 || (TREE_CODE (decl) == VAR_DECL
15247 && !TREE_STATIC (decl)))
15250 if (TREE_READONLY (decl)
15251 && ! TREE_THIS_VOLATILE (decl)
15252 && DECL_INITIAL (decl))
15257 /* Don't add DW_AT_const_value if abstract origin already has one. */
15258 if (get_AT (var_die, DW_AT_const_value))
15261 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
15264 /* Convert the CFI instructions for the current function into a
15265 location list. This is used for DW_AT_frame_base when we targeting
15266 a dwarf2 consumer that does not support the dwarf3
15267 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15270 static dw_loc_list_ref
15271 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
15275 dw_loc_list_ref list, *list_tail;
15277 dw_cfa_location last_cfa, next_cfa;
15278 const char *start_label, *last_label, *section;
15279 dw_cfa_location remember;
15282 gcc_assert (fde != NULL);
15284 section = secname_for_decl (current_function_decl);
15288 memset (&next_cfa, 0, sizeof (next_cfa));
15289 next_cfa.reg = INVALID_REGNUM;
15290 remember = next_cfa;
15292 start_label = fde->dw_fde_begin;
15294 /* ??? Bald assumption that the CIE opcode list does not contain
15295 advance opcodes. */
15296 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
15297 lookup_cfa_1 (cfi, &next_cfa, &remember);
15299 last_cfa = next_cfa;
15300 last_label = start_label;
15302 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
15304 /* If the first partition contained no CFI adjustments, the
15305 CIE opcodes apply to the whole first partition. */
15306 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15307 fde->dw_fde_begin, fde->dw_fde_end, section);
15308 list_tail =&(*list_tail)->dw_loc_next;
15309 start_label = last_label = fde->dw_fde_second_begin;
15312 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
15314 switch (cfi->dw_cfi_opc)
15316 case DW_CFA_set_loc:
15317 case DW_CFA_advance_loc1:
15318 case DW_CFA_advance_loc2:
15319 case DW_CFA_advance_loc4:
15320 if (!cfa_equal_p (&last_cfa, &next_cfa))
15322 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15323 start_label, last_label, section);
15325 list_tail = &(*list_tail)->dw_loc_next;
15326 last_cfa = next_cfa;
15327 start_label = last_label;
15329 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
15332 case DW_CFA_advance_loc:
15333 /* The encoding is complex enough that we should never emit this. */
15334 gcc_unreachable ();
15337 lookup_cfa_1 (cfi, &next_cfa, &remember);
15340 if (ix + 1 == fde->dw_fde_switch_cfi_index)
15342 if (!cfa_equal_p (&last_cfa, &next_cfa))
15344 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15345 start_label, last_label, section);
15347 list_tail = &(*list_tail)->dw_loc_next;
15348 last_cfa = next_cfa;
15349 start_label = last_label;
15351 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15352 start_label, fde->dw_fde_end, section);
15353 list_tail = &(*list_tail)->dw_loc_next;
15354 start_label = last_label = fde->dw_fde_second_begin;
15358 if (!cfa_equal_p (&last_cfa, &next_cfa))
15360 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15361 start_label, last_label, section);
15362 list_tail = &(*list_tail)->dw_loc_next;
15363 start_label = last_label;
15366 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
15368 fde->dw_fde_second_begin
15369 ? fde->dw_fde_second_end : fde->dw_fde_end,
15372 if (list && list->dw_loc_next)
15378 /* Compute a displacement from the "steady-state frame pointer" to the
15379 frame base (often the same as the CFA), and store it in
15380 frame_pointer_fb_offset. OFFSET is added to the displacement
15381 before the latter is negated. */
15384 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
15388 #ifdef FRAME_POINTER_CFA_OFFSET
15389 reg = frame_pointer_rtx;
15390 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
15392 reg = arg_pointer_rtx;
15393 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
15396 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
15397 if (GET_CODE (elim) == PLUS)
15399 offset += INTVAL (XEXP (elim, 1));
15400 elim = XEXP (elim, 0);
15403 frame_pointer_fb_offset = -offset;
15405 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15406 in which to eliminate. This is because it's stack pointer isn't
15407 directly accessible as a register within the ISA. To work around
15408 this, assume that while we cannot provide a proper value for
15409 frame_pointer_fb_offset, we won't need one either. */
15410 frame_pointer_fb_offset_valid
15411 = ((SUPPORTS_STACK_ALIGNMENT
15412 && (elim == hard_frame_pointer_rtx
15413 || elim == stack_pointer_rtx))
15414 || elim == (frame_pointer_needed
15415 ? hard_frame_pointer_rtx
15416 : stack_pointer_rtx));
15419 /* Generate a DW_AT_name attribute given some string value to be included as
15420 the value of the attribute. */
15423 add_name_attribute (dw_die_ref die, const char *name_string)
15425 if (name_string != NULL && *name_string != 0)
15427 if (demangle_name_func)
15428 name_string = (*demangle_name_func) (name_string);
15430 add_AT_string (die, DW_AT_name, name_string);
15434 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15435 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15436 of TYPE accordingly.
15438 ??? This is a temporary measure until after we're able to generate
15439 regular DWARF for the complex Ada type system. */
15442 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
15443 dw_die_ref context_die)
15446 dw_die_ref dtype_die;
15448 if (!lang_hooks.types.descriptive_type)
15451 dtype = lang_hooks.types.descriptive_type (type);
15455 dtype_die = lookup_type_die (dtype);
15458 /* The descriptive type indirectly references TYPE if this is also the
15459 case for TYPE itself. Do not deal with the circularity here. */
15460 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) = 1;
15461 gen_type_die (dtype, context_die);
15462 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) = 0;
15463 dtype_die = lookup_type_die (dtype);
15464 gcc_assert (dtype_die);
15467 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
15470 /* Generate a DW_AT_comp_dir attribute for DIE. */
15473 add_comp_dir_attribute (dw_die_ref die)
15475 const char *wd = get_src_pwd ();
15481 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
15485 wdlen = strlen (wd);
15486 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
15488 wd1 [wdlen] = DIR_SEPARATOR;
15489 wd1 [wdlen + 1] = 0;
15493 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
15496 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15500 lower_bound_default (void)
15502 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
15507 case DW_LANG_C_plus_plus:
15509 case DW_LANG_ObjC_plus_plus:
15512 case DW_LANG_Fortran77:
15513 case DW_LANG_Fortran90:
15514 case DW_LANG_Fortran95:
15518 case DW_LANG_Python:
15519 return dwarf_version >= 4 ? 0 : -1;
15520 case DW_LANG_Ada95:
15521 case DW_LANG_Ada83:
15522 case DW_LANG_Cobol74:
15523 case DW_LANG_Cobol85:
15524 case DW_LANG_Pascal83:
15525 case DW_LANG_Modula2:
15527 return dwarf_version >= 4 ? 1 : -1;
15533 /* Given a tree node describing an array bound (either lower or upper) output
15534 a representation for that bound. */
15537 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
15539 switch (TREE_CODE (bound))
15544 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15547 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
15550 /* Use the default if possible. */
15551 if (bound_attr == DW_AT_lower_bound
15552 && host_integerp (bound, 0)
15553 && (dflt = lower_bound_default ()) != -1
15554 && tree_low_cst (bound, 0) == dflt)
15557 /* Otherwise represent the bound as an unsigned value with the
15558 precision of its type. The precision and signedness of the
15559 type will be necessary to re-interpret it unambiguously. */
15560 else if (prec < HOST_BITS_PER_WIDE_INT)
15562 unsigned HOST_WIDE_INT mask
15563 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
15564 add_AT_unsigned (subrange_die, bound_attr,
15565 TREE_INT_CST_LOW (bound) & mask);
15567 else if (prec == HOST_BITS_PER_WIDE_INT
15568 || TREE_INT_CST_HIGH (bound) == 0)
15569 add_AT_unsigned (subrange_die, bound_attr,
15570 TREE_INT_CST_LOW (bound));
15572 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
15573 TREE_INT_CST_LOW (bound));
15578 case VIEW_CONVERT_EXPR:
15579 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
15589 dw_die_ref decl_die = lookup_decl_die (bound);
15591 /* ??? Can this happen, or should the variable have been bound
15592 first? Probably it can, since I imagine that we try to create
15593 the types of parameters in the order in which they exist in
15594 the list, and won't have created a forward reference to a
15595 later parameter. */
15596 if (decl_die != NULL)
15598 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15606 /* Otherwise try to create a stack operation procedure to
15607 evaluate the value of the array bound. */
15609 dw_die_ref ctx, decl_die;
15610 dw_loc_list_ref list;
15612 list = loc_list_from_tree (bound, 2);
15613 if (list == NULL || single_element_loc_list_p (list))
15615 /* If DW_AT_*bound is not a reference nor constant, it is
15616 a DWARF expression rather than location description.
15617 For that loc_list_from_tree (bound, 0) is needed.
15618 If that fails to give a single element list,
15619 fall back to outputting this as a reference anyway. */
15620 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
15621 if (list2 && single_element_loc_list_p (list2))
15623 add_AT_loc (subrange_die, bound_attr, list2->expr);
15630 if (current_function_decl == 0)
15631 ctx = comp_unit_die ();
15633 ctx = lookup_decl_die (current_function_decl);
15635 decl_die = new_die (DW_TAG_variable, ctx, bound);
15636 add_AT_flag (decl_die, DW_AT_artificial, 1);
15637 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
15638 add_AT_location_description (decl_die, DW_AT_location, list);
15639 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15645 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15646 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15647 Note that the block of subscript information for an array type also
15648 includes information about the element type of the given array type. */
15651 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
15653 unsigned dimension_number;
15655 dw_die_ref subrange_die;
15657 for (dimension_number = 0;
15658 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
15659 type = TREE_TYPE (type), dimension_number++)
15661 tree domain = TYPE_DOMAIN (type);
15663 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
15666 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15667 and (in GNU C only) variable bounds. Handle all three forms
15669 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
15672 /* We have an array type with specified bounds. */
15673 lower = TYPE_MIN_VALUE (domain);
15674 upper = TYPE_MAX_VALUE (domain);
15676 /* Define the index type. */
15677 if (TREE_TYPE (domain))
15679 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15680 TREE_TYPE field. We can't emit debug info for this
15681 because it is an unnamed integral type. */
15682 if (TREE_CODE (domain) == INTEGER_TYPE
15683 && TYPE_NAME (domain) == NULL_TREE
15684 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
15685 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
15688 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
15692 /* ??? If upper is NULL, the array has unspecified length,
15693 but it does have a lower bound. This happens with Fortran
15695 Since the debugger is definitely going to need to know N
15696 to produce useful results, go ahead and output the lower
15697 bound solo, and hope the debugger can cope. */
15699 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
15701 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
15704 /* Otherwise we have an array type with an unspecified length. The
15705 DWARF-2 spec does not say how to handle this; let's just leave out the
15711 add_byte_size_attribute (dw_die_ref die, tree tree_node)
15715 switch (TREE_CODE (tree_node))
15720 case ENUMERAL_TYPE:
15723 case QUAL_UNION_TYPE:
15724 size = int_size_in_bytes (tree_node);
15727 /* For a data member of a struct or union, the DW_AT_byte_size is
15728 generally given as the number of bytes normally allocated for an
15729 object of the *declared* type of the member itself. This is true
15730 even for bit-fields. */
15731 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
15734 gcc_unreachable ();
15737 /* Note that `size' might be -1 when we get to this point. If it is, that
15738 indicates that the byte size of the entity in question is variable. We
15739 have no good way of expressing this fact in Dwarf at the present time,
15740 so just let the -1 pass on through. */
15741 add_AT_unsigned (die, DW_AT_byte_size, size);
15744 /* For a FIELD_DECL node which represents a bit-field, output an attribute
15745 which specifies the distance in bits from the highest order bit of the
15746 "containing object" for the bit-field to the highest order bit of the
15749 For any given bit-field, the "containing object" is a hypothetical object
15750 (of some integral or enum type) within which the given bit-field lives. The
15751 type of this hypothetical "containing object" is always the same as the
15752 declared type of the individual bit-field itself. The determination of the
15753 exact location of the "containing object" for a bit-field is rather
15754 complicated. It's handled by the `field_byte_offset' function (above).
15756 Note that it is the size (in bytes) of the hypothetical "containing object"
15757 which will be given in the DW_AT_byte_size attribute for this bit-field.
15758 (See `byte_size_attribute' above). */
15761 add_bit_offset_attribute (dw_die_ref die, tree decl)
15763 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
15764 tree type = DECL_BIT_FIELD_TYPE (decl);
15765 HOST_WIDE_INT bitpos_int;
15766 HOST_WIDE_INT highest_order_object_bit_offset;
15767 HOST_WIDE_INT highest_order_field_bit_offset;
15768 HOST_WIDE_INT bit_offset;
15770 /* Must be a field and a bit field. */
15771 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
15773 /* We can't yet handle bit-fields whose offsets are variable, so if we
15774 encounter such things, just return without generating any attribute
15775 whatsoever. Likewise for variable or too large size. */
15776 if (! host_integerp (bit_position (decl), 0)
15777 || ! host_integerp (DECL_SIZE (decl), 1))
15780 bitpos_int = int_bit_position (decl);
15782 /* Note that the bit offset is always the distance (in bits) from the
15783 highest-order bit of the "containing object" to the highest-order bit of
15784 the bit-field itself. Since the "high-order end" of any object or field
15785 is different on big-endian and little-endian machines, the computation
15786 below must take account of these differences. */
15787 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
15788 highest_order_field_bit_offset = bitpos_int;
15790 if (! BYTES_BIG_ENDIAN)
15792 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
15793 highest_order_object_bit_offset += simple_type_size_in_bits (type);
15797 = (! BYTES_BIG_ENDIAN
15798 ? highest_order_object_bit_offset - highest_order_field_bit_offset
15799 : highest_order_field_bit_offset - highest_order_object_bit_offset);
15801 if (bit_offset < 0)
15802 add_AT_int (die, DW_AT_bit_offset, bit_offset);
15804 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
15807 /* For a FIELD_DECL node which represents a bit field, output an attribute
15808 which specifies the length in bits of the given field. */
15811 add_bit_size_attribute (dw_die_ref die, tree decl)
15813 /* Must be a field and a bit field. */
15814 gcc_assert (TREE_CODE (decl) == FIELD_DECL
15815 && DECL_BIT_FIELD_TYPE (decl));
15817 if (host_integerp (DECL_SIZE (decl), 1))
15818 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
15821 /* If the compiled language is ANSI C, then add a 'prototyped'
15822 attribute, if arg types are given for the parameters of a function. */
15825 add_prototyped_attribute (dw_die_ref die, tree func_type)
15827 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
15828 && prototype_p (func_type))
15829 add_AT_flag (die, DW_AT_prototyped, 1);
15832 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
15833 by looking in either the type declaration or object declaration
15836 static inline dw_die_ref
15837 add_abstract_origin_attribute (dw_die_ref die, tree origin)
15839 dw_die_ref origin_die = NULL;
15841 if (TREE_CODE (origin) != FUNCTION_DECL)
15843 /* We may have gotten separated from the block for the inlined
15844 function, if we're in an exception handler or some such; make
15845 sure that the abstract function has been written out.
15847 Doing this for nested functions is wrong, however; functions are
15848 distinct units, and our context might not even be inline. */
15852 fn = TYPE_STUB_DECL (fn);
15854 fn = decl_function_context (fn);
15856 dwarf2out_abstract_function (fn);
15859 if (DECL_P (origin))
15860 origin_die = lookup_decl_die (origin);
15861 else if (TYPE_P (origin))
15862 origin_die = lookup_type_die (origin);
15864 /* XXX: Functions that are never lowered don't always have correct block
15865 trees (in the case of java, they simply have no block tree, in some other
15866 languages). For these functions, there is nothing we can really do to
15867 output correct debug info for inlined functions in all cases. Rather
15868 than die, we'll just produce deficient debug info now, in that we will
15869 have variables without a proper abstract origin. In the future, when all
15870 functions are lowered, we should re-add a gcc_assert (origin_die)
15874 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
15878 /* We do not currently support the pure_virtual attribute. */
15881 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
15883 if (DECL_VINDEX (func_decl))
15885 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
15887 if (host_integerp (DECL_VINDEX (func_decl), 0))
15888 add_AT_loc (die, DW_AT_vtable_elem_location,
15889 new_loc_descr (DW_OP_constu,
15890 tree_low_cst (DECL_VINDEX (func_decl), 0),
15893 /* GNU extension: Record what type this method came from originally. */
15894 if (debug_info_level > DINFO_LEVEL_TERSE
15895 && DECL_CONTEXT (func_decl))
15896 add_AT_die_ref (die, DW_AT_containing_type,
15897 lookup_type_die (DECL_CONTEXT (func_decl)));
15901 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
15902 given decl. This used to be a vendor extension until after DWARF 4
15903 standardized it. */
15906 add_linkage_attr (dw_die_ref die, tree decl)
15908 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15910 /* Mimic what assemble_name_raw does with a leading '*'. */
15911 if (name[0] == '*')
15914 if (dwarf_version >= 4)
15915 add_AT_string (die, DW_AT_linkage_name, name);
15917 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
15920 /* Add source coordinate attributes for the given decl. */
15923 add_src_coords_attributes (dw_die_ref die, tree decl)
15925 expanded_location s;
15927 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
15929 s = expand_location (DECL_SOURCE_LOCATION (decl));
15930 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
15931 add_AT_unsigned (die, DW_AT_decl_line, s.line);
15934 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
15937 add_linkage_name (dw_die_ref die, tree decl)
15939 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
15940 && TREE_PUBLIC (decl)
15941 && !DECL_ABSTRACT (decl)
15942 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
15943 && die->die_tag != DW_TAG_member)
15945 /* Defer until we have an assembler name set. */
15946 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
15948 limbo_die_node *asm_name;
15950 asm_name = ggc_alloc_cleared_limbo_die_node ();
15951 asm_name->die = die;
15952 asm_name->created_for = decl;
15953 asm_name->next = deferred_asm_name;
15954 deferred_asm_name = asm_name;
15956 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
15957 add_linkage_attr (die, decl);
15961 /* Add a DW_AT_name attribute and source coordinate attribute for the
15962 given decl, but only if it actually has a name. */
15965 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
15969 decl_name = DECL_NAME (decl);
15970 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
15972 const char *name = dwarf2_name (decl, 0);
15974 add_name_attribute (die, name);
15975 if (! DECL_ARTIFICIAL (decl))
15976 add_src_coords_attributes (die, decl);
15978 add_linkage_name (die, decl);
15981 #ifdef VMS_DEBUGGING_INFO
15982 /* Get the function's name, as described by its RTL. This may be different
15983 from the DECL_NAME name used in the source file. */
15984 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
15986 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
15987 XEXP (DECL_RTL (decl), 0));
15988 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
15990 #endif /* VMS_DEBUGGING_INFO */
15993 #ifdef VMS_DEBUGGING_INFO
15994 /* Output the debug main pointer die for VMS */
15997 dwarf2out_vms_debug_main_pointer (void)
15999 char label[MAX_ARTIFICIAL_LABEL_BYTES];
16002 /* Allocate the VMS debug main subprogram die. */
16003 die = ggc_alloc_cleared_die_node ();
16004 die->die_tag = DW_TAG_subprogram;
16005 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
16006 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
16007 current_function_funcdef_no);
16008 add_AT_lbl_id (die, DW_AT_entry_pc, label);
16010 /* Make it the first child of comp_unit_die (). */
16011 die->die_parent = comp_unit_die ();
16012 if (comp_unit_die ()->die_child)
16014 die->die_sib = comp_unit_die ()->die_child->die_sib;
16015 comp_unit_die ()->die_child->die_sib = die;
16019 die->die_sib = die;
16020 comp_unit_die ()->die_child = die;
16023 #endif /* VMS_DEBUGGING_INFO */
16025 /* Push a new declaration scope. */
16028 push_decl_scope (tree scope)
16030 VEC_safe_push (tree, gc, decl_scope_table, scope);
16033 /* Pop a declaration scope. */
16036 pop_decl_scope (void)
16038 VEC_pop (tree, decl_scope_table);
16041 /* Return the DIE for the scope that immediately contains this type.
16042 Non-named types get global scope. Named types nested in other
16043 types get their containing scope if it's open, or global scope
16044 otherwise. All other types (i.e. function-local named types) get
16045 the current active scope. */
16048 scope_die_for (tree t, dw_die_ref context_die)
16050 dw_die_ref scope_die = NULL;
16051 tree containing_scope;
16054 /* Non-types always go in the current scope. */
16055 gcc_assert (TYPE_P (t));
16057 containing_scope = TYPE_CONTEXT (t);
16059 /* Use the containing namespace if it was passed in (for a declaration). */
16060 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
16062 if (context_die == lookup_decl_die (containing_scope))
16065 containing_scope = NULL_TREE;
16068 /* Ignore function type "scopes" from the C frontend. They mean that
16069 a tagged type is local to a parmlist of a function declarator, but
16070 that isn't useful to DWARF. */
16071 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
16072 containing_scope = NULL_TREE;
16074 if (SCOPE_FILE_SCOPE_P (containing_scope))
16075 scope_die = comp_unit_die ();
16076 else if (TYPE_P (containing_scope))
16078 /* For types, we can just look up the appropriate DIE. But
16079 first we check to see if we're in the middle of emitting it
16080 so we know where the new DIE should go. */
16081 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
16082 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
16087 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
16088 || TREE_ASM_WRITTEN (containing_scope));
16089 /*We are not in the middle of emitting the type
16090 CONTAINING_SCOPE. Let's see if it's emitted already. */
16091 scope_die = lookup_type_die (containing_scope);
16093 /* If none of the current dies are suitable, we get file scope. */
16094 if (scope_die == NULL)
16095 scope_die = comp_unit_die ();
16098 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
16101 scope_die = context_die;
16106 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16109 local_scope_p (dw_die_ref context_die)
16111 for (; context_die; context_die = context_die->die_parent)
16112 if (context_die->die_tag == DW_TAG_inlined_subroutine
16113 || context_die->die_tag == DW_TAG_subprogram)
16119 /* Returns nonzero if CONTEXT_DIE is a class. */
16122 class_scope_p (dw_die_ref context_die)
16124 return (context_die
16125 && (context_die->die_tag == DW_TAG_structure_type
16126 || context_die->die_tag == DW_TAG_class_type
16127 || context_die->die_tag == DW_TAG_interface_type
16128 || context_die->die_tag == DW_TAG_union_type));
16131 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16132 whether or not to treat a DIE in this context as a declaration. */
16135 class_or_namespace_scope_p (dw_die_ref context_die)
16137 return (class_scope_p (context_die)
16138 || (context_die && context_die->die_tag == DW_TAG_namespace));
16141 /* Many forms of DIEs require a "type description" attribute. This
16142 routine locates the proper "type descriptor" die for the type given
16143 by 'type', and adds a DW_AT_type attribute below the given die. */
16146 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
16147 int decl_volatile, dw_die_ref context_die)
16149 enum tree_code code = TREE_CODE (type);
16150 dw_die_ref type_die = NULL;
16152 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16153 or fixed-point type, use the inner type. This is because we have no
16154 support for unnamed types in base_type_die. This can happen if this is
16155 an Ada subrange type. Correct solution is emit a subrange type die. */
16156 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
16157 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
16158 type = TREE_TYPE (type), code = TREE_CODE (type);
16160 if (code == ERROR_MARK
16161 /* Handle a special case. For functions whose return type is void, we
16162 generate *no* type attribute. (Note that no object may have type
16163 `void', so this only applies to function return types). */
16164 || code == VOID_TYPE)
16167 type_die = modified_type_die (type,
16168 decl_const || TYPE_READONLY (type),
16169 decl_volatile || TYPE_VOLATILE (type),
16172 if (type_die != NULL)
16173 add_AT_die_ref (object_die, DW_AT_type, type_die);
16176 /* Given an object die, add the calling convention attribute for the
16177 function call type. */
16179 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
16181 enum dwarf_calling_convention value = DW_CC_normal;
16183 value = ((enum dwarf_calling_convention)
16184 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
16187 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
16189 /* DWARF 2 doesn't provide a way to identify a program's source-level
16190 entry point. DW_AT_calling_convention attributes are only meant
16191 to describe functions' calling conventions. However, lacking a
16192 better way to signal the Fortran main program, we used this for
16193 a long time, following existing custom. Now, DWARF 4 has
16194 DW_AT_main_subprogram, which we add below, but some tools still
16195 rely on the old way, which we thus keep. */
16196 value = DW_CC_program;
16198 if (dwarf_version >= 4 || !dwarf_strict)
16199 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
16202 /* Only add the attribute if the backend requests it, and
16203 is not DW_CC_normal. */
16204 if (value && (value != DW_CC_normal))
16205 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
16208 /* Given a tree pointer to a struct, class, union, or enum type node, return
16209 a pointer to the (string) tag name for the given type, or zero if the type
16210 was declared without a tag. */
16212 static const char *
16213 type_tag (const_tree type)
16215 const char *name = 0;
16217 if (TYPE_NAME (type) != 0)
16221 /* Find the IDENTIFIER_NODE for the type name. */
16222 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
16223 && !TYPE_NAMELESS (type))
16224 t = TYPE_NAME (type);
16226 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16227 a TYPE_DECL node, regardless of whether or not a `typedef' was
16229 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16230 && ! DECL_IGNORED_P (TYPE_NAME (type)))
16232 /* We want to be extra verbose. Don't call dwarf_name if
16233 DECL_NAME isn't set. The default hook for decl_printable_name
16234 doesn't like that, and in this context it's correct to return
16235 0, instead of "<anonymous>" or the like. */
16236 if (DECL_NAME (TYPE_NAME (type))
16237 && !DECL_NAMELESS (TYPE_NAME (type)))
16238 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
16241 /* Now get the name as a string, or invent one. */
16242 if (!name && t != 0)
16243 name = IDENTIFIER_POINTER (t);
16246 return (name == 0 || *name == '\0') ? 0 : name;
16249 /* Return the type associated with a data member, make a special check
16250 for bit field types. */
16253 member_declared_type (const_tree member)
16255 return (DECL_BIT_FIELD_TYPE (member)
16256 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
16259 /* Get the decl's label, as described by its RTL. This may be different
16260 from the DECL_NAME name used in the source file. */
16263 static const char *
16264 decl_start_label (tree decl)
16267 const char *fnname;
16269 x = DECL_RTL (decl);
16270 gcc_assert (MEM_P (x));
16273 gcc_assert (GET_CODE (x) == SYMBOL_REF);
16275 fnname = XSTR (x, 0);
16280 /* These routines generate the internal representation of the DIE's for
16281 the compilation unit. Debugging information is collected by walking
16282 the declaration trees passed in from dwarf2out_decl(). */
16285 gen_array_type_die (tree type, dw_die_ref context_die)
16287 dw_die_ref scope_die = scope_die_for (type, context_die);
16288 dw_die_ref array_die;
16290 /* GNU compilers represent multidimensional array types as sequences of one
16291 dimensional array types whose element types are themselves array types.
16292 We sometimes squish that down to a single array_type DIE with multiple
16293 subscripts in the Dwarf debugging info. The draft Dwarf specification
16294 say that we are allowed to do this kind of compression in C, because
16295 there is no difference between an array of arrays and a multidimensional
16296 array. We don't do this for Ada to remain as close as possible to the
16297 actual representation, which is especially important against the language
16298 flexibilty wrt arrays of variable size. */
16300 bool collapse_nested_arrays = !is_ada ();
16303 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16304 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16305 if (TYPE_STRING_FLAG (type)
16306 && TREE_CODE (type) == ARRAY_TYPE
16308 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
16310 HOST_WIDE_INT size;
16312 array_die = new_die (DW_TAG_string_type, scope_die, type);
16313 add_name_attribute (array_die, type_tag (type));
16314 equate_type_number_to_die (type, array_die);
16315 size = int_size_in_bytes (type);
16317 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16318 else if (TYPE_DOMAIN (type) != NULL_TREE
16319 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
16320 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
16322 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
16323 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
16325 size = int_size_in_bytes (TREE_TYPE (szdecl));
16326 if (loc && size > 0)
16328 add_AT_location_description (array_die, DW_AT_string_length, loc);
16329 if (size != DWARF2_ADDR_SIZE)
16330 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16336 /* ??? The SGI dwarf reader fails for array of array of enum types
16337 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
16338 array type comes before the outer array type. We thus call gen_type_die
16339 before we new_die and must prevent nested array types collapsing for this
16342 #ifdef MIPS_DEBUGGING_INFO
16343 gen_type_die (TREE_TYPE (type), context_die);
16344 collapse_nested_arrays = false;
16347 array_die = new_die (DW_TAG_array_type, scope_die, type);
16348 add_name_attribute (array_die, type_tag (type));
16349 add_gnat_descriptive_type_attribute (array_die, type, context_die);
16350 if (TYPE_ARTIFICIAL (type))
16351 add_AT_flag (array_die, DW_AT_artificial, 1);
16352 equate_type_number_to_die (type, array_die);
16354 if (TREE_CODE (type) == VECTOR_TYPE)
16355 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
16357 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16359 && TREE_CODE (type) == ARRAY_TYPE
16360 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
16361 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
16362 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16365 /* We default the array ordering. SDB will probably do
16366 the right things even if DW_AT_ordering is not present. It's not even
16367 an issue until we start to get into multidimensional arrays anyway. If
16368 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16369 then we'll have to put the DW_AT_ordering attribute back in. (But if
16370 and when we find out that we need to put these in, we will only do so
16371 for multidimensional arrays. */
16372 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
16375 #ifdef MIPS_DEBUGGING_INFO
16376 /* The SGI compilers handle arrays of unknown bound by setting
16377 AT_declaration and not emitting any subrange DIEs. */
16378 if (TREE_CODE (type) == ARRAY_TYPE
16379 && ! TYPE_DOMAIN (type))
16380 add_AT_flag (array_die, DW_AT_declaration, 1);
16383 if (TREE_CODE (type) == VECTOR_TYPE)
16385 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16386 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
16387 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
16388 add_bound_info (subrange_die, DW_AT_upper_bound,
16389 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
16392 add_subscript_info (array_die, type, collapse_nested_arrays);
16394 /* Add representation of the type of the elements of this array type and
16395 emit the corresponding DIE if we haven't done it already. */
16396 element_type = TREE_TYPE (type);
16397 if (collapse_nested_arrays)
16398 while (TREE_CODE (element_type) == ARRAY_TYPE)
16400 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
16402 element_type = TREE_TYPE (element_type);
16405 #ifndef MIPS_DEBUGGING_INFO
16406 gen_type_die (element_type, context_die);
16409 add_type_attribute (array_die, element_type, 0, 0, context_die);
16411 if (get_AT (array_die, DW_AT_name))
16412 add_pubtype (type, array_die);
16415 static dw_loc_descr_ref
16416 descr_info_loc (tree val, tree base_decl)
16418 HOST_WIDE_INT size;
16419 dw_loc_descr_ref loc, loc2;
16420 enum dwarf_location_atom op;
16422 if (val == base_decl)
16423 return new_loc_descr (DW_OP_push_object_address, 0, 0);
16425 switch (TREE_CODE (val))
16428 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16430 return loc_descriptor_from_tree (val, 0);
16432 if (host_integerp (val, 0))
16433 return int_loc_descriptor (tree_low_cst (val, 0));
16436 size = int_size_in_bytes (TREE_TYPE (val));
16439 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16442 if (size == DWARF2_ADDR_SIZE)
16443 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
16445 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
16447 case POINTER_PLUS_EXPR:
16449 if (host_integerp (TREE_OPERAND (val, 1), 1)
16450 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
16453 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16456 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
16462 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16465 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
16468 add_loc_descr (&loc, loc2);
16469 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
16491 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
16492 tree val, tree base_decl)
16494 dw_loc_descr_ref loc;
16496 if (host_integerp (val, 0))
16498 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
16502 loc = descr_info_loc (val, base_decl);
16506 add_AT_loc (die, attr, loc);
16509 /* This routine generates DIE for array with hidden descriptor, details
16510 are filled into *info by a langhook. */
16513 gen_descr_array_type_die (tree type, struct array_descr_info *info,
16514 dw_die_ref context_die)
16516 dw_die_ref scope_die = scope_die_for (type, context_die);
16517 dw_die_ref array_die;
16520 array_die = new_die (DW_TAG_array_type, scope_die, type);
16521 add_name_attribute (array_die, type_tag (type));
16522 equate_type_number_to_die (type, array_die);
16524 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16526 && info->ndimensions >= 2)
16527 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16529 if (info->data_location)
16530 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
16532 if (info->associated)
16533 add_descr_info_field (array_die, DW_AT_associated, info->associated,
16535 if (info->allocated)
16536 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
16539 for (dim = 0; dim < info->ndimensions; dim++)
16541 dw_die_ref subrange_die
16542 = new_die (DW_TAG_subrange_type, array_die, NULL);
16544 if (info->dimen[dim].lower_bound)
16546 /* If it is the default value, omit it. */
16549 if (host_integerp (info->dimen[dim].lower_bound, 0)
16550 && (dflt = lower_bound_default ()) != -1
16551 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
16554 add_descr_info_field (subrange_die, DW_AT_lower_bound,
16555 info->dimen[dim].lower_bound,
16558 if (info->dimen[dim].upper_bound)
16559 add_descr_info_field (subrange_die, DW_AT_upper_bound,
16560 info->dimen[dim].upper_bound,
16562 if (info->dimen[dim].stride)
16563 add_descr_info_field (subrange_die, DW_AT_byte_stride,
16564 info->dimen[dim].stride,
16568 gen_type_die (info->element_type, context_die);
16569 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
16571 if (get_AT (array_die, DW_AT_name))
16572 add_pubtype (type, array_die);
16577 gen_entry_point_die (tree decl, dw_die_ref context_die)
16579 tree origin = decl_ultimate_origin (decl);
16580 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
16582 if (origin != NULL)
16583 add_abstract_origin_attribute (decl_die, origin);
16586 add_name_and_src_coords_attributes (decl_die, decl);
16587 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
16588 0, 0, context_die);
16591 if (DECL_ABSTRACT (decl))
16592 equate_decl_number_to_die (decl, decl_die);
16594 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
16598 /* Walk through the list of incomplete types again, trying once more to
16599 emit full debugging info for them. */
16602 retry_incomplete_types (void)
16606 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
16607 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
16608 DINFO_USAGE_DIR_USE))
16609 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
16612 /* Determine what tag to use for a record type. */
16614 static enum dwarf_tag
16615 record_type_tag (tree type)
16617 if (! lang_hooks.types.classify_record)
16618 return DW_TAG_structure_type;
16620 switch (lang_hooks.types.classify_record (type))
16622 case RECORD_IS_STRUCT:
16623 return DW_TAG_structure_type;
16625 case RECORD_IS_CLASS:
16626 return DW_TAG_class_type;
16628 case RECORD_IS_INTERFACE:
16629 if (dwarf_version >= 3 || !dwarf_strict)
16630 return DW_TAG_interface_type;
16631 return DW_TAG_structure_type;
16634 gcc_unreachable ();
16638 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16639 include all of the information about the enumeration values also. Each
16640 enumerated type name/value is listed as a child of the enumerated type
16644 gen_enumeration_type_die (tree type, dw_die_ref context_die)
16646 dw_die_ref type_die = lookup_type_die (type);
16648 if (type_die == NULL)
16650 type_die = new_die (DW_TAG_enumeration_type,
16651 scope_die_for (type, context_die), type);
16652 equate_type_number_to_die (type, type_die);
16653 add_name_attribute (type_die, type_tag (type));
16654 add_gnat_descriptive_type_attribute (type_die, type, context_die);
16655 if (TYPE_ARTIFICIAL (type))
16656 add_AT_flag (type_die, DW_AT_artificial, 1);
16657 if (dwarf_version >= 4 || !dwarf_strict)
16659 if (ENUM_IS_SCOPED (type))
16660 add_AT_flag (type_die, DW_AT_enum_class, 1);
16661 if (ENUM_IS_OPAQUE (type))
16662 add_AT_flag (type_die, DW_AT_declaration, 1);
16665 else if (! TYPE_SIZE (type))
16668 remove_AT (type_die, DW_AT_declaration);
16670 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16671 given enum type is incomplete, do not generate the DW_AT_byte_size
16672 attribute or the DW_AT_element_list attribute. */
16673 if (TYPE_SIZE (type))
16677 TREE_ASM_WRITTEN (type) = 1;
16678 add_byte_size_attribute (type_die, type);
16679 if (TYPE_STUB_DECL (type) != NULL_TREE)
16681 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
16682 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
16685 /* If the first reference to this type was as the return type of an
16686 inline function, then it may not have a parent. Fix this now. */
16687 if (type_die->die_parent == NULL)
16688 add_child_die (scope_die_for (type, context_die), type_die);
16690 for (link = TYPE_VALUES (type);
16691 link != NULL; link = TREE_CHAIN (link))
16693 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
16694 tree value = TREE_VALUE (link);
16696 add_name_attribute (enum_die,
16697 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
16699 if (TREE_CODE (value) == CONST_DECL)
16700 value = DECL_INITIAL (value);
16702 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
16703 /* DWARF2 does not provide a way of indicating whether or
16704 not enumeration constants are signed or unsigned. GDB
16705 always assumes the values are signed, so we output all
16706 values as if they were signed. That means that
16707 enumeration constants with very large unsigned values
16708 will appear to have negative values in the debugger. */
16709 add_AT_int (enum_die, DW_AT_const_value,
16710 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
16714 add_AT_flag (type_die, DW_AT_declaration, 1);
16716 if (get_AT (type_die, DW_AT_name))
16717 add_pubtype (type, type_die);
16722 /* Generate a DIE to represent either a real live formal parameter decl or to
16723 represent just the type of some formal parameter position in some function
16726 Note that this routine is a bit unusual because its argument may be a
16727 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
16728 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
16729 node. If it's the former then this function is being called to output a
16730 DIE to represent a formal parameter object (or some inlining thereof). If
16731 it's the latter, then this function is only being called to output a
16732 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
16733 argument type of some subprogram type.
16734 If EMIT_NAME_P is true, name and source coordinate attributes
16738 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
16739 dw_die_ref context_die)
16741 tree node_or_origin = node ? node : origin;
16742 tree ultimate_origin;
16743 dw_die_ref parm_die
16744 = new_die (DW_TAG_formal_parameter, context_die, node);
16746 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
16748 case tcc_declaration:
16749 ultimate_origin = decl_ultimate_origin (node_or_origin);
16750 if (node || ultimate_origin)
16751 origin = ultimate_origin;
16752 if (origin != NULL)
16753 add_abstract_origin_attribute (parm_die, origin);
16754 else if (emit_name_p)
16755 add_name_and_src_coords_attributes (parm_die, node);
16757 || (! DECL_ABSTRACT (node_or_origin)
16758 && variably_modified_type_p (TREE_TYPE (node_or_origin),
16759 decl_function_context
16760 (node_or_origin))))
16762 tree type = TREE_TYPE (node_or_origin);
16763 if (decl_by_reference_p (node_or_origin))
16764 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
16767 add_type_attribute (parm_die, type,
16768 TREE_READONLY (node_or_origin),
16769 TREE_THIS_VOLATILE (node_or_origin),
16772 if (origin == NULL && DECL_ARTIFICIAL (node))
16773 add_AT_flag (parm_die, DW_AT_artificial, 1);
16775 if (node && node != origin)
16776 equate_decl_number_to_die (node, parm_die);
16777 if (! DECL_ABSTRACT (node_or_origin))
16778 add_location_or_const_value_attribute (parm_die, node_or_origin,
16779 node == NULL, DW_AT_location);
16784 /* We were called with some kind of a ..._TYPE node. */
16785 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
16789 gcc_unreachable ();
16795 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
16796 children DW_TAG_formal_parameter DIEs representing the arguments of the
16799 PARM_PACK must be a function parameter pack.
16800 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
16801 must point to the subsequent arguments of the function PACK_ARG belongs to.
16802 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
16803 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
16804 following the last one for which a DIE was generated. */
16807 gen_formal_parameter_pack_die (tree parm_pack,
16809 dw_die_ref subr_die,
16813 dw_die_ref parm_pack_die;
16815 gcc_assert (parm_pack
16816 && lang_hooks.function_parameter_pack_p (parm_pack)
16819 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
16820 add_src_coords_attributes (parm_pack_die, parm_pack);
16822 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
16824 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
16827 gen_formal_parameter_die (arg, NULL,
16828 false /* Don't emit name attribute. */,
16833 return parm_pack_die;
16836 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
16837 at the end of an (ANSI prototyped) formal parameters list. */
16840 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
16842 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
16845 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
16846 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
16847 parameters as specified in some function type specification (except for
16848 those which appear as part of a function *definition*). */
16851 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
16854 tree formal_type = NULL;
16855 tree first_parm_type;
16858 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
16860 arg = DECL_ARGUMENTS (function_or_method_type);
16861 function_or_method_type = TREE_TYPE (function_or_method_type);
16866 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
16868 /* Make our first pass over the list of formal parameter types and output a
16869 DW_TAG_formal_parameter DIE for each one. */
16870 for (link = first_parm_type; link; )
16872 dw_die_ref parm_die;
16874 formal_type = TREE_VALUE (link);
16875 if (formal_type == void_type_node)
16878 /* Output a (nameless) DIE to represent the formal parameter itself. */
16879 parm_die = gen_formal_parameter_die (formal_type, NULL,
16880 true /* Emit name attribute. */,
16882 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
16883 && link == first_parm_type)
16885 add_AT_flag (parm_die, DW_AT_artificial, 1);
16886 if (dwarf_version >= 3 || !dwarf_strict)
16887 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
16889 else if (arg && DECL_ARTIFICIAL (arg))
16890 add_AT_flag (parm_die, DW_AT_artificial, 1);
16892 link = TREE_CHAIN (link);
16894 arg = DECL_CHAIN (arg);
16897 /* If this function type has an ellipsis, add a
16898 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
16899 if (formal_type != void_type_node)
16900 gen_unspecified_parameters_die (function_or_method_type, context_die);
16902 /* Make our second (and final) pass over the list of formal parameter types
16903 and output DIEs to represent those types (as necessary). */
16904 for (link = TYPE_ARG_TYPES (function_or_method_type);
16905 link && TREE_VALUE (link);
16906 link = TREE_CHAIN (link))
16907 gen_type_die (TREE_VALUE (link), context_die);
16910 /* We want to generate the DIE for TYPE so that we can generate the
16911 die for MEMBER, which has been defined; we will need to refer back
16912 to the member declaration nested within TYPE. If we're trying to
16913 generate minimal debug info for TYPE, processing TYPE won't do the
16914 trick; we need to attach the member declaration by hand. */
16917 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
16919 gen_type_die (type, context_die);
16921 /* If we're trying to avoid duplicate debug info, we may not have
16922 emitted the member decl for this function. Emit it now. */
16923 if (TYPE_STUB_DECL (type)
16924 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
16925 && ! lookup_decl_die (member))
16927 dw_die_ref type_die;
16928 gcc_assert (!decl_ultimate_origin (member));
16930 push_decl_scope (type);
16931 type_die = lookup_type_die_strip_naming_typedef (type);
16932 if (TREE_CODE (member) == FUNCTION_DECL)
16933 gen_subprogram_die (member, type_die);
16934 else if (TREE_CODE (member) == FIELD_DECL)
16936 /* Ignore the nameless fields that are used to skip bits but handle
16937 C++ anonymous unions and structs. */
16938 if (DECL_NAME (member) != NULL_TREE
16939 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
16940 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
16942 gen_type_die (member_declared_type (member), type_die);
16943 gen_field_die (member, type_die);
16947 gen_variable_die (member, NULL_TREE, type_die);
16953 /* Generate the DWARF2 info for the "abstract" instance of a function which we
16954 may later generate inlined and/or out-of-line instances of. */
16957 dwarf2out_abstract_function (tree decl)
16959 dw_die_ref old_die;
16963 htab_t old_decl_loc_table;
16964 htab_t old_cached_dw_loc_list_table;
16965 int old_call_site_count, old_tail_call_site_count;
16966 struct call_arg_loc_node *old_call_arg_locations;
16968 /* Make sure we have the actual abstract inline, not a clone. */
16969 decl = DECL_ORIGIN (decl);
16971 old_die = lookup_decl_die (decl);
16972 if (old_die && get_AT (old_die, DW_AT_inline))
16973 /* We've already generated the abstract instance. */
16976 /* We can be called while recursively when seeing block defining inlined subroutine
16977 DIE. Be sure to not clobber the outer location table nor use it or we would
16978 get locations in abstract instantces. */
16979 old_decl_loc_table = decl_loc_table;
16980 decl_loc_table = NULL;
16981 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
16982 cached_dw_loc_list_table = NULL;
16983 old_call_arg_locations = call_arg_locations;
16984 call_arg_locations = NULL;
16985 old_call_site_count = call_site_count;
16986 call_site_count = -1;
16987 old_tail_call_site_count = tail_call_site_count;
16988 tail_call_site_count = -1;
16990 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
16991 we don't get confused by DECL_ABSTRACT. */
16992 if (debug_info_level > DINFO_LEVEL_TERSE)
16994 context = decl_class_context (decl);
16996 gen_type_die_for_member
16997 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
17000 /* Pretend we've just finished compiling this function. */
17001 save_fn = current_function_decl;
17002 current_function_decl = decl;
17003 push_cfun (DECL_STRUCT_FUNCTION (decl));
17005 was_abstract = DECL_ABSTRACT (decl);
17006 set_decl_abstract_flags (decl, 1);
17007 dwarf2out_decl (decl);
17008 if (! was_abstract)
17009 set_decl_abstract_flags (decl, 0);
17011 current_function_decl = save_fn;
17012 decl_loc_table = old_decl_loc_table;
17013 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
17014 call_arg_locations = old_call_arg_locations;
17015 call_site_count = old_call_site_count;
17016 tail_call_site_count = old_tail_call_site_count;
17020 /* Helper function of premark_used_types() which gets called through
17023 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17024 marked as unused by prune_unused_types. */
17027 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
17032 type = (tree) *slot;
17033 die = lookup_type_die (type);
17035 die->die_perennial_p = 1;
17039 /* Helper function of premark_types_used_by_global_vars which gets called
17040 through htab_traverse.
17042 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17043 marked as unused by prune_unused_types. The DIE of the type is marked
17044 only if the global variable using the type will actually be emitted. */
17047 premark_types_used_by_global_vars_helper (void **slot,
17048 void *data ATTRIBUTE_UNUSED)
17050 struct types_used_by_vars_entry *entry;
17053 entry = (struct types_used_by_vars_entry *) *slot;
17054 gcc_assert (entry->type != NULL
17055 && entry->var_decl != NULL);
17056 die = lookup_type_die (entry->type);
17059 /* Ask cgraph if the global variable really is to be emitted.
17060 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17061 struct varpool_node *node = varpool_get_node (entry->var_decl);
17062 if (node && node->needed)
17064 die->die_perennial_p = 1;
17065 /* Keep the parent DIEs as well. */
17066 while ((die = die->die_parent) && die->die_perennial_p == 0)
17067 die->die_perennial_p = 1;
17073 /* Mark all members of used_types_hash as perennial. */
17076 premark_used_types (void)
17078 if (cfun && cfun->used_types_hash)
17079 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
17082 /* Mark all members of types_used_by_vars_entry as perennial. */
17085 premark_types_used_by_global_vars (void)
17087 if (types_used_by_vars_hash)
17088 htab_traverse (types_used_by_vars_hash,
17089 premark_types_used_by_global_vars_helper, NULL);
17092 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17093 for CA_LOC call arg loc node. */
17096 gen_call_site_die (tree decl, dw_die_ref subr_die,
17097 struct call_arg_loc_node *ca_loc)
17099 dw_die_ref stmt_die = NULL, die;
17100 tree block = ca_loc->block;
17103 && block != DECL_INITIAL (decl)
17104 && TREE_CODE (block) == BLOCK)
17106 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
17107 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
17110 block = BLOCK_SUPERCONTEXT (block);
17112 if (stmt_die == NULL)
17113 stmt_die = subr_die;
17114 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
17115 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
17116 if (ca_loc->tail_call_p)
17117 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
17118 if (ca_loc->symbol_ref)
17120 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
17122 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
17124 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
17129 /* Generate a DIE to represent a declared function (either file-scope or
17133 gen_subprogram_die (tree decl, dw_die_ref context_die)
17135 tree origin = decl_ultimate_origin (decl);
17136 dw_die_ref subr_die;
17138 dw_die_ref old_die = lookup_decl_die (decl);
17139 int declaration = (current_function_decl != decl
17140 || class_or_namespace_scope_p (context_die));
17142 premark_used_types ();
17144 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17145 started to generate the abstract instance of an inline, decided to output
17146 its containing class, and proceeded to emit the declaration of the inline
17147 from the member list for the class. If so, DECLARATION takes priority;
17148 we'll get back to the abstract instance when done with the class. */
17150 /* The class-scope declaration DIE must be the primary DIE. */
17151 if (origin && declaration && class_or_namespace_scope_p (context_die))
17154 gcc_assert (!old_die);
17157 /* Now that the C++ front end lazily declares artificial member fns, we
17158 might need to retrofit the declaration into its class. */
17159 if (!declaration && !origin && !old_die
17160 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
17161 && !class_or_namespace_scope_p (context_die)
17162 && debug_info_level > DINFO_LEVEL_TERSE)
17163 old_die = force_decl_die (decl);
17165 if (origin != NULL)
17167 gcc_assert (!declaration || local_scope_p (context_die));
17169 /* Fixup die_parent for the abstract instance of a nested
17170 inline function. */
17171 if (old_die && old_die->die_parent == NULL)
17172 add_child_die (context_die, old_die);
17174 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17175 add_abstract_origin_attribute (subr_die, origin);
17176 /* This is where the actual code for a cloned function is.
17177 Let's emit linkage name attribute for it. This helps
17178 debuggers to e.g, set breakpoints into
17179 constructors/destructors when the user asks "break
17181 add_linkage_name (subr_die, decl);
17185 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17186 struct dwarf_file_data * file_index = lookup_filename (s.file);
17188 if (!get_AT_flag (old_die, DW_AT_declaration)
17189 /* We can have a normal definition following an inline one in the
17190 case of redefinition of GNU C extern inlines.
17191 It seems reasonable to use AT_specification in this case. */
17192 && !get_AT (old_die, DW_AT_inline))
17194 /* Detect and ignore this case, where we are trying to output
17195 something we have already output. */
17199 /* If the definition comes from the same place as the declaration,
17200 maybe use the old DIE. We always want the DIE for this function
17201 that has the *_pc attributes to be under comp_unit_die so the
17202 debugger can find it. We also need to do this for abstract
17203 instances of inlines, since the spec requires the out-of-line copy
17204 to have the same parent. For local class methods, this doesn't
17205 apply; we just use the old DIE. */
17206 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
17207 && (DECL_ARTIFICIAL (decl)
17208 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
17209 && (get_AT_unsigned (old_die, DW_AT_decl_line)
17210 == (unsigned) s.line))))
17212 subr_die = old_die;
17214 /* Clear out the declaration attribute and the formal parameters.
17215 Do not remove all children, because it is possible that this
17216 declaration die was forced using force_decl_die(). In such
17217 cases die that forced declaration die (e.g. TAG_imported_module)
17218 is one of the children that we do not want to remove. */
17219 remove_AT (subr_die, DW_AT_declaration);
17220 remove_AT (subr_die, DW_AT_object_pointer);
17221 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
17225 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17226 add_AT_specification (subr_die, old_die);
17227 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
17228 add_AT_file (subr_die, DW_AT_decl_file, file_index);
17229 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
17230 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
17235 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17237 if (TREE_PUBLIC (decl))
17238 add_AT_flag (subr_die, DW_AT_external, 1);
17240 add_name_and_src_coords_attributes (subr_die, decl);
17241 if (debug_info_level > DINFO_LEVEL_TERSE)
17243 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
17244 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
17245 0, 0, context_die);
17248 add_pure_or_virtual_attribute (subr_die, decl);
17249 if (DECL_ARTIFICIAL (decl))
17250 add_AT_flag (subr_die, DW_AT_artificial, 1);
17252 add_accessibility_attribute (subr_die, decl);
17257 if (!old_die || !get_AT (old_die, DW_AT_inline))
17259 add_AT_flag (subr_die, DW_AT_declaration, 1);
17261 /* If this is an explicit function declaration then generate
17262 a DW_AT_explicit attribute. */
17263 if (lang_hooks.decls.function_decl_explicit_p (decl)
17264 && (dwarf_version >= 3 || !dwarf_strict))
17265 add_AT_flag (subr_die, DW_AT_explicit, 1);
17267 /* The first time we see a member function, it is in the context of
17268 the class to which it belongs. We make sure of this by emitting
17269 the class first. The next time is the definition, which is
17270 handled above. The two may come from the same source text.
17272 Note that force_decl_die() forces function declaration die. It is
17273 later reused to represent definition. */
17274 equate_decl_number_to_die (decl, subr_die);
17277 else if (DECL_ABSTRACT (decl))
17279 if (DECL_DECLARED_INLINE_P (decl))
17281 if (cgraph_function_possibly_inlined_p (decl))
17282 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
17284 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
17288 if (cgraph_function_possibly_inlined_p (decl))
17289 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
17291 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
17294 if (DECL_DECLARED_INLINE_P (decl)
17295 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
17296 add_AT_flag (subr_die, DW_AT_artificial, 1);
17298 equate_decl_number_to_die (decl, subr_die);
17300 else if (!DECL_EXTERNAL (decl))
17302 HOST_WIDE_INT cfa_fb_offset;
17304 if (!old_die || !get_AT (old_die, DW_AT_inline))
17305 equate_decl_number_to_die (decl, subr_die);
17307 if (!flag_reorder_blocks_and_partition)
17309 dw_fde_ref fde = cfun->fde;
17310 if (fde->dw_fde_begin)
17312 /* We have already generated the labels. */
17313 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17314 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17318 /* Create start/end labels and add the range. */
17319 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
17320 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
17321 current_function_funcdef_no);
17322 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
17323 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
17324 current_function_funcdef_no);
17325 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
17328 #if VMS_DEBUGGING_INFO
17329 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17330 Section 2.3 Prologue and Epilogue Attributes:
17331 When a breakpoint is set on entry to a function, it is generally
17332 desirable for execution to be suspended, not on the very first
17333 instruction of the function, but rather at a point after the
17334 function's frame has been set up, after any language defined local
17335 declaration processing has been completed, and before execution of
17336 the first statement of the function begins. Debuggers generally
17337 cannot properly determine where this point is. Similarly for a
17338 breakpoint set on exit from a function. The prologue and epilogue
17339 attributes allow a compiler to communicate the location(s) to use. */
17342 if (fde->dw_fde_vms_end_prologue)
17343 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
17344 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
17346 if (fde->dw_fde_vms_begin_epilogue)
17347 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
17348 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
17352 add_pubname (decl, subr_die);
17356 /* Generate pubnames entries for the split function code ranges. */
17357 dw_fde_ref fde = cfun->fde;
17359 if (fde->dw_fde_second_begin)
17361 if (dwarf_version >= 3 || !dwarf_strict)
17363 /* We should use ranges for non-contiguous code section
17364 addresses. Use the actual code range for the initial
17365 section, since the HOT/COLD labels might precede an
17366 alignment offset. */
17367 bool range_list_added = false;
17368 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
17369 fde->dw_fde_end, &range_list_added);
17370 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
17371 fde->dw_fde_second_end,
17372 &range_list_added);
17373 add_pubname (decl, subr_die);
17374 if (range_list_added)
17379 /* There is no real support in DW2 for this .. so we make
17380 a work-around. First, emit the pub name for the segment
17381 containing the function label. Then make and emit a
17382 simplified subprogram DIE for the second segment with the
17383 name pre-fixed by __hot/cold_sect_of_. We use the same
17384 linkage name for the second die so that gdb will find both
17385 sections when given "b foo". */
17386 const char *name = NULL;
17387 tree decl_name = DECL_NAME (decl);
17388 dw_die_ref seg_die;
17390 /* Do the 'primary' section. */
17391 add_AT_lbl_id (subr_die, DW_AT_low_pc,
17392 fde->dw_fde_begin);
17393 add_AT_lbl_id (subr_die, DW_AT_high_pc,
17396 add_pubname (decl, subr_die);
17398 /* Build a minimal DIE for the secondary section. */
17399 seg_die = new_die (DW_TAG_subprogram,
17400 subr_die->die_parent, decl);
17402 if (TREE_PUBLIC (decl))
17403 add_AT_flag (seg_die, DW_AT_external, 1);
17405 if (decl_name != NULL
17406 && IDENTIFIER_POINTER (decl_name) != NULL)
17408 name = dwarf2_name (decl, 1);
17409 if (! DECL_ARTIFICIAL (decl))
17410 add_src_coords_attributes (seg_die, decl);
17412 add_linkage_name (seg_die, decl);
17414 gcc_assert (name != NULL);
17415 add_pure_or_virtual_attribute (seg_die, decl);
17416 if (DECL_ARTIFICIAL (decl))
17417 add_AT_flag (seg_die, DW_AT_artificial, 1);
17419 name = concat ("__second_sect_of_", name, NULL);
17420 add_AT_lbl_id (seg_die, DW_AT_low_pc,
17421 fde->dw_fde_second_begin);
17422 add_AT_lbl_id (seg_die, DW_AT_high_pc,
17423 fde->dw_fde_second_end);
17424 add_name_attribute (seg_die, name);
17425 add_pubname_string (name, seg_die);
17430 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17431 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17432 add_pubname (decl, subr_die);
17436 #ifdef MIPS_DEBUGGING_INFO
17437 /* Add a reference to the FDE for this routine. */
17438 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, cfun->fde->fde_index);
17441 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
17443 /* We define the "frame base" as the function's CFA. This is more
17444 convenient for several reasons: (1) It's stable across the prologue
17445 and epilogue, which makes it better than just a frame pointer,
17446 (2) With dwarf3, there exists a one-byte encoding that allows us
17447 to reference the .debug_frame data by proxy, but failing that,
17448 (3) We can at least reuse the code inspection and interpretation
17449 code that determines the CFA position at various points in the
17451 if (dwarf_version >= 3)
17453 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
17454 add_AT_loc (subr_die, DW_AT_frame_base, op);
17458 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
17459 if (list->dw_loc_next)
17460 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
17462 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
17465 /* Compute a displacement from the "steady-state frame pointer" to
17466 the CFA. The former is what all stack slots and argument slots
17467 will reference in the rtl; the later is what we've told the
17468 debugger about. We'll need to adjust all frame_base references
17469 by this displacement. */
17470 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
17472 if (cfun->static_chain_decl)
17473 add_AT_location_description (subr_die, DW_AT_static_link,
17474 loc_list_from_tree (cfun->static_chain_decl, 2));
17477 /* Generate child dies for template paramaters. */
17478 if (debug_info_level > DINFO_LEVEL_TERSE)
17479 gen_generic_params_dies (decl);
17481 /* Now output descriptions of the arguments for this function. This gets
17482 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17483 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17484 `...' at the end of the formal parameter list. In order to find out if
17485 there was a trailing ellipsis or not, we must instead look at the type
17486 associated with the FUNCTION_DECL. This will be a node of type
17487 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17488 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17489 an ellipsis at the end. */
17491 /* In the case where we are describing a mere function declaration, all we
17492 need to do here (and all we *can* do here) is to describe the *types* of
17493 its formal parameters. */
17494 if (debug_info_level <= DINFO_LEVEL_TERSE)
17496 else if (declaration)
17497 gen_formal_types_die (decl, subr_die);
17500 /* Generate DIEs to represent all known formal parameters. */
17501 tree parm = DECL_ARGUMENTS (decl);
17502 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
17503 tree generic_decl_parm = generic_decl
17504 ? DECL_ARGUMENTS (generic_decl)
17507 /* Now we want to walk the list of parameters of the function and
17508 emit their relevant DIEs.
17510 We consider the case of DECL being an instance of a generic function
17511 as well as it being a normal function.
17513 If DECL is an instance of a generic function we walk the
17514 parameters of the generic function declaration _and_ the parameters of
17515 DECL itself. This is useful because we want to emit specific DIEs for
17516 function parameter packs and those are declared as part of the
17517 generic function declaration. In that particular case,
17518 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17519 That DIE has children DIEs representing the set of arguments
17520 of the pack. Note that the set of pack arguments can be empty.
17521 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17524 Otherwise, we just consider the parameters of DECL. */
17525 while (generic_decl_parm || parm)
17527 if (generic_decl_parm
17528 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
17529 gen_formal_parameter_pack_die (generic_decl_parm,
17534 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
17536 if (parm == DECL_ARGUMENTS (decl)
17537 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
17539 && (dwarf_version >= 3 || !dwarf_strict))
17540 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
17542 parm = DECL_CHAIN (parm);
17545 if (generic_decl_parm)
17546 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
17549 /* Decide whether we need an unspecified_parameters DIE at the end.
17550 There are 2 more cases to do this for: 1) the ansi ... declaration -
17551 this is detectable when the end of the arg list is not a
17552 void_type_node 2) an unprototyped function declaration (not a
17553 definition). This just means that we have no info about the
17554 parameters at all. */
17555 if (prototype_p (TREE_TYPE (decl)))
17557 /* This is the prototyped case, check for.... */
17558 if (stdarg_p (TREE_TYPE (decl)))
17559 gen_unspecified_parameters_die (decl, subr_die);
17561 else if (DECL_INITIAL (decl) == NULL_TREE)
17562 gen_unspecified_parameters_die (decl, subr_die);
17565 /* Output Dwarf info for all of the stuff within the body of the function
17566 (if it has one - it may be just a declaration). */
17567 outer_scope = DECL_INITIAL (decl);
17569 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17570 a function. This BLOCK actually represents the outermost binding contour
17571 for the function, i.e. the contour in which the function's formal
17572 parameters and labels get declared. Curiously, it appears that the front
17573 end doesn't actually put the PARM_DECL nodes for the current function onto
17574 the BLOCK_VARS list for this outer scope, but are strung off of the
17575 DECL_ARGUMENTS list for the function instead.
17577 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17578 the LABEL_DECL nodes for the function however, and we output DWARF info
17579 for those in decls_for_scope. Just within the `outer_scope' there will be
17580 a BLOCK node representing the function's outermost pair of curly braces,
17581 and any blocks used for the base and member initializers of a C++
17582 constructor function. */
17583 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
17585 int call_site_note_count = 0;
17586 int tail_call_site_note_count = 0;
17588 /* Emit a DW_TAG_variable DIE for a named return value. */
17589 if (DECL_NAME (DECL_RESULT (decl)))
17590 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
17592 current_function_has_inlines = 0;
17593 decls_for_scope (outer_scope, subr_die, 0);
17595 if (call_arg_locations && !dwarf_strict)
17597 struct call_arg_loc_node *ca_loc;
17598 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
17600 dw_die_ref die = NULL;
17601 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
17604 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
17605 arg; arg = next_arg)
17607 dw_loc_descr_ref reg, val;
17608 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
17609 dw_die_ref cdie, tdie = NULL;
17611 next_arg = XEXP (arg, 1);
17612 if (REG_P (XEXP (XEXP (arg, 0), 0))
17614 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
17615 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
17616 && REGNO (XEXP (XEXP (arg, 0), 0))
17617 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
17618 next_arg = XEXP (next_arg, 1);
17619 if (mode == VOIDmode)
17621 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
17622 if (mode == VOIDmode)
17623 mode = GET_MODE (XEXP (arg, 0));
17625 if (mode == VOIDmode || mode == BLKmode)
17627 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
17629 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17630 tloc = XEXP (XEXP (arg, 0), 1);
17633 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
17634 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
17636 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17637 tlocc = XEXP (XEXP (arg, 0), 1);
17641 if (REG_P (XEXP (XEXP (arg, 0), 0)))
17642 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
17643 VAR_INIT_STATUS_INITIALIZED);
17644 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
17646 rtx mem = XEXP (XEXP (arg, 0), 0);
17647 reg = mem_loc_descriptor (XEXP (mem, 0),
17648 get_address_mode (mem),
17650 VAR_INIT_STATUS_INITIALIZED);
17652 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
17653 == DEBUG_PARAMETER_REF)
17656 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
17657 tdie = lookup_decl_die (tdecl);
17664 && GET_CODE (XEXP (XEXP (arg, 0), 0))
17665 != DEBUG_PARAMETER_REF)
17667 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
17669 VAR_INIT_STATUS_INITIALIZED);
17673 die = gen_call_site_die (decl, subr_die, ca_loc);
17674 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
17677 add_AT_loc (cdie, DW_AT_location, reg);
17678 else if (tdie != NULL)
17679 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
17680 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
17681 if (next_arg != XEXP (arg, 1))
17683 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
17684 if (mode == VOIDmode)
17685 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
17686 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
17689 VAR_INIT_STATUS_INITIALIZED);
17691 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
17695 && (ca_loc->symbol_ref || tloc))
17696 die = gen_call_site_die (decl, subr_die, ca_loc);
17697 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
17699 dw_loc_descr_ref tval = NULL;
17701 if (tloc != NULL_RTX)
17702 tval = mem_loc_descriptor (tloc,
17703 GET_MODE (tloc) == VOIDmode
17704 ? Pmode : GET_MODE (tloc),
17706 VAR_INIT_STATUS_INITIALIZED);
17708 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
17709 else if (tlocc != NULL_RTX)
17711 tval = mem_loc_descriptor (tlocc,
17712 GET_MODE (tlocc) == VOIDmode
17713 ? Pmode : GET_MODE (tlocc),
17715 VAR_INIT_STATUS_INITIALIZED);
17717 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
17723 call_site_note_count++;
17724 if (ca_loc->tail_call_p)
17725 tail_call_site_note_count++;
17729 call_arg_locations = NULL;
17730 call_arg_loc_last = NULL;
17731 if (tail_call_site_count >= 0
17732 && tail_call_site_count == tail_call_site_note_count
17735 if (call_site_count >= 0
17736 && call_site_count == call_site_note_count)
17737 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
17739 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
17741 call_site_count = -1;
17742 tail_call_site_count = -1;
17744 /* Add the calling convention attribute if requested. */
17745 add_calling_convention_attribute (subr_die, decl);
17749 /* Returns a hash value for X (which really is a die_struct). */
17752 common_block_die_table_hash (const void *x)
17754 const_dw_die_ref d = (const_dw_die_ref) x;
17755 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
17758 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17759 as decl_id and die_parent of die_struct Y. */
17762 common_block_die_table_eq (const void *x, const void *y)
17764 const_dw_die_ref d = (const_dw_die_ref) x;
17765 const_dw_die_ref e = (const_dw_die_ref) y;
17766 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
17769 /* Generate a DIE to represent a declared data object.
17770 Either DECL or ORIGIN must be non-null. */
17773 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
17777 tree decl_or_origin = decl ? decl : origin;
17778 tree ultimate_origin;
17779 dw_die_ref var_die;
17780 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
17781 dw_die_ref origin_die;
17782 bool declaration = (DECL_EXTERNAL (decl_or_origin)
17783 || class_or_namespace_scope_p (context_die));
17784 bool specialization_p = false;
17786 ultimate_origin = decl_ultimate_origin (decl_or_origin);
17787 if (decl || ultimate_origin)
17788 origin = ultimate_origin;
17789 com_decl = fortran_common (decl_or_origin, &off);
17791 /* Symbol in common gets emitted as a child of the common block, in the form
17792 of a data member. */
17795 dw_die_ref com_die;
17796 dw_loc_list_ref loc;
17797 die_node com_die_arg;
17799 var_die = lookup_decl_die (decl_or_origin);
17802 if (get_AT (var_die, DW_AT_location) == NULL)
17804 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
17809 /* Optimize the common case. */
17810 if (single_element_loc_list_p (loc)
17811 && loc->expr->dw_loc_opc == DW_OP_addr
17812 && loc->expr->dw_loc_next == NULL
17813 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
17815 loc->expr->dw_loc_oprnd1.v.val_addr
17816 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
17818 loc_list_plus_const (loc, off);
17820 add_AT_location_description (var_die, DW_AT_location, loc);
17821 remove_AT (var_die, DW_AT_declaration);
17827 if (common_block_die_table == NULL)
17828 common_block_die_table
17829 = htab_create_ggc (10, common_block_die_table_hash,
17830 common_block_die_table_eq, NULL);
17832 com_die_arg.decl_id = DECL_UID (com_decl);
17833 com_die_arg.die_parent = context_die;
17834 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
17835 loc = loc_list_from_tree (com_decl, 2);
17836 if (com_die == NULL)
17839 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
17842 com_die = new_die (DW_TAG_common_block, context_die, decl);
17843 add_name_and_src_coords_attributes (com_die, com_decl);
17846 add_AT_location_description (com_die, DW_AT_location, loc);
17847 /* Avoid sharing the same loc descriptor between
17848 DW_TAG_common_block and DW_TAG_variable. */
17849 loc = loc_list_from_tree (com_decl, 2);
17851 else if (DECL_EXTERNAL (decl))
17852 add_AT_flag (com_die, DW_AT_declaration, 1);
17853 add_pubname_string (cnam, com_die); /* ??? needed? */
17854 com_die->decl_id = DECL_UID (com_decl);
17855 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
17856 *slot = (void *) com_die;
17858 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
17860 add_AT_location_description (com_die, DW_AT_location, loc);
17861 loc = loc_list_from_tree (com_decl, 2);
17862 remove_AT (com_die, DW_AT_declaration);
17864 var_die = new_die (DW_TAG_variable, com_die, decl);
17865 add_name_and_src_coords_attributes (var_die, decl);
17866 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
17867 TREE_THIS_VOLATILE (decl), context_die);
17868 add_AT_flag (var_die, DW_AT_external, 1);
17873 /* Optimize the common case. */
17874 if (single_element_loc_list_p (loc)
17875 && loc->expr->dw_loc_opc == DW_OP_addr
17876 && loc->expr->dw_loc_next == NULL
17877 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
17878 loc->expr->dw_loc_oprnd1.v.val_addr
17879 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
17881 loc_list_plus_const (loc, off);
17883 add_AT_location_description (var_die, DW_AT_location, loc);
17885 else if (DECL_EXTERNAL (decl))
17886 add_AT_flag (var_die, DW_AT_declaration, 1);
17887 equate_decl_number_to_die (decl, var_die);
17891 /* If the compiler emitted a definition for the DECL declaration
17892 and if we already emitted a DIE for it, don't emit a second
17893 DIE for it again. Allow re-declarations of DECLs that are
17894 inside functions, though. */
17895 if (old_die && declaration && !local_scope_p (context_die))
17898 /* For static data members, the declaration in the class is supposed
17899 to have DW_TAG_member tag; the specification should still be
17900 DW_TAG_variable referencing the DW_TAG_member DIE. */
17901 if (declaration && class_scope_p (context_die))
17902 var_die = new_die (DW_TAG_member, context_die, decl);
17904 var_die = new_die (DW_TAG_variable, context_die, decl);
17907 if (origin != NULL)
17908 origin_die = add_abstract_origin_attribute (var_die, origin);
17910 /* Loop unrolling can create multiple blocks that refer to the same
17911 static variable, so we must test for the DW_AT_declaration flag.
17913 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17914 copy decls and set the DECL_ABSTRACT flag on them instead of
17917 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17919 ??? The declare_in_namespace support causes us to get two DIEs for one
17920 variable, both of which are declarations. We want to avoid considering
17921 one to be a specification, so we must test that this DIE is not a
17923 else if (old_die && TREE_STATIC (decl) && ! declaration
17924 && get_AT_flag (old_die, DW_AT_declaration) == 1)
17926 /* This is a definition of a C++ class level static. */
17927 add_AT_specification (var_die, old_die);
17928 specialization_p = true;
17929 if (DECL_NAME (decl))
17931 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17932 struct dwarf_file_data * file_index = lookup_filename (s.file);
17934 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
17935 add_AT_file (var_die, DW_AT_decl_file, file_index);
17937 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
17938 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
17940 if (old_die->die_tag == DW_TAG_member)
17941 add_linkage_name (var_die, decl);
17945 add_name_and_src_coords_attributes (var_die, decl);
17947 if ((origin == NULL && !specialization_p)
17949 && !DECL_ABSTRACT (decl_or_origin)
17950 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
17951 decl_function_context
17952 (decl_or_origin))))
17954 tree type = TREE_TYPE (decl_or_origin);
17956 if (decl_by_reference_p (decl_or_origin))
17957 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
17959 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
17960 TREE_THIS_VOLATILE (decl_or_origin), context_die);
17963 if (origin == NULL && !specialization_p)
17965 if (TREE_PUBLIC (decl))
17966 add_AT_flag (var_die, DW_AT_external, 1);
17968 if (DECL_ARTIFICIAL (decl))
17969 add_AT_flag (var_die, DW_AT_artificial, 1);
17971 add_accessibility_attribute (var_die, decl);
17975 add_AT_flag (var_die, DW_AT_declaration, 1);
17977 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
17978 equate_decl_number_to_die (decl, var_die);
17981 && (! DECL_ABSTRACT (decl_or_origin)
17982 /* Local static vars are shared between all clones/inlines,
17983 so emit DW_AT_location on the abstract DIE if DECL_RTL is
17985 || (TREE_CODE (decl_or_origin) == VAR_DECL
17986 && TREE_STATIC (decl_or_origin)
17987 && DECL_RTL_SET_P (decl_or_origin)))
17988 /* When abstract origin already has DW_AT_location attribute, no need
17989 to add it again. */
17990 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
17992 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
17993 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
17994 defer_location (decl_or_origin, var_die);
17996 add_location_or_const_value_attribute (var_die, decl_or_origin,
17997 decl == NULL, DW_AT_location);
17998 add_pubname (decl_or_origin, var_die);
18001 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
18004 /* Generate a DIE to represent a named constant. */
18007 gen_const_die (tree decl, dw_die_ref context_die)
18009 dw_die_ref const_die;
18010 tree type = TREE_TYPE (decl);
18012 const_die = new_die (DW_TAG_constant, context_die, decl);
18013 add_name_and_src_coords_attributes (const_die, decl);
18014 add_type_attribute (const_die, type, 1, 0, context_die);
18015 if (TREE_PUBLIC (decl))
18016 add_AT_flag (const_die, DW_AT_external, 1);
18017 if (DECL_ARTIFICIAL (decl))
18018 add_AT_flag (const_die, DW_AT_artificial, 1);
18019 tree_add_const_value_attribute_for_decl (const_die, decl);
18022 /* Generate a DIE to represent a label identifier. */
18025 gen_label_die (tree decl, dw_die_ref context_die)
18027 tree origin = decl_ultimate_origin (decl);
18028 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
18030 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18032 if (origin != NULL)
18033 add_abstract_origin_attribute (lbl_die, origin);
18035 add_name_and_src_coords_attributes (lbl_die, decl);
18037 if (DECL_ABSTRACT (decl))
18038 equate_decl_number_to_die (decl, lbl_die);
18041 insn = DECL_RTL_IF_SET (decl);
18043 /* Deleted labels are programmer specified labels which have been
18044 eliminated because of various optimizations. We still emit them
18045 here so that it is possible to put breakpoints on them. */
18049 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
18051 /* When optimization is enabled (via -O) some parts of the compiler
18052 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18053 represent source-level labels which were explicitly declared by
18054 the user. This really shouldn't be happening though, so catch
18055 it if it ever does happen. */
18056 gcc_assert (!INSN_DELETED_P (insn));
18058 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
18059 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
18063 && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL
18064 && CODE_LABEL_NUMBER (insn) != -1)
18066 ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn));
18067 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
18072 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18073 attributes to the DIE for a block STMT, to describe where the inlined
18074 function was called from. This is similar to add_src_coords_attributes. */
18077 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
18079 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
18081 if (dwarf_version >= 3 || !dwarf_strict)
18083 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
18084 add_AT_unsigned (die, DW_AT_call_line, s.line);
18089 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18090 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18093 add_high_low_attributes (tree stmt, dw_die_ref die)
18095 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18097 if (BLOCK_FRAGMENT_CHAIN (stmt)
18098 && (dwarf_version >= 3 || !dwarf_strict))
18102 if (inlined_function_outer_scope_p (stmt))
18104 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
18105 BLOCK_NUMBER (stmt));
18106 add_AT_lbl_id (die, DW_AT_entry_pc, label);
18109 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
18111 chain = BLOCK_FRAGMENT_CHAIN (stmt);
18114 add_ranges (chain);
18115 chain = BLOCK_FRAGMENT_CHAIN (chain);
18122 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
18123 BLOCK_NUMBER (stmt));
18124 add_AT_lbl_id (die, DW_AT_low_pc, label);
18125 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
18126 BLOCK_NUMBER (stmt));
18127 add_AT_lbl_id (die, DW_AT_high_pc, label);
18131 /* Generate a DIE for a lexical block. */
18134 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
18136 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
18138 if (call_arg_locations)
18140 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
18141 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
18142 BLOCK_NUMBER (stmt) + 1);
18143 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
18146 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
18147 add_high_low_attributes (stmt, stmt_die);
18149 decls_for_scope (stmt, stmt_die, depth);
18152 /* Generate a DIE for an inlined subprogram. */
18155 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
18159 /* The instance of function that is effectively being inlined shall not
18161 gcc_assert (! BLOCK_ABSTRACT (stmt));
18163 decl = block_ultimate_origin (stmt);
18165 /* Emit info for the abstract instance first, if we haven't yet. We
18166 must emit this even if the block is abstract, otherwise when we
18167 emit the block below (or elsewhere), we may end up trying to emit
18168 a die whose origin die hasn't been emitted, and crashing. */
18169 dwarf2out_abstract_function (decl);
18171 if (! BLOCK_ABSTRACT (stmt))
18173 dw_die_ref subr_die
18174 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
18176 if (call_arg_locations)
18178 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
18179 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
18180 BLOCK_NUMBER (stmt) + 1);
18181 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
18183 add_abstract_origin_attribute (subr_die, decl);
18184 if (TREE_ASM_WRITTEN (stmt))
18185 add_high_low_attributes (stmt, subr_die);
18186 add_call_src_coords_attributes (stmt, subr_die);
18188 decls_for_scope (stmt, subr_die, depth);
18189 current_function_has_inlines = 1;
18193 /* Generate a DIE for a field in a record, or structure. */
18196 gen_field_die (tree decl, dw_die_ref context_die)
18198 dw_die_ref decl_die;
18200 if (TREE_TYPE (decl) == error_mark_node)
18203 decl_die = new_die (DW_TAG_member, context_die, decl);
18204 add_name_and_src_coords_attributes (decl_die, decl);
18205 add_type_attribute (decl_die, member_declared_type (decl),
18206 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
18209 if (DECL_BIT_FIELD_TYPE (decl))
18211 add_byte_size_attribute (decl_die, decl);
18212 add_bit_size_attribute (decl_die, decl);
18213 add_bit_offset_attribute (decl_die, decl);
18216 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
18217 add_data_member_location_attribute (decl_die, decl);
18219 if (DECL_ARTIFICIAL (decl))
18220 add_AT_flag (decl_die, DW_AT_artificial, 1);
18222 add_accessibility_attribute (decl_die, decl);
18224 /* Equate decl number to die, so that we can look up this decl later on. */
18225 equate_decl_number_to_die (decl, decl_die);
18229 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18230 Use modified_type_die instead.
18231 We keep this code here just in case these types of DIEs may be needed to
18232 represent certain things in other languages (e.g. Pascal) someday. */
18235 gen_pointer_type_die (tree type, dw_die_ref context_die)
18238 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
18240 equate_type_number_to_die (type, ptr_die);
18241 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18242 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18245 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18246 Use modified_type_die instead.
18247 We keep this code here just in case these types of DIEs may be needed to
18248 represent certain things in other languages (e.g. Pascal) someday. */
18251 gen_reference_type_die (tree type, dw_die_ref context_die)
18253 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
18255 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
18256 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
18258 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
18260 equate_type_number_to_die (type, ref_die);
18261 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
18262 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18266 /* Generate a DIE for a pointer to a member type. */
18269 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
18272 = new_die (DW_TAG_ptr_to_member_type,
18273 scope_die_for (type, context_die), type);
18275 equate_type_number_to_die (type, ptr_die);
18276 add_AT_die_ref (ptr_die, DW_AT_containing_type,
18277 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
18278 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18281 typedef const char *dchar_p; /* For DEF_VEC_P. */
18282 DEF_VEC_P(dchar_p);
18283 DEF_VEC_ALLOC_P(dchar_p,heap);
18285 static char *producer_string;
18287 /* Return a heap allocated producer string including command line options
18288 if -grecord-gcc-switches. */
18291 gen_producer_string (void)
18294 VEC(dchar_p, heap) *switches = NULL;
18295 const char *language_string = lang_hooks.name;
18296 char *producer, *tail;
18298 size_t len = dwarf_record_gcc_switches ? 0 : 3;
18299 size_t plen = strlen (language_string) + 1 + strlen (version_string);
18301 for (j = 1; dwarf_record_gcc_switches && j < save_decoded_options_count; j++)
18302 switch (save_decoded_options[j].opt_index)
18309 case OPT_auxbase_strip:
18318 case OPT_SPECIAL_unknown:
18319 case OPT_SPECIAL_ignore:
18320 case OPT_SPECIAL_program_name:
18321 case OPT_SPECIAL_input_file:
18322 case OPT_grecord_gcc_switches:
18323 case OPT_gno_record_gcc_switches:
18324 case OPT__output_pch_:
18325 case OPT_fdiagnostics_show_location_:
18326 case OPT_fdiagnostics_show_option:
18327 case OPT_fverbose_asm:
18329 case OPT__sysroot_:
18331 case OPT_nostdinc__:
18332 /* Ignore these. */
18335 gcc_checking_assert (save_decoded_options[j].canonical_option[0][0]
18337 switch (save_decoded_options[j].canonical_option[0][1])
18344 if (strncmp (save_decoded_options[j].canonical_option[0] + 2,
18351 VEC_safe_push (dchar_p, heap, switches,
18352 save_decoded_options[j].orig_option_with_args_text);
18353 len += strlen (save_decoded_options[j].orig_option_with_args_text) + 1;
18357 producer = XNEWVEC (char, plen + 1 + len + 1);
18359 sprintf (tail, "%s %s", language_string, version_string);
18362 if (!dwarf_record_gcc_switches)
18364 #ifdef MIPS_DEBUGGING_INFO
18365 /* The MIPS/SGI compilers place the 'cc' command line options in the
18366 producer string. The SGI debugger looks for -g, -g1, -g2, or -g3;
18367 if they do not appear in the producer string, the debugger reaches
18368 the conclusion that the object file is stripped and has no debugging
18369 information. To get the MIPS/SGI debugger to believe that there is
18370 debugging information in the object file, we add a -g to the producer
18372 if (debug_info_level > DINFO_LEVEL_TERSE)
18374 memcpy (tail, " -g", 3);
18380 FOR_EACH_VEC_ELT (dchar_p, switches, j, p)
18384 memcpy (tail + 1, p, len);
18389 VEC_free (dchar_p, heap, switches);
18393 /* Generate the DIE for the compilation unit. */
18396 gen_compile_unit_die (const char *filename)
18399 const char *language_string = lang_hooks.name;
18402 die = new_die (DW_TAG_compile_unit, NULL, NULL);
18406 add_name_attribute (die, filename);
18407 /* Don't add cwd for <built-in>. */
18408 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
18409 add_comp_dir_attribute (die);
18412 if (producer_string == NULL)
18413 producer_string = gen_producer_string ();
18414 add_AT_string (die, DW_AT_producer, producer_string);
18416 /* If our producer is LTO try to figure out a common language to use
18417 from the global list of translation units. */
18418 if (strcmp (language_string, "GNU GIMPLE") == 0)
18422 const char *common_lang = NULL;
18424 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
18426 if (!TRANSLATION_UNIT_LANGUAGE (t))
18429 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
18430 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
18432 else if (strncmp (common_lang, "GNU C", 5) == 0
18433 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
18434 /* Mixing C and C++ is ok, use C++ in that case. */
18435 common_lang = "GNU C++";
18438 /* Fall back to C. */
18439 common_lang = NULL;
18445 language_string = common_lang;
18448 language = DW_LANG_C89;
18449 if (strcmp (language_string, "GNU C++") == 0)
18450 language = DW_LANG_C_plus_plus;
18451 else if (strcmp (language_string, "GNU F77") == 0)
18452 language = DW_LANG_Fortran77;
18453 else if (strcmp (language_string, "GNU Pascal") == 0)
18454 language = DW_LANG_Pascal83;
18455 else if (dwarf_version >= 3 || !dwarf_strict)
18457 if (strcmp (language_string, "GNU Ada") == 0)
18458 language = DW_LANG_Ada95;
18459 else if (strcmp (language_string, "GNU Fortran") == 0)
18460 language = DW_LANG_Fortran95;
18461 else if (strcmp (language_string, "GNU Java") == 0)
18462 language = DW_LANG_Java;
18463 else if (strcmp (language_string, "GNU Objective-C") == 0)
18464 language = DW_LANG_ObjC;
18465 else if (strcmp (language_string, "GNU Objective-C++") == 0)
18466 language = DW_LANG_ObjC_plus_plus;
18467 else if (dwarf_version >= 5 || !dwarf_strict)
18469 if (strcmp (language_string, "GNU Go") == 0)
18470 language = DW_LANG_Go;
18474 add_AT_unsigned (die, DW_AT_language, language);
18478 case DW_LANG_Fortran77:
18479 case DW_LANG_Fortran90:
18480 case DW_LANG_Fortran95:
18481 /* Fortran has case insensitive identifiers and the front-end
18482 lowercases everything. */
18483 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
18486 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18492 /* Generate the DIE for a base class. */
18495 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
18497 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
18499 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
18500 add_data_member_location_attribute (die, binfo);
18502 if (BINFO_VIRTUAL_P (binfo))
18503 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18505 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18506 children, otherwise the default is DW_ACCESS_public. In DWARF2
18507 the default has always been DW_ACCESS_private. */
18508 if (access == access_public_node)
18510 if (dwarf_version == 2
18511 || context_die->die_tag == DW_TAG_class_type)
18512 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
18514 else if (access == access_protected_node)
18515 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
18516 else if (dwarf_version > 2
18517 && context_die->die_tag != DW_TAG_class_type)
18518 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
18521 /* Generate a DIE for a class member. */
18524 gen_member_die (tree type, dw_die_ref context_die)
18527 tree binfo = TYPE_BINFO (type);
18530 /* If this is not an incomplete type, output descriptions of each of its
18531 members. Note that as we output the DIEs necessary to represent the
18532 members of this record or union type, we will also be trying to output
18533 DIEs to represent the *types* of those members. However the `type'
18534 function (above) will specifically avoid generating type DIEs for member
18535 types *within* the list of member DIEs for this (containing) type except
18536 for those types (of members) which are explicitly marked as also being
18537 members of this (containing) type themselves. The g++ front- end can
18538 force any given type to be treated as a member of some other (containing)
18539 type by setting the TYPE_CONTEXT of the given (member) type to point to
18540 the TREE node representing the appropriate (containing) type. */
18542 /* First output info about the base classes. */
18545 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
18549 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
18550 gen_inheritance_die (base,
18551 (accesses ? VEC_index (tree, accesses, i)
18552 : access_public_node), context_die);
18555 /* Now output info about the data members and type members. */
18556 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
18558 /* If we thought we were generating minimal debug info for TYPE
18559 and then changed our minds, some of the member declarations
18560 may have already been defined. Don't define them again, but
18561 do put them in the right order. */
18563 child = lookup_decl_die (member);
18565 splice_child_die (context_die, child);
18567 gen_decl_die (member, NULL, context_die);
18570 /* Now output info about the function members (if any). */
18571 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
18573 /* Don't include clones in the member list. */
18574 if (DECL_ABSTRACT_ORIGIN (member))
18577 child = lookup_decl_die (member);
18579 splice_child_die (context_die, child);
18581 gen_decl_die (member, NULL, context_die);
18585 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18586 is set, we pretend that the type was never defined, so we only get the
18587 member DIEs needed by later specification DIEs. */
18590 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
18591 enum debug_info_usage usage)
18593 dw_die_ref type_die = lookup_type_die (type);
18594 dw_die_ref scope_die = 0;
18596 int complete = (TYPE_SIZE (type)
18597 && (! TYPE_STUB_DECL (type)
18598 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
18599 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
18600 complete = complete && should_emit_struct_debug (type, usage);
18602 if (type_die && ! complete)
18605 if (TYPE_CONTEXT (type) != NULL_TREE
18606 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18607 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
18610 scope_die = scope_die_for (type, context_die);
18612 if (! type_die || (nested && is_cu_die (scope_die)))
18613 /* First occurrence of type or toplevel definition of nested class. */
18615 dw_die_ref old_die = type_die;
18617 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
18618 ? record_type_tag (type) : DW_TAG_union_type,
18620 equate_type_number_to_die (type, type_die);
18622 add_AT_specification (type_die, old_die);
18625 add_name_attribute (type_die, type_tag (type));
18626 add_gnat_descriptive_type_attribute (type_die, type, context_die);
18627 if (TYPE_ARTIFICIAL (type))
18628 add_AT_flag (type_die, DW_AT_artificial, 1);
18632 remove_AT (type_die, DW_AT_declaration);
18634 /* Generate child dies for template paramaters. */
18635 if (debug_info_level > DINFO_LEVEL_TERSE
18636 && COMPLETE_TYPE_P (type))
18637 schedule_generic_params_dies_gen (type);
18639 /* If this type has been completed, then give it a byte_size attribute and
18640 then give a list of members. */
18641 if (complete && !ns_decl)
18643 /* Prevent infinite recursion in cases where the type of some member of
18644 this type is expressed in terms of this type itself. */
18645 TREE_ASM_WRITTEN (type) = 1;
18646 add_byte_size_attribute (type_die, type);
18647 if (TYPE_STUB_DECL (type) != NULL_TREE)
18649 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18650 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18653 /* If the first reference to this type was as the return type of an
18654 inline function, then it may not have a parent. Fix this now. */
18655 if (type_die->die_parent == NULL)
18656 add_child_die (scope_die, type_die);
18658 push_decl_scope (type);
18659 gen_member_die (type, type_die);
18662 /* GNU extension: Record what type our vtable lives in. */
18663 if (TYPE_VFIELD (type))
18665 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
18667 gen_type_die (vtype, context_die);
18668 add_AT_die_ref (type_die, DW_AT_containing_type,
18669 lookup_type_die (vtype));
18674 add_AT_flag (type_die, DW_AT_declaration, 1);
18676 /* We don't need to do this for function-local types. */
18677 if (TYPE_STUB_DECL (type)
18678 && ! decl_function_context (TYPE_STUB_DECL (type)))
18679 VEC_safe_push (tree, gc, incomplete_types, type);
18682 if (get_AT (type_die, DW_AT_name))
18683 add_pubtype (type, type_die);
18686 /* Generate a DIE for a subroutine _type_. */
18689 gen_subroutine_type_die (tree type, dw_die_ref context_die)
18691 tree return_type = TREE_TYPE (type);
18692 dw_die_ref subr_die
18693 = new_die (DW_TAG_subroutine_type,
18694 scope_die_for (type, context_die), type);
18696 equate_type_number_to_die (type, subr_die);
18697 add_prototyped_attribute (subr_die, type);
18698 add_type_attribute (subr_die, return_type, 0, 0, context_die);
18699 gen_formal_types_die (type, subr_die);
18701 if (get_AT (subr_die, DW_AT_name))
18702 add_pubtype (type, subr_die);
18705 /* Generate a DIE for a type definition. */
18708 gen_typedef_die (tree decl, dw_die_ref context_die)
18710 dw_die_ref type_die;
18713 if (TREE_ASM_WRITTEN (decl))
18716 TREE_ASM_WRITTEN (decl) = 1;
18717 type_die = new_die (DW_TAG_typedef, context_die, decl);
18718 origin = decl_ultimate_origin (decl);
18719 if (origin != NULL)
18720 add_abstract_origin_attribute (type_die, origin);
18725 add_name_and_src_coords_attributes (type_die, decl);
18726 if (DECL_ORIGINAL_TYPE (decl))
18728 type = DECL_ORIGINAL_TYPE (decl);
18730 gcc_assert (type != TREE_TYPE (decl));
18731 equate_type_number_to_die (TREE_TYPE (decl), type_die);
18735 type = TREE_TYPE (decl);
18737 if (is_naming_typedef_decl (TYPE_NAME (type)))
18739 /* Here, we are in the case of decl being a typedef naming
18740 an anonymous type, e.g:
18741 typedef struct {...} foo;
18742 In that case TREE_TYPE (decl) is not a typedef variant
18743 type and TYPE_NAME of the anonymous type is set to the
18744 TYPE_DECL of the typedef. This construct is emitted by
18747 TYPE is the anonymous struct named by the typedef
18748 DECL. As we need the DW_AT_type attribute of the
18749 DW_TAG_typedef to point to the DIE of TYPE, let's
18750 generate that DIE right away. add_type_attribute
18751 called below will then pick (via lookup_type_die) that
18752 anonymous struct DIE. */
18753 if (!TREE_ASM_WRITTEN (type))
18754 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
18756 /* This is a GNU Extension. We are adding a
18757 DW_AT_linkage_name attribute to the DIE of the
18758 anonymous struct TYPE. The value of that attribute
18759 is the name of the typedef decl naming the anonymous
18760 struct. This greatly eases the work of consumers of
18761 this debug info. */
18762 add_linkage_attr (lookup_type_die (type), decl);
18766 add_type_attribute (type_die, type, TREE_READONLY (decl),
18767 TREE_THIS_VOLATILE (decl), context_die);
18769 if (is_naming_typedef_decl (decl))
18770 /* We want that all subsequent calls to lookup_type_die with
18771 TYPE in argument yield the DW_TAG_typedef we have just
18773 equate_type_number_to_die (type, type_die);
18775 add_accessibility_attribute (type_die, decl);
18778 if (DECL_ABSTRACT (decl))
18779 equate_decl_number_to_die (decl, type_die);
18781 if (get_AT (type_die, DW_AT_name))
18782 add_pubtype (decl, type_die);
18785 /* Generate a DIE for a struct, class, enum or union type. */
18788 gen_tagged_type_die (tree type,
18789 dw_die_ref context_die,
18790 enum debug_info_usage usage)
18794 if (type == NULL_TREE
18795 || !is_tagged_type (type))
18798 /* If this is a nested type whose containing class hasn't been written
18799 out yet, writing it out will cover this one, too. This does not apply
18800 to instantiations of member class templates; they need to be added to
18801 the containing class as they are generated. FIXME: This hurts the
18802 idea of combining type decls from multiple TUs, since we can't predict
18803 what set of template instantiations we'll get. */
18804 if (TYPE_CONTEXT (type)
18805 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18806 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
18808 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
18810 if (TREE_ASM_WRITTEN (type))
18813 /* If that failed, attach ourselves to the stub. */
18814 push_decl_scope (TYPE_CONTEXT (type));
18815 context_die = lookup_type_die (TYPE_CONTEXT (type));
18818 else if (TYPE_CONTEXT (type) != NULL_TREE
18819 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
18821 /* If this type is local to a function that hasn't been written
18822 out yet, use a NULL context for now; it will be fixed up in
18823 decls_for_scope. */
18824 context_die = lookup_decl_die (TYPE_CONTEXT (type));
18825 /* A declaration DIE doesn't count; nested types need to go in the
18827 if (context_die && is_declaration_die (context_die))
18828 context_die = NULL;
18833 context_die = declare_in_namespace (type, context_die);
18837 if (TREE_CODE (type) == ENUMERAL_TYPE)
18839 /* This might have been written out by the call to
18840 declare_in_namespace. */
18841 if (!TREE_ASM_WRITTEN (type))
18842 gen_enumeration_type_die (type, context_die);
18845 gen_struct_or_union_type_die (type, context_die, usage);
18850 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18851 it up if it is ever completed. gen_*_type_die will set it for us
18852 when appropriate. */
18855 /* Generate a type description DIE. */
18858 gen_type_die_with_usage (tree type, dw_die_ref context_die,
18859 enum debug_info_usage usage)
18861 struct array_descr_info info;
18863 if (type == NULL_TREE || type == error_mark_node)
18866 if (TYPE_NAME (type) != NULL_TREE
18867 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18868 && is_redundant_typedef (TYPE_NAME (type))
18869 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
18870 /* The DECL of this type is a typedef we don't want to emit debug
18871 info for but we want debug info for its underlying typedef.
18872 This can happen for e.g, the injected-class-name of a C++
18874 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
18876 /* If TYPE is a typedef type variant, let's generate debug info
18877 for the parent typedef which TYPE is a type of. */
18878 if (typedef_variant_p (type))
18880 if (TREE_ASM_WRITTEN (type))
18883 /* Prevent broken recursion; we can't hand off to the same type. */
18884 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
18886 /* Use the DIE of the containing namespace as the parent DIE of
18887 the type description DIE we want to generate. */
18888 if (DECL_FILE_SCOPE_P (TYPE_NAME (type))
18889 || (DECL_CONTEXT (TYPE_NAME (type))
18890 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL))
18891 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
18893 TREE_ASM_WRITTEN (type) = 1;
18895 gen_decl_die (TYPE_NAME (type), NULL, context_die);
18899 /* If type is an anonymous tagged type named by a typedef, let's
18900 generate debug info for the typedef. */
18901 if (is_naming_typedef_decl (TYPE_NAME (type)))
18903 /* Use the DIE of the containing namespace as the parent DIE of
18904 the type description DIE we want to generate. */
18905 if (DECL_CONTEXT (TYPE_NAME (type))
18906 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
18907 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
18909 gen_decl_die (TYPE_NAME (type), NULL, context_die);
18913 /* If this is an array type with hidden descriptor, handle it first. */
18914 if (!TREE_ASM_WRITTEN (type)
18915 && lang_hooks.types.get_array_descr_info
18916 && lang_hooks.types.get_array_descr_info (type, &info)
18917 && (dwarf_version >= 3 || !dwarf_strict))
18919 gen_descr_array_type_die (type, &info, context_die);
18920 TREE_ASM_WRITTEN (type) = 1;
18924 /* We are going to output a DIE to represent the unqualified version
18925 of this type (i.e. without any const or volatile qualifiers) so
18926 get the main variant (i.e. the unqualified version) of this type
18927 now. (Vectors are special because the debugging info is in the
18928 cloned type itself). */
18929 if (TREE_CODE (type) != VECTOR_TYPE)
18930 type = type_main_variant (type);
18932 if (TREE_ASM_WRITTEN (type))
18935 switch (TREE_CODE (type))
18941 case REFERENCE_TYPE:
18942 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
18943 ensures that the gen_type_die recursion will terminate even if the
18944 type is recursive. Recursive types are possible in Ada. */
18945 /* ??? We could perhaps do this for all types before the switch
18947 TREE_ASM_WRITTEN (type) = 1;
18949 /* For these types, all that is required is that we output a DIE (or a
18950 set of DIEs) to represent the "basis" type. */
18951 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18952 DINFO_USAGE_IND_USE);
18956 /* This code is used for C++ pointer-to-data-member types.
18957 Output a description of the relevant class type. */
18958 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
18959 DINFO_USAGE_IND_USE);
18961 /* Output a description of the type of the object pointed to. */
18962 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18963 DINFO_USAGE_IND_USE);
18965 /* Now output a DIE to represent this pointer-to-data-member type
18967 gen_ptr_to_mbr_type_die (type, context_die);
18970 case FUNCTION_TYPE:
18971 /* Force out return type (in case it wasn't forced out already). */
18972 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18973 DINFO_USAGE_DIR_USE);
18974 gen_subroutine_type_die (type, context_die);
18978 /* Force out return type (in case it wasn't forced out already). */
18979 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18980 DINFO_USAGE_DIR_USE);
18981 gen_subroutine_type_die (type, context_die);
18985 gen_array_type_die (type, context_die);
18989 gen_array_type_die (type, context_die);
18992 case ENUMERAL_TYPE:
18995 case QUAL_UNION_TYPE:
18996 gen_tagged_type_die (type, context_die, usage);
19002 case FIXED_POINT_TYPE:
19005 /* No DIEs needed for fundamental types. */
19010 /* Just use DW_TAG_unspecified_type. */
19012 dw_die_ref type_die = lookup_type_die (type);
19013 if (type_die == NULL)
19015 tree name = TYPE_NAME (type);
19016 if (TREE_CODE (name) == TYPE_DECL)
19017 name = DECL_NAME (name);
19018 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
19019 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
19020 equate_type_number_to_die (type, type_die);
19026 gcc_unreachable ();
19029 TREE_ASM_WRITTEN (type) = 1;
19033 gen_type_die (tree type, dw_die_ref context_die)
19035 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
19038 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19039 things which are local to the given block. */
19042 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
19044 int must_output_die = 0;
19047 /* Ignore blocks that are NULL. */
19048 if (stmt == NULL_TREE)
19051 inlined_func = inlined_function_outer_scope_p (stmt);
19053 /* If the block is one fragment of a non-contiguous block, do not
19054 process the variables, since they will have been done by the
19055 origin block. Do process subblocks. */
19056 if (BLOCK_FRAGMENT_ORIGIN (stmt))
19060 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
19061 gen_block_die (sub, context_die, depth + 1);
19066 /* Determine if we need to output any Dwarf DIEs at all to represent this
19069 /* The outer scopes for inlinings *must* always be represented. We
19070 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19071 must_output_die = 1;
19074 /* Determine if this block directly contains any "significant"
19075 local declarations which we will need to output DIEs for. */
19076 if (debug_info_level > DINFO_LEVEL_TERSE)
19077 /* We are not in terse mode so *any* local declaration counts
19078 as being a "significant" one. */
19079 must_output_die = ((BLOCK_VARS (stmt) != NULL
19080 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
19081 && (TREE_USED (stmt)
19082 || TREE_ASM_WRITTEN (stmt)
19083 || BLOCK_ABSTRACT (stmt)));
19084 else if ((TREE_USED (stmt)
19085 || TREE_ASM_WRITTEN (stmt)
19086 || BLOCK_ABSTRACT (stmt))
19087 && !dwarf2out_ignore_block (stmt))
19088 must_output_die = 1;
19091 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19092 DIE for any block which contains no significant local declarations at
19093 all. Rather, in such cases we just call `decls_for_scope' so that any
19094 needed Dwarf info for any sub-blocks will get properly generated. Note
19095 that in terse mode, our definition of what constitutes a "significant"
19096 local declaration gets restricted to include only inlined function
19097 instances and local (nested) function definitions. */
19098 if (must_output_die)
19102 /* If STMT block is abstract, that means we have been called
19103 indirectly from dwarf2out_abstract_function.
19104 That function rightfully marks the descendent blocks (of
19105 the abstract function it is dealing with) as being abstract,
19106 precisely to prevent us from emitting any
19107 DW_TAG_inlined_subroutine DIE as a descendent
19108 of an abstract function instance. So in that case, we should
19109 not call gen_inlined_subroutine_die.
19111 Later though, when cgraph asks dwarf2out to emit info
19112 for the concrete instance of the function decl into which
19113 the concrete instance of STMT got inlined, the later will lead
19114 to the generation of a DW_TAG_inlined_subroutine DIE. */
19115 if (! BLOCK_ABSTRACT (stmt))
19116 gen_inlined_subroutine_die (stmt, context_die, depth);
19119 gen_lexical_block_die (stmt, context_die, depth);
19122 decls_for_scope (stmt, context_die, depth);
19125 /* Process variable DECL (or variable with origin ORIGIN) within
19126 block STMT and add it to CONTEXT_DIE. */
19128 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
19131 tree decl_or_origin = decl ? decl : origin;
19133 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
19134 die = lookup_decl_die (decl_or_origin);
19135 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
19136 && TYPE_DECL_IS_STUB (decl_or_origin))
19137 die = lookup_type_die (TREE_TYPE (decl_or_origin));
19141 if (die != NULL && die->die_parent == NULL)
19142 add_child_die (context_die, die);
19143 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
19144 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
19145 stmt, context_die);
19147 gen_decl_die (decl, origin, context_die);
19150 /* Generate all of the decls declared within a given scope and (recursively)
19151 all of its sub-blocks. */
19154 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
19160 /* Ignore NULL blocks. */
19161 if (stmt == NULL_TREE)
19164 /* Output the DIEs to represent all of the data objects and typedefs
19165 declared directly within this block but not within any nested
19166 sub-blocks. Also, nested function and tag DIEs have been
19167 generated with a parent of NULL; fix that up now. */
19168 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
19169 process_scope_var (stmt, decl, NULL_TREE, context_die);
19170 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
19171 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
19174 /* If we're at -g1, we're not interested in subblocks. */
19175 if (debug_info_level <= DINFO_LEVEL_TERSE)
19178 /* Output the DIEs to represent all sub-blocks (and the items declared
19179 therein) of this block. */
19180 for (subblocks = BLOCK_SUBBLOCKS (stmt);
19182 subblocks = BLOCK_CHAIN (subblocks))
19183 gen_block_die (subblocks, context_die, depth + 1);
19186 /* Is this a typedef we can avoid emitting? */
19189 is_redundant_typedef (const_tree decl)
19191 if (TYPE_DECL_IS_STUB (decl))
19194 if (DECL_ARTIFICIAL (decl)
19195 && DECL_CONTEXT (decl)
19196 && is_tagged_type (DECL_CONTEXT (decl))
19197 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
19198 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
19199 /* Also ignore the artificial member typedef for the class name. */
19205 /* Return TRUE if TYPE is a typedef that names a type for linkage
19206 purposes. This kind of typedefs is produced by the C++ FE for
19209 typedef struct {...} foo;
19211 In that case, there is no typedef variant type produced for foo.
19212 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19216 is_naming_typedef_decl (const_tree decl)
19218 if (decl == NULL_TREE
19219 || TREE_CODE (decl) != TYPE_DECL
19220 || !is_tagged_type (TREE_TYPE (decl))
19221 || DECL_IS_BUILTIN (decl)
19222 || is_redundant_typedef (decl)
19223 /* It looks like Ada produces TYPE_DECLs that are very similar
19224 to C++ naming typedefs but that have different
19225 semantics. Let's be specific to c++ for now. */
19229 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
19230 && TYPE_NAME (TREE_TYPE (decl)) == decl
19231 && (TYPE_STUB_DECL (TREE_TYPE (decl))
19232 != TYPE_NAME (TREE_TYPE (decl))));
19235 /* Returns the DIE for a context. */
19237 static inline dw_die_ref
19238 get_context_die (tree context)
19242 /* Find die that represents this context. */
19243 if (TYPE_P (context))
19245 context = TYPE_MAIN_VARIANT (context);
19246 return strip_naming_typedef (context, force_type_die (context));
19249 return force_decl_die (context);
19251 return comp_unit_die ();
19254 /* Returns the DIE for decl. A DIE will always be returned. */
19257 force_decl_die (tree decl)
19259 dw_die_ref decl_die;
19260 unsigned saved_external_flag;
19261 tree save_fn = NULL_TREE;
19262 decl_die = lookup_decl_die (decl);
19265 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
19267 decl_die = lookup_decl_die (decl);
19271 switch (TREE_CODE (decl))
19273 case FUNCTION_DECL:
19274 /* Clear current_function_decl, so that gen_subprogram_die thinks
19275 that this is a declaration. At this point, we just want to force
19276 declaration die. */
19277 save_fn = current_function_decl;
19278 current_function_decl = NULL_TREE;
19279 gen_subprogram_die (decl, context_die);
19280 current_function_decl = save_fn;
19284 /* Set external flag to force declaration die. Restore it after
19285 gen_decl_die() call. */
19286 saved_external_flag = DECL_EXTERNAL (decl);
19287 DECL_EXTERNAL (decl) = 1;
19288 gen_decl_die (decl, NULL, context_die);
19289 DECL_EXTERNAL (decl) = saved_external_flag;
19292 case NAMESPACE_DECL:
19293 if (dwarf_version >= 3 || !dwarf_strict)
19294 dwarf2out_decl (decl);
19296 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19297 decl_die = comp_unit_die ();
19300 case TRANSLATION_UNIT_DECL:
19301 decl_die = comp_unit_die ();
19305 gcc_unreachable ();
19308 /* We should be able to find the DIE now. */
19310 decl_die = lookup_decl_die (decl);
19311 gcc_assert (decl_die);
19317 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19318 always returned. */
19321 force_type_die (tree type)
19323 dw_die_ref type_die;
19325 type_die = lookup_type_die (type);
19328 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
19330 type_die = modified_type_die (type, TYPE_READONLY (type),
19331 TYPE_VOLATILE (type), context_die);
19332 gcc_assert (type_die);
19337 /* Force out any required namespaces to be able to output DECL,
19338 and return the new context_die for it, if it's changed. */
19341 setup_namespace_context (tree thing, dw_die_ref context_die)
19343 tree context = (DECL_P (thing)
19344 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
19345 if (context && TREE_CODE (context) == NAMESPACE_DECL)
19346 /* Force out the namespace. */
19347 context_die = force_decl_die (context);
19349 return context_die;
19352 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19353 type) within its namespace, if appropriate.
19355 For compatibility with older debuggers, namespace DIEs only contain
19356 declarations; all definitions are emitted at CU scope. */
19359 declare_in_namespace (tree thing, dw_die_ref context_die)
19361 dw_die_ref ns_context;
19363 if (debug_info_level <= DINFO_LEVEL_TERSE)
19364 return context_die;
19366 /* If this decl is from an inlined function, then don't try to emit it in its
19367 namespace, as we will get confused. It would have already been emitted
19368 when the abstract instance of the inline function was emitted anyways. */
19369 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
19370 return context_die;
19372 ns_context = setup_namespace_context (thing, context_die);
19374 if (ns_context != context_die)
19378 if (DECL_P (thing))
19379 gen_decl_die (thing, NULL, ns_context);
19381 gen_type_die (thing, ns_context);
19383 return context_die;
19386 /* Generate a DIE for a namespace or namespace alias. */
19389 gen_namespace_die (tree decl, dw_die_ref context_die)
19391 dw_die_ref namespace_die;
19393 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19394 they are an alias of. */
19395 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
19397 /* Output a real namespace or module. */
19398 context_die = setup_namespace_context (decl, comp_unit_die ());
19399 namespace_die = new_die (is_fortran ()
19400 ? DW_TAG_module : DW_TAG_namespace,
19401 context_die, decl);
19402 /* For Fortran modules defined in different CU don't add src coords. */
19403 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
19405 const char *name = dwarf2_name (decl, 0);
19407 add_name_attribute (namespace_die, name);
19410 add_name_and_src_coords_attributes (namespace_die, decl);
19411 if (DECL_EXTERNAL (decl))
19412 add_AT_flag (namespace_die, DW_AT_declaration, 1);
19413 equate_decl_number_to_die (decl, namespace_die);
19417 /* Output a namespace alias. */
19419 /* Force out the namespace we are an alias of, if necessary. */
19420 dw_die_ref origin_die
19421 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
19423 if (DECL_FILE_SCOPE_P (decl)
19424 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
19425 context_die = setup_namespace_context (decl, comp_unit_die ());
19426 /* Now create the namespace alias DIE. */
19427 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
19428 add_name_and_src_coords_attributes (namespace_die, decl);
19429 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
19430 equate_decl_number_to_die (decl, namespace_die);
19434 /* Generate Dwarf debug information for a decl described by DECL.
19435 The return value is currently only meaningful for PARM_DECLs,
19436 for all other decls it returns NULL. */
19439 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
19441 tree decl_or_origin = decl ? decl : origin;
19442 tree class_origin = NULL, ultimate_origin;
19444 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
19447 switch (TREE_CODE (decl_or_origin))
19453 if (!is_fortran () && !is_ada ())
19455 /* The individual enumerators of an enum type get output when we output
19456 the Dwarf representation of the relevant enum type itself. */
19460 /* Emit its type. */
19461 gen_type_die (TREE_TYPE (decl), context_die);
19463 /* And its containing namespace. */
19464 context_die = declare_in_namespace (decl, context_die);
19466 gen_const_die (decl, context_die);
19469 case FUNCTION_DECL:
19470 /* Don't output any DIEs to represent mere function declarations,
19471 unless they are class members or explicit block externs. */
19472 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
19473 && DECL_FILE_SCOPE_P (decl_or_origin)
19474 && (current_function_decl == NULL_TREE
19475 || DECL_ARTIFICIAL (decl_or_origin)))
19480 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19481 on local redeclarations of global functions. That seems broken. */
19482 if (current_function_decl != decl)
19483 /* This is only a declaration. */;
19486 /* If we're emitting a clone, emit info for the abstract instance. */
19487 if (origin || DECL_ORIGIN (decl) != decl)
19488 dwarf2out_abstract_function (origin
19489 ? DECL_ORIGIN (origin)
19490 : DECL_ABSTRACT_ORIGIN (decl));
19492 /* If we're emitting an out-of-line copy of an inline function,
19493 emit info for the abstract instance and set up to refer to it. */
19494 else if (cgraph_function_possibly_inlined_p (decl)
19495 && ! DECL_ABSTRACT (decl)
19496 && ! class_or_namespace_scope_p (context_die)
19497 /* dwarf2out_abstract_function won't emit a die if this is just
19498 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19499 that case, because that works only if we have a die. */
19500 && DECL_INITIAL (decl) != NULL_TREE)
19502 dwarf2out_abstract_function (decl);
19503 set_decl_origin_self (decl);
19506 /* Otherwise we're emitting the primary DIE for this decl. */
19507 else if (debug_info_level > DINFO_LEVEL_TERSE)
19509 /* Before we describe the FUNCTION_DECL itself, make sure that we
19510 have its containing type. */
19512 origin = decl_class_context (decl);
19513 if (origin != NULL_TREE)
19514 gen_type_die (origin, context_die);
19516 /* And its return type. */
19517 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
19519 /* And its virtual context. */
19520 if (DECL_VINDEX (decl) != NULL_TREE)
19521 gen_type_die (DECL_CONTEXT (decl), context_die);
19523 /* Make sure we have a member DIE for decl. */
19524 if (origin != NULL_TREE)
19525 gen_type_die_for_member (origin, decl, context_die);
19527 /* And its containing namespace. */
19528 context_die = declare_in_namespace (decl, context_die);
19531 /* Now output a DIE to represent the function itself. */
19533 gen_subprogram_die (decl, context_die);
19537 /* If we are in terse mode, don't generate any DIEs to represent any
19538 actual typedefs. */
19539 if (debug_info_level <= DINFO_LEVEL_TERSE)
19542 /* In the special case of a TYPE_DECL node representing the declaration
19543 of some type tag, if the given TYPE_DECL is marked as having been
19544 instantiated from some other (original) TYPE_DECL node (e.g. one which
19545 was generated within the original definition of an inline function) we
19546 used to generate a special (abbreviated) DW_TAG_structure_type,
19547 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19548 should be actually referencing those DIEs, as variable DIEs with that
19549 type would be emitted already in the abstract origin, so it was always
19550 removed during unused type prunning. Don't add anything in this
19552 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
19555 if (is_redundant_typedef (decl))
19556 gen_type_die (TREE_TYPE (decl), context_die);
19558 /* Output a DIE to represent the typedef itself. */
19559 gen_typedef_die (decl, context_die);
19563 if (debug_info_level >= DINFO_LEVEL_NORMAL)
19564 gen_label_die (decl, context_die);
19569 /* If we are in terse mode, don't generate any DIEs to represent any
19570 variable declarations or definitions. */
19571 if (debug_info_level <= DINFO_LEVEL_TERSE)
19574 /* Output any DIEs that are needed to specify the type of this data
19576 if (decl_by_reference_p (decl_or_origin))
19577 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19579 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19581 /* And its containing type. */
19582 class_origin = decl_class_context (decl_or_origin);
19583 if (class_origin != NULL_TREE)
19584 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
19586 /* And its containing namespace. */
19587 context_die = declare_in_namespace (decl_or_origin, context_die);
19589 /* Now output the DIE to represent the data object itself. This gets
19590 complicated because of the possibility that the VAR_DECL really
19591 represents an inlined instance of a formal parameter for an inline
19593 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19594 if (ultimate_origin != NULL_TREE
19595 && TREE_CODE (ultimate_origin) == PARM_DECL)
19596 gen_formal_parameter_die (decl, origin,
19597 true /* Emit name attribute. */,
19600 gen_variable_die (decl, origin, context_die);
19604 /* Ignore the nameless fields that are used to skip bits but handle C++
19605 anonymous unions and structs. */
19606 if (DECL_NAME (decl) != NULL_TREE
19607 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
19608 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
19610 gen_type_die (member_declared_type (decl), context_die);
19611 gen_field_die (decl, context_die);
19616 if (DECL_BY_REFERENCE (decl_or_origin))
19617 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19619 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19620 return gen_formal_parameter_die (decl, origin,
19621 true /* Emit name attribute. */,
19624 case NAMESPACE_DECL:
19625 case IMPORTED_DECL:
19626 if (dwarf_version >= 3 || !dwarf_strict)
19627 gen_namespace_die (decl, context_die);
19631 /* Probably some frontend-internal decl. Assume we don't care. */
19632 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
19639 /* Output debug information for global decl DECL. Called from toplev.c after
19640 compilation proper has finished. */
19643 dwarf2out_global_decl (tree decl)
19645 /* Output DWARF2 information for file-scope tentative data object
19646 declarations, file-scope (extern) function declarations (which
19647 had no corresponding body) and file-scope tagged type declarations
19648 and definitions which have not yet been forced out. */
19649 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
19650 dwarf2out_decl (decl);
19653 /* Output debug information for type decl DECL. Called from toplev.c
19654 and from language front ends (to record built-in types). */
19656 dwarf2out_type_decl (tree decl, int local)
19659 dwarf2out_decl (decl);
19662 /* Output debug information for imported module or decl DECL.
19663 NAME is non-NULL name in the lexical block if the decl has been renamed.
19664 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19665 that DECL belongs to.
19666 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19668 dwarf2out_imported_module_or_decl_1 (tree decl,
19670 tree lexical_block,
19671 dw_die_ref lexical_block_die)
19673 expanded_location xloc;
19674 dw_die_ref imported_die = NULL;
19675 dw_die_ref at_import_die;
19677 if (TREE_CODE (decl) == IMPORTED_DECL)
19679 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
19680 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
19684 xloc = expand_location (input_location);
19686 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
19688 at_import_die = force_type_die (TREE_TYPE (decl));
19689 /* For namespace N { typedef void T; } using N::T; base_type_die
19690 returns NULL, but DW_TAG_imported_declaration requires
19691 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19692 if (!at_import_die)
19694 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
19695 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
19696 at_import_die = lookup_type_die (TREE_TYPE (decl));
19697 gcc_assert (at_import_die);
19702 at_import_die = lookup_decl_die (decl);
19703 if (!at_import_die)
19705 /* If we're trying to avoid duplicate debug info, we may not have
19706 emitted the member decl for this field. Emit it now. */
19707 if (TREE_CODE (decl) == FIELD_DECL)
19709 tree type = DECL_CONTEXT (decl);
19711 if (TYPE_CONTEXT (type)
19712 && TYPE_P (TYPE_CONTEXT (type))
19713 && !should_emit_struct_debug (TYPE_CONTEXT (type),
19714 DINFO_USAGE_DIR_USE))
19716 gen_type_die_for_member (type, decl,
19717 get_context_die (TYPE_CONTEXT (type)));
19719 at_import_die = force_decl_die (decl);
19723 if (TREE_CODE (decl) == NAMESPACE_DECL)
19725 if (dwarf_version >= 3 || !dwarf_strict)
19726 imported_die = new_die (DW_TAG_imported_module,
19733 imported_die = new_die (DW_TAG_imported_declaration,
19737 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
19738 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
19740 add_AT_string (imported_die, DW_AT_name,
19741 IDENTIFIER_POINTER (name));
19742 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
19745 /* Output debug information for imported module or decl DECL.
19746 NAME is non-NULL name in context if the decl has been renamed.
19747 CHILD is true if decl is one of the renamed decls as part of
19748 importing whole module. */
19751 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
19754 /* dw_die_ref at_import_die; */
19755 dw_die_ref scope_die;
19757 if (debug_info_level <= DINFO_LEVEL_TERSE)
19762 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19763 We need decl DIE for reference and scope die. First, get DIE for the decl
19766 /* Get the scope die for decl context. Use comp_unit_die for global module
19767 or decl. If die is not found for non globals, force new die. */
19769 && TYPE_P (context)
19770 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
19773 if (!(dwarf_version >= 3 || !dwarf_strict))
19776 scope_die = get_context_die (context);
19780 gcc_assert (scope_die->die_child);
19781 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
19782 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
19783 scope_die = scope_die->die_child;
19786 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19787 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
19791 /* Write the debugging output for DECL. */
19794 dwarf2out_decl (tree decl)
19796 dw_die_ref context_die = comp_unit_die ();
19798 switch (TREE_CODE (decl))
19803 case FUNCTION_DECL:
19804 /* What we would really like to do here is to filter out all mere
19805 file-scope declarations of file-scope functions which are never
19806 referenced later within this translation unit (and keep all of ones
19807 that *are* referenced later on) but we aren't clairvoyant, so we have
19808 no idea which functions will be referenced in the future (i.e. later
19809 on within the current translation unit). So here we just ignore all
19810 file-scope function declarations which are not also definitions. If
19811 and when the debugger needs to know something about these functions,
19812 it will have to hunt around and find the DWARF information associated
19813 with the definition of the function.
19815 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19816 nodes represent definitions and which ones represent mere
19817 declarations. We have to check DECL_INITIAL instead. That's because
19818 the C front-end supports some weird semantics for "extern inline"
19819 function definitions. These can get inlined within the current
19820 translation unit (and thus, we need to generate Dwarf info for their
19821 abstract instances so that the Dwarf info for the concrete inlined
19822 instances can have something to refer to) but the compiler never
19823 generates any out-of-lines instances of such things (despite the fact
19824 that they *are* definitions).
19826 The important point is that the C front-end marks these "extern
19827 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19828 them anyway. Note that the C++ front-end also plays some similar games
19829 for inline function definitions appearing within include files which
19830 also contain `#pragma interface' pragmas. */
19831 if (DECL_INITIAL (decl) == NULL_TREE)
19834 /* If we're a nested function, initially use a parent of NULL; if we're
19835 a plain function, this will be fixed up in decls_for_scope. If
19836 we're a method, it will be ignored, since we already have a DIE. */
19837 if (decl_function_context (decl)
19838 /* But if we're in terse mode, we don't care about scope. */
19839 && debug_info_level > DINFO_LEVEL_TERSE)
19840 context_die = NULL;
19844 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19845 declaration and if the declaration was never even referenced from
19846 within this entire compilation unit. We suppress these DIEs in
19847 order to save space in the .debug section (by eliminating entries
19848 which are probably useless). Note that we must not suppress
19849 block-local extern declarations (whether used or not) because that
19850 would screw-up the debugger's name lookup mechanism and cause it to
19851 miss things which really ought to be in scope at a given point. */
19852 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
19855 /* For local statics lookup proper context die. */
19856 if (TREE_STATIC (decl) && decl_function_context (decl))
19857 context_die = lookup_decl_die (DECL_CONTEXT (decl));
19859 /* If we are in terse mode, don't generate any DIEs to represent any
19860 variable declarations or definitions. */
19861 if (debug_info_level <= DINFO_LEVEL_TERSE)
19866 if (debug_info_level <= DINFO_LEVEL_TERSE)
19868 if (!is_fortran () && !is_ada ())
19870 if (TREE_STATIC (decl) && decl_function_context (decl))
19871 context_die = lookup_decl_die (DECL_CONTEXT (decl));
19874 case NAMESPACE_DECL:
19875 case IMPORTED_DECL:
19876 if (debug_info_level <= DINFO_LEVEL_TERSE)
19878 if (lookup_decl_die (decl) != NULL)
19883 /* Don't emit stubs for types unless they are needed by other DIEs. */
19884 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
19887 /* Don't bother trying to generate any DIEs to represent any of the
19888 normal built-in types for the language we are compiling. */
19889 if (DECL_IS_BUILTIN (decl))
19892 /* If we are in terse mode, don't generate any DIEs for types. */
19893 if (debug_info_level <= DINFO_LEVEL_TERSE)
19896 /* If we're a function-scope tag, initially use a parent of NULL;
19897 this will be fixed up in decls_for_scope. */
19898 if (decl_function_context (decl))
19899 context_die = NULL;
19907 gen_decl_die (decl, NULL, context_die);
19910 /* Write the debugging output for DECL. */
19913 dwarf2out_function_decl (tree decl)
19915 dwarf2out_decl (decl);
19916 call_arg_locations = NULL;
19917 call_arg_loc_last = NULL;
19918 call_site_count = -1;
19919 tail_call_site_count = -1;
19920 VEC_free (dw_die_ref, heap, block_map);
19921 htab_empty (decl_loc_table);
19922 htab_empty (cached_dw_loc_list_table);
19925 /* Output a marker (i.e. a label) for the beginning of the generated code for
19926 a lexical block. */
19929 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
19930 unsigned int blocknum)
19932 switch_to_section (current_function_section ());
19933 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
19936 /* Output a marker (i.e. a label) for the end of the generated code for a
19940 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
19942 switch_to_section (current_function_section ());
19943 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
19946 /* Returns nonzero if it is appropriate not to emit any debugging
19947 information for BLOCK, because it doesn't contain any instructions.
19949 Don't allow this for blocks with nested functions or local classes
19950 as we would end up with orphans, and in the presence of scheduling
19951 we may end up calling them anyway. */
19954 dwarf2out_ignore_block (const_tree block)
19959 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
19960 if (TREE_CODE (decl) == FUNCTION_DECL
19961 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
19963 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
19965 decl = BLOCK_NONLOCALIZED_VAR (block, i);
19966 if (TREE_CODE (decl) == FUNCTION_DECL
19967 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
19974 /* Hash table routines for file_hash. */
19977 file_table_eq (const void *p1_p, const void *p2_p)
19979 const struct dwarf_file_data *const p1 =
19980 (const struct dwarf_file_data *) p1_p;
19981 const char *const p2 = (const char *) p2_p;
19982 return filename_cmp (p1->filename, p2) == 0;
19986 file_table_hash (const void *p_p)
19988 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
19989 return htab_hash_string (p->filename);
19992 /* Lookup FILE_NAME (in the list of filenames that we know about here in
19993 dwarf2out.c) and return its "index". The index of each (known) filename is
19994 just a unique number which is associated with only that one filename. We
19995 need such numbers for the sake of generating labels (in the .debug_sfnames
19996 section) and references to those files numbers (in the .debug_srcinfo
19997 and.debug_macinfo sections). If the filename given as an argument is not
19998 found in our current list, add it to the list and assign it the next
19999 available unique index number. In order to speed up searches, we remember
20000 the index of the filename was looked up last. This handles the majority of
20003 static struct dwarf_file_data *
20004 lookup_filename (const char *file_name)
20007 struct dwarf_file_data * created;
20009 /* Check to see if the file name that was searched on the previous
20010 call matches this file name. If so, return the index. */
20011 if (file_table_last_lookup
20012 && (file_name == file_table_last_lookup->filename
20013 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
20014 return file_table_last_lookup;
20016 /* Didn't match the previous lookup, search the table. */
20017 slot = htab_find_slot_with_hash (file_table, file_name,
20018 htab_hash_string (file_name), INSERT);
20020 return (struct dwarf_file_data *) *slot;
20022 created = ggc_alloc_dwarf_file_data ();
20023 created->filename = file_name;
20024 created->emitted_number = 0;
20029 /* If the assembler will construct the file table, then translate the compiler
20030 internal file table number into the assembler file table number, and emit
20031 a .file directive if we haven't already emitted one yet. The file table
20032 numbers are different because we prune debug info for unused variables and
20033 types, which may include filenames. */
20036 maybe_emit_file (struct dwarf_file_data * fd)
20038 if (! fd->emitted_number)
20040 if (last_emitted_file)
20041 fd->emitted_number = last_emitted_file->emitted_number + 1;
20043 fd->emitted_number = 1;
20044 last_emitted_file = fd;
20046 if (DWARF2_ASM_LINE_DEBUG_INFO)
20048 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
20049 output_quoted_string (asm_out_file,
20050 remap_debug_filename (fd->filename));
20051 fputc ('\n', asm_out_file);
20055 return fd->emitted_number;
20058 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20059 That generation should happen after function debug info has been
20060 generated. The value of the attribute is the constant value of ARG. */
20063 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
20065 die_arg_entry entry;
20070 if (!tmpl_value_parm_die_table)
20071 tmpl_value_parm_die_table
20072 = VEC_alloc (die_arg_entry, gc, 32);
20076 VEC_safe_push (die_arg_entry, gc,
20077 tmpl_value_parm_die_table,
20081 /* Return TRUE if T is an instance of generic type, FALSE
20085 generic_type_p (tree t)
20087 if (t == NULL_TREE || !TYPE_P (t))
20089 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
20092 /* Schedule the generation of the generic parameter dies for the
20093 instance of generic type T. The proper generation itself is later
20094 done by gen_scheduled_generic_parms_dies. */
20097 schedule_generic_params_dies_gen (tree t)
20099 if (!generic_type_p (t))
20102 if (generic_type_instances == NULL)
20103 generic_type_instances = VEC_alloc (tree, gc, 256);
20105 VEC_safe_push (tree, gc, generic_type_instances, t);
20108 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20109 by append_entry_to_tmpl_value_parm_die_table. This function must
20110 be called after function DIEs have been generated. */
20113 gen_remaining_tmpl_value_param_die_attribute (void)
20115 if (tmpl_value_parm_die_table)
20120 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
20121 tree_add_const_value_attribute (e->die, e->arg);
20125 /* Generate generic parameters DIEs for instances of generic types
20126 that have been previously scheduled by
20127 schedule_generic_params_dies_gen. This function must be called
20128 after all the types of the CU have been laid out. */
20131 gen_scheduled_generic_parms_dies (void)
20136 if (generic_type_instances == NULL)
20139 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
20140 gen_generic_params_dies (t);
20144 /* Replace DW_AT_name for the decl with name. */
20147 dwarf2out_set_name (tree decl, tree name)
20153 die = TYPE_SYMTAB_DIE (decl);
20157 dname = dwarf2_name (name, 0);
20161 attr = get_AT (die, DW_AT_name);
20164 struct indirect_string_node *node;
20166 node = find_AT_string (dname);
20167 /* replace the string. */
20168 attr->dw_attr_val.v.val_str = node;
20172 add_name_attribute (die, dname);
20175 /* Called by the final INSN scan whenever we see a var location. We
20176 use it to drop labels in the right places, and throw the location in
20177 our lookup table. */
20180 dwarf2out_var_location (rtx loc_note)
20182 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
20183 struct var_loc_node *newloc;
20184 rtx next_real, next_note;
20185 static const char *last_label;
20186 static const char *last_postcall_label;
20187 static bool last_in_cold_section_p;
20188 static rtx expected_next_loc_note;
20192 if (!NOTE_P (loc_note))
20194 if (CALL_P (loc_note))
20197 if (SIBLING_CALL_P (loc_note))
20198 tail_call_site_count++;
20203 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
20204 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
20207 /* Optimize processing a large consecutive sequence of location
20208 notes so we don't spend too much time in next_real_insn. If the
20209 next insn is another location note, remember the next_real_insn
20210 calculation for next time. */
20211 next_real = cached_next_real_insn;
20214 if (expected_next_loc_note != loc_note)
20215 next_real = NULL_RTX;
20218 next_note = NEXT_INSN (loc_note);
20220 || INSN_DELETED_P (next_note)
20221 || GET_CODE (next_note) != NOTE
20222 || (NOTE_KIND (next_note) != NOTE_INSN_VAR_LOCATION
20223 && NOTE_KIND (next_note) != NOTE_INSN_CALL_ARG_LOCATION))
20224 next_note = NULL_RTX;
20227 next_real = next_real_insn (loc_note);
20231 expected_next_loc_note = next_note;
20232 cached_next_real_insn = next_real;
20235 cached_next_real_insn = NULL_RTX;
20237 /* If there are no instructions which would be affected by this note,
20238 don't do anything. */
20240 && next_real == NULL_RTX
20241 && !NOTE_DURING_CALL_P (loc_note))
20244 if (next_real == NULL_RTX)
20245 next_real = get_last_insn ();
20247 /* If there were any real insns between note we processed last time
20248 and this note (or if it is the first note), clear
20249 last_{,postcall_}label so that they are not reused this time. */
20250 if (last_var_location_insn == NULL_RTX
20251 || last_var_location_insn != next_real
20252 || last_in_cold_section_p != in_cold_section_p)
20255 last_postcall_label = NULL;
20260 decl = NOTE_VAR_LOCATION_DECL (loc_note);
20261 newloc = add_var_loc_to_decl (decl, loc_note,
20262 NOTE_DURING_CALL_P (loc_note)
20263 ? last_postcall_label : last_label);
20264 if (newloc == NULL)
20273 /* If there were no real insns between note we processed last time
20274 and this note, use the label we emitted last time. Otherwise
20275 create a new label and emit it. */
20276 if (last_label == NULL)
20278 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
20279 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
20281 last_label = ggc_strdup (loclabel);
20286 struct call_arg_loc_node *ca_loc
20287 = ggc_alloc_cleared_call_arg_loc_node ();
20288 rtx prev = prev_real_insn (loc_note), x;
20289 ca_loc->call_arg_loc_note = loc_note;
20290 ca_loc->next = NULL;
20291 ca_loc->label = last_label;
20294 || (NONJUMP_INSN_P (prev)
20295 && GET_CODE (PATTERN (prev)) == SEQUENCE
20296 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
20297 if (!CALL_P (prev))
20298 prev = XVECEXP (PATTERN (prev), 0, 0);
20299 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
20300 x = PATTERN (prev);
20301 if (GET_CODE (x) == PARALLEL)
20302 x = XVECEXP (x, 0, 0);
20303 if (GET_CODE (x) == SET)
20305 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
20307 x = XEXP (XEXP (x, 0), 0);
20308 if (GET_CODE (x) == SYMBOL_REF
20309 && SYMBOL_REF_DECL (x)
20310 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
20311 ca_loc->symbol_ref = x;
20313 ca_loc->block = insn_scope (prev);
20314 if (call_arg_locations)
20315 call_arg_loc_last->next = ca_loc;
20317 call_arg_locations = ca_loc;
20318 call_arg_loc_last = ca_loc;
20320 else if (!NOTE_DURING_CALL_P (loc_note))
20321 newloc->label = last_label;
20324 if (!last_postcall_label)
20326 sprintf (loclabel, "%s-1", last_label);
20327 last_postcall_label = ggc_strdup (loclabel);
20329 newloc->label = last_postcall_label;
20332 last_var_location_insn = next_real;
20333 last_in_cold_section_p = in_cold_section_p;
20336 /* Note in one location list that text section has changed. */
20339 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
20341 var_loc_list *list = (var_loc_list *) *slot;
20343 list->last_before_switch
20344 = list->last->next ? list->last->next : list->last;
20348 /* Note in all location lists that text section has changed. */
20351 var_location_switch_text_section (void)
20353 if (decl_loc_table == NULL)
20356 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
20359 /* Create a new line number table. */
20361 static dw_line_info_table *
20362 new_line_info_table (void)
20364 dw_line_info_table *table;
20366 table = ggc_alloc_cleared_dw_line_info_table_struct ();
20367 table->file_num = 1;
20368 table->line_num = 1;
20369 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
20374 /* Lookup the "current" table into which we emit line info, so
20375 that we don't have to do it for every source line. */
20378 set_cur_line_info_table (section *sec)
20380 dw_line_info_table *table;
20382 if (sec == text_section)
20383 table = text_section_line_info;
20384 else if (sec == cold_text_section)
20386 table = cold_text_section_line_info;
20389 cold_text_section_line_info = table = new_line_info_table ();
20390 table->end_label = cold_end_label;
20395 const char *end_label;
20397 if (flag_reorder_blocks_and_partition)
20399 if (in_cold_section_p)
20400 end_label = crtl->subsections.cold_section_end_label;
20402 end_label = crtl->subsections.hot_section_end_label;
20406 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20407 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
20408 current_function_funcdef_no);
20409 end_label = ggc_strdup (label);
20412 table = new_line_info_table ();
20413 table->end_label = end_label;
20415 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
20418 if (DWARF2_ASM_LINE_DEBUG_INFO)
20419 table->is_stmt = (cur_line_info_table
20420 ? cur_line_info_table->is_stmt
20421 : DWARF_LINE_DEFAULT_IS_STMT_START);
20422 cur_line_info_table = table;
20426 /* We need to reset the locations at the beginning of each
20427 function. We can't do this in the end_function hook, because the
20428 declarations that use the locations won't have been output when
20429 that hook is called. Also compute have_multiple_function_sections here. */
20432 dwarf2out_begin_function (tree fun)
20434 section *sec = function_section (fun);
20436 if (sec != text_section)
20437 have_multiple_function_sections = true;
20439 if (flag_reorder_blocks_and_partition && !cold_text_section)
20441 gcc_assert (current_function_decl == fun);
20442 cold_text_section = unlikely_text_section ();
20443 switch_to_section (cold_text_section);
20444 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
20445 switch_to_section (sec);
20448 dwarf2out_note_section_used ();
20449 call_site_count = 0;
20450 tail_call_site_count = 0;
20452 set_cur_line_info_table (sec);
20455 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20458 push_dw_line_info_entry (dw_line_info_table *table,
20459 enum dw_line_info_opcode opcode, unsigned int val)
20461 dw_line_info_entry e;
20464 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
20467 /* Output a label to mark the beginning of a source code line entry
20468 and record information relating to this source line, in
20469 'line_info_table' for later output of the .debug_line section. */
20470 /* ??? The discriminator parameter ought to be unsigned. */
20473 dwarf2out_source_line (unsigned int line, const char *filename,
20474 int discriminator, bool is_stmt)
20476 unsigned int file_num;
20477 dw_line_info_table *table;
20479 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
20482 /* The discriminator column was added in dwarf4. Simplify the below
20483 by simply removing it if we're not supposed to output it. */
20484 if (dwarf_version < 4 && dwarf_strict)
20487 table = cur_line_info_table;
20488 file_num = maybe_emit_file (lookup_filename (filename));
20490 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20491 the debugger has used the second (possibly duplicate) line number
20492 at the beginning of the function to mark the end of the prologue.
20493 We could eliminate any other duplicates within the function. For
20494 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20495 that second line number entry. */
20496 /* Recall that this end-of-prologue indication is *not* the same thing
20497 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20498 to which the hook corresponds, follows the last insn that was
20499 emitted by gen_prologue. What we need is to preceed the first insn
20500 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20501 insn that corresponds to something the user wrote. These may be
20502 very different locations once scheduling is enabled. */
20504 if (0 && file_num == table->file_num
20505 && line == table->line_num
20506 && discriminator == table->discrim_num
20507 && is_stmt == table->is_stmt)
20510 switch_to_section (current_function_section ());
20512 /* If requested, emit something human-readable. */
20513 if (flag_debug_asm)
20514 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
20516 if (DWARF2_ASM_LINE_DEBUG_INFO)
20518 /* Emit the .loc directive understood by GNU as. */
20519 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
20520 file_num, line, is_stmt, discriminator */
20521 fputs ("\t.loc ", asm_out_file);
20522 fprint_ul (asm_out_file, file_num);
20523 putc (' ', asm_out_file);
20524 fprint_ul (asm_out_file, line);
20525 putc (' ', asm_out_file);
20526 putc ('0', asm_out_file);
20528 if (is_stmt != table->is_stmt)
20530 fputs (" is_stmt ", asm_out_file);
20531 putc (is_stmt ? '1' : '0', asm_out_file);
20533 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
20535 gcc_assert (discriminator > 0);
20536 fputs (" discriminator ", asm_out_file);
20537 fprint_ul (asm_out_file, (unsigned long) discriminator);
20539 putc ('\n', asm_out_file);
20543 unsigned int label_num = ++line_info_label_num;
20545 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
20547 push_dw_line_info_entry (table, LI_set_address, label_num);
20548 if (file_num != table->file_num)
20549 push_dw_line_info_entry (table, LI_set_file, file_num);
20550 if (discriminator != table->discrim_num)
20551 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
20552 if (is_stmt != table->is_stmt)
20553 push_dw_line_info_entry (table, LI_negate_stmt, 0);
20554 push_dw_line_info_entry (table, LI_set_line, line);
20557 table->file_num = file_num;
20558 table->line_num = line;
20559 table->discrim_num = discriminator;
20560 table->is_stmt = is_stmt;
20561 table->in_use = true;
20564 /* Record the beginning of a new source file. */
20567 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
20569 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20571 /* Record the beginning of the file for break_out_includes. */
20572 dw_die_ref bincl_die;
20574 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
20575 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
20578 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20581 e.code = DW_MACINFO_start_file;
20583 e.info = ggc_strdup (filename);
20584 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20588 /* Record the end of a source file. */
20591 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
20593 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20594 /* Record the end of the file for break_out_includes. */
20595 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
20597 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20600 e.code = DW_MACINFO_end_file;
20603 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20607 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20608 the tail part of the directive line, i.e. the part which is past the
20609 initial whitespace, #, whitespace, directive-name, whitespace part. */
20612 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
20613 const char *buffer ATTRIBUTE_UNUSED)
20615 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20618 /* Insert a dummy first entry to be able to optimize the whole
20619 predefined macro block using DW_MACRO_GNU_transparent_include. */
20620 if (VEC_empty (macinfo_entry, macinfo_table) && lineno == 0)
20625 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20627 e.code = DW_MACINFO_define;
20629 e.info = ggc_strdup (buffer);
20630 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20634 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20635 the tail part of the directive line, i.e. the part which is past the
20636 initial whitespace, #, whitespace, directive-name, whitespace part. */
20639 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
20640 const char *buffer ATTRIBUTE_UNUSED)
20642 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20645 /* Insert a dummy first entry to be able to optimize the whole
20646 predefined macro block using DW_MACRO_GNU_transparent_include. */
20647 if (VEC_empty (macinfo_entry, macinfo_table) && lineno == 0)
20652 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20654 e.code = DW_MACINFO_undef;
20656 e.info = ggc_strdup (buffer);
20657 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20661 /* Routines to manipulate hash table of CUs. */
20664 htab_macinfo_hash (const void *of)
20666 const macinfo_entry *const entry =
20667 (const macinfo_entry *) of;
20669 return htab_hash_string (entry->info);
20673 htab_macinfo_eq (const void *of1, const void *of2)
20675 const macinfo_entry *const entry1 = (const macinfo_entry *) of1;
20676 const macinfo_entry *const entry2 = (const macinfo_entry *) of2;
20678 return !strcmp (entry1->info, entry2->info);
20681 /* Output a single .debug_macinfo entry. */
20684 output_macinfo_op (macinfo_entry *ref)
20688 struct indirect_string_node *node;
20689 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20690 struct dwarf_file_data *fd;
20694 case DW_MACINFO_start_file:
20695 fd = lookup_filename (ref->info);
20696 file_num = maybe_emit_file (fd);
20697 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
20698 dw2_asm_output_data_uleb128 (ref->lineno,
20699 "Included from line number %lu",
20700 (unsigned long) ref->lineno);
20701 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
20703 case DW_MACINFO_end_file:
20704 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
20706 case DW_MACINFO_define:
20707 case DW_MACINFO_undef:
20708 len = strlen (ref->info) + 1;
20710 && len > DWARF_OFFSET_SIZE
20711 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
20712 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
20714 ref->code = ref->code == DW_MACINFO_define
20715 ? DW_MACRO_GNU_define_indirect
20716 : DW_MACRO_GNU_undef_indirect;
20717 output_macinfo_op (ref);
20720 dw2_asm_output_data (1, ref->code,
20721 ref->code == DW_MACINFO_define
20722 ? "Define macro" : "Undefine macro");
20723 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20724 (unsigned long) ref->lineno);
20725 dw2_asm_output_nstring (ref->info, -1, "The macro");
20727 case DW_MACRO_GNU_define_indirect:
20728 case DW_MACRO_GNU_undef_indirect:
20729 node = find_AT_string (ref->info);
20730 if (node->form != DW_FORM_strp)
20733 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
20734 ++dw2_string_counter;
20735 node->label = xstrdup (label);
20736 node->form = DW_FORM_strp;
20738 dw2_asm_output_data (1, ref->code,
20739 ref->code == DW_MACRO_GNU_define_indirect
20740 ? "Define macro indirect"
20741 : "Undefine macro indirect");
20742 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20743 (unsigned long) ref->lineno);
20744 dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
20745 debug_str_section, "The macro: \"%s\"",
20748 case DW_MACRO_GNU_transparent_include:
20749 dw2_asm_output_data (1, ref->code, "Transparent include");
20750 ASM_GENERATE_INTERNAL_LABEL (label,
20751 DEBUG_MACRO_SECTION_LABEL, ref->lineno);
20752 dw2_asm_output_offset (DWARF_OFFSET_SIZE, label, NULL, NULL);
20755 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
20756 ASM_COMMENT_START, (unsigned long) ref->code);
20761 /* Attempt to make a sequence of define/undef macinfo ops shareable with
20762 other compilation unit .debug_macinfo sections. IDX is the first
20763 index of a define/undef, return the number of ops that should be
20764 emitted in a comdat .debug_macinfo section and emit
20765 a DW_MACRO_GNU_transparent_include entry referencing it.
20766 If the define/undef entry should be emitted normally, return 0. */
20769 optimize_macinfo_range (unsigned int idx, VEC (macinfo_entry, gc) *files,
20770 htab_t *macinfo_htab)
20772 macinfo_entry *first, *second, *cur, *inc;
20773 char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
20774 unsigned char checksum[16];
20775 struct md5_ctx ctx;
20776 char *grp_name, *tail;
20778 unsigned int i, count, encoded_filename_len, linebuf_len;
20781 first = VEC_index (macinfo_entry, macinfo_table, idx);
20782 second = VEC_index (macinfo_entry, macinfo_table, idx + 1);
20784 /* Optimize only if there are at least two consecutive define/undef ops,
20785 and either all of them are before first DW_MACINFO_start_file
20786 with lineno 0 (i.e. predefined macro block), or all of them are
20787 in some included header file. */
20788 if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
20790 if (VEC_empty (macinfo_entry, files))
20792 if (first->lineno != 0 || second->lineno != 0)
20795 else if (first->lineno == 0)
20798 /* Find the last define/undef entry that can be grouped together
20799 with first and at the same time compute md5 checksum of their
20800 codes, linenumbers and strings. */
20801 md5_init_ctx (&ctx);
20802 for (i = idx; VEC_iterate (macinfo_entry, macinfo_table, i, cur); i++)
20803 if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
20805 else if (first->lineno == 0 && cur->lineno != 0)
20809 unsigned char code = cur->code;
20810 md5_process_bytes (&code, 1, &ctx);
20811 checksum_uleb128 (cur->lineno, &ctx);
20812 md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
20814 md5_finish_ctx (&ctx, checksum);
20817 /* From the containing include filename (if any) pick up just
20818 usable characters from its basename. */
20819 if (first->lineno == 0)
20822 base = lbasename (VEC_last (macinfo_entry, files)->info);
20823 for (encoded_filename_len = 0, i = 0; base[i]; i++)
20824 if (ISIDNUM (base[i]) || base[i] == '.')
20825 encoded_filename_len++;
20826 /* Count . at the end. */
20827 if (encoded_filename_len)
20828 encoded_filename_len++;
20830 sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
20831 linebuf_len = strlen (linebuf);
20833 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
20834 grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
20836 memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4);
20837 tail = grp_name + 4;
20838 if (encoded_filename_len)
20840 for (i = 0; base[i]; i++)
20841 if (ISIDNUM (base[i]) || base[i] == '.')
20845 memcpy (tail, linebuf, linebuf_len);
20846 tail += linebuf_len;
20848 for (i = 0; i < 16; i++)
20849 sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
20851 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
20852 in the empty vector entry before the first define/undef. */
20853 inc = VEC_index (macinfo_entry, macinfo_table, idx - 1);
20854 inc->code = DW_MACRO_GNU_transparent_include;
20856 inc->info = ggc_strdup (grp_name);
20857 if (*macinfo_htab == NULL)
20858 *macinfo_htab = htab_create (10, htab_macinfo_hash, htab_macinfo_eq, NULL);
20859 /* Avoid emitting duplicates. */
20860 slot = htab_find_slot (*macinfo_htab, inc, INSERT);
20865 /* If such an entry has been used before, just emit
20866 a DW_MACRO_GNU_transparent_include op. */
20867 inc = (macinfo_entry *) *slot;
20868 output_macinfo_op (inc);
20869 /* And clear all macinfo_entry in the range to avoid emitting them
20870 in the second pass. */
20872 VEC_iterate (macinfo_entry, macinfo_table, i, cur)
20873 && i < idx + count;
20883 inc->lineno = htab_elements (*macinfo_htab);
20884 output_macinfo_op (inc);
20889 /* Output macinfo section(s). */
20892 output_macinfo (void)
20895 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
20896 macinfo_entry *ref;
20897 VEC (macinfo_entry, gc) *files = NULL;
20898 htab_t macinfo_htab = NULL;
20903 /* output_macinfo* uses these interchangeably. */
20904 gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_GNU_define
20905 && (int) DW_MACINFO_undef == (int) DW_MACRO_GNU_undef
20906 && (int) DW_MACINFO_start_file == (int) DW_MACRO_GNU_start_file
20907 && (int) DW_MACINFO_end_file == (int) DW_MACRO_GNU_end_file);
20909 /* For .debug_macro emit the section header. */
20912 dw2_asm_output_data (2, 4, "DWARF macro version number");
20913 if (DWARF_OFFSET_SIZE == 8)
20914 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
20916 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
20917 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_line_section_label,
20918 debug_line_section, NULL);
20921 /* In the first loop, it emits the primary .debug_macinfo section
20922 and after each emitted op the macinfo_entry is cleared.
20923 If a longer range of define/undef ops can be optimized using
20924 DW_MACRO_GNU_transparent_include, the
20925 DW_MACRO_GNU_transparent_include op is emitted and kept in
20926 the vector before the first define/undef in the range and the
20927 whole range of define/undef ops is not emitted and kept. */
20928 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
20932 case DW_MACINFO_start_file:
20933 VEC_safe_push (macinfo_entry, gc, files, ref);
20935 case DW_MACINFO_end_file:
20936 if (!VEC_empty (macinfo_entry, files))
20937 VEC_pop (macinfo_entry, files);
20939 case DW_MACINFO_define:
20940 case DW_MACINFO_undef:
20942 && HAVE_COMDAT_GROUP
20943 && VEC_length (macinfo_entry, files) != 1
20946 && VEC_index (macinfo_entry, macinfo_table, i - 1)->code == 0)
20948 unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
20957 /* A dummy entry may be inserted at the beginning to be able
20958 to optimize the whole block of predefined macros. */
20964 output_macinfo_op (ref);
20969 if (macinfo_htab == NULL)
20972 htab_delete (macinfo_htab);
20974 /* If any DW_MACRO_GNU_transparent_include were used, on those
20975 DW_MACRO_GNU_transparent_include entries terminate the
20976 current chain and switch to a new comdat .debug_macinfo
20977 section and emit the define/undef entries within it. */
20978 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
20983 case DW_MACRO_GNU_transparent_include:
20985 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20986 tree comdat_key = get_identifier (ref->info);
20987 /* Terminate the previous .debug_macinfo section. */
20988 dw2_asm_output_data (1, 0, "End compilation unit");
20989 targetm.asm_out.named_section (DEBUG_MACRO_SECTION,
20991 | SECTION_LINKONCE,
20993 ASM_GENERATE_INTERNAL_LABEL (label,
20994 DEBUG_MACRO_SECTION_LABEL,
20996 ASM_OUTPUT_LABEL (asm_out_file, label);
20999 dw2_asm_output_data (2, 4, "DWARF macro version number");
21000 if (DWARF_OFFSET_SIZE == 8)
21001 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21003 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21006 case DW_MACINFO_define:
21007 case DW_MACINFO_undef:
21008 output_macinfo_op (ref);
21013 gcc_unreachable ();
21017 /* Set up for Dwarf output at the start of compilation. */
21020 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
21022 /* Allocate the file_table. */
21023 file_table = htab_create_ggc (50, file_table_hash,
21024 file_table_eq, NULL);
21026 /* Allocate the decl_die_table. */
21027 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
21028 decl_die_table_eq, NULL);
21030 /* Allocate the decl_loc_table. */
21031 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
21032 decl_loc_table_eq, NULL);
21034 /* Allocate the cached_dw_loc_list_table. */
21035 cached_dw_loc_list_table
21036 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
21037 cached_dw_loc_list_table_eq, NULL);
21039 /* Allocate the initial hunk of the decl_scope_table. */
21040 decl_scope_table = VEC_alloc (tree, gc, 256);
21042 /* Allocate the initial hunk of the abbrev_die_table. */
21043 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
21044 (ABBREV_DIE_TABLE_INCREMENT);
21045 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
21046 /* Zero-th entry is allocated, but unused. */
21047 abbrev_die_table_in_use = 1;
21049 /* Allocate the pubtypes and pubnames vectors. */
21050 pubname_table = VEC_alloc (pubname_entry, gc, 32);
21051 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
21053 incomplete_types = VEC_alloc (tree, gc, 64);
21055 used_rtx_array = VEC_alloc (rtx, gc, 32);
21057 debug_info_section = get_section (DEBUG_INFO_SECTION,
21058 SECTION_DEBUG, NULL);
21059 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
21060 SECTION_DEBUG, NULL);
21061 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
21062 SECTION_DEBUG, NULL);
21063 debug_macinfo_section = get_section (dwarf_strict
21064 ? DEBUG_MACINFO_SECTION
21065 : DEBUG_MACRO_SECTION,
21066 SECTION_DEBUG, NULL);
21067 debug_line_section = get_section (DEBUG_LINE_SECTION,
21068 SECTION_DEBUG, NULL);
21069 debug_loc_section = get_section (DEBUG_LOC_SECTION,
21070 SECTION_DEBUG, NULL);
21071 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
21072 SECTION_DEBUG, NULL);
21073 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
21074 SECTION_DEBUG, NULL);
21075 debug_str_section = get_section (DEBUG_STR_SECTION,
21076 DEBUG_STR_SECTION_FLAGS, NULL);
21077 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
21078 SECTION_DEBUG, NULL);
21079 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
21080 SECTION_DEBUG, NULL);
21082 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
21083 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
21084 DEBUG_ABBREV_SECTION_LABEL, 0);
21085 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
21086 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
21087 COLD_TEXT_SECTION_LABEL, 0);
21088 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
21090 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
21091 DEBUG_INFO_SECTION_LABEL, 0);
21092 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
21093 DEBUG_LINE_SECTION_LABEL, 0);
21094 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
21095 DEBUG_RANGES_SECTION_LABEL, 0);
21096 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
21098 ? DEBUG_MACINFO_SECTION_LABEL
21099 : DEBUG_MACRO_SECTION_LABEL, 0);
21101 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21102 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
21104 switch_to_section (text_section);
21105 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
21107 /* Make sure the line number table for .text always exists. */
21108 text_section_line_info = new_line_info_table ();
21109 text_section_line_info->end_label = text_end_label;
21112 /* Called before cgraph_optimize starts outputtting functions, variables
21113 and toplevel asms into assembly. */
21116 dwarf2out_assembly_start (void)
21118 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21119 && dwarf2out_do_cfi_asm ()
21120 && (!(flag_unwind_tables || flag_exceptions)
21121 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
21122 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
21125 /* A helper function for dwarf2out_finish called through
21126 htab_traverse. Emit one queued .debug_str string. */
21129 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
21131 struct indirect_string_node *node = (struct indirect_string_node *) *h;
21133 if (node->form == DW_FORM_strp)
21135 switch_to_section (debug_str_section);
21136 ASM_OUTPUT_LABEL (asm_out_file, node->label);
21137 assemble_string (node->str, strlen (node->str) + 1);
21143 #if ENABLE_ASSERT_CHECKING
21144 /* Verify that all marks are clear. */
21147 verify_marks_clear (dw_die_ref die)
21151 gcc_assert (! die->die_mark);
21152 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
21154 #endif /* ENABLE_ASSERT_CHECKING */
21156 /* Clear the marks for a die and its children.
21157 Be cool if the mark isn't set. */
21160 prune_unmark_dies (dw_die_ref die)
21166 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
21169 /* Given DIE that we're marking as used, find any other dies
21170 it references as attributes and mark them as used. */
21173 prune_unused_types_walk_attribs (dw_die_ref die)
21178 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21180 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
21182 /* A reference to another DIE.
21183 Make sure that it will get emitted.
21184 If it was broken out into a comdat group, don't follow it. */
21185 if (! use_debug_types
21186 || a->dw_attr == DW_AT_specification
21187 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
21188 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
21190 /* Set the string's refcount to 0 so that prune_unused_types_mark
21191 accounts properly for it. */
21192 if (AT_class (a) == dw_val_class_str)
21193 a->dw_attr_val.v.val_str->refcount = 0;
21197 /* Mark the generic parameters and arguments children DIEs of DIE. */
21200 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
21204 if (die == NULL || die->die_child == NULL)
21206 c = die->die_child;
21209 switch (c->die_tag)
21211 case DW_TAG_template_type_param:
21212 case DW_TAG_template_value_param:
21213 case DW_TAG_GNU_template_template_param:
21214 case DW_TAG_GNU_template_parameter_pack:
21215 prune_unused_types_mark (c, 1);
21221 } while (c && c != die->die_child);
21224 /* Mark DIE as being used. If DOKIDS is true, then walk down
21225 to DIE's children. */
21228 prune_unused_types_mark (dw_die_ref die, int dokids)
21232 if (die->die_mark == 0)
21234 /* We haven't done this node yet. Mark it as used. */
21236 /* If this is the DIE of a generic type instantiation,
21237 mark the children DIEs that describe its generic parms and
21239 prune_unused_types_mark_generic_parms_dies (die);
21241 /* We also have to mark its parents as used.
21242 (But we don't want to mark our parents' kids due to this.) */
21243 if (die->die_parent)
21244 prune_unused_types_mark (die->die_parent, 0);
21246 /* Mark any referenced nodes. */
21247 prune_unused_types_walk_attribs (die);
21249 /* If this node is a specification,
21250 also mark the definition, if it exists. */
21251 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
21252 prune_unused_types_mark (die->die_definition, 1);
21255 if (dokids && die->die_mark != 2)
21257 /* We need to walk the children, but haven't done so yet.
21258 Remember that we've walked the kids. */
21261 /* If this is an array type, we need to make sure our
21262 kids get marked, even if they're types. If we're
21263 breaking out types into comdat sections, do this
21264 for all type definitions. */
21265 if (die->die_tag == DW_TAG_array_type
21266 || (use_debug_types
21267 && is_type_die (die) && ! is_declaration_die (die)))
21268 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
21270 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21274 /* For local classes, look if any static member functions were emitted
21275 and if so, mark them. */
21278 prune_unused_types_walk_local_classes (dw_die_ref die)
21282 if (die->die_mark == 2)
21285 switch (die->die_tag)
21287 case DW_TAG_structure_type:
21288 case DW_TAG_union_type:
21289 case DW_TAG_class_type:
21292 case DW_TAG_subprogram:
21293 if (!get_AT_flag (die, DW_AT_declaration)
21294 || die->die_definition != NULL)
21295 prune_unused_types_mark (die, 1);
21302 /* Mark children. */
21303 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
21306 /* Walk the tree DIE and mark types that we actually use. */
21309 prune_unused_types_walk (dw_die_ref die)
21313 /* Don't do anything if this node is already marked and
21314 children have been marked as well. */
21315 if (die->die_mark == 2)
21318 switch (die->die_tag)
21320 case DW_TAG_structure_type:
21321 case DW_TAG_union_type:
21322 case DW_TAG_class_type:
21323 if (die->die_perennial_p)
21326 for (c = die->die_parent; c; c = c->die_parent)
21327 if (c->die_tag == DW_TAG_subprogram)
21330 /* Finding used static member functions inside of classes
21331 is needed just for local classes, because for other classes
21332 static member function DIEs with DW_AT_specification
21333 are emitted outside of the DW_TAG_*_type. If we ever change
21334 it, we'd need to call this even for non-local classes. */
21336 prune_unused_types_walk_local_classes (die);
21338 /* It's a type node --- don't mark it. */
21341 case DW_TAG_const_type:
21342 case DW_TAG_packed_type:
21343 case DW_TAG_pointer_type:
21344 case DW_TAG_reference_type:
21345 case DW_TAG_rvalue_reference_type:
21346 case DW_TAG_volatile_type:
21347 case DW_TAG_typedef:
21348 case DW_TAG_array_type:
21349 case DW_TAG_interface_type:
21350 case DW_TAG_friend:
21351 case DW_TAG_variant_part:
21352 case DW_TAG_enumeration_type:
21353 case DW_TAG_subroutine_type:
21354 case DW_TAG_string_type:
21355 case DW_TAG_set_type:
21356 case DW_TAG_subrange_type:
21357 case DW_TAG_ptr_to_member_type:
21358 case DW_TAG_file_type:
21359 if (die->die_perennial_p)
21362 /* It's a type node --- don't mark it. */
21366 /* Mark everything else. */
21370 if (die->die_mark == 0)
21374 /* Now, mark any dies referenced from here. */
21375 prune_unused_types_walk_attribs (die);
21380 /* Mark children. */
21381 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21384 /* Increment the string counts on strings referred to from DIE's
21388 prune_unused_types_update_strings (dw_die_ref die)
21393 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21394 if (AT_class (a) == dw_val_class_str)
21396 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
21398 /* Avoid unnecessarily putting strings that are used less than
21399 twice in the hash table. */
21401 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
21404 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
21405 htab_hash_string (s->str),
21407 gcc_assert (*slot == NULL);
21413 /* Remove from the tree DIE any dies that aren't marked. */
21416 prune_unused_types_prune (dw_die_ref die)
21420 gcc_assert (die->die_mark);
21421 prune_unused_types_update_strings (die);
21423 if (! die->die_child)
21426 c = die->die_child;
21428 dw_die_ref prev = c;
21429 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
21430 if (c == die->die_child)
21432 /* No marked children between 'prev' and the end of the list. */
21434 /* No marked children at all. */
21435 die->die_child = NULL;
21438 prev->die_sib = c->die_sib;
21439 die->die_child = prev;
21444 if (c != prev->die_sib)
21446 prune_unused_types_prune (c);
21447 } while (c != die->die_child);
21450 /* Remove dies representing declarations that we never use. */
21453 prune_unused_types (void)
21456 limbo_die_node *node;
21457 comdat_type_node *ctnode;
21459 dw_die_ref base_type;
21461 #if ENABLE_ASSERT_CHECKING
21462 /* All the marks should already be clear. */
21463 verify_marks_clear (comp_unit_die ());
21464 for (node = limbo_die_list; node; node = node->next)
21465 verify_marks_clear (node->die);
21466 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21467 verify_marks_clear (ctnode->root_die);
21468 #endif /* ENABLE_ASSERT_CHECKING */
21470 /* Mark types that are used in global variables. */
21471 premark_types_used_by_global_vars ();
21473 /* Set the mark on nodes that are actually used. */
21474 prune_unused_types_walk (comp_unit_die ());
21475 for (node = limbo_die_list; node; node = node->next)
21476 prune_unused_types_walk (node->die);
21477 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21479 prune_unused_types_walk (ctnode->root_die);
21480 prune_unused_types_mark (ctnode->type_die, 1);
21483 /* Also set the mark on nodes referenced from the
21485 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
21486 prune_unused_types_mark (pub->die, 1);
21487 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21488 prune_unused_types_mark (base_type, 1);
21490 if (debug_str_hash)
21491 htab_empty (debug_str_hash);
21492 prune_unused_types_prune (comp_unit_die ());
21493 for (node = limbo_die_list; node; node = node->next)
21494 prune_unused_types_prune (node->die);
21495 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21496 prune_unused_types_prune (ctnode->root_die);
21498 /* Leave the marks clear. */
21499 prune_unmark_dies (comp_unit_die ());
21500 for (node = limbo_die_list; node; node = node->next)
21501 prune_unmark_dies (node->die);
21502 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21503 prune_unmark_dies (ctnode->root_die);
21506 /* Set the parameter to true if there are any relative pathnames in
21509 file_table_relative_p (void ** slot, void *param)
21511 bool *p = (bool *) param;
21512 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
21513 if (!IS_ABSOLUTE_PATH (d->filename))
21521 /* Routines to manipulate hash table of comdat type units. */
21524 htab_ct_hash (const void *of)
21527 const comdat_type_node *const type_node = (const comdat_type_node *) of;
21529 memcpy (&h, type_node->signature, sizeof (h));
21534 htab_ct_eq (const void *of1, const void *of2)
21536 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
21537 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
21539 return (! memcmp (type_node_1->signature, type_node_2->signature,
21540 DWARF_TYPE_SIGNATURE_SIZE));
21543 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21544 to the location it would have been added, should we know its
21545 DECL_ASSEMBLER_NAME when we added other attributes. This will
21546 probably improve compactness of debug info, removing equivalent
21547 abbrevs, and hide any differences caused by deferring the
21548 computation of the assembler name, triggered by e.g. PCH. */
21551 move_linkage_attr (dw_die_ref die)
21553 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
21554 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
21556 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
21557 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
21561 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
21563 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
21567 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
21569 VEC_pop (dw_attr_node, die->die_attr);
21570 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
21574 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21575 referenced from typed stack ops and count how often they are used. */
21578 mark_base_types (dw_loc_descr_ref loc)
21580 dw_die_ref base_type = NULL;
21582 for (; loc; loc = loc->dw_loc_next)
21584 switch (loc->dw_loc_opc)
21586 case DW_OP_GNU_regval_type:
21587 case DW_OP_GNU_deref_type:
21588 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
21590 case DW_OP_GNU_convert:
21591 case DW_OP_GNU_reinterpret:
21592 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
21595 case DW_OP_GNU_const_type:
21596 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
21598 case DW_OP_GNU_entry_value:
21599 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
21604 gcc_assert (base_type->die_parent == comp_unit_die ());
21605 if (base_type->die_mark)
21606 base_type->die_mark++;
21609 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
21610 base_type->die_mark = 1;
21615 /* Comparison function for sorting marked base types. */
21618 base_type_cmp (const void *x, const void *y)
21620 dw_die_ref dx = *(const dw_die_ref *) x;
21621 dw_die_ref dy = *(const dw_die_ref *) y;
21622 unsigned int byte_size1, byte_size2;
21623 unsigned int encoding1, encoding2;
21624 if (dx->die_mark > dy->die_mark)
21626 if (dx->die_mark < dy->die_mark)
21628 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
21629 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
21630 if (byte_size1 < byte_size2)
21632 if (byte_size1 > byte_size2)
21634 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
21635 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
21636 if (encoding1 < encoding2)
21638 if (encoding1 > encoding2)
21643 /* Move base types marked by mark_base_types as early as possible
21644 in the CU, sorted by decreasing usage count both to make the
21645 uleb128 references as small as possible and to make sure they
21646 will have die_offset already computed by calc_die_sizes when
21647 sizes of typed stack loc ops is computed. */
21650 move_marked_base_types (void)
21653 dw_die_ref base_type, die, c;
21655 if (VEC_empty (dw_die_ref, base_types))
21658 /* Sort by decreasing usage count, they will be added again in that
21660 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
21661 die = comp_unit_die ();
21662 c = die->die_child;
21665 dw_die_ref prev = c;
21667 while (c->die_mark)
21669 remove_child_with_prev (c, prev);
21670 /* As base types got marked, there must be at least
21671 one node other than DW_TAG_base_type. */
21672 gcc_assert (c != c->die_sib);
21676 while (c != die->die_child);
21677 gcc_assert (die->die_child);
21678 c = die->die_child;
21679 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21681 base_type->die_mark = 0;
21682 base_type->die_sib = c->die_sib;
21683 c->die_sib = base_type;
21688 /* Helper function for resolve_addr, attempt to resolve
21689 one CONST_STRING, return non-zero if not successful. Similarly verify that
21690 SYMBOL_REFs refer to variables emitted in the current CU. */
21693 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
21697 if (GET_CODE (rtl) == CONST_STRING)
21699 size_t len = strlen (XSTR (rtl, 0)) + 1;
21700 tree t = build_string (len, XSTR (rtl, 0));
21701 tree tlen = size_int (len - 1);
21703 = build_array_type (char_type_node, build_index_type (tlen));
21704 rtl = lookup_constant_def (t);
21705 if (!rtl || !MEM_P (rtl))
21707 rtl = XEXP (rtl, 0);
21708 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
21713 if (GET_CODE (rtl) == SYMBOL_REF
21714 && SYMBOL_REF_DECL (rtl))
21716 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
21718 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
21721 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
21725 if (GET_CODE (rtl) == CONST
21726 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
21732 /* Helper function for resolve_addr, handle one location
21733 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21734 the location list couldn't be resolved. */
21737 resolve_addr_in_expr (dw_loc_descr_ref loc)
21739 dw_loc_descr_ref keep = NULL;
21740 for (; loc; loc = loc->dw_loc_next)
21741 switch (loc->dw_loc_opc)
21744 if (resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21747 case DW_OP_const4u:
21748 case DW_OP_const8u:
21750 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21753 case DW_OP_plus_uconst:
21754 if (size_of_loc_descr (loc)
21755 > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
21757 && loc->dw_loc_oprnd1.v.val_unsigned > 0)
21759 dw_loc_descr_ref repl
21760 = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
21761 add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
21762 add_loc_descr (&repl, loc->dw_loc_next);
21766 case DW_OP_implicit_value:
21767 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
21768 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL))
21771 case DW_OP_GNU_implicit_pointer:
21772 case DW_OP_GNU_parameter_ref:
21773 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
21776 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
21779 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
21780 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
21781 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
21784 case DW_OP_GNU_const_type:
21785 case DW_OP_GNU_regval_type:
21786 case DW_OP_GNU_deref_type:
21787 case DW_OP_GNU_convert:
21788 case DW_OP_GNU_reinterpret:
21789 while (loc->dw_loc_next
21790 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
21792 dw_die_ref base1, base2;
21793 unsigned enc1, enc2, size1, size2;
21794 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21795 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21796 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
21797 else if (loc->dw_loc_oprnd1.val_class
21798 == dw_val_class_unsigned_const)
21801 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
21802 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
21803 == dw_val_class_unsigned_const)
21805 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
21806 gcc_assert (base1->die_tag == DW_TAG_base_type
21807 && base2->die_tag == DW_TAG_base_type);
21808 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
21809 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
21810 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
21811 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
21813 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
21814 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
21818 /* Optimize away next DW_OP_GNU_convert after
21819 adjusting LOC's base type die reference. */
21820 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21821 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21822 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
21824 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
21825 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
21828 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21829 point typed stack entry. */
21830 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
21831 keep = loc->dw_loc_next;
21841 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21842 an address in .rodata section if the string literal is emitted there,
21843 or remove the containing location list or replace DW_AT_const_value
21844 with DW_AT_location and empty location expression, if it isn't found
21845 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21846 to something that has been emitted in the current CU. */
21849 resolve_addr (dw_die_ref die)
21853 dw_loc_list_ref *curr, *start, loc;
21856 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21857 switch (AT_class (a))
21859 case dw_val_class_loc_list:
21860 start = curr = AT_loc_list_ptr (a);
21863 /* The same list can be referenced more than once. See if we have
21864 already recorded the result from a previous pass. */
21866 *curr = loc->dw_loc_next;
21867 else if (!loc->resolved_addr)
21869 /* As things stand, we do not expect or allow one die to
21870 reference a suffix of another die's location list chain.
21871 References must be identical or completely separate.
21872 There is therefore no need to cache the result of this
21873 pass on any list other than the first; doing so
21874 would lead to unnecessary writes. */
21877 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
21878 if (!resolve_addr_in_expr ((*curr)->expr))
21880 dw_loc_list_ref next = (*curr)->dw_loc_next;
21881 if (next && (*curr)->ll_symbol)
21883 gcc_assert (!next->ll_symbol);
21884 next->ll_symbol = (*curr)->ll_symbol;
21890 mark_base_types ((*curr)->expr);
21891 curr = &(*curr)->dw_loc_next;
21895 loc->resolved_addr = 1;
21899 loc->dw_loc_next = *start;
21904 remove_AT (die, a->dw_attr);
21908 case dw_val_class_loc:
21910 dw_loc_descr_ref l = AT_loc (a);
21911 /* For -gdwarf-2 don't attempt to optimize
21912 DW_AT_data_member_location containing
21913 DW_OP_plus_uconst - older consumers might
21914 rely on it being that op instead of a more complex,
21915 but shorter, location description. */
21916 if ((dwarf_version > 2
21917 || a->dw_attr != DW_AT_data_member_location
21919 || l->dw_loc_opc != DW_OP_plus_uconst
21920 || l->dw_loc_next != NULL)
21921 && !resolve_addr_in_expr (l))
21923 remove_AT (die, a->dw_attr);
21927 mark_base_types (l);
21930 case dw_val_class_addr:
21931 if (a->dw_attr == DW_AT_const_value
21932 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
21934 remove_AT (die, a->dw_attr);
21937 if (die->die_tag == DW_TAG_GNU_call_site
21938 && a->dw_attr == DW_AT_abstract_origin)
21940 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
21941 dw_die_ref tdie = lookup_decl_die (tdecl);
21943 && DECL_EXTERNAL (tdecl)
21944 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
21946 force_decl_die (tdecl);
21947 tdie = lookup_decl_die (tdecl);
21951 a->dw_attr_val.val_class = dw_val_class_die_ref;
21952 a->dw_attr_val.v.val_die_ref.die = tdie;
21953 a->dw_attr_val.v.val_die_ref.external = 0;
21957 remove_AT (die, a->dw_attr);
21966 FOR_EACH_CHILD (die, c, resolve_addr (c));
21969 /* Helper routines for optimize_location_lists.
21970 This pass tries to share identical local lists in .debug_loc
21973 /* Iteratively hash operands of LOC opcode. */
21975 static inline hashval_t
21976 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
21978 dw_val_ref val1 = &loc->dw_loc_oprnd1;
21979 dw_val_ref val2 = &loc->dw_loc_oprnd2;
21981 switch (loc->dw_loc_opc)
21983 case DW_OP_const4u:
21984 case DW_OP_const8u:
21988 case DW_OP_const1u:
21989 case DW_OP_const1s:
21990 case DW_OP_const2u:
21991 case DW_OP_const2s:
21992 case DW_OP_const4s:
21993 case DW_OP_const8s:
21997 case DW_OP_plus_uconst:
22033 case DW_OP_deref_size:
22034 case DW_OP_xderef_size:
22035 hash = iterative_hash_object (val1->v.val_int, hash);
22042 gcc_assert (val1->val_class == dw_val_class_loc);
22043 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
22044 hash = iterative_hash_object (offset, hash);
22047 case DW_OP_implicit_value:
22048 hash = iterative_hash_object (val1->v.val_unsigned, hash);
22049 switch (val2->val_class)
22051 case dw_val_class_const:
22052 hash = iterative_hash_object (val2->v.val_int, hash);
22054 case dw_val_class_vec:
22056 unsigned int elt_size = val2->v.val_vec.elt_size;
22057 unsigned int len = val2->v.val_vec.length;
22059 hash = iterative_hash_object (elt_size, hash);
22060 hash = iterative_hash_object (len, hash);
22061 hash = iterative_hash (val2->v.val_vec.array,
22062 len * elt_size, hash);
22065 case dw_val_class_const_double:
22066 hash = iterative_hash_object (val2->v.val_double.low, hash);
22067 hash = iterative_hash_object (val2->v.val_double.high, hash);
22069 case dw_val_class_addr:
22070 hash = iterative_hash_rtx (val2->v.val_addr, hash);
22073 gcc_unreachable ();
22077 case DW_OP_bit_piece:
22078 hash = iterative_hash_object (val1->v.val_int, hash);
22079 hash = iterative_hash_object (val2->v.val_int, hash);
22085 unsigned char dtprel = 0xd1;
22086 hash = iterative_hash_object (dtprel, hash);
22088 hash = iterative_hash_rtx (val1->v.val_addr, hash);
22090 case DW_OP_GNU_implicit_pointer:
22091 hash = iterative_hash_object (val2->v.val_int, hash);
22093 case DW_OP_GNU_entry_value:
22094 hash = hash_loc_operands (val1->v.val_loc, hash);
22096 case DW_OP_GNU_regval_type:
22097 case DW_OP_GNU_deref_type:
22099 unsigned int byte_size
22100 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
22101 unsigned int encoding
22102 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
22103 hash = iterative_hash_object (val1->v.val_int, hash);
22104 hash = iterative_hash_object (byte_size, hash);
22105 hash = iterative_hash_object (encoding, hash);
22108 case DW_OP_GNU_convert:
22109 case DW_OP_GNU_reinterpret:
22110 if (val1->val_class == dw_val_class_unsigned_const)
22112 hash = iterative_hash_object (val1->v.val_unsigned, hash);
22116 case DW_OP_GNU_const_type:
22118 unsigned int byte_size
22119 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
22120 unsigned int encoding
22121 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
22122 hash = iterative_hash_object (byte_size, hash);
22123 hash = iterative_hash_object (encoding, hash);
22124 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
22126 hash = iterative_hash_object (val2->val_class, hash);
22127 switch (val2->val_class)
22129 case dw_val_class_const:
22130 hash = iterative_hash_object (val2->v.val_int, hash);
22132 case dw_val_class_vec:
22134 unsigned int elt_size = val2->v.val_vec.elt_size;
22135 unsigned int len = val2->v.val_vec.length;
22137 hash = iterative_hash_object (elt_size, hash);
22138 hash = iterative_hash_object (len, hash);
22139 hash = iterative_hash (val2->v.val_vec.array,
22140 len * elt_size, hash);
22143 case dw_val_class_const_double:
22144 hash = iterative_hash_object (val2->v.val_double.low, hash);
22145 hash = iterative_hash_object (val2->v.val_double.high, hash);
22148 gcc_unreachable ();
22154 /* Other codes have no operands. */
22160 /* Iteratively hash the whole DWARF location expression LOC. */
22162 static inline hashval_t
22163 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
22165 dw_loc_descr_ref l;
22166 bool sizes_computed = false;
22167 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22168 size_of_locs (loc);
22170 for (l = loc; l != NULL; l = l->dw_loc_next)
22172 enum dwarf_location_atom opc = l->dw_loc_opc;
22173 hash = iterative_hash_object (opc, hash);
22174 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
22176 size_of_locs (loc);
22177 sizes_computed = true;
22179 hash = hash_loc_operands (l, hash);
22184 /* Compute hash of the whole location list LIST_HEAD. */
22187 hash_loc_list (dw_loc_list_ref list_head)
22189 dw_loc_list_ref curr = list_head;
22190 hashval_t hash = 0;
22192 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
22194 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
22195 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
22197 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
22199 hash = hash_locs (curr->expr, hash);
22201 list_head->hash = hash;
22204 /* Return true if X and Y opcodes have the same operands. */
22207 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
22209 dw_val_ref valx1 = &x->dw_loc_oprnd1;
22210 dw_val_ref valx2 = &x->dw_loc_oprnd2;
22211 dw_val_ref valy1 = &y->dw_loc_oprnd1;
22212 dw_val_ref valy2 = &y->dw_loc_oprnd2;
22214 switch (x->dw_loc_opc)
22216 case DW_OP_const4u:
22217 case DW_OP_const8u:
22221 case DW_OP_const1u:
22222 case DW_OP_const1s:
22223 case DW_OP_const2u:
22224 case DW_OP_const2s:
22225 case DW_OP_const4s:
22226 case DW_OP_const8s:
22230 case DW_OP_plus_uconst:
22266 case DW_OP_deref_size:
22267 case DW_OP_xderef_size:
22268 return valx1->v.val_int == valy1->v.val_int;
22271 gcc_assert (valx1->val_class == dw_val_class_loc
22272 && valy1->val_class == dw_val_class_loc
22273 && x->dw_loc_addr == y->dw_loc_addr);
22274 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
22275 case DW_OP_implicit_value:
22276 if (valx1->v.val_unsigned != valy1->v.val_unsigned
22277 || valx2->val_class != valy2->val_class)
22279 switch (valx2->val_class)
22281 case dw_val_class_const:
22282 return valx2->v.val_int == valy2->v.val_int;
22283 case dw_val_class_vec:
22284 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22285 && valx2->v.val_vec.length == valy2->v.val_vec.length
22286 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22287 valx2->v.val_vec.elt_size
22288 * valx2->v.val_vec.length) == 0;
22289 case dw_val_class_const_double:
22290 return valx2->v.val_double.low == valy2->v.val_double.low
22291 && valx2->v.val_double.high == valy2->v.val_double.high;
22292 case dw_val_class_addr:
22293 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
22295 gcc_unreachable ();
22298 case DW_OP_bit_piece:
22299 return valx1->v.val_int == valy1->v.val_int
22300 && valx2->v.val_int == valy2->v.val_int;
22303 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
22304 case DW_OP_GNU_implicit_pointer:
22305 return valx1->val_class == dw_val_class_die_ref
22306 && valx1->val_class == valy1->val_class
22307 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
22308 && valx2->v.val_int == valy2->v.val_int;
22309 case DW_OP_GNU_entry_value:
22310 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
22311 case DW_OP_GNU_const_type:
22312 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
22313 || valx2->val_class != valy2->val_class)
22315 switch (valx2->val_class)
22317 case dw_val_class_const:
22318 return valx2->v.val_int == valy2->v.val_int;
22319 case dw_val_class_vec:
22320 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22321 && valx2->v.val_vec.length == valy2->v.val_vec.length
22322 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22323 valx2->v.val_vec.elt_size
22324 * valx2->v.val_vec.length) == 0;
22325 case dw_val_class_const_double:
22326 return valx2->v.val_double.low == valy2->v.val_double.low
22327 && valx2->v.val_double.high == valy2->v.val_double.high;
22329 gcc_unreachable ();
22331 case DW_OP_GNU_regval_type:
22332 case DW_OP_GNU_deref_type:
22333 return valx1->v.val_int == valy1->v.val_int
22334 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
22335 case DW_OP_GNU_convert:
22336 case DW_OP_GNU_reinterpret:
22337 if (valx1->val_class != valy1->val_class)
22339 if (valx1->val_class == dw_val_class_unsigned_const)
22340 return valx1->v.val_unsigned == valy1->v.val_unsigned;
22341 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
22342 case DW_OP_GNU_parameter_ref:
22343 return valx1->val_class == dw_val_class_die_ref
22344 && valx1->val_class == valy1->val_class
22345 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
22347 /* Other codes have no operands. */
22352 /* Return true if DWARF location expressions X and Y are the same. */
22355 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
22357 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
22358 if (x->dw_loc_opc != y->dw_loc_opc
22359 || x->dtprel != y->dtprel
22360 || !compare_loc_operands (x, y))
22362 return x == NULL && y == NULL;
22365 /* Return precomputed hash of location list X. */
22368 loc_list_hash (const void *x)
22370 return ((const struct dw_loc_list_struct *) x)->hash;
22373 /* Return 1 if location lists X and Y are the same. */
22376 loc_list_eq (const void *x, const void *y)
22378 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
22379 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
22382 if (a->hash != b->hash)
22384 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
22385 if (strcmp (a->begin, b->begin) != 0
22386 || strcmp (a->end, b->end) != 0
22387 || (a->section == NULL) != (b->section == NULL)
22388 || (a->section && strcmp (a->section, b->section) != 0)
22389 || !compare_locs (a->expr, b->expr))
22391 return a == NULL && b == NULL;
22394 /* Recursively optimize location lists referenced from DIE
22395 children and share them whenever possible. */
22398 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
22405 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22406 if (AT_class (a) == dw_val_class_loc_list)
22408 dw_loc_list_ref list = AT_loc_list (a);
22409 /* TODO: perform some optimizations here, before hashing
22410 it and storing into the hash table. */
22411 hash_loc_list (list);
22412 slot = htab_find_slot_with_hash (htab, list, list->hash,
22415 *slot = (void *) list;
22417 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
22420 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
22423 /* Optimize location lists referenced from DIE
22424 children and share them whenever possible. */
22427 optimize_location_lists (dw_die_ref die)
22429 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
22430 optimize_location_lists_1 (die, htab);
22431 htab_delete (htab);
22434 /* Output stuff that dwarf requires at the end of every file,
22435 and generate the DWARF-2 debugging info. */
22438 dwarf2out_finish (const char *filename)
22440 limbo_die_node *node, *next_node;
22441 comdat_type_node *ctnode;
22442 htab_t comdat_type_table;
22445 /* PCH might result in DW_AT_producer string being restored from the
22446 header compilation, fix it up if needed. */
22447 dw_attr_ref producer = get_AT (comp_unit_die (), DW_AT_producer);
22448 if (strcmp (AT_string (producer), producer_string) != 0)
22450 struct indirect_string_node *node = find_AT_string (producer_string);
22451 producer->dw_attr_val.v.val_str = node;
22454 gen_scheduled_generic_parms_dies ();
22455 gen_remaining_tmpl_value_param_die_attribute ();
22457 /* Add the name for the main input file now. We delayed this from
22458 dwarf2out_init to avoid complications with PCH. */
22459 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
22460 if (!IS_ABSOLUTE_PATH (filename))
22461 add_comp_dir_attribute (comp_unit_die ());
22462 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
22465 htab_traverse (file_table, file_table_relative_p, &p);
22467 add_comp_dir_attribute (comp_unit_die ());
22470 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
22472 add_location_or_const_value_attribute (
22473 VEC_index (deferred_locations, deferred_locations_list, i)->die,
22474 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
22479 /* Traverse the limbo die list, and add parent/child links. The only
22480 dies without parents that should be here are concrete instances of
22481 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22482 For concrete instances, we can get the parent die from the abstract
22484 for (node = limbo_die_list; node; node = next_node)
22486 dw_die_ref die = node->die;
22487 next_node = node->next;
22489 if (die->die_parent == NULL)
22491 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
22493 if (origin && origin->die_parent)
22494 add_child_die (origin->die_parent, die);
22495 else if (is_cu_die (die))
22497 else if (seen_error ())
22498 /* It's OK to be confused by errors in the input. */
22499 add_child_die (comp_unit_die (), die);
22502 /* In certain situations, the lexical block containing a
22503 nested function can be optimized away, which results
22504 in the nested function die being orphaned. Likewise
22505 with the return type of that nested function. Force
22506 this to be a child of the containing function.
22508 It may happen that even the containing function got fully
22509 inlined and optimized out. In that case we are lost and
22510 assign the empty child. This should not be big issue as
22511 the function is likely unreachable too. */
22512 tree context = NULL_TREE;
22514 gcc_assert (node->created_for);
22516 if (DECL_P (node->created_for))
22517 context = DECL_CONTEXT (node->created_for);
22518 else if (TYPE_P (node->created_for))
22519 context = TYPE_CONTEXT (node->created_for);
22521 origin = get_context_die (context);
22522 add_child_die (origin, die);
22527 limbo_die_list = NULL;
22529 #if ENABLE_ASSERT_CHECKING
22531 dw_die_ref die = comp_unit_die (), c;
22532 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
22535 resolve_addr (comp_unit_die ());
22536 move_marked_base_types ();
22538 for (node = deferred_asm_name; node; node = node->next)
22540 tree decl = node->created_for;
22541 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22543 add_linkage_attr (node->die, decl);
22544 move_linkage_attr (node->die);
22548 deferred_asm_name = NULL;
22550 /* Walk through the list of incomplete types again, trying once more to
22551 emit full debugging info for them. */
22552 retry_incomplete_types ();
22554 if (flag_eliminate_unused_debug_types)
22555 prune_unused_types ();
22557 /* Generate separate CUs for each of the include files we've seen.
22558 They will go into limbo_die_list. */
22559 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22560 break_out_includes (comp_unit_die ());
22562 /* Generate separate COMDAT sections for type DIEs. */
22563 if (use_debug_types)
22565 break_out_comdat_types (comp_unit_die ());
22567 /* Each new type_unit DIE was added to the limbo die list when created.
22568 Since these have all been added to comdat_type_list, clear the
22570 limbo_die_list = NULL;
22572 /* For each new comdat type unit, copy declarations for incomplete
22573 types to make the new unit self-contained (i.e., no direct
22574 references to the main compile unit). */
22575 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22576 copy_decls_for_unworthy_types (ctnode->root_die);
22577 copy_decls_for_unworthy_types (comp_unit_die ());
22579 /* In the process of copying declarations from one unit to another,
22580 we may have left some declarations behind that are no longer
22581 referenced. Prune them. */
22582 prune_unused_types ();
22585 /* Traverse the DIE's and add add sibling attributes to those DIE's
22586 that have children. */
22587 add_sibling_attributes (comp_unit_die ());
22588 for (node = limbo_die_list; node; node = node->next)
22589 add_sibling_attributes (node->die);
22590 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22591 add_sibling_attributes (ctnode->root_die);
22593 /* Output a terminator label for the .text section. */
22594 switch_to_section (text_section);
22595 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
22596 if (cold_text_section)
22598 switch_to_section (cold_text_section);
22599 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
22602 /* We can only use the low/high_pc attributes if all of the code was
22604 if (!have_multiple_function_sections
22605 || (dwarf_version < 3 && dwarf_strict))
22607 /* Don't add if the CU has no associated code. */
22608 if (text_section_used)
22610 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
22611 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
22618 bool range_list_added = false;
22620 if (text_section_used)
22621 add_ranges_by_labels (comp_unit_die (), text_section_label,
22622 text_end_label, &range_list_added);
22623 if (cold_text_section_used)
22624 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
22625 cold_end_label, &range_list_added);
22627 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
22629 if (!fde->in_std_section)
22630 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
22631 fde->dw_fde_end, &range_list_added);
22632 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
22633 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
22634 fde->dw_fde_second_end, &range_list_added);
22637 if (range_list_added)
22639 /* We need to give .debug_loc and .debug_ranges an appropriate
22640 "base address". Use zero so that these addresses become
22641 absolute. Historically, we've emitted the unexpected
22642 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22643 Emit both to give time for other tools to adapt. */
22644 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
22645 if (! dwarf_strict && dwarf_version < 4)
22646 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
22652 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22653 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
22654 debug_line_section_label);
22656 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22657 add_AT_macptr (comp_unit_die (),
22658 dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros,
22659 macinfo_section_label);
22661 if (have_location_lists)
22662 optimize_location_lists (comp_unit_die ());
22664 /* Output all of the compilation units. We put the main one last so that
22665 the offsets are available to output_pubnames. */
22666 for (node = limbo_die_list; node; node = node->next)
22667 output_comp_unit (node->die, 0);
22669 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
22670 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22672 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
22674 /* Don't output duplicate types. */
22675 if (*slot != HTAB_EMPTY_ENTRY)
22678 /* Add a pointer to the line table for the main compilation unit
22679 so that the debugger can make sense of DW_AT_decl_file
22681 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22682 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
22683 debug_line_section_label);
22685 output_comdat_type_unit (ctnode);
22688 htab_delete (comdat_type_table);
22690 /* Output the main compilation unit if non-empty or if .debug_macinfo
22691 will be emitted. */
22692 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
22694 /* Output the abbreviation table. */
22695 if (abbrev_die_table_in_use != 1)
22697 switch_to_section (debug_abbrev_section);
22698 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
22699 output_abbrev_section ();
22702 /* Output location list section if necessary. */
22703 if (have_location_lists)
22705 /* Output the location lists info. */
22706 switch_to_section (debug_loc_section);
22707 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
22708 DEBUG_LOC_SECTION_LABEL, 0);
22709 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
22710 output_location_lists (comp_unit_die ());
22713 /* Output public names table if necessary. */
22714 if (!VEC_empty (pubname_entry, pubname_table))
22716 gcc_assert (info_section_emitted);
22717 switch_to_section (debug_pubnames_section);
22718 output_pubnames (pubname_table);
22721 /* Output public types table if necessary. */
22722 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22723 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22724 simply won't look for the section. */
22725 if (!VEC_empty (pubname_entry, pubtype_table))
22727 bool empty = false;
22729 if (flag_eliminate_unused_debug_types)
22731 /* The pubtypes table might be emptied by pruning unused items. */
22735 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
22736 if (p->die->die_offset != 0)
22744 gcc_assert (info_section_emitted);
22745 switch_to_section (debug_pubtypes_section);
22746 output_pubnames (pubtype_table);
22750 /* Output the address range information if a CU (.debug_info section)
22751 was emitted. We output an empty table even if we had no functions
22752 to put in it. This because the consumer has no way to tell the
22753 difference between an empty table that we omitted and failure to
22754 generate a table that would have contained data. */
22755 if (info_section_emitted)
22757 unsigned long aranges_length = size_of_aranges ();
22759 switch_to_section (debug_aranges_section);
22760 output_aranges (aranges_length);
22763 /* Output ranges section if necessary. */
22764 if (ranges_table_in_use)
22766 switch_to_section (debug_ranges_section);
22767 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
22771 /* Have to end the macro section. */
22772 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22774 switch_to_section (debug_macinfo_section);
22775 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
22776 if (!VEC_empty (macinfo_entry, macinfo_table))
22778 dw2_asm_output_data (1, 0, "End compilation unit");
22781 /* Output the source line correspondence table. We must do this
22782 even if there is no line information. Otherwise, on an empty
22783 translation unit, we will generate a present, but empty,
22784 .debug_info section. IRIX 6.5 `nm' will then complain when
22785 examining the file. This is done late so that any filenames
22786 used by the debug_info section are marked as 'used'. */
22787 switch_to_section (debug_line_section);
22788 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
22789 if (! DWARF2_ASM_LINE_DEBUG_INFO)
22790 output_line_info ();
22792 /* If we emitted any DW_FORM_strp form attribute, output the string
22794 if (debug_str_hash)
22795 htab_traverse (debug_str_hash, output_indirect_string, NULL);
22798 #include "gt-dwarf2out.h"