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 if (cold_text_section != NULL)
1181 set_cur_line_info_table (sect);
1184 /* And now, the subset of the debugging information support code necessary
1185 for emitting location expressions. */
1187 /* Data about a single source file. */
1188 struct GTY(()) dwarf_file_data {
1189 const char * filename;
1193 typedef struct GTY(()) deferred_locations_struct
1197 } deferred_locations;
1199 DEF_VEC_O(deferred_locations);
1200 DEF_VEC_ALLOC_O(deferred_locations,gc);
1202 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
1204 DEF_VEC_P(dw_die_ref);
1205 DEF_VEC_ALLOC_P(dw_die_ref,heap);
1207 /* Location lists are ranges + location descriptions for that range,
1208 so you can track variables that are in different places over
1209 their entire life. */
1210 typedef struct GTY(()) dw_loc_list_struct {
1211 dw_loc_list_ref dw_loc_next;
1212 const char *begin; /* Label for begin address of range */
1213 const char *end; /* Label for end address of range */
1214 char *ll_symbol; /* Label for beginning of location list.
1215 Only on head of list */
1216 const char *section; /* Section this loclist is relative to */
1217 dw_loc_descr_ref expr;
1219 /* True if all addresses in this and subsequent lists are known to be
1222 /* True if this list has been replaced by dw_loc_next. */
1225 /* True if the range should be emitted even if begin and end
1230 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
1232 /* Convert a DWARF stack opcode into its string name. */
1235 dwarf_stack_op_name (unsigned int op)
1240 return "DW_OP_addr";
1242 return "DW_OP_deref";
1244 return "DW_OP_const1u";
1246 return "DW_OP_const1s";
1248 return "DW_OP_const2u";
1250 return "DW_OP_const2s";
1252 return "DW_OP_const4u";
1254 return "DW_OP_const4s";
1256 return "DW_OP_const8u";
1258 return "DW_OP_const8s";
1260 return "DW_OP_constu";
1262 return "DW_OP_consts";
1266 return "DW_OP_drop";
1268 return "DW_OP_over";
1270 return "DW_OP_pick";
1272 return "DW_OP_swap";
1276 return "DW_OP_xderef";
1284 return "DW_OP_minus";
1296 return "DW_OP_plus";
1297 case DW_OP_plus_uconst:
1298 return "DW_OP_plus_uconst";
1304 return "DW_OP_shra";
1322 return "DW_OP_skip";
1324 return "DW_OP_lit0";
1326 return "DW_OP_lit1";
1328 return "DW_OP_lit2";
1330 return "DW_OP_lit3";
1332 return "DW_OP_lit4";
1334 return "DW_OP_lit5";
1336 return "DW_OP_lit6";
1338 return "DW_OP_lit7";
1340 return "DW_OP_lit8";
1342 return "DW_OP_lit9";
1344 return "DW_OP_lit10";
1346 return "DW_OP_lit11";
1348 return "DW_OP_lit12";
1350 return "DW_OP_lit13";
1352 return "DW_OP_lit14";
1354 return "DW_OP_lit15";
1356 return "DW_OP_lit16";
1358 return "DW_OP_lit17";
1360 return "DW_OP_lit18";
1362 return "DW_OP_lit19";
1364 return "DW_OP_lit20";
1366 return "DW_OP_lit21";
1368 return "DW_OP_lit22";
1370 return "DW_OP_lit23";
1372 return "DW_OP_lit24";
1374 return "DW_OP_lit25";
1376 return "DW_OP_lit26";
1378 return "DW_OP_lit27";
1380 return "DW_OP_lit28";
1382 return "DW_OP_lit29";
1384 return "DW_OP_lit30";
1386 return "DW_OP_lit31";
1388 return "DW_OP_reg0";
1390 return "DW_OP_reg1";
1392 return "DW_OP_reg2";
1394 return "DW_OP_reg3";
1396 return "DW_OP_reg4";
1398 return "DW_OP_reg5";
1400 return "DW_OP_reg6";
1402 return "DW_OP_reg7";
1404 return "DW_OP_reg8";
1406 return "DW_OP_reg9";
1408 return "DW_OP_reg10";
1410 return "DW_OP_reg11";
1412 return "DW_OP_reg12";
1414 return "DW_OP_reg13";
1416 return "DW_OP_reg14";
1418 return "DW_OP_reg15";
1420 return "DW_OP_reg16";
1422 return "DW_OP_reg17";
1424 return "DW_OP_reg18";
1426 return "DW_OP_reg19";
1428 return "DW_OP_reg20";
1430 return "DW_OP_reg21";
1432 return "DW_OP_reg22";
1434 return "DW_OP_reg23";
1436 return "DW_OP_reg24";
1438 return "DW_OP_reg25";
1440 return "DW_OP_reg26";
1442 return "DW_OP_reg27";
1444 return "DW_OP_reg28";
1446 return "DW_OP_reg29";
1448 return "DW_OP_reg30";
1450 return "DW_OP_reg31";
1452 return "DW_OP_breg0";
1454 return "DW_OP_breg1";
1456 return "DW_OP_breg2";
1458 return "DW_OP_breg3";
1460 return "DW_OP_breg4";
1462 return "DW_OP_breg5";
1464 return "DW_OP_breg6";
1466 return "DW_OP_breg7";
1468 return "DW_OP_breg8";
1470 return "DW_OP_breg9";
1472 return "DW_OP_breg10";
1474 return "DW_OP_breg11";
1476 return "DW_OP_breg12";
1478 return "DW_OP_breg13";
1480 return "DW_OP_breg14";
1482 return "DW_OP_breg15";
1484 return "DW_OP_breg16";
1486 return "DW_OP_breg17";
1488 return "DW_OP_breg18";
1490 return "DW_OP_breg19";
1492 return "DW_OP_breg20";
1494 return "DW_OP_breg21";
1496 return "DW_OP_breg22";
1498 return "DW_OP_breg23";
1500 return "DW_OP_breg24";
1502 return "DW_OP_breg25";
1504 return "DW_OP_breg26";
1506 return "DW_OP_breg27";
1508 return "DW_OP_breg28";
1510 return "DW_OP_breg29";
1512 return "DW_OP_breg30";
1514 return "DW_OP_breg31";
1516 return "DW_OP_regx";
1518 return "DW_OP_fbreg";
1520 return "DW_OP_bregx";
1522 return "DW_OP_piece";
1523 case DW_OP_deref_size:
1524 return "DW_OP_deref_size";
1525 case DW_OP_xderef_size:
1526 return "DW_OP_xderef_size";
1530 case DW_OP_push_object_address:
1531 return "DW_OP_push_object_address";
1533 return "DW_OP_call2";
1535 return "DW_OP_call4";
1536 case DW_OP_call_ref:
1537 return "DW_OP_call_ref";
1538 case DW_OP_implicit_value:
1539 return "DW_OP_implicit_value";
1540 case DW_OP_stack_value:
1541 return "DW_OP_stack_value";
1542 case DW_OP_form_tls_address:
1543 return "DW_OP_form_tls_address";
1544 case DW_OP_call_frame_cfa:
1545 return "DW_OP_call_frame_cfa";
1546 case DW_OP_bit_piece:
1547 return "DW_OP_bit_piece";
1549 case DW_OP_GNU_push_tls_address:
1550 return "DW_OP_GNU_push_tls_address";
1551 case DW_OP_GNU_uninit:
1552 return "DW_OP_GNU_uninit";
1553 case DW_OP_GNU_encoded_addr:
1554 return "DW_OP_GNU_encoded_addr";
1555 case DW_OP_GNU_implicit_pointer:
1556 return "DW_OP_GNU_implicit_pointer";
1557 case DW_OP_GNU_entry_value:
1558 return "DW_OP_GNU_entry_value";
1559 case DW_OP_GNU_const_type:
1560 return "DW_OP_GNU_const_type";
1561 case DW_OP_GNU_regval_type:
1562 return "DW_OP_GNU_regval_type";
1563 case DW_OP_GNU_deref_type:
1564 return "DW_OP_GNU_deref_type";
1565 case DW_OP_GNU_convert:
1566 return "DW_OP_GNU_convert";
1567 case DW_OP_GNU_reinterpret:
1568 return "DW_OP_GNU_reinterpret";
1569 case DW_OP_GNU_parameter_ref:
1570 return "DW_OP_GNU_parameter_ref";
1573 return "OP_<unknown>";
1577 /* Return a pointer to a newly allocated location description. Location
1578 descriptions are simple expression terms that can be strung
1579 together to form more complicated location (address) descriptions. */
1581 static inline dw_loc_descr_ref
1582 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
1583 unsigned HOST_WIDE_INT oprnd2)
1585 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
1587 descr->dw_loc_opc = op;
1588 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
1589 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
1590 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
1591 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
1596 /* Return a pointer to a newly allocated location description for
1599 static inline dw_loc_descr_ref
1600 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
1603 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
1606 return new_loc_descr (DW_OP_bregx, reg, offset);
1609 /* Add a location description term to a location description expression. */
1612 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
1614 dw_loc_descr_ref *d;
1616 /* Find the end of the chain. */
1617 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
1623 /* Compare two location operands for exact equality. */
1626 dw_val_equal_p (dw_val_node *a, dw_val_node *b)
1628 if (a->val_class != b->val_class)
1630 switch (a->val_class)
1632 case dw_val_class_none:
1634 case dw_val_class_addr:
1635 return rtx_equal_p (a->v.val_addr, b->v.val_addr);
1637 case dw_val_class_offset:
1638 case dw_val_class_unsigned_const:
1639 case dw_val_class_const:
1640 case dw_val_class_range_list:
1641 case dw_val_class_lineptr:
1642 case dw_val_class_macptr:
1643 /* These are all HOST_WIDE_INT, signed or unsigned. */
1644 return a->v.val_unsigned == b->v.val_unsigned;
1646 case dw_val_class_loc:
1647 return a->v.val_loc == b->v.val_loc;
1648 case dw_val_class_loc_list:
1649 return a->v.val_loc_list == b->v.val_loc_list;
1650 case dw_val_class_die_ref:
1651 return a->v.val_die_ref.die == b->v.val_die_ref.die;
1652 case dw_val_class_fde_ref:
1653 return a->v.val_fde_index == b->v.val_fde_index;
1654 case dw_val_class_lbl_id:
1655 return strcmp (a->v.val_lbl_id, b->v.val_lbl_id) == 0;
1656 case dw_val_class_str:
1657 return a->v.val_str == b->v.val_str;
1658 case dw_val_class_flag:
1659 return a->v.val_flag == b->v.val_flag;
1660 case dw_val_class_file:
1661 return a->v.val_file == b->v.val_file;
1662 case dw_val_class_decl_ref:
1663 return a->v.val_decl_ref == b->v.val_decl_ref;
1665 case dw_val_class_const_double:
1666 return (a->v.val_double.high == b->v.val_double.high
1667 && a->v.val_double.low == b->v.val_double.low);
1669 case dw_val_class_vec:
1671 size_t a_len = a->v.val_vec.elt_size * a->v.val_vec.length;
1672 size_t b_len = b->v.val_vec.elt_size * b->v.val_vec.length;
1674 return (a_len == b_len
1675 && !memcmp (a->v.val_vec.array, b->v.val_vec.array, a_len));
1678 case dw_val_class_data8:
1679 return memcmp (a->v.val_data8, b->v.val_data8, 8) == 0;
1681 case dw_val_class_vms_delta:
1682 return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)
1683 && !strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1));
1688 /* Compare two location atoms for exact equality. */
1691 loc_descr_equal_p_1 (dw_loc_descr_ref a, dw_loc_descr_ref b)
1693 if (a->dw_loc_opc != b->dw_loc_opc)
1696 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1697 address size, but since we always allocate cleared storage it
1698 should be zero for other types of locations. */
1699 if (a->dtprel != b->dtprel)
1702 return (dw_val_equal_p (&a->dw_loc_oprnd1, &b->dw_loc_oprnd1)
1703 && dw_val_equal_p (&a->dw_loc_oprnd2, &b->dw_loc_oprnd2));
1706 /* Compare two complete location expressions for exact equality. */
1709 loc_descr_equal_p (dw_loc_descr_ref a, dw_loc_descr_ref b)
1715 if (a == NULL || b == NULL)
1717 if (!loc_descr_equal_p_1 (a, b))
1726 /* Add a constant OFFSET to a location expression. */
1729 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
1731 dw_loc_descr_ref loc;
1734 gcc_assert (*list_head != NULL);
1739 /* Find the end of the chain. */
1740 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
1744 if (loc->dw_loc_opc == DW_OP_fbreg
1745 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
1746 p = &loc->dw_loc_oprnd1.v.val_int;
1747 else if (loc->dw_loc_opc == DW_OP_bregx)
1748 p = &loc->dw_loc_oprnd2.v.val_int;
1750 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1751 offset. Don't optimize if an signed integer overflow would happen. */
1753 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
1754 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
1757 else if (offset > 0)
1758 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
1762 loc->dw_loc_next = int_loc_descriptor (-offset);
1763 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
1767 /* Add a constant OFFSET to a location list. */
1770 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
1773 for (d = list_head; d != NULL; d = d->dw_loc_next)
1774 loc_descr_plus_const (&d->expr, offset);
1777 #define DWARF_REF_SIZE \
1778 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1780 static unsigned long int get_base_type_offset (dw_die_ref);
1782 /* Return the size of a location descriptor. */
1784 static unsigned long
1785 size_of_loc_descr (dw_loc_descr_ref loc)
1787 unsigned long size = 1;
1789 switch (loc->dw_loc_opc)
1792 size += DWARF2_ADDR_SIZE;
1811 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1814 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1819 case DW_OP_plus_uconst:
1820 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1858 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1861 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1864 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1867 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1868 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1871 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1873 case DW_OP_bit_piece:
1874 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1875 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
1877 case DW_OP_deref_size:
1878 case DW_OP_xderef_size:
1887 case DW_OP_call_ref:
1888 size += DWARF_REF_SIZE;
1890 case DW_OP_implicit_value:
1891 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1892 + loc->dw_loc_oprnd1.v.val_unsigned;
1894 case DW_OP_GNU_implicit_pointer:
1895 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1897 case DW_OP_GNU_entry_value:
1899 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
1900 size += size_of_uleb128 (op_size) + op_size;
1903 case DW_OP_GNU_const_type:
1906 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1907 size += size_of_uleb128 (o) + 1;
1908 switch (loc->dw_loc_oprnd2.val_class)
1910 case dw_val_class_vec:
1911 size += loc->dw_loc_oprnd2.v.val_vec.length
1912 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
1914 case dw_val_class_const:
1915 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1917 case dw_val_class_const_double:
1918 size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1925 case DW_OP_GNU_regval_type:
1928 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1929 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1930 + size_of_uleb128 (o);
1933 case DW_OP_GNU_deref_type:
1936 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1937 size += 1 + size_of_uleb128 (o);
1940 case DW_OP_GNU_convert:
1941 case DW_OP_GNU_reinterpret:
1942 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
1943 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1947 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1948 size += size_of_uleb128 (o);
1951 case DW_OP_GNU_parameter_ref:
1961 /* Return the size of a series of location descriptors. */
1964 size_of_locs (dw_loc_descr_ref loc)
1969 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1970 field, to avoid writing to a PCH file. */
1971 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1973 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
1975 size += size_of_loc_descr (l);
1980 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1982 l->dw_loc_addr = size;
1983 size += size_of_loc_descr (l);
1989 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
1990 static void get_ref_die_offset_label (char *, dw_die_ref);
1991 static unsigned long int get_ref_die_offset (dw_die_ref);
1993 /* Output location description stack opcode's operands (if any).
1994 The for_eh_or_skip parameter controls whether register numbers are
1995 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1996 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1997 info). This should be suppressed for the cases that have not been converted
1998 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2001 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
2003 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2004 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2006 switch (loc->dw_loc_opc)
2008 #ifdef DWARF2_DEBUGGING_INFO
2011 dw2_asm_output_data (2, val1->v.val_int, NULL);
2016 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2017 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
2019 fputc ('\n', asm_out_file);
2024 dw2_asm_output_data (4, val1->v.val_int, NULL);
2029 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2030 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
2032 fputc ('\n', asm_out_file);
2037 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2038 dw2_asm_output_data (8, val1->v.val_int, NULL);
2045 gcc_assert (val1->val_class == dw_val_class_loc);
2046 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2048 dw2_asm_output_data (2, offset, NULL);
2051 case DW_OP_implicit_value:
2052 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2053 switch (val2->val_class)
2055 case dw_val_class_const:
2056 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
2058 case dw_val_class_vec:
2060 unsigned int elt_size = val2->v.val_vec.elt_size;
2061 unsigned int len = val2->v.val_vec.length;
2065 if (elt_size > sizeof (HOST_WIDE_INT))
2070 for (i = 0, p = val2->v.val_vec.array;
2073 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2074 "fp or vector constant word %u", i);
2077 case dw_val_class_const_double:
2079 unsigned HOST_WIDE_INT first, second;
2081 if (WORDS_BIG_ENDIAN)
2083 first = val2->v.val_double.high;
2084 second = val2->v.val_double.low;
2088 first = val2->v.val_double.low;
2089 second = val2->v.val_double.high;
2091 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2093 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2097 case dw_val_class_addr:
2098 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
2099 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
2114 case DW_OP_implicit_value:
2115 /* We currently don't make any attempt to make sure these are
2116 aligned properly like we do for the main unwind info, so
2117 don't support emitting things larger than a byte if we're
2118 only doing unwinding. */
2123 dw2_asm_output_data (1, val1->v.val_int, NULL);
2126 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2129 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2132 dw2_asm_output_data (1, val1->v.val_int, NULL);
2134 case DW_OP_plus_uconst:
2135 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2169 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2173 unsigned r = val1->v.val_unsigned;
2174 if (for_eh_or_skip >= 0)
2175 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2176 gcc_assert (size_of_uleb128 (r)
2177 == size_of_uleb128 (val1->v.val_unsigned));
2178 dw2_asm_output_data_uleb128 (r, NULL);
2182 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2186 unsigned r = val1->v.val_unsigned;
2187 if (for_eh_or_skip >= 0)
2188 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2189 gcc_assert (size_of_uleb128 (r)
2190 == size_of_uleb128 (val1->v.val_unsigned));
2191 dw2_asm_output_data_uleb128 (r, NULL);
2192 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2196 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2198 case DW_OP_bit_piece:
2199 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2200 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
2202 case DW_OP_deref_size:
2203 case DW_OP_xderef_size:
2204 dw2_asm_output_data (1, val1->v.val_int, NULL);
2210 if (targetm.asm_out.output_dwarf_dtprel)
2212 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
2215 fputc ('\n', asm_out_file);
2222 #ifdef DWARF2_DEBUGGING_INFO
2223 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2230 case DW_OP_GNU_implicit_pointer:
2232 char label[MAX_ARTIFICIAL_LABEL_BYTES
2233 + HOST_BITS_PER_WIDE_INT / 2 + 2];
2234 gcc_assert (val1->val_class == dw_val_class_die_ref);
2235 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2236 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2237 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2241 case DW_OP_GNU_entry_value:
2242 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2243 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2246 case DW_OP_GNU_const_type:
2248 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2250 dw2_asm_output_data_uleb128 (o, NULL);
2251 switch (val2->val_class)
2253 case dw_val_class_const:
2254 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2255 dw2_asm_output_data (1, l, NULL);
2256 dw2_asm_output_data (l, val2->v.val_int, NULL);
2258 case dw_val_class_vec:
2260 unsigned int elt_size = val2->v.val_vec.elt_size;
2261 unsigned int len = val2->v.val_vec.length;
2266 dw2_asm_output_data (1, l, NULL);
2267 if (elt_size > sizeof (HOST_WIDE_INT))
2272 for (i = 0, p = val2->v.val_vec.array;
2275 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2276 "fp or vector constant word %u", i);
2279 case dw_val_class_const_double:
2281 unsigned HOST_WIDE_INT first, second;
2282 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2284 dw2_asm_output_data (1, 2 * l, NULL);
2285 if (WORDS_BIG_ENDIAN)
2287 first = val2->v.val_double.high;
2288 second = val2->v.val_double.low;
2292 first = val2->v.val_double.low;
2293 second = val2->v.val_double.high;
2295 dw2_asm_output_data (l, first, NULL);
2296 dw2_asm_output_data (l, second, NULL);
2304 case DW_OP_GNU_regval_type:
2306 unsigned r = val1->v.val_unsigned;
2307 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2309 if (for_eh_or_skip >= 0)
2311 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2312 gcc_assert (size_of_uleb128 (r)
2313 == size_of_uleb128 (val1->v.val_unsigned));
2315 dw2_asm_output_data_uleb128 (r, NULL);
2316 dw2_asm_output_data_uleb128 (o, NULL);
2319 case DW_OP_GNU_deref_type:
2321 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2323 dw2_asm_output_data (1, val1->v.val_int, NULL);
2324 dw2_asm_output_data_uleb128 (o, NULL);
2327 case DW_OP_GNU_convert:
2328 case DW_OP_GNU_reinterpret:
2329 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2330 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2333 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2335 dw2_asm_output_data_uleb128 (o, NULL);
2339 case DW_OP_GNU_parameter_ref:
2342 gcc_assert (val1->val_class == dw_val_class_die_ref);
2343 o = get_ref_die_offset (val1->v.val_die_ref.die);
2344 dw2_asm_output_data (4, o, NULL);
2349 /* Other codes have no operands. */
2354 /* Output a sequence of location operations.
2355 The for_eh_or_skip parameter controls whether register numbers are
2356 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2357 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2358 info). This should be suppressed for the cases that have not been converted
2359 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2362 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2364 for (; loc != NULL; loc = loc->dw_loc_next)
2366 enum dwarf_location_atom opc = loc->dw_loc_opc;
2367 /* Output the opcode. */
2368 if (for_eh_or_skip >= 0
2369 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2371 unsigned r = (opc - DW_OP_breg0);
2372 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2373 gcc_assert (r <= 31);
2374 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2376 else if (for_eh_or_skip >= 0
2377 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2379 unsigned r = (opc - DW_OP_reg0);
2380 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2381 gcc_assert (r <= 31);
2382 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2385 dw2_asm_output_data (1, opc,
2386 "%s", dwarf_stack_op_name (opc));
2388 /* Output the operand(s) (if any). */
2389 output_loc_operands (loc, for_eh_or_skip);
2393 /* Output location description stack opcode's operands (if any).
2394 The output is single bytes on a line, suitable for .cfi_escape. */
2397 output_loc_operands_raw (dw_loc_descr_ref loc)
2399 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2400 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2402 switch (loc->dw_loc_opc)
2405 case DW_OP_implicit_value:
2406 /* We cannot output addresses in .cfi_escape, only bytes. */
2412 case DW_OP_deref_size:
2413 case DW_OP_xderef_size:
2414 fputc (',', asm_out_file);
2415 dw2_asm_output_data_raw (1, val1->v.val_int);
2420 fputc (',', asm_out_file);
2421 dw2_asm_output_data_raw (2, val1->v.val_int);
2426 fputc (',', asm_out_file);
2427 dw2_asm_output_data_raw (4, val1->v.val_int);
2432 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2433 fputc (',', asm_out_file);
2434 dw2_asm_output_data_raw (8, val1->v.val_int);
2442 gcc_assert (val1->val_class == dw_val_class_loc);
2443 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2445 fputc (',', asm_out_file);
2446 dw2_asm_output_data_raw (2, offset);
2452 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2453 gcc_assert (size_of_uleb128 (r)
2454 == size_of_uleb128 (val1->v.val_unsigned));
2455 fputc (',', asm_out_file);
2456 dw2_asm_output_data_uleb128_raw (r);
2461 case DW_OP_plus_uconst:
2463 fputc (',', asm_out_file);
2464 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2467 case DW_OP_bit_piece:
2468 fputc (',', asm_out_file);
2469 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2470 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
2507 fputc (',', asm_out_file);
2508 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
2513 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2514 gcc_assert (size_of_uleb128 (r)
2515 == size_of_uleb128 (val1->v.val_unsigned));
2516 fputc (',', asm_out_file);
2517 dw2_asm_output_data_uleb128_raw (r);
2518 fputc (',', asm_out_file);
2519 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
2523 case DW_OP_GNU_implicit_pointer:
2524 case DW_OP_GNU_entry_value:
2525 case DW_OP_GNU_const_type:
2526 case DW_OP_GNU_regval_type:
2527 case DW_OP_GNU_deref_type:
2528 case DW_OP_GNU_convert:
2529 case DW_OP_GNU_reinterpret:
2530 case DW_OP_GNU_parameter_ref:
2535 /* Other codes have no operands. */
2541 output_loc_sequence_raw (dw_loc_descr_ref loc)
2545 enum dwarf_location_atom opc = loc->dw_loc_opc;
2546 /* Output the opcode. */
2547 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2549 unsigned r = (opc - DW_OP_breg0);
2550 r = DWARF2_FRAME_REG_OUT (r, 1);
2551 gcc_assert (r <= 31);
2552 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2554 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2556 unsigned r = (opc - DW_OP_reg0);
2557 r = DWARF2_FRAME_REG_OUT (r, 1);
2558 gcc_assert (r <= 31);
2559 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2561 /* Output the opcode. */
2562 fprintf (asm_out_file, "%#x", opc);
2563 output_loc_operands_raw (loc);
2565 if (!loc->dw_loc_next)
2567 loc = loc->dw_loc_next;
2569 fputc (',', asm_out_file);
2573 /* This function builds a dwarf location descriptor sequence from a
2574 dw_cfa_location, adding the given OFFSET to the result of the
2577 struct dw_loc_descr_struct *
2578 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
2580 struct dw_loc_descr_struct *head, *tmp;
2582 offset += cfa->offset;
2586 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
2587 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2588 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2589 add_loc_descr (&head, tmp);
2592 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
2593 add_loc_descr (&head, tmp);
2597 head = new_reg_loc_descr (cfa->reg, offset);
2602 /* This function builds a dwarf location descriptor sequence for
2603 the address at OFFSET from the CFA when stack is aligned to
2606 struct dw_loc_descr_struct *
2607 build_cfa_aligned_loc (dw_cfa_location *cfa,
2608 HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
2610 struct dw_loc_descr_struct *head;
2611 unsigned int dwarf_fp
2612 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
2614 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2615 if (cfa->reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
2617 head = new_reg_loc_descr (dwarf_fp, 0);
2618 add_loc_descr (&head, int_loc_descriptor (alignment));
2619 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
2620 loc_descr_plus_const (&head, offset);
2623 head = new_reg_loc_descr (dwarf_fp, offset);
2627 /* And now, the support for symbolic debugging information. */
2629 /* .debug_str support. */
2630 static int output_indirect_string (void **, void *);
2632 static void dwarf2out_init (const char *);
2633 static void dwarf2out_finish (const char *);
2634 static void dwarf2out_assembly_start (void);
2635 static void dwarf2out_define (unsigned int, const char *);
2636 static void dwarf2out_undef (unsigned int, const char *);
2637 static void dwarf2out_start_source_file (unsigned, const char *);
2638 static void dwarf2out_end_source_file (unsigned);
2639 static void dwarf2out_function_decl (tree);
2640 static void dwarf2out_begin_block (unsigned, unsigned);
2641 static void dwarf2out_end_block (unsigned, unsigned);
2642 static bool dwarf2out_ignore_block (const_tree);
2643 static void dwarf2out_global_decl (tree);
2644 static void dwarf2out_type_decl (tree, int);
2645 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
2646 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
2648 static void dwarf2out_abstract_function (tree);
2649 static void dwarf2out_var_location (rtx);
2650 static void dwarf2out_begin_function (tree);
2651 static void dwarf2out_set_name (tree, tree);
2653 /* The debug hooks structure. */
2655 const struct gcc_debug_hooks dwarf2_debug_hooks =
2659 dwarf2out_assembly_start,
2662 dwarf2out_start_source_file,
2663 dwarf2out_end_source_file,
2664 dwarf2out_begin_block,
2665 dwarf2out_end_block,
2666 dwarf2out_ignore_block,
2667 dwarf2out_source_line,
2668 dwarf2out_begin_prologue,
2669 #if VMS_DEBUGGING_INFO
2670 dwarf2out_vms_end_prologue,
2671 dwarf2out_vms_begin_epilogue,
2673 debug_nothing_int_charstar,
2674 debug_nothing_int_charstar,
2676 dwarf2out_end_epilogue,
2677 dwarf2out_begin_function,
2678 debug_nothing_int, /* end_function */
2679 dwarf2out_function_decl, /* function_decl */
2680 dwarf2out_global_decl,
2681 dwarf2out_type_decl, /* type_decl */
2682 dwarf2out_imported_module_or_decl,
2683 debug_nothing_tree, /* deferred_inline_function */
2684 /* The DWARF 2 backend tries to reduce debugging bloat by not
2685 emitting the abstract description of inline functions until
2686 something tries to reference them. */
2687 dwarf2out_abstract_function, /* outlining_inline_function */
2688 debug_nothing_rtx, /* label */
2689 debug_nothing_int, /* handle_pch */
2690 dwarf2out_var_location,
2691 dwarf2out_switch_text_section,
2693 1, /* start_end_main_source_file */
2694 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
2697 /* NOTE: In the comments in this file, many references are made to
2698 "Debugging Information Entries". This term is abbreviated as `DIE'
2699 throughout the remainder of this file. */
2701 /* An internal representation of the DWARF output is built, and then
2702 walked to generate the DWARF debugging info. The walk of the internal
2703 representation is done after the entire program has been compiled.
2704 The types below are used to describe the internal representation. */
2706 /* Whether to put type DIEs into their own section .debug_types instead
2707 of making them part of the .debug_info section. Only supported for
2708 Dwarf V4 or higher and the user didn't disable them through
2709 -fno-debug-types-section. It is more efficient to put them in a
2710 separate comdat sections since the linker will then be able to
2711 remove duplicates. But not all tools support .debug_types sections
2714 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2716 /* Various DIE's use offsets relative to the beginning of the
2717 .debug_info section to refer to each other. */
2719 typedef long int dw_offset;
2721 /* Define typedefs here to avoid circular dependencies. */
2723 typedef struct dw_attr_struct *dw_attr_ref;
2724 typedef struct dw_line_info_struct *dw_line_info_ref;
2725 typedef struct pubname_struct *pubname_ref;
2726 typedef struct dw_ranges_struct *dw_ranges_ref;
2727 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
2728 typedef struct comdat_type_struct *comdat_type_node_ref;
2730 /* The entries in the line_info table more-or-less mirror the opcodes
2731 that are used in the real dwarf line table. Arrays of these entries
2732 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2735 enum dw_line_info_opcode {
2736 /* Emit DW_LNE_set_address; the operand is the label index. */
2739 /* Emit a row to the matrix with the given line. This may be done
2740 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2744 /* Emit a DW_LNS_set_file. */
2747 /* Emit a DW_LNS_set_column. */
2750 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2753 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2754 LI_set_prologue_end,
2755 LI_set_epilogue_begin,
2757 /* Emit a DW_LNE_set_discriminator. */
2758 LI_set_discriminator
2761 typedef struct GTY(()) dw_line_info_struct {
2762 enum dw_line_info_opcode opcode;
2764 } dw_line_info_entry;
2766 DEF_VEC_O(dw_line_info_entry);
2767 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
2769 typedef struct GTY(()) dw_line_info_table_struct {
2770 /* The label that marks the end of this section. */
2771 const char *end_label;
2773 /* The values for the last row of the matrix, as collected in the table.
2774 These are used to minimize the changes to the next row. */
2775 unsigned int file_num;
2776 unsigned int line_num;
2777 unsigned int column_num;
2782 VEC(dw_line_info_entry, gc) *entries;
2783 } dw_line_info_table;
2785 typedef dw_line_info_table *dw_line_info_table_p;
2787 DEF_VEC_P(dw_line_info_table_p);
2788 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
2790 /* Each DIE attribute has a field specifying the attribute kind,
2791 a link to the next attribute in the chain, and an attribute value.
2792 Attributes are typically linked below the DIE they modify. */
2794 typedef struct GTY(()) dw_attr_struct {
2795 enum dwarf_attribute dw_attr;
2796 dw_val_node dw_attr_val;
2800 DEF_VEC_O(dw_attr_node);
2801 DEF_VEC_ALLOC_O(dw_attr_node,gc);
2803 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2804 The children of each node form a circular list linked by
2805 die_sib. die_child points to the node *before* the "first" child node. */
2807 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
2808 union die_symbol_or_type_node
2810 char * GTY ((tag ("0"))) die_symbol;
2811 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
2813 GTY ((desc ("use_debug_types"))) die_id;
2814 VEC(dw_attr_node,gc) * die_attr;
2815 dw_die_ref die_parent;
2816 dw_die_ref die_child;
2818 dw_die_ref die_definition; /* ref from a specification to its definition */
2819 dw_offset die_offset;
2820 unsigned long die_abbrev;
2822 /* Die is used and must not be pruned as unused. */
2823 int die_perennial_p;
2824 unsigned int decl_id;
2825 enum dwarf_tag die_tag;
2829 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2830 #define FOR_EACH_CHILD(die, c, expr) do { \
2831 c = die->die_child; \
2835 } while (c != die->die_child); \
2838 /* The pubname structure */
2840 typedef struct GTY(()) pubname_struct {
2846 DEF_VEC_O(pubname_entry);
2847 DEF_VEC_ALLOC_O(pubname_entry, gc);
2849 struct GTY(()) dw_ranges_struct {
2850 /* If this is positive, it's a block number, otherwise it's a
2851 bitwise-negated index into dw_ranges_by_label. */
2855 /* A structure to hold a macinfo entry. */
2857 typedef struct GTY(()) macinfo_struct {
2859 unsigned HOST_WIDE_INT lineno;
2864 DEF_VEC_O(macinfo_entry);
2865 DEF_VEC_ALLOC_O(macinfo_entry, gc);
2867 struct GTY(()) dw_ranges_by_label_struct {
2872 /* The comdat type node structure. */
2873 typedef struct GTY(()) comdat_type_struct
2875 dw_die_ref root_die;
2876 dw_die_ref type_die;
2877 char signature[DWARF_TYPE_SIGNATURE_SIZE];
2878 struct comdat_type_struct *next;
2882 /* The limbo die list structure. */
2883 typedef struct GTY(()) limbo_die_struct {
2886 struct limbo_die_struct *next;
2890 typedef struct skeleton_chain_struct
2894 struct skeleton_chain_struct *parent;
2896 skeleton_chain_node;
2898 /* Define a macro which returns nonzero for a TYPE_DECL which was
2899 implicitly generated for a type.
2901 Note that, unlike the C front-end (which generates a NULL named
2902 TYPE_DECL node for each complete tagged type, each array type,
2903 and each function type node created) the C++ front-end generates
2904 a _named_ TYPE_DECL node for each tagged type node created.
2905 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2906 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2907 front-end, but for each type, tagged or not. */
2909 #define TYPE_DECL_IS_STUB(decl) \
2910 (DECL_NAME (decl) == NULL_TREE \
2911 || (DECL_ARTIFICIAL (decl) \
2912 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2913 /* This is necessary for stub decls that \
2914 appear in nested inline functions. */ \
2915 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2916 && (decl_ultimate_origin (decl) \
2917 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2919 /* Information concerning the compilation unit's programming
2920 language, and compiler version. */
2922 /* Fixed size portion of the DWARF compilation unit header. */
2923 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2924 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2926 /* Fixed size portion of the DWARF comdat type unit header. */
2927 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2928 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2929 + DWARF_OFFSET_SIZE)
2931 /* Fixed size portion of public names info. */
2932 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2934 /* Fixed size portion of the address range info. */
2935 #define DWARF_ARANGES_HEADER_SIZE \
2936 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2937 DWARF2_ADDR_SIZE * 2) \
2938 - DWARF_INITIAL_LENGTH_SIZE)
2940 /* Size of padding portion in the address range info. It must be
2941 aligned to twice the pointer size. */
2942 #define DWARF_ARANGES_PAD_SIZE \
2943 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2944 DWARF2_ADDR_SIZE * 2) \
2945 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2947 /* Use assembler line directives if available. */
2948 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2949 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2950 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2952 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2956 /* Minimum line offset in a special line info. opcode.
2957 This value was chosen to give a reasonable range of values. */
2958 #define DWARF_LINE_BASE -10
2960 /* First special line opcode - leave room for the standard opcodes. */
2961 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2963 /* Range of line offsets in a special line info. opcode. */
2964 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2966 /* Flag that indicates the initial value of the is_stmt_start flag.
2967 In the present implementation, we do not mark any lines as
2968 the beginning of a source statement, because that information
2969 is not made available by the GCC front-end. */
2970 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2972 /* Maximum number of operations per instruction bundle. */
2973 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2974 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2977 /* This location is used by calc_die_sizes() to keep track
2978 the offset of each DIE within the .debug_info section. */
2979 static unsigned long next_die_offset;
2981 /* Record the root of the DIE's built for the current compilation unit. */
2982 static GTY(()) dw_die_ref single_comp_unit_die;
2984 /* A list of type DIEs that have been separated into comdat sections. */
2985 static GTY(()) comdat_type_node *comdat_type_list;
2987 /* A list of DIEs with a NULL parent waiting to be relocated. */
2988 static GTY(()) limbo_die_node *limbo_die_list;
2990 /* A list of DIEs for which we may have to generate
2991 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2992 static GTY(()) limbo_die_node *deferred_asm_name;
2994 /* Filenames referenced by this compilation unit. */
2995 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
2997 /* A hash table of references to DIE's that describe declarations.
2998 The key is a DECL_UID() which is a unique number identifying each decl. */
2999 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3001 /* A hash table of references to DIE's that describe COMMON blocks.
3002 The key is DECL_UID() ^ die_parent. */
3003 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
3005 typedef struct GTY(()) die_arg_entry_struct {
3010 DEF_VEC_O(die_arg_entry);
3011 DEF_VEC_ALLOC_O(die_arg_entry,gc);
3013 /* Node of the variable location list. */
3014 struct GTY ((chain_next ("%h.next"))) var_loc_node {
3015 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3016 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3017 in mode of the EXPR_LIST node and first EXPR_LIST operand
3018 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3019 location or NULL for padding. For larger bitsizes,
3020 mode is 0 and first operand is a CONCAT with bitsize
3021 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3022 NULL as second operand. */
3024 const char * GTY (()) label;
3025 struct var_loc_node * GTY (()) next;
3028 /* Variable location list. */
3029 struct GTY (()) var_loc_list_def {
3030 struct var_loc_node * GTY (()) first;
3032 /* Pointer to the last but one or last element of the
3033 chained list. If the list is empty, both first and
3034 last are NULL, if the list contains just one node
3035 or the last node certainly is not redundant, it points
3036 to the last node, otherwise points to the last but one.
3037 Do not mark it for GC because it is marked through the chain. */
3038 struct var_loc_node * GTY ((skip ("%h"))) last;
3040 /* Pointer to the last element before section switch,
3041 if NULL, either sections weren't switched or first
3042 is after section switch. */
3043 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
3045 /* DECL_UID of the variable decl. */
3046 unsigned int decl_id;
3048 typedef struct var_loc_list_def var_loc_list;
3050 /* Call argument location list. */
3051 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
3052 rtx GTY (()) call_arg_loc_note;
3053 const char * GTY (()) label;
3054 tree GTY (()) block;
3056 rtx GTY (()) symbol_ref;
3057 struct call_arg_loc_node * GTY (()) next;
3061 /* Table of decl location linked lists. */
3062 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3064 /* Head and tail of call_arg_loc chain. */
3065 static GTY (()) struct call_arg_loc_node *call_arg_locations;
3066 static struct call_arg_loc_node *call_arg_loc_last;
3068 /* Number of call sites in the current function. */
3069 static int call_site_count = -1;
3070 /* Number of tail call sites in the current function. */
3071 static int tail_call_site_count = -1;
3073 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
3075 static VEC (dw_die_ref, heap) *block_map;
3077 /* A cached location list. */
3078 struct GTY (()) cached_dw_loc_list_def {
3079 /* The DECL_UID of the decl that this entry describes. */
3080 unsigned int decl_id;
3082 /* The cached location list. */
3083 dw_loc_list_ref loc_list;
3085 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
3087 /* Table of cached location lists. */
3088 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
3090 /* A pointer to the base of a list of references to DIE's that
3091 are uniquely identified by their tag, presence/absence of
3092 children DIE's, and list of attribute/value pairs. */
3093 static GTY((length ("abbrev_die_table_allocated")))
3094 dw_die_ref *abbrev_die_table;
3096 /* Number of elements currently allocated for abbrev_die_table. */
3097 static GTY(()) unsigned abbrev_die_table_allocated;
3099 /* Number of elements in type_die_table currently in use. */
3100 static GTY(()) unsigned abbrev_die_table_in_use;
3102 /* Size (in elements) of increments by which we may expand the
3103 abbrev_die_table. */
3104 #define ABBREV_DIE_TABLE_INCREMENT 256
3106 /* A global counter for generating labels for line number data. */
3107 static unsigned int line_info_label_num;
3109 /* The current table to which we should emit line number information
3110 for the current function. This will be set up at the beginning of
3111 assembly for the function. */
3112 static dw_line_info_table *cur_line_info_table;
3114 /* The two default tables of line number info. */
3115 static GTY(()) dw_line_info_table *text_section_line_info;
3116 static GTY(()) dw_line_info_table *cold_text_section_line_info;
3118 /* The set of all non-default tables of line number info. */
3119 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
3121 /* A flag to tell pubnames/types export if there is an info section to
3123 static bool info_section_emitted;
3125 /* A pointer to the base of a table that contains a list of publicly
3126 accessible names. */
3127 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
3129 /* A pointer to the base of a table that contains a list of publicly
3130 accessible types. */
3131 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
3133 /* A pointer to the base of a table that contains a list of macro
3134 defines/undefines (and file start/end markers). */
3135 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
3137 /* True if .debug_macinfo or .debug_macros section is going to be
3139 #define have_macinfo \
3140 (debug_info_level >= DINFO_LEVEL_VERBOSE \
3141 && !VEC_empty (macinfo_entry, macinfo_table))
3143 /* Array of dies for which we should generate .debug_ranges info. */
3144 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3146 /* Number of elements currently allocated for ranges_table. */
3147 static GTY(()) unsigned ranges_table_allocated;
3149 /* Number of elements in ranges_table currently in use. */
3150 static GTY(()) unsigned ranges_table_in_use;
3152 /* Array of pairs of labels referenced in ranges_table. */
3153 static GTY ((length ("ranges_by_label_allocated")))
3154 dw_ranges_by_label_ref ranges_by_label;
3156 /* Number of elements currently allocated for ranges_by_label. */
3157 static GTY(()) unsigned ranges_by_label_allocated;
3159 /* Number of elements in ranges_by_label currently in use. */
3160 static GTY(()) unsigned ranges_by_label_in_use;
3162 /* Size (in elements) of increments by which we may expand the
3164 #define RANGES_TABLE_INCREMENT 64
3166 /* Whether we have location lists that need outputting */
3167 static GTY(()) bool have_location_lists;
3169 /* Unique label counter. */
3170 static GTY(()) unsigned int loclabel_num;
3172 /* Unique label counter for point-of-call tables. */
3173 static GTY(()) unsigned int poc_label_num;
3175 /* Record whether the function being analyzed contains inlined functions. */
3176 static int current_function_has_inlines;
3178 /* The last file entry emitted by maybe_emit_file(). */
3179 static GTY(()) struct dwarf_file_data * last_emitted_file;
3181 /* Number of internal labels generated by gen_internal_sym(). */
3182 static GTY(()) int label_num;
3184 /* Cached result of previous call to lookup_filename. */
3185 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
3187 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
3189 /* Instances of generic types for which we need to generate debug
3190 info that describe their generic parameters and arguments. That
3191 generation needs to happen once all types are properly laid out so
3192 we do it at the end of compilation. */
3193 static GTY(()) VEC(tree,gc) *generic_type_instances;
3195 /* Offset from the "steady-state frame pointer" to the frame base,
3196 within the current function. */
3197 static HOST_WIDE_INT frame_pointer_fb_offset;
3198 static bool frame_pointer_fb_offset_valid;
3200 static VEC (dw_die_ref, heap) *base_types;
3202 /* Forward declarations for functions defined in this file. */
3204 static int is_pseudo_reg (const_rtx);
3205 static tree type_main_variant (tree);
3206 static int is_tagged_type (const_tree);
3207 static const char *dwarf_tag_name (unsigned);
3208 static const char *dwarf_attr_name (unsigned);
3209 static const char *dwarf_form_name (unsigned);
3210 static tree decl_ultimate_origin (const_tree);
3211 static tree decl_class_context (tree);
3212 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3213 static inline enum dw_val_class AT_class (dw_attr_ref);
3214 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3215 static inline unsigned AT_flag (dw_attr_ref);
3216 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3217 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3218 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3219 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3220 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3221 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3222 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3223 unsigned int, unsigned char *);
3224 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3225 static hashval_t debug_str_do_hash (const void *);
3226 static int debug_str_eq (const void *, const void *);
3227 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3228 static inline const char *AT_string (dw_attr_ref);
3229 static enum dwarf_form AT_string_form (dw_attr_ref);
3230 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3231 static void add_AT_specification (dw_die_ref, dw_die_ref);
3232 static inline dw_die_ref AT_ref (dw_attr_ref);
3233 static inline int AT_ref_external (dw_attr_ref);
3234 static inline void set_AT_ref_external (dw_attr_ref, int);
3235 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3236 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3237 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3238 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3240 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3241 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3242 static inline rtx AT_addr (dw_attr_ref);
3243 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3244 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3245 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3246 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3247 unsigned HOST_WIDE_INT);
3248 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3250 static inline const char *AT_lbl (dw_attr_ref);
3251 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3252 static const char *get_AT_low_pc (dw_die_ref);
3253 static const char *get_AT_hi_pc (dw_die_ref);
3254 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3255 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3256 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3257 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3258 static bool is_cxx (void);
3259 static bool is_fortran (void);
3260 static bool is_ada (void);
3261 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3262 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3263 static void add_child_die (dw_die_ref, dw_die_ref);
3264 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3265 static dw_die_ref lookup_type_die (tree);
3266 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3267 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3268 static void equate_type_number_to_die (tree, dw_die_ref);
3269 static hashval_t decl_die_table_hash (const void *);
3270 static int decl_die_table_eq (const void *, const void *);
3271 static dw_die_ref lookup_decl_die (tree);
3272 static hashval_t common_block_die_table_hash (const void *);
3273 static int common_block_die_table_eq (const void *, const void *);
3274 static hashval_t decl_loc_table_hash (const void *);
3275 static int decl_loc_table_eq (const void *, const void *);
3276 static var_loc_list *lookup_decl_loc (const_tree);
3277 static void equate_decl_number_to_die (tree, dw_die_ref);
3278 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
3279 static void print_spaces (FILE *);
3280 static void print_die (dw_die_ref, FILE *);
3281 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3282 static dw_die_ref pop_compile_unit (dw_die_ref);
3283 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3284 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3285 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3286 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3287 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3288 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3289 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
3290 struct md5_ctx *, int *);
3291 struct checksum_attributes;
3292 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3293 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3294 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3295 static void generate_type_signature (dw_die_ref, comdat_type_node *);
3296 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3297 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3298 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3299 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3300 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3301 static void compute_section_prefix (dw_die_ref);
3302 static int is_type_die (dw_die_ref);
3303 static int is_comdat_die (dw_die_ref);
3304 static int is_symbol_die (dw_die_ref);
3305 static void assign_symbol_names (dw_die_ref);
3306 static void break_out_includes (dw_die_ref);
3307 static int is_declaration_die (dw_die_ref);
3308 static int should_move_die_to_comdat (dw_die_ref);
3309 static dw_die_ref clone_as_declaration (dw_die_ref);
3310 static dw_die_ref clone_die (dw_die_ref);
3311 static dw_die_ref clone_tree (dw_die_ref);
3312 static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref);
3313 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3314 static void generate_skeleton_bottom_up (skeleton_chain_node *);
3315 static dw_die_ref generate_skeleton (dw_die_ref);
3316 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3319 static void break_out_comdat_types (dw_die_ref);
3320 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
3321 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
3322 static void copy_decls_for_unworthy_types (dw_die_ref);
3324 static hashval_t htab_cu_hash (const void *);
3325 static int htab_cu_eq (const void *, const void *);
3326 static void htab_cu_del (void *);
3327 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3328 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3329 static void add_sibling_attributes (dw_die_ref);
3330 static void build_abbrev_table (dw_die_ref);
3331 static void output_location_lists (dw_die_ref);
3332 static int constant_size (unsigned HOST_WIDE_INT);
3333 static unsigned long size_of_die (dw_die_ref);
3334 static void calc_die_sizes (dw_die_ref);
3335 static void calc_base_type_die_sizes (void);
3336 static void mark_dies (dw_die_ref);
3337 static void unmark_dies (dw_die_ref);
3338 static void unmark_all_dies (dw_die_ref);
3339 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
3340 static unsigned long size_of_aranges (void);
3341 static enum dwarf_form value_format (dw_attr_ref);
3342 static void output_value_format (dw_attr_ref);
3343 static void output_abbrev_section (void);
3344 static void output_die_symbol (dw_die_ref);
3345 static void output_die (dw_die_ref);
3346 static void output_compilation_unit_header (void);
3347 static void output_comp_unit (dw_die_ref, int);
3348 static void output_comdat_type_unit (comdat_type_node *);
3349 static const char *dwarf2_name (tree, int);
3350 static void add_pubname (tree, dw_die_ref);
3351 static void add_pubname_string (const char *, dw_die_ref);
3352 static void add_pubtype (tree, dw_die_ref);
3353 static void output_pubnames (VEC (pubname_entry,gc) *);
3354 static void output_aranges (unsigned long);
3355 static unsigned int add_ranges_num (int);
3356 static unsigned int add_ranges (const_tree);
3357 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3359 static void output_ranges (void);
3360 static dw_line_info_table *new_line_info_table (void);
3361 static void output_line_info (void);
3362 static void output_file_names (void);
3363 static dw_die_ref base_type_die (tree);
3364 static int is_base_type (tree);
3365 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
3366 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3367 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3368 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3369 static int type_is_enum (const_tree);
3370 static unsigned int dbx_reg_number (const_rtx);
3371 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3372 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3373 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3374 enum var_init_status);
3375 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3376 enum var_init_status);
3377 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
3378 enum var_init_status);
3379 static int is_based_loc (const_rtx);
3380 static int resolve_one_addr (rtx *, void *);
3381 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3382 enum var_init_status);
3383 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
3384 enum var_init_status);
3385 static dw_loc_list_ref loc_list_from_tree (tree, int);
3386 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3387 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3388 static tree field_type (const_tree);
3389 static unsigned int simple_type_align_in_bits (const_tree);
3390 static unsigned int simple_decl_align_in_bits (const_tree);
3391 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3392 static HOST_WIDE_INT field_byte_offset (const_tree);
3393 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3395 static void add_data_member_location_attribute (dw_die_ref, tree);
3396 static bool add_const_value_attribute (dw_die_ref, rtx);
3397 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3398 static void insert_double (double_int, unsigned char *);
3399 static void insert_float (const_rtx, unsigned char *);
3400 static rtx rtl_for_decl_location (tree);
3401 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
3402 enum dwarf_attribute);
3403 static bool tree_add_const_value_attribute (dw_die_ref, tree);
3404 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3405 static void add_name_attribute (dw_die_ref, const char *);
3406 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3407 static void add_comp_dir_attribute (dw_die_ref);
3408 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3409 static void add_subscript_info (dw_die_ref, tree, bool);
3410 static void add_byte_size_attribute (dw_die_ref, tree);
3411 static void add_bit_offset_attribute (dw_die_ref, tree);
3412 static void add_bit_size_attribute (dw_die_ref, tree);
3413 static void add_prototyped_attribute (dw_die_ref, tree);
3414 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
3415 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3416 static void add_src_coords_attributes (dw_die_ref, tree);
3417 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3418 static void push_decl_scope (tree);
3419 static void pop_decl_scope (void);
3420 static dw_die_ref scope_die_for (tree, dw_die_ref);
3421 static inline int local_scope_p (dw_die_ref);
3422 static inline int class_scope_p (dw_die_ref);
3423 static inline int class_or_namespace_scope_p (dw_die_ref);
3424 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3425 static void add_calling_convention_attribute (dw_die_ref, tree);
3426 static const char *type_tag (const_tree);
3427 static tree member_declared_type (const_tree);
3429 static const char *decl_start_label (tree);
3431 static void gen_array_type_die (tree, dw_die_ref);
3432 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
3434 static void gen_entry_point_die (tree, dw_die_ref);
3436 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3437 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
3438 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
3439 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3440 static void gen_formal_types_die (tree, dw_die_ref);
3441 static void gen_subprogram_die (tree, dw_die_ref);
3442 static void gen_variable_die (tree, tree, dw_die_ref);
3443 static void gen_const_die (tree, dw_die_ref);
3444 static void gen_label_die (tree, dw_die_ref);
3445 static void gen_lexical_block_die (tree, dw_die_ref, int);
3446 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3447 static void gen_field_die (tree, dw_die_ref);
3448 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3449 static dw_die_ref gen_compile_unit_die (const char *);
3450 static void gen_inheritance_die (tree, tree, dw_die_ref);
3451 static void gen_member_die (tree, dw_die_ref);
3452 static void gen_struct_or_union_type_die (tree, dw_die_ref,
3453 enum debug_info_usage);
3454 static void gen_subroutine_type_die (tree, dw_die_ref);
3455 static void gen_typedef_die (tree, dw_die_ref);
3456 static void gen_type_die (tree, dw_die_ref);
3457 static void gen_block_die (tree, dw_die_ref, int);
3458 static void decls_for_scope (tree, dw_die_ref, int);
3459 static inline int is_redundant_typedef (const_tree);
3460 static bool is_naming_typedef_decl (const_tree);
3461 static inline dw_die_ref get_context_die (tree);
3462 static void gen_namespace_die (tree, dw_die_ref);
3463 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
3464 static dw_die_ref force_decl_die (tree);
3465 static dw_die_ref force_type_die (tree);
3466 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3467 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
3468 static struct dwarf_file_data * lookup_filename (const char *);
3469 static void retry_incomplete_types (void);
3470 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3471 static void gen_generic_params_dies (tree);
3472 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
3473 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
3474 static void splice_child_die (dw_die_ref, dw_die_ref);
3475 static int file_info_cmp (const void *, const void *);
3476 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3477 const char *, const char *);
3478 static void output_loc_list (dw_loc_list_ref);
3479 static char *gen_internal_sym (const char *);
3481 static void prune_unmark_dies (dw_die_ref);
3482 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
3483 static void prune_unused_types_mark (dw_die_ref, int);
3484 static void prune_unused_types_walk (dw_die_ref);
3485 static void prune_unused_types_walk_attribs (dw_die_ref);
3486 static void prune_unused_types_prune (dw_die_ref);
3487 static void prune_unused_types (void);
3488 static int maybe_emit_file (struct dwarf_file_data *fd);
3489 static inline const char *AT_vms_delta1 (dw_attr_ref);
3490 static inline const char *AT_vms_delta2 (dw_attr_ref);
3491 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
3492 const char *, const char *);
3493 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
3494 static void gen_remaining_tmpl_value_param_die_attribute (void);
3495 static bool generic_type_p (tree);
3496 static void schedule_generic_params_dies_gen (tree t);
3497 static void gen_scheduled_generic_parms_dies (void);
3499 /* Section names used to hold DWARF debugging information. */
3500 #ifndef DEBUG_INFO_SECTION
3501 #define DEBUG_INFO_SECTION ".debug_info"
3503 #ifndef DEBUG_ABBREV_SECTION
3504 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3506 #ifndef DEBUG_ARANGES_SECTION
3507 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3509 #ifndef DEBUG_MACINFO_SECTION
3510 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3512 #ifndef DEBUG_MACRO_SECTION
3513 #define DEBUG_MACRO_SECTION ".debug_macro"
3515 #ifndef DEBUG_LINE_SECTION
3516 #define DEBUG_LINE_SECTION ".debug_line"
3518 #ifndef DEBUG_LOC_SECTION
3519 #define DEBUG_LOC_SECTION ".debug_loc"
3521 #ifndef DEBUG_PUBNAMES_SECTION
3522 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3524 #ifndef DEBUG_PUBTYPES_SECTION
3525 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3527 #ifndef DEBUG_STR_SECTION
3528 #define DEBUG_STR_SECTION ".debug_str"
3530 #ifndef DEBUG_RANGES_SECTION
3531 #define DEBUG_RANGES_SECTION ".debug_ranges"
3534 /* Standard ELF section names for compiled code and data. */
3535 #ifndef TEXT_SECTION_NAME
3536 #define TEXT_SECTION_NAME ".text"
3539 /* Section flags for .debug_str section. */
3540 #define DEBUG_STR_SECTION_FLAGS \
3541 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3542 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3545 /* Labels we insert at beginning sections we can reference instead of
3546 the section names themselves. */
3548 #ifndef TEXT_SECTION_LABEL
3549 #define TEXT_SECTION_LABEL "Ltext"
3551 #ifndef COLD_TEXT_SECTION_LABEL
3552 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3554 #ifndef DEBUG_LINE_SECTION_LABEL
3555 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3557 #ifndef DEBUG_INFO_SECTION_LABEL
3558 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3560 #ifndef DEBUG_ABBREV_SECTION_LABEL
3561 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3563 #ifndef DEBUG_LOC_SECTION_LABEL
3564 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3566 #ifndef DEBUG_RANGES_SECTION_LABEL
3567 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3569 #ifndef DEBUG_MACINFO_SECTION_LABEL
3570 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3572 #ifndef DEBUG_MACRO_SECTION_LABEL
3573 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3577 /* Definitions of defaults for formats and names of various special
3578 (artificial) labels which may be generated within this file (when the -g
3579 options is used and DWARF2_DEBUGGING_INFO is in effect.
3580 If necessary, these may be overridden from within the tm.h file, but
3581 typically, overriding these defaults is unnecessary. */
3583 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3584 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3585 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3586 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3587 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3588 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3589 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3590 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3591 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3592 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3594 #ifndef TEXT_END_LABEL
3595 #define TEXT_END_LABEL "Letext"
3597 #ifndef COLD_END_LABEL
3598 #define COLD_END_LABEL "Letext_cold"
3600 #ifndef BLOCK_BEGIN_LABEL
3601 #define BLOCK_BEGIN_LABEL "LBB"
3603 #ifndef BLOCK_END_LABEL
3604 #define BLOCK_END_LABEL "LBE"
3606 #ifndef LINE_CODE_LABEL
3607 #define LINE_CODE_LABEL "LM"
3611 /* Return the root of the DIE's built for the current compilation unit. */
3613 comp_unit_die (void)
3615 if (!single_comp_unit_die)
3616 single_comp_unit_die = gen_compile_unit_die (NULL);
3617 return single_comp_unit_die;
3620 /* We allow a language front-end to designate a function that is to be
3621 called to "demangle" any name before it is put into a DIE. */
3623 static const char *(*demangle_name_func) (const char *);
3626 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3628 demangle_name_func = func;
3631 /* Test if rtl node points to a pseudo register. */
3634 is_pseudo_reg (const_rtx rtl)
3636 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3637 || (GET_CODE (rtl) == SUBREG
3638 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3641 /* Return a reference to a type, with its const and volatile qualifiers
3645 type_main_variant (tree type)
3647 type = TYPE_MAIN_VARIANT (type);
3649 /* ??? There really should be only one main variant among any group of
3650 variants of a given type (and all of the MAIN_VARIANT values for all
3651 members of the group should point to that one type) but sometimes the C
3652 front-end messes this up for array types, so we work around that bug
3654 if (TREE_CODE (type) == ARRAY_TYPE)
3655 while (type != TYPE_MAIN_VARIANT (type))
3656 type = TYPE_MAIN_VARIANT (type);
3661 /* Return nonzero if the given type node represents a tagged type. */
3664 is_tagged_type (const_tree type)
3666 enum tree_code code = TREE_CODE (type);
3668 return (code == RECORD_TYPE || code == UNION_TYPE
3669 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3672 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3675 get_ref_die_offset_label (char *label, dw_die_ref ref)
3677 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
3680 /* Return die_offset of a DIE reference to a base type. */
3682 static unsigned long int
3683 get_base_type_offset (dw_die_ref ref)
3685 if (ref->die_offset)
3686 return ref->die_offset;
3687 if (comp_unit_die ()->die_abbrev)
3689 calc_base_type_die_sizes ();
3690 gcc_assert (ref->die_offset);
3692 return ref->die_offset;
3695 /* Return die_offset of a DIE reference other than base type. */
3697 static unsigned long int
3698 get_ref_die_offset (dw_die_ref ref)
3700 gcc_assert (ref->die_offset);
3701 return ref->die_offset;
3704 /* Convert a DIE tag into its string name. */
3707 dwarf_tag_name (unsigned int tag)
3711 case DW_TAG_padding:
3712 return "DW_TAG_padding";
3713 case DW_TAG_array_type:
3714 return "DW_TAG_array_type";
3715 case DW_TAG_class_type:
3716 return "DW_TAG_class_type";
3717 case DW_TAG_entry_point:
3718 return "DW_TAG_entry_point";
3719 case DW_TAG_enumeration_type:
3720 return "DW_TAG_enumeration_type";
3721 case DW_TAG_formal_parameter:
3722 return "DW_TAG_formal_parameter";
3723 case DW_TAG_imported_declaration:
3724 return "DW_TAG_imported_declaration";
3726 return "DW_TAG_label";
3727 case DW_TAG_lexical_block:
3728 return "DW_TAG_lexical_block";
3730 return "DW_TAG_member";
3731 case DW_TAG_pointer_type:
3732 return "DW_TAG_pointer_type";
3733 case DW_TAG_reference_type:
3734 return "DW_TAG_reference_type";
3735 case DW_TAG_compile_unit:
3736 return "DW_TAG_compile_unit";
3737 case DW_TAG_string_type:
3738 return "DW_TAG_string_type";
3739 case DW_TAG_structure_type:
3740 return "DW_TAG_structure_type";
3741 case DW_TAG_subroutine_type:
3742 return "DW_TAG_subroutine_type";
3743 case DW_TAG_typedef:
3744 return "DW_TAG_typedef";
3745 case DW_TAG_union_type:
3746 return "DW_TAG_union_type";
3747 case DW_TAG_unspecified_parameters:
3748 return "DW_TAG_unspecified_parameters";
3749 case DW_TAG_variant:
3750 return "DW_TAG_variant";
3751 case DW_TAG_common_block:
3752 return "DW_TAG_common_block";
3753 case DW_TAG_common_inclusion:
3754 return "DW_TAG_common_inclusion";
3755 case DW_TAG_inheritance:
3756 return "DW_TAG_inheritance";
3757 case DW_TAG_inlined_subroutine:
3758 return "DW_TAG_inlined_subroutine";
3760 return "DW_TAG_module";
3761 case DW_TAG_ptr_to_member_type:
3762 return "DW_TAG_ptr_to_member_type";
3763 case DW_TAG_set_type:
3764 return "DW_TAG_set_type";
3765 case DW_TAG_subrange_type:
3766 return "DW_TAG_subrange_type";
3767 case DW_TAG_with_stmt:
3768 return "DW_TAG_with_stmt";
3769 case DW_TAG_access_declaration:
3770 return "DW_TAG_access_declaration";
3771 case DW_TAG_base_type:
3772 return "DW_TAG_base_type";
3773 case DW_TAG_catch_block:
3774 return "DW_TAG_catch_block";
3775 case DW_TAG_const_type:
3776 return "DW_TAG_const_type";
3777 case DW_TAG_constant:
3778 return "DW_TAG_constant";
3779 case DW_TAG_enumerator:
3780 return "DW_TAG_enumerator";
3781 case DW_TAG_file_type:
3782 return "DW_TAG_file_type";
3784 return "DW_TAG_friend";
3785 case DW_TAG_namelist:
3786 return "DW_TAG_namelist";
3787 case DW_TAG_namelist_item:
3788 return "DW_TAG_namelist_item";
3789 case DW_TAG_packed_type:
3790 return "DW_TAG_packed_type";
3791 case DW_TAG_subprogram:
3792 return "DW_TAG_subprogram";
3793 case DW_TAG_template_type_param:
3794 return "DW_TAG_template_type_param";
3795 case DW_TAG_template_value_param:
3796 return "DW_TAG_template_value_param";
3797 case DW_TAG_thrown_type:
3798 return "DW_TAG_thrown_type";
3799 case DW_TAG_try_block:
3800 return "DW_TAG_try_block";
3801 case DW_TAG_variant_part:
3802 return "DW_TAG_variant_part";
3803 case DW_TAG_variable:
3804 return "DW_TAG_variable";
3805 case DW_TAG_volatile_type:
3806 return "DW_TAG_volatile_type";
3807 case DW_TAG_dwarf_procedure:
3808 return "DW_TAG_dwarf_procedure";
3809 case DW_TAG_restrict_type:
3810 return "DW_TAG_restrict_type";
3811 case DW_TAG_interface_type:
3812 return "DW_TAG_interface_type";
3813 case DW_TAG_namespace:
3814 return "DW_TAG_namespace";
3815 case DW_TAG_imported_module:
3816 return "DW_TAG_imported_module";
3817 case DW_TAG_unspecified_type:
3818 return "DW_TAG_unspecified_type";
3819 case DW_TAG_partial_unit:
3820 return "DW_TAG_partial_unit";
3821 case DW_TAG_imported_unit:
3822 return "DW_TAG_imported_unit";
3823 case DW_TAG_condition:
3824 return "DW_TAG_condition";
3825 case DW_TAG_shared_type:
3826 return "DW_TAG_shared_type";
3827 case DW_TAG_type_unit:
3828 return "DW_TAG_type_unit";
3829 case DW_TAG_rvalue_reference_type:
3830 return "DW_TAG_rvalue_reference_type";
3831 case DW_TAG_template_alias:
3832 return "DW_TAG_template_alias";
3833 case DW_TAG_GNU_template_parameter_pack:
3834 return "DW_TAG_GNU_template_parameter_pack";
3835 case DW_TAG_GNU_formal_parameter_pack:
3836 return "DW_TAG_GNU_formal_parameter_pack";
3837 case DW_TAG_MIPS_loop:
3838 return "DW_TAG_MIPS_loop";
3839 case DW_TAG_format_label:
3840 return "DW_TAG_format_label";
3841 case DW_TAG_function_template:
3842 return "DW_TAG_function_template";
3843 case DW_TAG_class_template:
3844 return "DW_TAG_class_template";
3845 case DW_TAG_GNU_BINCL:
3846 return "DW_TAG_GNU_BINCL";
3847 case DW_TAG_GNU_EINCL:
3848 return "DW_TAG_GNU_EINCL";
3849 case DW_TAG_GNU_template_template_param:
3850 return "DW_TAG_GNU_template_template_param";
3851 case DW_TAG_GNU_call_site:
3852 return "DW_TAG_GNU_call_site";
3853 case DW_TAG_GNU_call_site_parameter:
3854 return "DW_TAG_GNU_call_site_parameter";
3856 return "DW_TAG_<unknown>";
3860 /* Convert a DWARF attribute code into its string name. */
3863 dwarf_attr_name (unsigned int attr)
3868 return "DW_AT_sibling";
3869 case DW_AT_location:
3870 return "DW_AT_location";
3872 return "DW_AT_name";
3873 case DW_AT_ordering:
3874 return "DW_AT_ordering";
3875 case DW_AT_subscr_data:
3876 return "DW_AT_subscr_data";
3877 case DW_AT_byte_size:
3878 return "DW_AT_byte_size";
3879 case DW_AT_bit_offset:
3880 return "DW_AT_bit_offset";
3881 case DW_AT_bit_size:
3882 return "DW_AT_bit_size";
3883 case DW_AT_element_list:
3884 return "DW_AT_element_list";
3885 case DW_AT_stmt_list:
3886 return "DW_AT_stmt_list";
3888 return "DW_AT_low_pc";
3890 return "DW_AT_high_pc";
3891 case DW_AT_language:
3892 return "DW_AT_language";
3894 return "DW_AT_member";
3896 return "DW_AT_discr";
3897 case DW_AT_discr_value:
3898 return "DW_AT_discr_value";
3899 case DW_AT_visibility:
3900 return "DW_AT_visibility";
3902 return "DW_AT_import";
3903 case DW_AT_string_length:
3904 return "DW_AT_string_length";
3905 case DW_AT_common_reference:
3906 return "DW_AT_common_reference";
3907 case DW_AT_comp_dir:
3908 return "DW_AT_comp_dir";
3909 case DW_AT_const_value:
3910 return "DW_AT_const_value";
3911 case DW_AT_containing_type:
3912 return "DW_AT_containing_type";
3913 case DW_AT_default_value:
3914 return "DW_AT_default_value";
3916 return "DW_AT_inline";
3917 case DW_AT_is_optional:
3918 return "DW_AT_is_optional";
3919 case DW_AT_lower_bound:
3920 return "DW_AT_lower_bound";
3921 case DW_AT_producer:
3922 return "DW_AT_producer";
3923 case DW_AT_prototyped:
3924 return "DW_AT_prototyped";
3925 case DW_AT_return_addr:
3926 return "DW_AT_return_addr";
3927 case DW_AT_start_scope:
3928 return "DW_AT_start_scope";
3929 case DW_AT_bit_stride:
3930 return "DW_AT_bit_stride";
3931 case DW_AT_upper_bound:
3932 return "DW_AT_upper_bound";
3933 case DW_AT_abstract_origin:
3934 return "DW_AT_abstract_origin";
3935 case DW_AT_accessibility:
3936 return "DW_AT_accessibility";
3937 case DW_AT_address_class:
3938 return "DW_AT_address_class";
3939 case DW_AT_artificial:
3940 return "DW_AT_artificial";
3941 case DW_AT_base_types:
3942 return "DW_AT_base_types";
3943 case DW_AT_calling_convention:
3944 return "DW_AT_calling_convention";
3946 return "DW_AT_count";
3947 case DW_AT_data_member_location:
3948 return "DW_AT_data_member_location";
3949 case DW_AT_decl_column:
3950 return "DW_AT_decl_column";
3951 case DW_AT_decl_file:
3952 return "DW_AT_decl_file";
3953 case DW_AT_decl_line:
3954 return "DW_AT_decl_line";
3955 case DW_AT_declaration:
3956 return "DW_AT_declaration";
3957 case DW_AT_discr_list:
3958 return "DW_AT_discr_list";
3959 case DW_AT_encoding:
3960 return "DW_AT_encoding";
3961 case DW_AT_external:
3962 return "DW_AT_external";
3963 case DW_AT_explicit:
3964 return "DW_AT_explicit";
3965 case DW_AT_frame_base:
3966 return "DW_AT_frame_base";
3968 return "DW_AT_friend";
3969 case DW_AT_identifier_case:
3970 return "DW_AT_identifier_case";
3971 case DW_AT_macro_info:
3972 return "DW_AT_macro_info";
3973 case DW_AT_namelist_items:
3974 return "DW_AT_namelist_items";
3975 case DW_AT_priority:
3976 return "DW_AT_priority";
3978 return "DW_AT_segment";
3979 case DW_AT_specification:
3980 return "DW_AT_specification";
3981 case DW_AT_static_link:
3982 return "DW_AT_static_link";
3984 return "DW_AT_type";
3985 case DW_AT_use_location:
3986 return "DW_AT_use_location";
3987 case DW_AT_variable_parameter:
3988 return "DW_AT_variable_parameter";
3989 case DW_AT_virtuality:
3990 return "DW_AT_virtuality";
3991 case DW_AT_vtable_elem_location:
3992 return "DW_AT_vtable_elem_location";
3994 case DW_AT_allocated:
3995 return "DW_AT_allocated";
3996 case DW_AT_associated:
3997 return "DW_AT_associated";
3998 case DW_AT_data_location:
3999 return "DW_AT_data_location";
4000 case DW_AT_byte_stride:
4001 return "DW_AT_byte_stride";
4002 case DW_AT_entry_pc:
4003 return "DW_AT_entry_pc";
4004 case DW_AT_use_UTF8:
4005 return "DW_AT_use_UTF8";
4006 case DW_AT_extension:
4007 return "DW_AT_extension";
4009 return "DW_AT_ranges";
4010 case DW_AT_trampoline:
4011 return "DW_AT_trampoline";
4012 case DW_AT_call_column:
4013 return "DW_AT_call_column";
4014 case DW_AT_call_file:
4015 return "DW_AT_call_file";
4016 case DW_AT_call_line:
4017 return "DW_AT_call_line";
4018 case DW_AT_object_pointer:
4019 return "DW_AT_object_pointer";
4021 case DW_AT_signature:
4022 return "DW_AT_signature";
4023 case DW_AT_main_subprogram:
4024 return "DW_AT_main_subprogram";
4025 case DW_AT_data_bit_offset:
4026 return "DW_AT_data_bit_offset";
4027 case DW_AT_const_expr:
4028 return "DW_AT_const_expr";
4029 case DW_AT_enum_class:
4030 return "DW_AT_enum_class";
4031 case DW_AT_linkage_name:
4032 return "DW_AT_linkage_name";
4034 case DW_AT_MIPS_fde:
4035 return "DW_AT_MIPS_fde";
4036 case DW_AT_MIPS_loop_begin:
4037 return "DW_AT_MIPS_loop_begin";
4038 case DW_AT_MIPS_tail_loop_begin:
4039 return "DW_AT_MIPS_tail_loop_begin";
4040 case DW_AT_MIPS_epilog_begin:
4041 return "DW_AT_MIPS_epilog_begin";
4042 #if VMS_DEBUGGING_INFO
4043 case DW_AT_HP_prologue:
4044 return "DW_AT_HP_prologue";
4046 case DW_AT_MIPS_loop_unroll_factor:
4047 return "DW_AT_MIPS_loop_unroll_factor";
4049 case DW_AT_MIPS_software_pipeline_depth:
4050 return "DW_AT_MIPS_software_pipeline_depth";
4051 case DW_AT_MIPS_linkage_name:
4052 return "DW_AT_MIPS_linkage_name";
4053 #if VMS_DEBUGGING_INFO
4054 case DW_AT_HP_epilogue:
4055 return "DW_AT_HP_epilogue";
4057 case DW_AT_MIPS_stride:
4058 return "DW_AT_MIPS_stride";
4060 case DW_AT_MIPS_abstract_name:
4061 return "DW_AT_MIPS_abstract_name";
4062 case DW_AT_MIPS_clone_origin:
4063 return "DW_AT_MIPS_clone_origin";
4064 case DW_AT_MIPS_has_inlines:
4065 return "DW_AT_MIPS_has_inlines";
4067 case DW_AT_sf_names:
4068 return "DW_AT_sf_names";
4069 case DW_AT_src_info:
4070 return "DW_AT_src_info";
4071 case DW_AT_mac_info:
4072 return "DW_AT_mac_info";
4073 case DW_AT_src_coords:
4074 return "DW_AT_src_coords";
4075 case DW_AT_body_begin:
4076 return "DW_AT_body_begin";
4077 case DW_AT_body_end:
4078 return "DW_AT_body_end";
4080 case DW_AT_GNU_vector:
4081 return "DW_AT_GNU_vector";
4082 case DW_AT_GNU_guarded_by:
4083 return "DW_AT_GNU_guarded_by";
4084 case DW_AT_GNU_pt_guarded_by:
4085 return "DW_AT_GNU_pt_guarded_by";
4086 case DW_AT_GNU_guarded:
4087 return "DW_AT_GNU_guarded";
4088 case DW_AT_GNU_pt_guarded:
4089 return "DW_AT_GNU_pt_guarded";
4090 case DW_AT_GNU_locks_excluded:
4091 return "DW_AT_GNU_locks_excluded";
4092 case DW_AT_GNU_exclusive_locks_required:
4093 return "DW_AT_GNU_exclusive_locks_required";
4094 case DW_AT_GNU_shared_locks_required:
4095 return "DW_AT_GNU_shared_locks_required";
4096 case DW_AT_GNU_odr_signature:
4097 return "DW_AT_GNU_odr_signature";
4098 case DW_AT_GNU_template_name:
4099 return "DW_AT_GNU_template_name";
4100 case DW_AT_GNU_call_site_value:
4101 return "DW_AT_GNU_call_site_value";
4102 case DW_AT_GNU_call_site_data_value:
4103 return "DW_AT_GNU_call_site_data_value";
4104 case DW_AT_GNU_call_site_target:
4105 return "DW_AT_GNU_call_site_target";
4106 case DW_AT_GNU_call_site_target_clobbered:
4107 return "DW_AT_GNU_call_site_target_clobbered";
4108 case DW_AT_GNU_tail_call:
4109 return "DW_AT_GNU_tail_call";
4110 case DW_AT_GNU_all_tail_call_sites:
4111 return "DW_AT_GNU_all_tail_call_sites";
4112 case DW_AT_GNU_all_call_sites:
4113 return "DW_AT_GNU_all_call_sites";
4114 case DW_AT_GNU_all_source_call_sites:
4115 return "DW_AT_GNU_all_source_call_sites";
4116 case DW_AT_GNU_macros:
4117 return "DW_AT_GNU_macros";
4119 case DW_AT_GNAT_descriptive_type:
4120 return "DW_AT_GNAT_descriptive_type";
4122 case DW_AT_VMS_rtnbeg_pd_address:
4123 return "DW_AT_VMS_rtnbeg_pd_address";
4126 return "DW_AT_<unknown>";
4130 /* Convert a DWARF value form code into its string name. */
4133 dwarf_form_name (unsigned int form)
4138 return "DW_FORM_addr";
4139 case DW_FORM_block2:
4140 return "DW_FORM_block2";
4141 case DW_FORM_block4:
4142 return "DW_FORM_block4";
4144 return "DW_FORM_data2";
4146 return "DW_FORM_data4";
4148 return "DW_FORM_data8";
4149 case DW_FORM_string:
4150 return "DW_FORM_string";
4152 return "DW_FORM_block";
4153 case DW_FORM_block1:
4154 return "DW_FORM_block1";
4156 return "DW_FORM_data1";
4158 return "DW_FORM_flag";
4160 return "DW_FORM_sdata";
4162 return "DW_FORM_strp";
4164 return "DW_FORM_udata";
4165 case DW_FORM_ref_addr:
4166 return "DW_FORM_ref_addr";
4168 return "DW_FORM_ref1";
4170 return "DW_FORM_ref2";
4172 return "DW_FORM_ref4";
4174 return "DW_FORM_ref8";
4175 case DW_FORM_ref_udata:
4176 return "DW_FORM_ref_udata";
4177 case DW_FORM_indirect:
4178 return "DW_FORM_indirect";
4179 case DW_FORM_sec_offset:
4180 return "DW_FORM_sec_offset";
4181 case DW_FORM_exprloc:
4182 return "DW_FORM_exprloc";
4183 case DW_FORM_flag_present:
4184 return "DW_FORM_flag_present";
4185 case DW_FORM_ref_sig8:
4186 return "DW_FORM_ref_sig8";
4188 return "DW_FORM_<unknown>";
4192 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4193 instance of an inlined instance of a decl which is local to an inline
4194 function, so we have to trace all of the way back through the origin chain
4195 to find out what sort of node actually served as the original seed for the
4199 decl_ultimate_origin (const_tree decl)
4201 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4204 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4205 nodes in the function to point to themselves; ignore that if
4206 we're trying to output the abstract instance of this function. */
4207 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4210 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4211 most distant ancestor, this should never happen. */
4212 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4214 return DECL_ABSTRACT_ORIGIN (decl);
4217 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4218 of a virtual function may refer to a base class, so we check the 'this'
4222 decl_class_context (tree decl)
4224 tree context = NULL_TREE;
4226 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4227 context = DECL_CONTEXT (decl);
4229 context = TYPE_MAIN_VARIANT
4230 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4232 if (context && !TYPE_P (context))
4233 context = NULL_TREE;
4238 /* Add an attribute/value pair to a DIE. */
4241 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4243 /* Maybe this should be an assert? */
4247 if (die->die_attr == NULL)
4248 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4249 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4252 static inline enum dw_val_class
4253 AT_class (dw_attr_ref a)
4255 return a->dw_attr_val.val_class;
4258 /* Add a flag value attribute to a DIE. */
4261 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4265 attr.dw_attr = attr_kind;
4266 attr.dw_attr_val.val_class = dw_val_class_flag;
4267 attr.dw_attr_val.v.val_flag = flag;
4268 add_dwarf_attr (die, &attr);
4271 static inline unsigned
4272 AT_flag (dw_attr_ref a)
4274 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4275 return a->dw_attr_val.v.val_flag;
4278 /* Add a signed integer attribute value to a DIE. */
4281 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4285 attr.dw_attr = attr_kind;
4286 attr.dw_attr_val.val_class = dw_val_class_const;
4287 attr.dw_attr_val.v.val_int = int_val;
4288 add_dwarf_attr (die, &attr);
4291 static inline HOST_WIDE_INT
4292 AT_int (dw_attr_ref a)
4294 gcc_assert (a && AT_class (a) == dw_val_class_const);
4295 return a->dw_attr_val.v.val_int;
4298 /* Add an unsigned integer attribute value to a DIE. */
4301 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4302 unsigned HOST_WIDE_INT unsigned_val)
4306 attr.dw_attr = attr_kind;
4307 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4308 attr.dw_attr_val.v.val_unsigned = unsigned_val;
4309 add_dwarf_attr (die, &attr);
4312 static inline unsigned HOST_WIDE_INT
4313 AT_unsigned (dw_attr_ref a)
4315 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4316 return a->dw_attr_val.v.val_unsigned;
4319 /* Add an unsigned double integer attribute value to a DIE. */
4322 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
4323 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
4327 attr.dw_attr = attr_kind;
4328 attr.dw_attr_val.val_class = dw_val_class_const_double;
4329 attr.dw_attr_val.v.val_double.high = high;
4330 attr.dw_attr_val.v.val_double.low = low;
4331 add_dwarf_attr (die, &attr);
4334 /* Add a floating point attribute value to a DIE and return it. */
4337 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4338 unsigned int length, unsigned int elt_size, unsigned char *array)
4342 attr.dw_attr = attr_kind;
4343 attr.dw_attr_val.val_class = dw_val_class_vec;
4344 attr.dw_attr_val.v.val_vec.length = length;
4345 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4346 attr.dw_attr_val.v.val_vec.array = array;
4347 add_dwarf_attr (die, &attr);
4350 /* Add an 8-byte data attribute value to a DIE. */
4353 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
4354 unsigned char data8[8])
4358 attr.dw_attr = attr_kind;
4359 attr.dw_attr_val.val_class = dw_val_class_data8;
4360 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
4361 add_dwarf_attr (die, &attr);
4364 /* Hash and equality functions for debug_str_hash. */
4367 debug_str_do_hash (const void *x)
4369 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4373 debug_str_eq (const void *x1, const void *x2)
4375 return strcmp ((((const struct indirect_string_node *)x1)->str),
4376 (const char *)x2) == 0;
4379 /* Add STR to the indirect string hash table. */
4381 static struct indirect_string_node *
4382 find_AT_string (const char *str)
4384 struct indirect_string_node *node;
4387 if (! debug_str_hash)
4388 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4389 debug_str_eq, NULL);
4391 slot = htab_find_slot_with_hash (debug_str_hash, str,
4392 htab_hash_string (str), INSERT);
4395 node = ggc_alloc_cleared_indirect_string_node ();
4396 node->str = ggc_strdup (str);
4400 node = (struct indirect_string_node *) *slot;
4406 /* Add a string attribute value to a DIE. */
4409 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4412 struct indirect_string_node *node;
4414 node = find_AT_string (str);
4416 attr.dw_attr = attr_kind;
4417 attr.dw_attr_val.val_class = dw_val_class_str;
4418 attr.dw_attr_val.v.val_str = node;
4419 add_dwarf_attr (die, &attr);
4422 static inline const char *
4423 AT_string (dw_attr_ref a)
4425 gcc_assert (a && AT_class (a) == dw_val_class_str);
4426 return a->dw_attr_val.v.val_str->str;
4429 /* Find out whether a string should be output inline in DIE
4430 or out-of-line in .debug_str section. */
4432 static enum dwarf_form
4433 AT_string_form (dw_attr_ref a)
4435 struct indirect_string_node *node;
4439 gcc_assert (a && AT_class (a) == dw_val_class_str);
4441 node = a->dw_attr_val.v.val_str;
4445 len = strlen (node->str) + 1;
4447 /* If the string is shorter or equal to the size of the reference, it is
4448 always better to put it inline. */
4449 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4450 return node->form = DW_FORM_string;
4452 /* If we cannot expect the linker to merge strings in .debug_str
4453 section, only put it into .debug_str if it is worth even in this
4455 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4456 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
4457 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
4458 return node->form = DW_FORM_string;
4460 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4461 ++dw2_string_counter;
4462 node->label = xstrdup (label);
4464 return node->form = DW_FORM_strp;
4467 /* Add a DIE reference attribute value to a DIE. */
4470 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4474 #ifdef ENABLE_CHECKING
4475 gcc_assert (targ_die != NULL);
4477 /* With LTO we can end up trying to reference something we didn't create
4478 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4479 if (targ_die == NULL)
4483 attr.dw_attr = attr_kind;
4484 attr.dw_attr_val.val_class = dw_val_class_die_ref;
4485 attr.dw_attr_val.v.val_die_ref.die = targ_die;
4486 attr.dw_attr_val.v.val_die_ref.external = 0;
4487 add_dwarf_attr (die, &attr);
4490 /* Add an AT_specification attribute to a DIE, and also make the back
4491 pointer from the specification to the definition. */
4494 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4496 add_AT_die_ref (die, DW_AT_specification, targ_die);
4497 gcc_assert (!targ_die->die_definition);
4498 targ_die->die_definition = die;
4501 static inline dw_die_ref
4502 AT_ref (dw_attr_ref a)
4504 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4505 return a->dw_attr_val.v.val_die_ref.die;
4509 AT_ref_external (dw_attr_ref a)
4511 if (a && AT_class (a) == dw_val_class_die_ref)
4512 return a->dw_attr_val.v.val_die_ref.external;
4518 set_AT_ref_external (dw_attr_ref a, int i)
4520 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4521 a->dw_attr_val.v.val_die_ref.external = i;
4524 /* Add an FDE reference attribute value to a DIE. */
4527 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4531 attr.dw_attr = attr_kind;
4532 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
4533 attr.dw_attr_val.v.val_fde_index = targ_fde;
4534 add_dwarf_attr (die, &attr);
4537 /* Add a location description attribute value to a DIE. */
4540 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4544 attr.dw_attr = attr_kind;
4545 attr.dw_attr_val.val_class = dw_val_class_loc;
4546 attr.dw_attr_val.v.val_loc = loc;
4547 add_dwarf_attr (die, &attr);
4550 static inline dw_loc_descr_ref
4551 AT_loc (dw_attr_ref a)
4553 gcc_assert (a && AT_class (a) == dw_val_class_loc);
4554 return a->dw_attr_val.v.val_loc;
4558 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4562 attr.dw_attr = attr_kind;
4563 attr.dw_attr_val.val_class = dw_val_class_loc_list;
4564 attr.dw_attr_val.v.val_loc_list = loc_list;
4565 add_dwarf_attr (die, &attr);
4566 have_location_lists = true;
4569 static inline dw_loc_list_ref
4570 AT_loc_list (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 static inline dw_loc_list_ref *
4577 AT_loc_list_ptr (dw_attr_ref a)
4579 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4580 return &a->dw_attr_val.v.val_loc_list;
4583 /* Add an address constant attribute value to a DIE. */
4586 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
4590 attr.dw_attr = attr_kind;
4591 attr.dw_attr_val.val_class = dw_val_class_addr;
4592 attr.dw_attr_val.v.val_addr = addr;
4593 add_dwarf_attr (die, &attr);
4596 /* Get the RTX from to an address DIE attribute. */
4599 AT_addr (dw_attr_ref a)
4601 gcc_assert (a && AT_class (a) == dw_val_class_addr);
4602 return a->dw_attr_val.v.val_addr;
4605 /* Add a file attribute value to a DIE. */
4608 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
4609 struct dwarf_file_data *fd)
4613 attr.dw_attr = attr_kind;
4614 attr.dw_attr_val.val_class = dw_val_class_file;
4615 attr.dw_attr_val.v.val_file = fd;
4616 add_dwarf_attr (die, &attr);
4619 /* Get the dwarf_file_data from a file DIE attribute. */
4621 static inline struct dwarf_file_data *
4622 AT_file (dw_attr_ref a)
4624 gcc_assert (a && AT_class (a) == dw_val_class_file);
4625 return a->dw_attr_val.v.val_file;
4628 /* Add a vms delta attribute value to a DIE. */
4631 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
4632 const char *lbl1, const char *lbl2)
4636 attr.dw_attr = attr_kind;
4637 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
4638 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
4639 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
4640 add_dwarf_attr (die, &attr);
4643 /* Add a label identifier attribute value to a DIE. */
4646 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
4650 attr.dw_attr = attr_kind;
4651 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4652 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4653 add_dwarf_attr (die, &attr);
4656 /* Add a section offset attribute value to a DIE, an offset into the
4657 debug_line section. */
4660 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4665 attr.dw_attr = attr_kind;
4666 attr.dw_attr_val.val_class = dw_val_class_lineptr;
4667 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4668 add_dwarf_attr (die, &attr);
4671 /* Add a section offset attribute value to a DIE, an offset into the
4672 debug_macinfo section. */
4675 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4680 attr.dw_attr = attr_kind;
4681 attr.dw_attr_val.val_class = dw_val_class_macptr;
4682 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4683 add_dwarf_attr (die, &attr);
4686 /* Add an offset attribute value to a DIE. */
4689 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
4690 unsigned HOST_WIDE_INT offset)
4694 attr.dw_attr = attr_kind;
4695 attr.dw_attr_val.val_class = dw_val_class_offset;
4696 attr.dw_attr_val.v.val_offset = offset;
4697 add_dwarf_attr (die, &attr);
4700 /* Add an range_list attribute value to a DIE. */
4703 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4704 long unsigned int offset)
4708 attr.dw_attr = attr_kind;
4709 attr.dw_attr_val.val_class = dw_val_class_range_list;
4710 attr.dw_attr_val.v.val_offset = offset;
4711 add_dwarf_attr (die, &attr);
4714 /* Return the start label of a delta attribute. */
4716 static inline const char *
4717 AT_vms_delta1 (dw_attr_ref a)
4719 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4720 return a->dw_attr_val.v.val_vms_delta.lbl1;
4723 /* Return the end label of a delta attribute. */
4725 static inline const char *
4726 AT_vms_delta2 (dw_attr_ref a)
4728 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4729 return a->dw_attr_val.v.val_vms_delta.lbl2;
4732 static inline const char *
4733 AT_lbl (dw_attr_ref a)
4735 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
4736 || AT_class (a) == dw_val_class_lineptr
4737 || AT_class (a) == dw_val_class_macptr));
4738 return a->dw_attr_val.v.val_lbl_id;
4741 /* Get the attribute of type attr_kind. */
4744 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4748 dw_die_ref spec = NULL;
4753 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
4754 if (a->dw_attr == attr_kind)
4756 else if (a->dw_attr == DW_AT_specification
4757 || a->dw_attr == DW_AT_abstract_origin)
4761 return get_AT (spec, attr_kind);
4766 /* Return the "low pc" attribute value, typically associated with a subprogram
4767 DIE. Return null if the "low pc" attribute is either not present, or if it
4768 cannot be represented as an assembler label identifier. */
4770 static inline const char *
4771 get_AT_low_pc (dw_die_ref die)
4773 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4775 return a ? AT_lbl (a) : NULL;
4778 /* Return the "high pc" attribute value, typically associated with a subprogram
4779 DIE. Return null if the "high pc" attribute is either not present, or if it
4780 cannot be represented as an assembler label identifier. */
4782 static inline const char *
4783 get_AT_hi_pc (dw_die_ref die)
4785 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4787 return a ? AT_lbl (a) : NULL;
4790 /* Return the value of the string attribute designated by ATTR_KIND, or
4791 NULL if it is not present. */
4793 static inline const char *
4794 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4796 dw_attr_ref a = get_AT (die, attr_kind);
4798 return a ? AT_string (a) : NULL;
4801 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4802 if it is not present. */
4805 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4807 dw_attr_ref a = get_AT (die, attr_kind);
4809 return a ? AT_flag (a) : 0;
4812 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4813 if it is not present. */
4815 static inline unsigned
4816 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4818 dw_attr_ref a = get_AT (die, attr_kind);
4820 return a ? AT_unsigned (a) : 0;
4823 static inline dw_die_ref
4824 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4826 dw_attr_ref a = get_AT (die, attr_kind);
4828 return a ? AT_ref (a) : NULL;
4831 static inline struct dwarf_file_data *
4832 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
4834 dw_attr_ref a = get_AT (die, attr_kind);
4836 return a ? AT_file (a) : NULL;
4839 /* Return TRUE if the language is C++. */
4844 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4846 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
4849 /* Return TRUE if the language is Fortran. */
4854 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4856 return (lang == DW_LANG_Fortran77
4857 || lang == DW_LANG_Fortran90
4858 || lang == DW_LANG_Fortran95);
4861 /* Return TRUE if the language is Ada. */
4866 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4868 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4871 /* Remove the specified attribute if present. */
4874 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4882 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
4883 if (a->dw_attr == attr_kind)
4885 if (AT_class (a) == dw_val_class_str)
4886 if (a->dw_attr_val.v.val_str->refcount)
4887 a->dw_attr_val.v.val_str->refcount--;
4889 /* VEC_ordered_remove should help reduce the number of abbrevs
4891 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
4896 /* Remove CHILD from its parent. PREV must have the property that
4897 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4900 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
4902 gcc_assert (child->die_parent == prev->die_parent);
4903 gcc_assert (prev->die_sib == child);
4906 gcc_assert (child->die_parent->die_child == child);
4910 prev->die_sib = child->die_sib;
4911 if (child->die_parent->die_child == child)
4912 child->die_parent->die_child = prev;
4915 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4916 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4919 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
4921 dw_die_ref parent = old_child->die_parent;
4923 gcc_assert (parent == prev->die_parent);
4924 gcc_assert (prev->die_sib == old_child);
4926 new_child->die_parent = parent;
4927 if (prev == old_child)
4929 gcc_assert (parent->die_child == old_child);
4930 new_child->die_sib = new_child;
4934 prev->die_sib = new_child;
4935 new_child->die_sib = old_child->die_sib;
4937 if (old_child->die_parent->die_child == old_child)
4938 old_child->die_parent->die_child = new_child;
4941 /* Move all children from OLD_PARENT to NEW_PARENT. */
4944 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
4947 new_parent->die_child = old_parent->die_child;
4948 old_parent->die_child = NULL;
4949 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
4952 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4956 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
4962 dw_die_ref prev = c;
4964 while (c->die_tag == tag)
4966 remove_child_with_prev (c, prev);
4967 /* Might have removed every child. */
4968 if (c == c->die_sib)
4972 } while (c != die->die_child);
4975 /* Add a CHILD_DIE as the last child of DIE. */
4978 add_child_die (dw_die_ref die, dw_die_ref child_die)
4980 /* FIXME this should probably be an assert. */
4981 if (! die || ! child_die)
4983 gcc_assert (die != child_die);
4985 child_die->die_parent = die;
4988 child_die->die_sib = die->die_child->die_sib;
4989 die->die_child->die_sib = child_die;
4992 child_die->die_sib = child_die;
4993 die->die_child = child_die;
4996 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4997 is the specification, to the end of PARENT's list of children.
4998 This is done by removing and re-adding it. */
5001 splice_child_die (dw_die_ref parent, dw_die_ref child)
5005 /* We want the declaration DIE from inside the class, not the
5006 specification DIE at toplevel. */
5007 if (child->die_parent != parent)
5009 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5015 gcc_assert (child->die_parent == parent
5016 || (child->die_parent
5017 == get_AT_ref (parent, DW_AT_specification)));
5019 for (p = child->die_parent->die_child; ; p = p->die_sib)
5020 if (p->die_sib == child)
5022 remove_child_with_prev (child, p);
5026 add_child_die (parent, child);
5029 /* Return a pointer to a newly created DIE node. */
5031 static inline dw_die_ref
5032 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5034 dw_die_ref die = ggc_alloc_cleared_die_node ();
5036 die->die_tag = tag_value;
5038 if (parent_die != NULL)
5039 add_child_die (parent_die, die);
5042 limbo_die_node *limbo_node;
5044 limbo_node = ggc_alloc_cleared_limbo_die_node ();
5045 limbo_node->die = die;
5046 limbo_node->created_for = t;
5047 limbo_node->next = limbo_die_list;
5048 limbo_die_list = limbo_node;
5054 /* Return the DIE associated with the given type specifier. */
5056 static inline dw_die_ref
5057 lookup_type_die (tree type)
5059 return TYPE_SYMTAB_DIE (type);
5062 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5063 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5064 anonymous type instead the one of the naming typedef. */
5066 static inline dw_die_ref
5067 strip_naming_typedef (tree type, dw_die_ref type_die)
5070 && TREE_CODE (type) == RECORD_TYPE
5072 && type_die->die_tag == DW_TAG_typedef
5073 && is_naming_typedef_decl (TYPE_NAME (type)))
5074 type_die = get_AT_ref (type_die, DW_AT_type);
5078 /* Like lookup_type_die, but if type is an anonymous type named by a
5079 typedef[1], return the DIE of the anonymous type instead the one of
5080 the naming typedef. This is because in gen_typedef_die, we did
5081 equate the anonymous struct named by the typedef with the DIE of
5082 the naming typedef. So by default, lookup_type_die on an anonymous
5083 struct yields the DIE of the naming typedef.
5085 [1]: Read the comment of is_naming_typedef_decl to learn about what
5086 a naming typedef is. */
5088 static inline dw_die_ref
5089 lookup_type_die_strip_naming_typedef (tree type)
5091 dw_die_ref die = lookup_type_die (type);
5092 return strip_naming_typedef (type, die);
5095 /* Equate a DIE to a given type specifier. */
5098 equate_type_number_to_die (tree type, dw_die_ref type_die)
5100 TYPE_SYMTAB_DIE (type) = type_die;
5103 /* Returns a hash value for X (which really is a die_struct). */
5106 decl_die_table_hash (const void *x)
5108 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5111 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5114 decl_die_table_eq (const void *x, const void *y)
5116 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5119 /* Return the DIE associated with a given declaration. */
5121 static inline dw_die_ref
5122 lookup_decl_die (tree decl)
5124 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5127 /* Returns a hash value for X (which really is a var_loc_list). */
5130 decl_loc_table_hash (const void *x)
5132 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5135 /* Return nonzero if decl_id of var_loc_list X is the same as
5139 decl_loc_table_eq (const void *x, const void *y)
5141 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5144 /* Return the var_loc list associated with a given declaration. */
5146 static inline var_loc_list *
5147 lookup_decl_loc (const_tree decl)
5149 if (!decl_loc_table)
5151 return (var_loc_list *)
5152 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5155 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5158 cached_dw_loc_list_table_hash (const void *x)
5160 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
5163 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5167 cached_dw_loc_list_table_eq (const void *x, const void *y)
5169 return (((const cached_dw_loc_list *) x)->decl_id
5170 == DECL_UID ((const_tree) y));
5173 /* Equate a DIE to a particular declaration. */
5176 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5178 unsigned int decl_id = DECL_UID (decl);
5181 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5183 decl_die->decl_id = decl_id;
5186 /* Return how many bits covers PIECE EXPR_LIST. */
5189 decl_piece_bitsize (rtx piece)
5191 int ret = (int) GET_MODE (piece);
5194 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
5195 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
5196 return INTVAL (XEXP (XEXP (piece, 0), 0));
5199 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5202 decl_piece_varloc_ptr (rtx piece)
5204 if ((int) GET_MODE (piece))
5205 return &XEXP (piece, 0);
5207 return &XEXP (XEXP (piece, 0), 1);
5210 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5211 Next is the chain of following piece nodes. */
5214 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
5216 if (bitsize <= (int) MAX_MACHINE_MODE)
5217 return alloc_EXPR_LIST (bitsize, loc_note, next);
5219 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
5224 /* Return rtx that should be stored into loc field for
5225 LOC_NOTE and BITPOS/BITSIZE. */
5228 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
5229 HOST_WIDE_INT bitsize)
5233 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
5235 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
5240 /* This function either modifies location piece list *DEST in
5241 place (if SRC and INNER is NULL), or copies location piece list
5242 *SRC to *DEST while modifying it. Location BITPOS is modified
5243 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5244 not copied and if needed some padding around it is added.
5245 When modifying in place, DEST should point to EXPR_LIST where
5246 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5247 to the start of the whole list and INNER points to the EXPR_LIST
5248 where earlier pieces cover PIECE_BITPOS bits. */
5251 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
5252 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
5253 HOST_WIDE_INT bitsize, rtx loc_note)
5256 bool copy = inner != NULL;
5260 /* First copy all nodes preceeding the current bitpos. */
5261 while (src != inner)
5263 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5264 decl_piece_bitsize (*src), NULL_RTX);
5265 dest = &XEXP (*dest, 1);
5266 src = &XEXP (*src, 1);
5269 /* Add padding if needed. */
5270 if (bitpos != piece_bitpos)
5272 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
5273 copy ? NULL_RTX : *dest);
5274 dest = &XEXP (*dest, 1);
5276 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
5279 /* A piece with correct bitpos and bitsize already exist,
5280 just update the location for it and return. */
5281 *decl_piece_varloc_ptr (*dest) = loc_note;
5284 /* Add the piece that changed. */
5285 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
5286 dest = &XEXP (*dest, 1);
5287 /* Skip over pieces that overlap it. */
5288 diff = bitpos - piece_bitpos + bitsize;
5291 while (diff > 0 && *src)
5294 diff -= decl_piece_bitsize (piece);
5296 src = &XEXP (piece, 1);
5299 *src = XEXP (piece, 1);
5300 free_EXPR_LIST_node (piece);
5303 /* Add padding if needed. */
5304 if (diff < 0 && *src)
5308 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
5309 dest = &XEXP (*dest, 1);
5313 /* Finally copy all nodes following it. */
5316 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5317 decl_piece_bitsize (*src), NULL_RTX);
5318 dest = &XEXP (*dest, 1);
5319 src = &XEXP (*src, 1);
5323 /* Add a variable location node to the linked list for DECL. */
5325 static struct var_loc_node *
5326 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
5328 unsigned int decl_id;
5331 struct var_loc_node *loc = NULL;
5332 HOST_WIDE_INT bitsize = -1, bitpos = -1;
5334 if (DECL_DEBUG_EXPR_IS_FROM (decl))
5336 tree realdecl = DECL_DEBUG_EXPR (decl);
5337 if (realdecl && handled_component_p (realdecl))
5339 HOST_WIDE_INT maxsize;
5342 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
5343 if (!DECL_P (innerdecl)
5344 || DECL_IGNORED_P (innerdecl)
5345 || TREE_STATIC (innerdecl)
5347 || bitpos + bitsize > 256
5348 || bitsize != maxsize)
5354 decl_id = DECL_UID (decl);
5355 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5358 temp = ggc_alloc_cleared_var_loc_list ();
5359 temp->decl_id = decl_id;
5363 temp = (var_loc_list *) *slot;
5365 /* For PARM_DECLs try to keep around the original incoming value,
5366 even if that means we'll emit a zero-range .debug_loc entry. */
5368 && temp->first == temp->last
5369 && TREE_CODE (decl) == PARM_DECL
5370 && GET_CODE (temp->first->loc) == NOTE
5371 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
5372 && DECL_INCOMING_RTL (decl)
5373 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
5374 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
5375 == GET_CODE (DECL_INCOMING_RTL (decl))
5376 && prev_real_insn (temp->first->loc) == NULL_RTX
5378 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
5379 NOTE_VAR_LOCATION_LOC (loc_note))
5380 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
5381 != NOTE_VAR_LOCATION_STATUS (loc_note))))
5383 loc = ggc_alloc_cleared_var_loc_node ();
5384 temp->first->next = loc;
5386 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5388 else if (temp->last)
5390 struct var_loc_node *last = temp->last, *unused = NULL;
5391 rtx *piece_loc = NULL, last_loc_note;
5392 int piece_bitpos = 0;
5396 gcc_assert (last->next == NULL);
5398 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
5400 piece_loc = &last->loc;
5403 int cur_bitsize = decl_piece_bitsize (*piece_loc);
5404 if (piece_bitpos + cur_bitsize > bitpos)
5406 piece_bitpos += cur_bitsize;
5407 piece_loc = &XEXP (*piece_loc, 1);
5411 /* TEMP->LAST here is either pointer to the last but one or
5412 last element in the chained list, LAST is pointer to the
5414 if (label && strcmp (last->label, label) == 0)
5416 /* For SRA optimized variables if there weren't any real
5417 insns since last note, just modify the last node. */
5418 if (piece_loc != NULL)
5420 adjust_piece_list (piece_loc, NULL, NULL,
5421 bitpos, piece_bitpos, bitsize, loc_note);
5424 /* If the last note doesn't cover any instructions, remove it. */
5425 if (temp->last != last)
5427 temp->last->next = NULL;
5430 gcc_assert (strcmp (last->label, label) != 0);
5434 gcc_assert (temp->first == temp->last
5435 || (temp->first->next == temp->last
5436 && TREE_CODE (decl) == PARM_DECL));
5437 memset (temp->last, '\0', sizeof (*temp->last));
5438 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
5442 if (bitsize == -1 && NOTE_P (last->loc))
5443 last_loc_note = last->loc;
5444 else if (piece_loc != NULL
5445 && *piece_loc != NULL_RTX
5446 && piece_bitpos == bitpos
5447 && decl_piece_bitsize (*piece_loc) == bitsize)
5448 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
5450 last_loc_note = NULL_RTX;
5451 /* If the current location is the same as the end of the list,
5452 and either both or neither of the locations is uninitialized,
5453 we have nothing to do. */
5454 if (last_loc_note == NULL_RTX
5455 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
5456 NOTE_VAR_LOCATION_LOC (loc_note)))
5457 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5458 != NOTE_VAR_LOCATION_STATUS (loc_note))
5459 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5460 == VAR_INIT_STATUS_UNINITIALIZED)
5461 || (NOTE_VAR_LOCATION_STATUS (loc_note)
5462 == VAR_INIT_STATUS_UNINITIALIZED))))
5464 /* Add LOC to the end of list and update LAST. If the last
5465 element of the list has been removed above, reuse its
5466 memory for the new node, otherwise allocate a new one. */
5470 memset (loc, '\0', sizeof (*loc));
5473 loc = ggc_alloc_cleared_var_loc_node ();
5474 if (bitsize == -1 || piece_loc == NULL)
5475 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5477 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
5478 bitpos, piece_bitpos, bitsize, loc_note);
5480 /* Ensure TEMP->LAST will point either to the new last but one
5481 element of the chain, or to the last element in it. */
5482 if (last != temp->last)
5490 loc = ggc_alloc_cleared_var_loc_node ();
5493 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5498 /* Keep track of the number of spaces used to indent the
5499 output of the debugging routines that print the structure of
5500 the DIE internal representation. */
5501 static int print_indent;
5503 /* Indent the line the number of spaces given by print_indent. */
5506 print_spaces (FILE *outfile)
5508 fprintf (outfile, "%*s", print_indent, "");
5511 /* Print a type signature in hex. */
5514 print_signature (FILE *outfile, char *sig)
5518 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
5519 fprintf (outfile, "%02x", sig[i] & 0xff);
5522 /* Print the information associated with a given DIE, and its children.
5523 This routine is a debugging aid only. */
5526 print_die (dw_die_ref die, FILE *outfile)
5532 print_spaces (outfile);
5533 fprintf (outfile, "DIE %4ld: %s (%p)\n",
5534 die->die_offset, dwarf_tag_name (die->die_tag),
5536 print_spaces (outfile);
5537 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5538 fprintf (outfile, " offset: %ld", die->die_offset);
5539 fprintf (outfile, " mark: %d\n", die->die_mark);
5541 if (use_debug_types && die->die_id.die_type_node)
5543 print_spaces (outfile);
5544 fprintf (outfile, " signature: ");
5545 print_signature (outfile, die->die_id.die_type_node->signature);
5546 fprintf (outfile, "\n");
5549 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5551 print_spaces (outfile);
5552 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5554 switch (AT_class (a))
5556 case dw_val_class_addr:
5557 fprintf (outfile, "address");
5559 case dw_val_class_offset:
5560 fprintf (outfile, "offset");
5562 case dw_val_class_loc:
5563 fprintf (outfile, "location descriptor");
5565 case dw_val_class_loc_list:
5566 fprintf (outfile, "location list -> label:%s",
5567 AT_loc_list (a)->ll_symbol);
5569 case dw_val_class_range_list:
5570 fprintf (outfile, "range list");
5572 case dw_val_class_const:
5573 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5575 case dw_val_class_unsigned_const:
5576 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5578 case dw_val_class_const_double:
5579 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
5580 HOST_WIDE_INT_PRINT_UNSIGNED")",
5581 a->dw_attr_val.v.val_double.high,
5582 a->dw_attr_val.v.val_double.low);
5584 case dw_val_class_vec:
5585 fprintf (outfile, "floating-point or vector constant");
5587 case dw_val_class_flag:
5588 fprintf (outfile, "%u", AT_flag (a));
5590 case dw_val_class_die_ref:
5591 if (AT_ref (a) != NULL)
5593 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
5595 fprintf (outfile, "die -> signature: ");
5596 print_signature (outfile,
5597 AT_ref (a)->die_id.die_type_node->signature);
5599 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
5600 fprintf (outfile, "die -> label: %s",
5601 AT_ref (a)->die_id.die_symbol);
5603 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5604 fprintf (outfile, " (%p)", (void *) AT_ref (a));
5607 fprintf (outfile, "die -> <null>");
5609 case dw_val_class_vms_delta:
5610 fprintf (outfile, "delta: @slotcount(%s-%s)",
5611 AT_vms_delta2 (a), AT_vms_delta1 (a));
5613 case dw_val_class_lbl_id:
5614 case dw_val_class_lineptr:
5615 case dw_val_class_macptr:
5616 fprintf (outfile, "label: %s", AT_lbl (a));
5618 case dw_val_class_str:
5619 if (AT_string (a) != NULL)
5620 fprintf (outfile, "\"%s\"", AT_string (a));
5622 fprintf (outfile, "<null>");
5624 case dw_val_class_file:
5625 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
5626 AT_file (a)->emitted_number);
5628 case dw_val_class_data8:
5632 for (i = 0; i < 8; i++)
5633 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
5640 fprintf (outfile, "\n");
5643 if (die->die_child != NULL)
5646 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5649 if (print_indent == 0)
5650 fprintf (outfile, "\n");
5653 /* Print the information collected for a given DIE. */
5656 debug_dwarf_die (dw_die_ref die)
5658 print_die (die, stderr);
5661 /* Print all DWARF information collected for the compilation unit.
5662 This routine is a debugging aid only. */
5668 print_die (comp_unit_die (), stderr);
5671 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5672 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5673 DIE that marks the start of the DIEs for this include file. */
5676 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5678 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5679 dw_die_ref new_unit = gen_compile_unit_die (filename);
5681 new_unit->die_sib = old_unit;
5685 /* Close an include-file CU and reopen the enclosing one. */
5688 pop_compile_unit (dw_die_ref old_unit)
5690 dw_die_ref new_unit = old_unit->die_sib;
5692 old_unit->die_sib = NULL;
5696 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5697 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5699 /* Calculate the checksum of a location expression. */
5702 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5706 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
5708 CHECKSUM (loc->dw_loc_oprnd1);
5709 CHECKSUM (loc->dw_loc_oprnd2);
5712 /* Calculate the checksum of an attribute. */
5715 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5717 dw_loc_descr_ref loc;
5720 CHECKSUM (at->dw_attr);
5722 /* We don't care that this was compiled with a different compiler
5723 snapshot; if the output is the same, that's what matters. */
5724 if (at->dw_attr == DW_AT_producer)
5727 switch (AT_class (at))
5729 case dw_val_class_const:
5730 CHECKSUM (at->dw_attr_val.v.val_int);
5732 case dw_val_class_unsigned_const:
5733 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5735 case dw_val_class_const_double:
5736 CHECKSUM (at->dw_attr_val.v.val_double);
5738 case dw_val_class_vec:
5739 CHECKSUM (at->dw_attr_val.v.val_vec);
5741 case dw_val_class_flag:
5742 CHECKSUM (at->dw_attr_val.v.val_flag);
5744 case dw_val_class_str:
5745 CHECKSUM_STRING (AT_string (at));
5748 case dw_val_class_addr:
5750 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5751 CHECKSUM_STRING (XSTR (r, 0));
5754 case dw_val_class_offset:
5755 CHECKSUM (at->dw_attr_val.v.val_offset);
5758 case dw_val_class_loc:
5759 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5760 loc_checksum (loc, ctx);
5763 case dw_val_class_die_ref:
5764 die_checksum (AT_ref (at), ctx, mark);
5767 case dw_val_class_fde_ref:
5768 case dw_val_class_vms_delta:
5769 case dw_val_class_lbl_id:
5770 case dw_val_class_lineptr:
5771 case dw_val_class_macptr:
5774 case dw_val_class_file:
5775 CHECKSUM_STRING (AT_file (at)->filename);
5778 case dw_val_class_data8:
5779 CHECKSUM (at->dw_attr_val.v.val_data8);
5787 /* Calculate the checksum of a DIE. */
5790 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5796 /* To avoid infinite recursion. */
5799 CHECKSUM (die->die_mark);
5802 die->die_mark = ++(*mark);
5804 CHECKSUM (die->die_tag);
5806 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5807 attr_checksum (a, ctx, mark);
5809 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
5813 #undef CHECKSUM_STRING
5815 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5816 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5817 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5818 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5819 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5820 #define CHECKSUM_ATTR(FOO) \
5821 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5823 /* Calculate the checksum of a number in signed LEB128 format. */
5826 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
5833 byte = (value & 0x7f);
5835 more = !((value == 0 && (byte & 0x40) == 0)
5836 || (value == -1 && (byte & 0x40) != 0));
5845 /* Calculate the checksum of a number in unsigned LEB128 format. */
5848 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
5852 unsigned char byte = (value & 0x7f);
5855 /* More bytes to follow. */
5863 /* Checksum the context of the DIE. This adds the names of any
5864 surrounding namespaces or structures to the checksum. */
5867 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
5871 int tag = die->die_tag;
5873 if (tag != DW_TAG_namespace
5874 && tag != DW_TAG_structure_type
5875 && tag != DW_TAG_class_type)
5878 name = get_AT_string (die, DW_AT_name);
5880 spec = get_AT_ref (die, DW_AT_specification);
5884 if (die->die_parent != NULL)
5885 checksum_die_context (die->die_parent, ctx);
5887 CHECKSUM_ULEB128 ('C');
5888 CHECKSUM_ULEB128 (tag);
5890 CHECKSUM_STRING (name);
5893 /* Calculate the checksum of a location expression. */
5896 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5898 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5899 were emitted as a DW_FORM_sdata instead of a location expression. */
5900 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
5902 CHECKSUM_ULEB128 (DW_FORM_sdata);
5903 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
5907 /* Otherwise, just checksum the raw location expression. */
5910 CHECKSUM_ULEB128 (loc->dw_loc_opc);
5911 CHECKSUM (loc->dw_loc_oprnd1);
5912 CHECKSUM (loc->dw_loc_oprnd2);
5913 loc = loc->dw_loc_next;
5917 /* Calculate the checksum of an attribute. */
5920 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
5921 struct md5_ctx *ctx, int *mark)
5923 dw_loc_descr_ref loc;
5926 if (AT_class (at) == dw_val_class_die_ref)
5928 dw_die_ref target_die = AT_ref (at);
5930 /* For pointer and reference types, we checksum only the (qualified)
5931 name of the target type (if there is a name). For friend entries,
5932 we checksum only the (qualified) name of the target type or function.
5933 This allows the checksum to remain the same whether the target type
5934 is complete or not. */
5935 if ((at->dw_attr == DW_AT_type
5936 && (tag == DW_TAG_pointer_type
5937 || tag == DW_TAG_reference_type
5938 || tag == DW_TAG_rvalue_reference_type
5939 || tag == DW_TAG_ptr_to_member_type))
5940 || (at->dw_attr == DW_AT_friend
5941 && tag == DW_TAG_friend))
5943 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
5945 if (name_attr != NULL)
5947 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
5951 CHECKSUM_ULEB128 ('N');
5952 CHECKSUM_ULEB128 (at->dw_attr);
5953 if (decl->die_parent != NULL)
5954 checksum_die_context (decl->die_parent, ctx);
5955 CHECKSUM_ULEB128 ('E');
5956 CHECKSUM_STRING (AT_string (name_attr));
5961 /* For all other references to another DIE, we check to see if the
5962 target DIE has already been visited. If it has, we emit a
5963 backward reference; if not, we descend recursively. */
5964 if (target_die->die_mark > 0)
5966 CHECKSUM_ULEB128 ('R');
5967 CHECKSUM_ULEB128 (at->dw_attr);
5968 CHECKSUM_ULEB128 (target_die->die_mark);
5972 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
5976 target_die->die_mark = ++(*mark);
5977 CHECKSUM_ULEB128 ('T');
5978 CHECKSUM_ULEB128 (at->dw_attr);
5979 if (decl->die_parent != NULL)
5980 checksum_die_context (decl->die_parent, ctx);
5981 die_checksum_ordered (target_die, ctx, mark);
5986 CHECKSUM_ULEB128 ('A');
5987 CHECKSUM_ULEB128 (at->dw_attr);
5989 switch (AT_class (at))
5991 case dw_val_class_const:
5992 CHECKSUM_ULEB128 (DW_FORM_sdata);
5993 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
5996 case dw_val_class_unsigned_const:
5997 CHECKSUM_ULEB128 (DW_FORM_sdata);
5998 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
6001 case dw_val_class_const_double:
6002 CHECKSUM_ULEB128 (DW_FORM_block);
6003 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
6004 CHECKSUM (at->dw_attr_val.v.val_double);
6007 case dw_val_class_vec:
6008 CHECKSUM_ULEB128 (DW_FORM_block);
6009 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
6010 CHECKSUM (at->dw_attr_val.v.val_vec);
6013 case dw_val_class_flag:
6014 CHECKSUM_ULEB128 (DW_FORM_flag);
6015 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
6018 case dw_val_class_str:
6019 CHECKSUM_ULEB128 (DW_FORM_string);
6020 CHECKSUM_STRING (AT_string (at));
6023 case dw_val_class_addr:
6025 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6026 CHECKSUM_ULEB128 (DW_FORM_string);
6027 CHECKSUM_STRING (XSTR (r, 0));
6030 case dw_val_class_offset:
6031 CHECKSUM_ULEB128 (DW_FORM_sdata);
6032 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
6035 case dw_val_class_loc:
6036 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6037 loc_checksum_ordered (loc, ctx);
6040 case dw_val_class_fde_ref:
6041 case dw_val_class_lbl_id:
6042 case dw_val_class_lineptr:
6043 case dw_val_class_macptr:
6046 case dw_val_class_file:
6047 CHECKSUM_ULEB128 (DW_FORM_string);
6048 CHECKSUM_STRING (AT_file (at)->filename);
6051 case dw_val_class_data8:
6052 CHECKSUM (at->dw_attr_val.v.val_data8);
6060 struct checksum_attributes
6062 dw_attr_ref at_name;
6063 dw_attr_ref at_type;
6064 dw_attr_ref at_friend;
6065 dw_attr_ref at_accessibility;
6066 dw_attr_ref at_address_class;
6067 dw_attr_ref at_allocated;
6068 dw_attr_ref at_artificial;
6069 dw_attr_ref at_associated;
6070 dw_attr_ref at_binary_scale;
6071 dw_attr_ref at_bit_offset;
6072 dw_attr_ref at_bit_size;
6073 dw_attr_ref at_bit_stride;
6074 dw_attr_ref at_byte_size;
6075 dw_attr_ref at_byte_stride;
6076 dw_attr_ref at_const_value;
6077 dw_attr_ref at_containing_type;
6078 dw_attr_ref at_count;
6079 dw_attr_ref at_data_location;
6080 dw_attr_ref at_data_member_location;
6081 dw_attr_ref at_decimal_scale;
6082 dw_attr_ref at_decimal_sign;
6083 dw_attr_ref at_default_value;
6084 dw_attr_ref at_digit_count;
6085 dw_attr_ref at_discr;
6086 dw_attr_ref at_discr_list;
6087 dw_attr_ref at_discr_value;
6088 dw_attr_ref at_encoding;
6089 dw_attr_ref at_endianity;
6090 dw_attr_ref at_explicit;
6091 dw_attr_ref at_is_optional;
6092 dw_attr_ref at_location;
6093 dw_attr_ref at_lower_bound;
6094 dw_attr_ref at_mutable;
6095 dw_attr_ref at_ordering;
6096 dw_attr_ref at_picture_string;
6097 dw_attr_ref at_prototyped;
6098 dw_attr_ref at_small;
6099 dw_attr_ref at_segment;
6100 dw_attr_ref at_string_length;
6101 dw_attr_ref at_threads_scaled;
6102 dw_attr_ref at_upper_bound;
6103 dw_attr_ref at_use_location;
6104 dw_attr_ref at_use_UTF8;
6105 dw_attr_ref at_variable_parameter;
6106 dw_attr_ref at_virtuality;
6107 dw_attr_ref at_visibility;
6108 dw_attr_ref at_vtable_elem_location;
6111 /* Collect the attributes that we will want to use for the checksum. */
6114 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
6119 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6130 attrs->at_friend = a;
6132 case DW_AT_accessibility:
6133 attrs->at_accessibility = a;
6135 case DW_AT_address_class:
6136 attrs->at_address_class = a;
6138 case DW_AT_allocated:
6139 attrs->at_allocated = a;
6141 case DW_AT_artificial:
6142 attrs->at_artificial = a;
6144 case DW_AT_associated:
6145 attrs->at_associated = a;
6147 case DW_AT_binary_scale:
6148 attrs->at_binary_scale = a;
6150 case DW_AT_bit_offset:
6151 attrs->at_bit_offset = a;
6153 case DW_AT_bit_size:
6154 attrs->at_bit_size = a;
6156 case DW_AT_bit_stride:
6157 attrs->at_bit_stride = a;
6159 case DW_AT_byte_size:
6160 attrs->at_byte_size = a;
6162 case DW_AT_byte_stride:
6163 attrs->at_byte_stride = a;
6165 case DW_AT_const_value:
6166 attrs->at_const_value = a;
6168 case DW_AT_containing_type:
6169 attrs->at_containing_type = a;
6172 attrs->at_count = a;
6174 case DW_AT_data_location:
6175 attrs->at_data_location = a;
6177 case DW_AT_data_member_location:
6178 attrs->at_data_member_location = a;
6180 case DW_AT_decimal_scale:
6181 attrs->at_decimal_scale = a;
6183 case DW_AT_decimal_sign:
6184 attrs->at_decimal_sign = a;
6186 case DW_AT_default_value:
6187 attrs->at_default_value = a;
6189 case DW_AT_digit_count:
6190 attrs->at_digit_count = a;
6193 attrs->at_discr = a;
6195 case DW_AT_discr_list:
6196 attrs->at_discr_list = a;
6198 case DW_AT_discr_value:
6199 attrs->at_discr_value = a;
6201 case DW_AT_encoding:
6202 attrs->at_encoding = a;
6204 case DW_AT_endianity:
6205 attrs->at_endianity = a;
6207 case DW_AT_explicit:
6208 attrs->at_explicit = a;
6210 case DW_AT_is_optional:
6211 attrs->at_is_optional = a;
6213 case DW_AT_location:
6214 attrs->at_location = a;
6216 case DW_AT_lower_bound:
6217 attrs->at_lower_bound = a;
6220 attrs->at_mutable = a;
6222 case DW_AT_ordering:
6223 attrs->at_ordering = a;
6225 case DW_AT_picture_string:
6226 attrs->at_picture_string = a;
6228 case DW_AT_prototyped:
6229 attrs->at_prototyped = a;
6232 attrs->at_small = a;
6235 attrs->at_segment = a;
6237 case DW_AT_string_length:
6238 attrs->at_string_length = a;
6240 case DW_AT_threads_scaled:
6241 attrs->at_threads_scaled = a;
6243 case DW_AT_upper_bound:
6244 attrs->at_upper_bound = a;
6246 case DW_AT_use_location:
6247 attrs->at_use_location = a;
6249 case DW_AT_use_UTF8:
6250 attrs->at_use_UTF8 = a;
6252 case DW_AT_variable_parameter:
6253 attrs->at_variable_parameter = a;
6255 case DW_AT_virtuality:
6256 attrs->at_virtuality = a;
6258 case DW_AT_visibility:
6259 attrs->at_visibility = a;
6261 case DW_AT_vtable_elem_location:
6262 attrs->at_vtable_elem_location = a;
6270 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6273 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6277 struct checksum_attributes attrs;
6279 CHECKSUM_ULEB128 ('D');
6280 CHECKSUM_ULEB128 (die->die_tag);
6282 memset (&attrs, 0, sizeof (attrs));
6284 decl = get_AT_ref (die, DW_AT_specification);
6286 collect_checksum_attributes (&attrs, decl);
6287 collect_checksum_attributes (&attrs, die);
6289 CHECKSUM_ATTR (attrs.at_name);
6290 CHECKSUM_ATTR (attrs.at_accessibility);
6291 CHECKSUM_ATTR (attrs.at_address_class);
6292 CHECKSUM_ATTR (attrs.at_allocated);
6293 CHECKSUM_ATTR (attrs.at_artificial);
6294 CHECKSUM_ATTR (attrs.at_associated);
6295 CHECKSUM_ATTR (attrs.at_binary_scale);
6296 CHECKSUM_ATTR (attrs.at_bit_offset);
6297 CHECKSUM_ATTR (attrs.at_bit_size);
6298 CHECKSUM_ATTR (attrs.at_bit_stride);
6299 CHECKSUM_ATTR (attrs.at_byte_size);
6300 CHECKSUM_ATTR (attrs.at_byte_stride);
6301 CHECKSUM_ATTR (attrs.at_const_value);
6302 CHECKSUM_ATTR (attrs.at_containing_type);
6303 CHECKSUM_ATTR (attrs.at_count);
6304 CHECKSUM_ATTR (attrs.at_data_location);
6305 CHECKSUM_ATTR (attrs.at_data_member_location);
6306 CHECKSUM_ATTR (attrs.at_decimal_scale);
6307 CHECKSUM_ATTR (attrs.at_decimal_sign);
6308 CHECKSUM_ATTR (attrs.at_default_value);
6309 CHECKSUM_ATTR (attrs.at_digit_count);
6310 CHECKSUM_ATTR (attrs.at_discr);
6311 CHECKSUM_ATTR (attrs.at_discr_list);
6312 CHECKSUM_ATTR (attrs.at_discr_value);
6313 CHECKSUM_ATTR (attrs.at_encoding);
6314 CHECKSUM_ATTR (attrs.at_endianity);
6315 CHECKSUM_ATTR (attrs.at_explicit);
6316 CHECKSUM_ATTR (attrs.at_is_optional);
6317 CHECKSUM_ATTR (attrs.at_location);
6318 CHECKSUM_ATTR (attrs.at_lower_bound);
6319 CHECKSUM_ATTR (attrs.at_mutable);
6320 CHECKSUM_ATTR (attrs.at_ordering);
6321 CHECKSUM_ATTR (attrs.at_picture_string);
6322 CHECKSUM_ATTR (attrs.at_prototyped);
6323 CHECKSUM_ATTR (attrs.at_small);
6324 CHECKSUM_ATTR (attrs.at_segment);
6325 CHECKSUM_ATTR (attrs.at_string_length);
6326 CHECKSUM_ATTR (attrs.at_threads_scaled);
6327 CHECKSUM_ATTR (attrs.at_upper_bound);
6328 CHECKSUM_ATTR (attrs.at_use_location);
6329 CHECKSUM_ATTR (attrs.at_use_UTF8);
6330 CHECKSUM_ATTR (attrs.at_variable_parameter);
6331 CHECKSUM_ATTR (attrs.at_virtuality);
6332 CHECKSUM_ATTR (attrs.at_visibility);
6333 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
6334 CHECKSUM_ATTR (attrs.at_type);
6335 CHECKSUM_ATTR (attrs.at_friend);
6337 /* Checksum the child DIEs, except for nested types and member functions. */
6340 dw_attr_ref name_attr;
6343 name_attr = get_AT (c, DW_AT_name);
6344 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
6345 && name_attr != NULL)
6347 CHECKSUM_ULEB128 ('S');
6348 CHECKSUM_ULEB128 (c->die_tag);
6349 CHECKSUM_STRING (AT_string (name_attr));
6353 /* Mark this DIE so it gets processed when unmarking. */
6354 if (c->die_mark == 0)
6356 die_checksum_ordered (c, ctx, mark);
6358 } while (c != die->die_child);
6360 CHECKSUM_ULEB128 (0);
6364 #undef CHECKSUM_STRING
6365 #undef CHECKSUM_ATTR
6366 #undef CHECKSUM_LEB128
6367 #undef CHECKSUM_ULEB128
6369 /* Generate the type signature for DIE. This is computed by generating an
6370 MD5 checksum over the DIE's tag, its relevant attributes, and its
6371 children. Attributes that are references to other DIEs are processed
6372 by recursion, using the MARK field to prevent infinite recursion.
6373 If the DIE is nested inside a namespace or another type, we also
6374 need to include that context in the signature. The lower 64 bits
6375 of the resulting MD5 checksum comprise the signature. */
6378 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
6382 unsigned char checksum[16];
6386 name = get_AT_string (die, DW_AT_name);
6387 decl = get_AT_ref (die, DW_AT_specification);
6389 /* First, compute a signature for just the type name (and its surrounding
6390 context, if any. This is stored in the type unit DIE for link-time
6391 ODR (one-definition rule) checking. */
6393 if (is_cxx() && name != NULL)
6395 md5_init_ctx (&ctx);
6397 /* Checksum the names of surrounding namespaces and structures. */
6398 if (decl != NULL && decl->die_parent != NULL)
6399 checksum_die_context (decl->die_parent, &ctx);
6401 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
6402 md5_process_bytes (name, strlen (name) + 1, &ctx);
6403 md5_finish_ctx (&ctx, checksum);
6405 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
6408 /* Next, compute the complete type signature. */
6410 md5_init_ctx (&ctx);
6412 die->die_mark = mark;
6414 /* Checksum the names of surrounding namespaces and structures. */
6415 if (decl != NULL && decl->die_parent != NULL)
6416 checksum_die_context (decl->die_parent, &ctx);
6418 /* Checksum the DIE and its children. */
6419 die_checksum_ordered (die, &ctx, &mark);
6420 unmark_all_dies (die);
6421 md5_finish_ctx (&ctx, checksum);
6423 /* Store the signature in the type node and link the type DIE and the
6424 type node together. */
6425 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
6426 DWARF_TYPE_SIGNATURE_SIZE);
6427 die->die_id.die_type_node = type_node;
6428 type_node->type_die = die;
6430 /* If the DIE is a specification, link its declaration to the type node
6433 decl->die_id.die_type_node = type_node;
6436 /* Do the location expressions look same? */
6438 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6440 return loc1->dw_loc_opc == loc2->dw_loc_opc
6441 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6442 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6445 /* Do the values look the same? */
6447 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6449 dw_loc_descr_ref loc1, loc2;
6452 if (v1->val_class != v2->val_class)
6455 switch (v1->val_class)
6457 case dw_val_class_const:
6458 return v1->v.val_int == v2->v.val_int;
6459 case dw_val_class_unsigned_const:
6460 return v1->v.val_unsigned == v2->v.val_unsigned;
6461 case dw_val_class_const_double:
6462 return v1->v.val_double.high == v2->v.val_double.high
6463 && v1->v.val_double.low == v2->v.val_double.low;
6464 case dw_val_class_vec:
6465 if (v1->v.val_vec.length != v2->v.val_vec.length
6466 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6468 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6469 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6472 case dw_val_class_flag:
6473 return v1->v.val_flag == v2->v.val_flag;
6474 case dw_val_class_str:
6475 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6477 case dw_val_class_addr:
6478 r1 = v1->v.val_addr;
6479 r2 = v2->v.val_addr;
6480 if (GET_CODE (r1) != GET_CODE (r2))
6482 return !rtx_equal_p (r1, r2);
6484 case dw_val_class_offset:
6485 return v1->v.val_offset == v2->v.val_offset;
6487 case dw_val_class_loc:
6488 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6490 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6491 if (!same_loc_p (loc1, loc2, mark))
6493 return !loc1 && !loc2;
6495 case dw_val_class_die_ref:
6496 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6498 case dw_val_class_fde_ref:
6499 case dw_val_class_vms_delta:
6500 case dw_val_class_lbl_id:
6501 case dw_val_class_lineptr:
6502 case dw_val_class_macptr:
6505 case dw_val_class_file:
6506 return v1->v.val_file == v2->v.val_file;
6508 case dw_val_class_data8:
6509 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
6516 /* Do the attributes look the same? */
6519 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6521 if (at1->dw_attr != at2->dw_attr)
6524 /* We don't care that this was compiled with a different compiler
6525 snapshot; if the output is the same, that's what matters. */
6526 if (at1->dw_attr == DW_AT_producer)
6529 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6532 /* Do the dies look the same? */
6535 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6541 /* To avoid infinite recursion. */
6543 return die1->die_mark == die2->die_mark;
6544 die1->die_mark = die2->die_mark = ++(*mark);
6546 if (die1->die_tag != die2->die_tag)
6549 if (VEC_length (dw_attr_node, die1->die_attr)
6550 != VEC_length (dw_attr_node, die2->die_attr))
6553 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
6554 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6557 c1 = die1->die_child;
6558 c2 = die2->die_child;
6567 if (!same_die_p (c1, c2, mark))
6571 if (c1 == die1->die_child)
6573 if (c2 == die2->die_child)
6583 /* Do the dies look the same? Wrapper around same_die_p. */
6586 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6589 int ret = same_die_p (die1, die2, &mark);
6591 unmark_all_dies (die1);
6592 unmark_all_dies (die2);
6597 /* The prefix to attach to symbols on DIEs in the current comdat debug
6599 static char *comdat_symbol_id;
6601 /* The index of the current symbol within the current comdat CU. */
6602 static unsigned int comdat_symbol_number;
6604 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6605 children, and set comdat_symbol_id accordingly. */
6608 compute_section_prefix (dw_die_ref unit_die)
6610 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6611 const char *base = die_name ? lbasename (die_name) : "anonymous";
6612 char *name = XALLOCAVEC (char, strlen (base) + 64);
6615 unsigned char checksum[16];
6618 /* Compute the checksum of the DIE, then append part of it as hex digits to
6619 the name filename of the unit. */
6621 md5_init_ctx (&ctx);
6623 die_checksum (unit_die, &ctx, &mark);
6624 unmark_all_dies (unit_die);
6625 md5_finish_ctx (&ctx, checksum);
6627 sprintf (name, "%s.", base);
6628 clean_symbol_name (name);
6630 p = name + strlen (name);
6631 for (i = 0; i < 4; i++)
6633 sprintf (p, "%.2x", checksum[i]);
6637 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
6638 comdat_symbol_number = 0;
6641 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6644 is_type_die (dw_die_ref die)
6646 switch (die->die_tag)
6648 case DW_TAG_array_type:
6649 case DW_TAG_class_type:
6650 case DW_TAG_interface_type:
6651 case DW_TAG_enumeration_type:
6652 case DW_TAG_pointer_type:
6653 case DW_TAG_reference_type:
6654 case DW_TAG_rvalue_reference_type:
6655 case DW_TAG_string_type:
6656 case DW_TAG_structure_type:
6657 case DW_TAG_subroutine_type:
6658 case DW_TAG_union_type:
6659 case DW_TAG_ptr_to_member_type:
6660 case DW_TAG_set_type:
6661 case DW_TAG_subrange_type:
6662 case DW_TAG_base_type:
6663 case DW_TAG_const_type:
6664 case DW_TAG_file_type:
6665 case DW_TAG_packed_type:
6666 case DW_TAG_volatile_type:
6667 case DW_TAG_typedef:
6674 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6675 Basically, we want to choose the bits that are likely to be shared between
6676 compilations (types) and leave out the bits that are specific to individual
6677 compilations (functions). */
6680 is_comdat_die (dw_die_ref c)
6682 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6683 we do for stabs. The advantage is a greater likelihood of sharing between
6684 objects that don't include headers in the same order (and therefore would
6685 put the base types in a different comdat). jason 8/28/00 */
6687 if (c->die_tag == DW_TAG_base_type)
6690 if (c->die_tag == DW_TAG_pointer_type
6691 || c->die_tag == DW_TAG_reference_type
6692 || c->die_tag == DW_TAG_rvalue_reference_type
6693 || c->die_tag == DW_TAG_const_type
6694 || c->die_tag == DW_TAG_volatile_type)
6696 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6698 return t ? is_comdat_die (t) : 0;
6701 return is_type_die (c);
6704 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6705 compilation unit. */
6708 is_symbol_die (dw_die_ref c)
6710 return (is_type_die (c)
6711 || is_declaration_die (c)
6712 || c->die_tag == DW_TAG_namespace
6713 || c->die_tag == DW_TAG_module);
6716 /* Returns true iff C is a compile-unit DIE. */
6719 is_cu_die (dw_die_ref c)
6721 return c && c->die_tag == DW_TAG_compile_unit;
6725 gen_internal_sym (const char *prefix)
6729 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6730 return xstrdup (buf);
6733 /* Assign symbols to all worthy DIEs under DIE. */
6736 assign_symbol_names (dw_die_ref die)
6740 if (is_symbol_die (die))
6742 if (comdat_symbol_id)
6744 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
6746 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6747 comdat_symbol_id, comdat_symbol_number++);
6748 die->die_id.die_symbol = xstrdup (p);
6751 die->die_id.die_symbol = gen_internal_sym ("LDIE");
6754 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6757 struct cu_hash_table_entry
6760 unsigned min_comdat_num, max_comdat_num;
6761 struct cu_hash_table_entry *next;
6764 /* Routines to manipulate hash table of CUs. */
6766 htab_cu_hash (const void *of)
6768 const struct cu_hash_table_entry *const entry =
6769 (const struct cu_hash_table_entry *) of;
6771 return htab_hash_string (entry->cu->die_id.die_symbol);
6775 htab_cu_eq (const void *of1, const void *of2)
6777 const struct cu_hash_table_entry *const entry1 =
6778 (const struct cu_hash_table_entry *) of1;
6779 const struct die_struct *const entry2 = (const struct die_struct *) of2;
6781 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
6785 htab_cu_del (void *what)
6787 struct cu_hash_table_entry *next,
6788 *entry = (struct cu_hash_table_entry *) what;
6798 /* Check whether we have already seen this CU and set up SYM_NUM
6801 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6803 struct cu_hash_table_entry dummy;
6804 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6806 dummy.max_comdat_num = 0;
6808 slot = (struct cu_hash_table_entry **)
6809 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
6813 for (; entry; last = entry, entry = entry->next)
6815 if (same_die_p_wrap (cu, entry->cu))
6821 *sym_num = entry->min_comdat_num;
6825 entry = XCNEW (struct cu_hash_table_entry);
6827 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6828 entry->next = *slot;
6834 /* Record SYM_NUM to record of CU in HTABLE. */
6836 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6838 struct cu_hash_table_entry **slot, *entry;
6840 slot = (struct cu_hash_table_entry **)
6841 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
6845 entry->max_comdat_num = sym_num;
6848 /* Traverse the DIE (which is always comp_unit_die), and set up
6849 additional compilation units for each of the include files we see
6850 bracketed by BINCL/EINCL. */
6853 break_out_includes (dw_die_ref die)
6856 dw_die_ref unit = NULL;
6857 limbo_die_node *node, **pnode;
6858 htab_t cu_hash_table;
6862 dw_die_ref prev = c;
6864 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6865 || (unit && is_comdat_die (c)))
6867 dw_die_ref next = c->die_sib;
6869 /* This DIE is for a secondary CU; remove it from the main one. */
6870 remove_child_with_prev (c, prev);
6872 if (c->die_tag == DW_TAG_GNU_BINCL)
6873 unit = push_new_compile_unit (unit, c);
6874 else if (c->die_tag == DW_TAG_GNU_EINCL)
6875 unit = pop_compile_unit (unit);
6877 add_child_die (unit, c);
6879 if (c == die->die_child)
6882 } while (c != die->die_child);
6885 /* We can only use this in debugging, since the frontend doesn't check
6886 to make sure that we leave every include file we enter. */
6890 assign_symbol_names (die);
6891 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6892 for (node = limbo_die_list, pnode = &limbo_die_list;
6898 compute_section_prefix (node->die);
6899 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6900 &comdat_symbol_number);
6901 assign_symbol_names (node->die);
6903 *pnode = node->next;
6906 pnode = &node->next;
6907 record_comdat_symbol_number (node->die, cu_hash_table,
6908 comdat_symbol_number);
6911 htab_delete (cu_hash_table);
6914 /* Return non-zero if this DIE is a declaration. */
6917 is_declaration_die (dw_die_ref die)
6922 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6923 if (a->dw_attr == DW_AT_declaration)
6929 /* Return non-zero if this DIE is nested inside a subprogram. */
6932 is_nested_in_subprogram (dw_die_ref die)
6934 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
6938 return local_scope_p (decl);
6941 /* Return non-zero if this DIE contains a defining declaration of a
6945 contains_subprogram_definition (dw_die_ref die)
6949 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
6951 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
6955 /* Return non-zero if this is a type DIE that should be moved to a
6956 COMDAT .debug_types section. */
6959 should_move_die_to_comdat (dw_die_ref die)
6961 switch (die->die_tag)
6963 case DW_TAG_class_type:
6964 case DW_TAG_structure_type:
6965 case DW_TAG_enumeration_type:
6966 case DW_TAG_union_type:
6967 /* Don't move declarations, inlined instances, or types nested in a
6969 if (is_declaration_die (die)
6970 || get_AT (die, DW_AT_abstract_origin)
6971 || is_nested_in_subprogram (die))
6973 /* A type definition should never contain a subprogram definition. */
6974 gcc_assert (!contains_subprogram_definition (die));
6976 case DW_TAG_array_type:
6977 case DW_TAG_interface_type:
6978 case DW_TAG_pointer_type:
6979 case DW_TAG_reference_type:
6980 case DW_TAG_rvalue_reference_type:
6981 case DW_TAG_string_type:
6982 case DW_TAG_subroutine_type:
6983 case DW_TAG_ptr_to_member_type:
6984 case DW_TAG_set_type:
6985 case DW_TAG_subrange_type:
6986 case DW_TAG_base_type:
6987 case DW_TAG_const_type:
6988 case DW_TAG_file_type:
6989 case DW_TAG_packed_type:
6990 case DW_TAG_volatile_type:
6991 case DW_TAG_typedef:
6997 /* Make a clone of DIE. */
7000 clone_die (dw_die_ref die)
7006 clone = ggc_alloc_cleared_die_node ();
7007 clone->die_tag = die->die_tag;
7009 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7010 add_dwarf_attr (clone, a);
7015 /* Make a clone of the tree rooted at DIE. */
7018 clone_tree (dw_die_ref die)
7021 dw_die_ref clone = clone_die (die);
7023 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
7028 /* Make a clone of DIE as a declaration. */
7031 clone_as_declaration (dw_die_ref die)
7038 /* If the DIE is already a declaration, just clone it. */
7039 if (is_declaration_die (die))
7040 return clone_die (die);
7042 /* If the DIE is a specification, just clone its declaration DIE. */
7043 decl = get_AT_ref (die, DW_AT_specification);
7045 return clone_die (decl);
7047 clone = ggc_alloc_cleared_die_node ();
7048 clone->die_tag = die->die_tag;
7050 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7052 /* We don't want to copy over all attributes.
7053 For example we don't want DW_AT_byte_size because otherwise we will no
7054 longer have a declaration and GDB will treat it as a definition. */
7058 case DW_AT_artificial:
7059 case DW_AT_containing_type:
7060 case DW_AT_external:
7063 case DW_AT_virtuality:
7064 case DW_AT_linkage_name:
7065 case DW_AT_MIPS_linkage_name:
7066 add_dwarf_attr (clone, a);
7068 case DW_AT_byte_size:
7074 if (die->die_id.die_type_node)
7075 add_AT_die_ref (clone, DW_AT_signature, die);
7077 add_AT_flag (clone, DW_AT_declaration, 1);
7081 /* Copy the declaration context to the new type unit DIE. This includes
7082 any surrounding namespace or type declarations. If the DIE has an
7083 AT_specification attribute, it also includes attributes and children
7084 attached to the specification, and returns a pointer to the original
7085 parent of the declaration DIE. Returns NULL otherwise. */
7088 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
7091 dw_die_ref new_decl;
7092 dw_die_ref orig_parent = NULL;
7094 decl = get_AT_ref (die, DW_AT_specification);
7103 /* The original DIE will be changed to a declaration, and must
7104 be moved to be a child of the original declaration DIE. */
7105 orig_parent = decl->die_parent;
7107 /* Copy the type node pointer from the new DIE to the original
7108 declaration DIE so we can forward references later. */
7109 decl->die_id.die_type_node = die->die_id.die_type_node;
7111 remove_AT (die, DW_AT_specification);
7113 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
7115 if (a->dw_attr != DW_AT_name
7116 && a->dw_attr != DW_AT_declaration
7117 && a->dw_attr != DW_AT_external)
7118 add_dwarf_attr (die, a);
7121 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
7124 if (decl->die_parent != NULL
7125 && decl->die_parent->die_tag != DW_TAG_compile_unit
7126 && decl->die_parent->die_tag != DW_TAG_type_unit)
7128 new_decl = copy_ancestor_tree (unit, decl, NULL);
7129 if (new_decl != NULL)
7131 remove_AT (new_decl, DW_AT_signature);
7132 add_AT_specification (die, new_decl);
7139 /* Generate the skeleton ancestor tree for the given NODE, then clone
7140 the DIE and add the clone into the tree. */
7143 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
7145 if (node->new_die != NULL)
7148 node->new_die = clone_as_declaration (node->old_die);
7150 if (node->parent != NULL)
7152 generate_skeleton_ancestor_tree (node->parent);
7153 add_child_die (node->parent->new_die, node->new_die);
7157 /* Generate a skeleton tree of DIEs containing any declarations that are
7158 found in the original tree. We traverse the tree looking for declaration
7159 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7162 generate_skeleton_bottom_up (skeleton_chain_node *parent)
7164 skeleton_chain_node node;
7167 dw_die_ref prev = NULL;
7168 dw_die_ref next = NULL;
7170 node.parent = parent;
7172 first = c = parent->old_die->die_child;
7176 if (prev == NULL || prev->die_sib == c)
7179 next = (c == first ? NULL : c->die_sib);
7181 node.new_die = NULL;
7182 if (is_declaration_die (c))
7184 /* Clone the existing DIE, move the original to the skeleton
7185 tree (which is in the main CU), and put the clone, with
7186 all the original's children, where the original came from. */
7187 dw_die_ref clone = clone_die (c);
7188 move_all_children (c, clone);
7190 replace_child (c, clone, prev);
7191 generate_skeleton_ancestor_tree (parent);
7192 add_child_die (parent->new_die, c);
7196 generate_skeleton_bottom_up (&node);
7197 } while (next != NULL);
7200 /* Wrapper function for generate_skeleton_bottom_up. */
7203 generate_skeleton (dw_die_ref die)
7205 skeleton_chain_node node;
7208 node.new_die = NULL;
7211 /* If this type definition is nested inside another type,
7212 always leave at least a declaration in its place. */
7213 if (die->die_parent != NULL && is_type_die (die->die_parent))
7214 node.new_die = clone_as_declaration (die);
7216 generate_skeleton_bottom_up (&node);
7217 return node.new_die;
7220 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7221 declaration. The original DIE is moved to a new compile unit so that
7222 existing references to it follow it to the new location. If any of the
7223 original DIE's descendants is a declaration, we need to replace the
7224 original DIE with a skeleton tree and move the declarations back into the
7228 remove_child_or_replace_with_skeleton (dw_die_ref unit, dw_die_ref child,
7231 dw_die_ref skeleton, orig_parent;
7233 /* Copy the declaration context to the type unit DIE. If the returned
7234 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7236 orig_parent = copy_declaration_context (unit, child);
7238 skeleton = generate_skeleton (child);
7239 if (skeleton == NULL)
7240 remove_child_with_prev (child, prev);
7243 skeleton->die_id.die_type_node = child->die_id.die_type_node;
7245 /* If the original DIE was a specification, we need to put
7246 the skeleton under the parent DIE of the declaration.
7247 This leaves the original declaration in the tree, but
7248 it will be pruned later since there are no longer any
7249 references to it. */
7250 if (orig_parent != NULL)
7252 remove_child_with_prev (child, prev);
7253 add_child_die (orig_parent, skeleton);
7256 replace_child (child, skeleton, prev);
7262 /* Traverse the DIE and set up additional .debug_types sections for each
7263 type worthy of being placed in a COMDAT section. */
7266 break_out_comdat_types (dw_die_ref die)
7270 dw_die_ref prev = NULL;
7271 dw_die_ref next = NULL;
7272 dw_die_ref unit = NULL;
7274 first = c = die->die_child;
7278 if (prev == NULL || prev->die_sib == c)
7281 next = (c == first ? NULL : c->die_sib);
7282 if (should_move_die_to_comdat (c))
7284 dw_die_ref replacement;
7285 comdat_type_node_ref type_node;
7287 /* Create a new type unit DIE as the root for the new tree, and
7288 add it to the list of comdat types. */
7289 unit = new_die (DW_TAG_type_unit, NULL, NULL);
7290 add_AT_unsigned (unit, DW_AT_language,
7291 get_AT_unsigned (comp_unit_die (), DW_AT_language));
7292 type_node = ggc_alloc_cleared_comdat_type_node ();
7293 type_node->root_die = unit;
7294 type_node->next = comdat_type_list;
7295 comdat_type_list = type_node;
7297 /* Generate the type signature. */
7298 generate_type_signature (c, type_node);
7300 /* Copy the declaration context, attributes, and children of the
7301 declaration into the new type unit DIE, then remove this DIE
7302 from the main CU (or replace it with a skeleton if necessary). */
7303 replacement = remove_child_or_replace_with_skeleton (unit, c, prev);
7305 /* Break out nested types into their own type units. */
7306 break_out_comdat_types (c);
7308 /* Add the DIE to the new compunit. */
7309 add_child_die (unit, c);
7311 if (replacement != NULL)
7314 else if (c->die_tag == DW_TAG_namespace
7315 || c->die_tag == DW_TAG_class_type
7316 || c->die_tag == DW_TAG_structure_type
7317 || c->die_tag == DW_TAG_union_type)
7319 /* Look for nested types that can be broken out. */
7320 break_out_comdat_types (c);
7322 } while (next != NULL);
7325 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7327 struct decl_table_entry
7333 /* Routines to manipulate hash table of copied declarations. */
7336 htab_decl_hash (const void *of)
7338 const struct decl_table_entry *const entry =
7339 (const struct decl_table_entry *) of;
7341 return htab_hash_pointer (entry->orig);
7345 htab_decl_eq (const void *of1, const void *of2)
7347 const struct decl_table_entry *const entry1 =
7348 (const struct decl_table_entry *) of1;
7349 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7351 return entry1->orig == entry2;
7355 htab_decl_del (void *what)
7357 struct decl_table_entry *entry = (struct decl_table_entry *) what;
7362 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7363 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7364 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7365 to check if the ancestor has already been copied into UNIT. */
7368 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7370 dw_die_ref parent = die->die_parent;
7371 dw_die_ref new_parent = unit;
7374 struct decl_table_entry *entry = NULL;
7378 /* Check if the entry has already been copied to UNIT. */
7379 slot = htab_find_slot_with_hash (decl_table, die,
7380 htab_hash_pointer (die), INSERT);
7381 if (*slot != HTAB_EMPTY_ENTRY)
7383 entry = (struct decl_table_entry *) *slot;
7387 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7388 entry = XCNEW (struct decl_table_entry);
7396 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
7399 if (parent->die_tag != DW_TAG_compile_unit
7400 && parent->die_tag != DW_TAG_type_unit)
7401 new_parent = copy_ancestor_tree (unit, parent, decl_table);
7404 copy = clone_as_declaration (die);
7405 add_child_die (new_parent, copy);
7407 if (decl_table != NULL)
7409 /* Record the pointer to the copy. */
7416 /* Like clone_tree, but additionally enter all the children into
7417 the hash table decl_table. */
7420 clone_tree_hash (dw_die_ref die, htab_t decl_table)
7423 dw_die_ref clone = clone_die (die);
7424 struct decl_table_entry *entry;
7425 void **slot = htab_find_slot_with_hash (decl_table, die,
7426 htab_hash_pointer (die), INSERT);
7427 /* Assert that DIE isn't in the hash table yet. If it would be there
7428 before, the ancestors would be necessarily there as well, therefore
7429 clone_tree_hash wouldn't be called. */
7430 gcc_assert (*slot == HTAB_EMPTY_ENTRY);
7431 entry = XCNEW (struct decl_table_entry);
7433 entry->copy = clone;
7436 FOR_EACH_CHILD (die, c,
7437 add_child_die (clone, clone_tree_hash (c, decl_table)));
7442 /* Walk the DIE and its children, looking for references to incomplete
7443 or trivial types that are unmarked (i.e., that are not in the current
7447 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7453 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7455 if (AT_class (a) == dw_val_class_die_ref)
7457 dw_die_ref targ = AT_ref (a);
7458 comdat_type_node_ref type_node = targ->die_id.die_type_node;
7460 struct decl_table_entry *entry;
7462 if (targ->die_mark != 0 || type_node != NULL)
7465 slot = htab_find_slot_with_hash (decl_table, targ,
7466 htab_hash_pointer (targ), INSERT);
7468 if (*slot != HTAB_EMPTY_ENTRY)
7470 /* TARG has already been copied, so we just need to
7471 modify the reference to point to the copy. */
7472 entry = (struct decl_table_entry *) *slot;
7473 a->dw_attr_val.v.val_die_ref.die = entry->copy;
7477 dw_die_ref parent = unit;
7478 dw_die_ref copy = clone_die (targ);
7480 /* Record in DECL_TABLE that TARG has been copied.
7481 Need to do this now, before the recursive call,
7482 because DECL_TABLE may be expanded and SLOT
7483 would no longer be a valid pointer. */
7484 entry = XCNEW (struct decl_table_entry);
7489 FOR_EACH_CHILD (targ, c,
7490 add_child_die (copy,
7491 clone_tree_hash (c, decl_table)));
7493 /* Make sure the cloned tree is marked as part of the
7497 /* If TARG has surrounding context, copy its ancestor tree
7498 into the new type unit. */
7499 if (targ->die_parent != NULL
7500 && targ->die_parent->die_tag != DW_TAG_compile_unit
7501 && targ->die_parent->die_tag != DW_TAG_type_unit)
7502 parent = copy_ancestor_tree (unit, targ->die_parent,
7505 add_child_die (parent, copy);
7506 a->dw_attr_val.v.val_die_ref.die = copy;
7508 /* Make sure the newly-copied DIE is walked. If it was
7509 installed in a previously-added context, it won't
7510 get visited otherwise. */
7513 /* Find the highest point of the newly-added tree,
7514 mark each node along the way, and walk from there. */
7515 parent->die_mark = 1;
7516 while (parent->die_parent
7517 && parent->die_parent->die_mark == 0)
7519 parent = parent->die_parent;
7520 parent->die_mark = 1;
7522 copy_decls_walk (unit, parent, decl_table);
7528 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
7531 /* Copy declarations for "unworthy" types into the new comdat section.
7532 Incomplete types, modified types, and certain other types aren't broken
7533 out into comdat sections of their own, so they don't have a signature,
7534 and we need to copy the declaration into the same section so that we
7535 don't have an external reference. */
7538 copy_decls_for_unworthy_types (dw_die_ref unit)
7543 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
7544 copy_decls_walk (unit, unit, decl_table);
7545 htab_delete (decl_table);
7549 /* Traverse the DIE and add a sibling attribute if it may have the
7550 effect of speeding up access to siblings. To save some space,
7551 avoid generating sibling attributes for DIE's without children. */
7554 add_sibling_attributes (dw_die_ref die)
7558 if (! die->die_child)
7561 if (die->die_parent && die != die->die_parent->die_child)
7562 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7564 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7567 /* Output all location lists for the DIE and its children. */
7570 output_location_lists (dw_die_ref die)
7576 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7577 if (AT_class (a) == dw_val_class_loc_list)
7578 output_loc_list (AT_loc_list (a));
7580 FOR_EACH_CHILD (die, c, output_location_lists (c));
7583 /* The format of each DIE (and its attribute value pairs) is encoded in an
7584 abbreviation table. This routine builds the abbreviation table and assigns
7585 a unique abbreviation id for each abbreviation entry. The children of each
7586 die are visited recursively. */
7589 build_abbrev_table (dw_die_ref die)
7591 unsigned long abbrev_id;
7592 unsigned int n_alloc;
7597 /* Scan the DIE references, and mark as external any that refer to
7598 DIEs from other CUs (i.e. those which are not marked). */
7599 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7600 if (AT_class (a) == dw_val_class_die_ref
7601 && AT_ref (a)->die_mark == 0)
7603 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
7604 set_AT_ref_external (a, 1);
7607 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7609 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7610 dw_attr_ref die_a, abbrev_a;
7614 if (abbrev->die_tag != die->die_tag)
7616 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7619 if (VEC_length (dw_attr_node, abbrev->die_attr)
7620 != VEC_length (dw_attr_node, die->die_attr))
7623 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
7625 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7626 if ((abbrev_a->dw_attr != die_a->dw_attr)
7627 || (value_format (abbrev_a) != value_format (die_a)))
7637 if (abbrev_id >= abbrev_die_table_in_use)
7639 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7641 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7642 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7645 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7646 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7647 abbrev_die_table_allocated = n_alloc;
7650 ++abbrev_die_table_in_use;
7651 abbrev_die_table[abbrev_id] = die;
7654 die->die_abbrev = abbrev_id;
7655 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7658 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7661 constant_size (unsigned HOST_WIDE_INT value)
7668 log = floor_log2 (value);
7671 log = 1 << (floor_log2 (log) + 1);
7676 /* Return the size of a DIE as it is represented in the
7677 .debug_info section. */
7679 static unsigned long
7680 size_of_die (dw_die_ref die)
7682 unsigned long size = 0;
7686 size += size_of_uleb128 (die->die_abbrev);
7687 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7689 switch (AT_class (a))
7691 case dw_val_class_addr:
7692 size += DWARF2_ADDR_SIZE;
7694 case dw_val_class_offset:
7695 size += DWARF_OFFSET_SIZE;
7697 case dw_val_class_loc:
7699 unsigned long lsize = size_of_locs (AT_loc (a));
7702 if (dwarf_version >= 4)
7703 size += size_of_uleb128 (lsize);
7705 size += constant_size (lsize);
7709 case dw_val_class_loc_list:
7710 size += DWARF_OFFSET_SIZE;
7712 case dw_val_class_range_list:
7713 size += DWARF_OFFSET_SIZE;
7715 case dw_val_class_const:
7716 size += size_of_sleb128 (AT_int (a));
7718 case dw_val_class_unsigned_const:
7720 int csize = constant_size (AT_unsigned (a));
7721 if (dwarf_version == 3
7722 && a->dw_attr == DW_AT_data_member_location
7724 size += size_of_uleb128 (AT_unsigned (a));
7729 case dw_val_class_const_double:
7730 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
7731 if (HOST_BITS_PER_WIDE_INT >= 64)
7734 case dw_val_class_vec:
7735 size += constant_size (a->dw_attr_val.v.val_vec.length
7736 * a->dw_attr_val.v.val_vec.elt_size)
7737 + a->dw_attr_val.v.val_vec.length
7738 * a->dw_attr_val.v.val_vec.elt_size; /* block */
7740 case dw_val_class_flag:
7741 if (dwarf_version >= 4)
7742 /* Currently all add_AT_flag calls pass in 1 as last argument,
7743 so DW_FORM_flag_present can be used. If that ever changes,
7744 we'll need to use DW_FORM_flag and have some optimization
7745 in build_abbrev_table that will change those to
7746 DW_FORM_flag_present if it is set to 1 in all DIEs using
7747 the same abbrev entry. */
7748 gcc_assert (a->dw_attr_val.v.val_flag == 1);
7752 case dw_val_class_die_ref:
7753 if (AT_ref_external (a))
7755 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7756 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7757 is sized by target address length, whereas in DWARF3
7758 it's always sized as an offset. */
7759 if (use_debug_types)
7760 size += DWARF_TYPE_SIGNATURE_SIZE;
7761 else if (dwarf_version == 2)
7762 size += DWARF2_ADDR_SIZE;
7764 size += DWARF_OFFSET_SIZE;
7767 size += DWARF_OFFSET_SIZE;
7769 case dw_val_class_fde_ref:
7770 size += DWARF_OFFSET_SIZE;
7772 case dw_val_class_lbl_id:
7773 size += DWARF2_ADDR_SIZE;
7775 case dw_val_class_lineptr:
7776 case dw_val_class_macptr:
7777 size += DWARF_OFFSET_SIZE;
7779 case dw_val_class_str:
7780 if (AT_string_form (a) == DW_FORM_strp)
7781 size += DWARF_OFFSET_SIZE;
7783 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7785 case dw_val_class_file:
7786 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7788 case dw_val_class_data8:
7791 case dw_val_class_vms_delta:
7792 size += DWARF_OFFSET_SIZE;
7802 /* Size the debugging information associated with a given DIE. Visits the
7803 DIE's children recursively. Updates the global variable next_die_offset, on
7804 each time through. Uses the current value of next_die_offset to update the
7805 die_offset field in each DIE. */
7808 calc_die_sizes (dw_die_ref die)
7812 gcc_assert (die->die_offset == 0
7813 || (unsigned long int) die->die_offset == next_die_offset);
7814 die->die_offset = next_die_offset;
7815 next_die_offset += size_of_die (die);
7817 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7819 if (die->die_child != NULL)
7820 /* Count the null byte used to terminate sibling lists. */
7821 next_die_offset += 1;
7824 /* Size just the base type children at the start of the CU.
7825 This is needed because build_abbrev needs to size locs
7826 and sizing of type based stack ops needs to know die_offset
7827 values for the base types. */
7830 calc_base_type_die_sizes (void)
7832 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7834 dw_die_ref base_type;
7835 #if ENABLE_ASSERT_CHECKING
7836 dw_die_ref prev = comp_unit_die ()->die_child;
7839 die_offset += size_of_die (comp_unit_die ());
7840 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
7842 #if ENABLE_ASSERT_CHECKING
7843 gcc_assert (base_type->die_offset == 0
7844 && prev->die_sib == base_type
7845 && base_type->die_child == NULL
7846 && base_type->die_abbrev);
7849 base_type->die_offset = die_offset;
7850 die_offset += size_of_die (base_type);
7854 /* Set the marks for a die and its children. We do this so
7855 that we know whether or not a reference needs to use FORM_ref_addr; only
7856 DIEs in the same CU will be marked. We used to clear out the offset
7857 and use that as the flag, but ran into ordering problems. */
7860 mark_dies (dw_die_ref die)
7864 gcc_assert (!die->die_mark);
7867 FOR_EACH_CHILD (die, c, mark_dies (c));
7870 /* Clear the marks for a die and its children. */
7873 unmark_dies (dw_die_ref die)
7877 if (! use_debug_types)
7878 gcc_assert (die->die_mark);
7881 FOR_EACH_CHILD (die, c, unmark_dies (c));
7884 /* Clear the marks for a die, its children and referred dies. */
7887 unmark_all_dies (dw_die_ref die)
7897 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7899 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7900 if (AT_class (a) == dw_val_class_die_ref)
7901 unmark_all_dies (AT_ref (a));
7904 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7905 generated for the compilation unit. */
7907 static unsigned long
7908 size_of_pubnames (VEC (pubname_entry, gc) * names)
7914 size = DWARF_PUBNAMES_HEADER_SIZE;
7915 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
7916 if (names != pubtype_table
7917 || p->die->die_offset != 0
7918 || !flag_eliminate_unused_debug_types)
7919 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7921 size += DWARF_OFFSET_SIZE;
7925 /* Return the size of the information in the .debug_aranges section. */
7927 static unsigned long
7928 size_of_aranges (void)
7932 size = DWARF_ARANGES_HEADER_SIZE;
7934 /* Count the address/length pair for this compilation unit. */
7935 if (text_section_used)
7936 size += 2 * DWARF2_ADDR_SIZE;
7937 if (cold_text_section_used)
7938 size += 2 * DWARF2_ADDR_SIZE;
7939 if (have_multiple_function_sections)
7944 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
7946 if (!fde->in_std_section)
7947 size += 2 * DWARF2_ADDR_SIZE;
7948 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
7949 size += 2 * DWARF2_ADDR_SIZE;
7953 /* Count the two zero words used to terminated the address range table. */
7954 size += 2 * DWARF2_ADDR_SIZE;
7958 /* Select the encoding of an attribute value. */
7960 static enum dwarf_form
7961 value_format (dw_attr_ref a)
7963 switch (a->dw_attr_val.val_class)
7965 case dw_val_class_addr:
7966 /* Only very few attributes allow DW_FORM_addr. */
7971 case DW_AT_entry_pc:
7972 case DW_AT_trampoline:
7973 return DW_FORM_addr;
7977 switch (DWARF2_ADDR_SIZE)
7980 return DW_FORM_data1;
7982 return DW_FORM_data2;
7984 return DW_FORM_data4;
7986 return DW_FORM_data8;
7990 case dw_val_class_range_list:
7991 case dw_val_class_loc_list:
7992 if (dwarf_version >= 4)
7993 return DW_FORM_sec_offset;
7995 case dw_val_class_vms_delta:
7996 case dw_val_class_offset:
7997 switch (DWARF_OFFSET_SIZE)
8000 return DW_FORM_data4;
8002 return DW_FORM_data8;
8006 case dw_val_class_loc:
8007 if (dwarf_version >= 4)
8008 return DW_FORM_exprloc;
8009 switch (constant_size (size_of_locs (AT_loc (a))))
8012 return DW_FORM_block1;
8014 return DW_FORM_block2;
8018 case dw_val_class_const:
8019 return DW_FORM_sdata;
8020 case dw_val_class_unsigned_const:
8021 switch (constant_size (AT_unsigned (a)))
8024 return DW_FORM_data1;
8026 return DW_FORM_data2;
8028 /* In DWARF3 DW_AT_data_member_location with
8029 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8030 constant, so we need to use DW_FORM_udata if we need
8031 a large constant. */
8032 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
8033 return DW_FORM_udata;
8034 return DW_FORM_data4;
8036 if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
8037 return DW_FORM_udata;
8038 return DW_FORM_data8;
8042 case dw_val_class_const_double:
8043 switch (HOST_BITS_PER_WIDE_INT)
8046 return DW_FORM_data2;
8048 return DW_FORM_data4;
8050 return DW_FORM_data8;
8053 return DW_FORM_block1;
8055 case dw_val_class_vec:
8056 switch (constant_size (a->dw_attr_val.v.val_vec.length
8057 * a->dw_attr_val.v.val_vec.elt_size))
8060 return DW_FORM_block1;
8062 return DW_FORM_block2;
8064 return DW_FORM_block4;
8068 case dw_val_class_flag:
8069 if (dwarf_version >= 4)
8071 /* Currently all add_AT_flag calls pass in 1 as last argument,
8072 so DW_FORM_flag_present can be used. If that ever changes,
8073 we'll need to use DW_FORM_flag and have some optimization
8074 in build_abbrev_table that will change those to
8075 DW_FORM_flag_present if it is set to 1 in all DIEs using
8076 the same abbrev entry. */
8077 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8078 return DW_FORM_flag_present;
8080 return DW_FORM_flag;
8081 case dw_val_class_die_ref:
8082 if (AT_ref_external (a))
8083 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
8086 case dw_val_class_fde_ref:
8087 return DW_FORM_data;
8088 case dw_val_class_lbl_id:
8089 return DW_FORM_addr;
8090 case dw_val_class_lineptr:
8091 case dw_val_class_macptr:
8092 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
8093 case dw_val_class_str:
8094 return AT_string_form (a);
8095 case dw_val_class_file:
8096 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8099 return DW_FORM_data1;
8101 return DW_FORM_data2;
8103 return DW_FORM_data4;
8108 case dw_val_class_data8:
8109 return DW_FORM_data8;
8116 /* Output the encoding of an attribute value. */
8119 output_value_format (dw_attr_ref a)
8121 enum dwarf_form form = value_format (a);
8123 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8126 /* Output the .debug_abbrev section which defines the DIE abbreviation
8130 output_abbrev_section (void)
8132 unsigned long abbrev_id;
8134 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8136 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8140 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8141 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8142 dwarf_tag_name (abbrev->die_tag));
8144 if (abbrev->die_child != NULL)
8145 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8147 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8149 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8152 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8153 dwarf_attr_name (a_attr->dw_attr));
8154 output_value_format (a_attr);
8157 dw2_asm_output_data (1, 0, NULL);
8158 dw2_asm_output_data (1, 0, NULL);
8161 /* Terminate the table. */
8162 dw2_asm_output_data (1, 0, NULL);
8165 /* Output a symbol we can use to refer to this DIE from another CU. */
8168 output_die_symbol (dw_die_ref die)
8170 char *sym = die->die_id.die_symbol;
8175 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8176 /* We make these global, not weak; if the target doesn't support
8177 .linkonce, it doesn't support combining the sections, so debugging
8179 targetm.asm_out.globalize_label (asm_out_file, sym);
8181 ASM_OUTPUT_LABEL (asm_out_file, sym);
8184 /* Return a new location list, given the begin and end range, and the
8187 static inline dw_loc_list_ref
8188 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8189 const char *section)
8191 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
8193 retlist->begin = begin;
8195 retlist->expr = expr;
8196 retlist->section = section;
8201 /* Generate a new internal symbol for this location list node, if it
8202 hasn't got one yet. */
8205 gen_llsym (dw_loc_list_ref list)
8207 gcc_assert (!list->ll_symbol);
8208 list->ll_symbol = gen_internal_sym ("LLST");
8211 /* Output the location list given to us. */
8214 output_loc_list (dw_loc_list_ref list_head)
8216 dw_loc_list_ref curr = list_head;
8218 if (list_head->emitted)
8220 list_head->emitted = true;
8222 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8224 /* Walk the location list, and output each range + expression. */
8225 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8228 /* Don't output an entry that starts and ends at the same address. */
8229 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
8231 size = size_of_locs (curr->expr);
8232 /* If the expression is too large, drop it on the floor. We could
8233 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8234 in the expression, but >= 64KB expressions for a single value
8235 in a single range are unlikely very useful. */
8238 if (!have_multiple_function_sections)
8240 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8241 "Location list begin address (%s)",
8242 list_head->ll_symbol);
8243 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8244 "Location list end address (%s)",
8245 list_head->ll_symbol);
8249 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8250 "Location list begin address (%s)",
8251 list_head->ll_symbol);
8252 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8253 "Location list end address (%s)",
8254 list_head->ll_symbol);
8257 /* Output the block length for this list of location operations. */
8258 gcc_assert (size <= 0xffff);
8259 dw2_asm_output_data (2, size, "%s", "Location expression size");
8261 output_loc_sequence (curr->expr, -1);
8264 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8265 "Location list terminator begin (%s)",
8266 list_head->ll_symbol);
8267 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8268 "Location list terminator end (%s)",
8269 list_head->ll_symbol);
8272 /* Output a type signature. */
8275 output_signature (const char *sig, const char *name)
8279 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8280 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
8283 /* Output the DIE and its attributes. Called recursively to generate
8284 the definitions of each child DIE. */
8287 output_die (dw_die_ref die)
8294 /* If someone in another CU might refer to us, set up a symbol for
8295 them to point to. */
8296 if (! use_debug_types && die->die_id.die_symbol)
8297 output_die_symbol (die);
8299 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
8300 (unsigned long)die->die_offset,
8301 dwarf_tag_name (die->die_tag));
8303 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8305 const char *name = dwarf_attr_name (a->dw_attr);
8307 switch (AT_class (a))
8309 case dw_val_class_addr:
8310 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8313 case dw_val_class_offset:
8314 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8318 case dw_val_class_range_list:
8320 char *p = strchr (ranges_section_label, '\0');
8322 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8323 a->dw_attr_val.v.val_offset);
8324 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8325 debug_ranges_section, "%s", name);
8330 case dw_val_class_loc:
8331 size = size_of_locs (AT_loc (a));
8333 /* Output the block length for this list of location operations. */
8334 if (dwarf_version >= 4)
8335 dw2_asm_output_data_uleb128 (size, "%s", name);
8337 dw2_asm_output_data (constant_size (size), size, "%s", name);
8339 output_loc_sequence (AT_loc (a), -1);
8342 case dw_val_class_const:
8343 /* ??? It would be slightly more efficient to use a scheme like is
8344 used for unsigned constants below, but gdb 4.x does not sign
8345 extend. Gdb 5.x does sign extend. */
8346 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8349 case dw_val_class_unsigned_const:
8351 int csize = constant_size (AT_unsigned (a));
8352 if (dwarf_version == 3
8353 && a->dw_attr == DW_AT_data_member_location
8355 dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name);
8357 dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
8361 case dw_val_class_const_double:
8363 unsigned HOST_WIDE_INT first, second;
8365 if (HOST_BITS_PER_WIDE_INT >= 64)
8366 dw2_asm_output_data (1,
8367 2 * HOST_BITS_PER_WIDE_INT
8368 / HOST_BITS_PER_CHAR,
8371 if (WORDS_BIG_ENDIAN)
8373 first = a->dw_attr_val.v.val_double.high;
8374 second = a->dw_attr_val.v.val_double.low;
8378 first = a->dw_attr_val.v.val_double.low;
8379 second = a->dw_attr_val.v.val_double.high;
8382 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8384 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8389 case dw_val_class_vec:
8391 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8392 unsigned int len = a->dw_attr_val.v.val_vec.length;
8396 dw2_asm_output_data (constant_size (len * elt_size),
8397 len * elt_size, "%s", name);
8398 if (elt_size > sizeof (HOST_WIDE_INT))
8403 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8406 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8407 "fp or vector constant word %u", i);
8411 case dw_val_class_flag:
8412 if (dwarf_version >= 4)
8414 /* Currently all add_AT_flag calls pass in 1 as last argument,
8415 so DW_FORM_flag_present can be used. If that ever changes,
8416 we'll need to use DW_FORM_flag and have some optimization
8417 in build_abbrev_table that will change those to
8418 DW_FORM_flag_present if it is set to 1 in all DIEs using
8419 the same abbrev entry. */
8420 gcc_assert (AT_flag (a) == 1);
8422 fprintf (asm_out_file, "\t\t\t%s %s\n",
8423 ASM_COMMENT_START, name);
8426 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8429 case dw_val_class_loc_list:
8431 char *sym = AT_loc_list (a)->ll_symbol;
8434 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8439 case dw_val_class_die_ref:
8440 if (AT_ref_external (a))
8442 if (use_debug_types)
8444 comdat_type_node_ref type_node =
8445 AT_ref (a)->die_id.die_type_node;
8447 gcc_assert (type_node);
8448 output_signature (type_node->signature, name);
8452 char *sym = AT_ref (a)->die_id.die_symbol;
8456 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8457 length, whereas in DWARF3 it's always sized as an
8459 if (dwarf_version == 2)
8460 size = DWARF2_ADDR_SIZE;
8462 size = DWARF_OFFSET_SIZE;
8463 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
8469 gcc_assert (AT_ref (a)->die_offset);
8470 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8475 case dw_val_class_fde_ref:
8479 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8480 a->dw_attr_val.v.val_fde_index * 2);
8481 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8486 case dw_val_class_vms_delta:
8487 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
8488 AT_vms_delta2 (a), AT_vms_delta1 (a),
8492 case dw_val_class_lbl_id:
8493 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8496 case dw_val_class_lineptr:
8497 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8498 debug_line_section, "%s", name);
8501 case dw_val_class_macptr:
8502 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8503 debug_macinfo_section, "%s", name);
8506 case dw_val_class_str:
8507 if (AT_string_form (a) == DW_FORM_strp)
8508 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8509 a->dw_attr_val.v.val_str->label,
8511 "%s: \"%s\"", name, AT_string (a));
8513 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8516 case dw_val_class_file:
8518 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8520 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8521 a->dw_attr_val.v.val_file->filename);
8525 case dw_val_class_data8:
8529 for (i = 0; i < 8; i++)
8530 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
8531 i == 0 ? "%s" : NULL, name);
8540 FOR_EACH_CHILD (die, c, output_die (c));
8542 /* Add null byte to terminate sibling list. */
8543 if (die->die_child != NULL)
8544 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8545 (unsigned long) die->die_offset);
8548 /* Output the compilation unit that appears at the beginning of the
8549 .debug_info section, and precedes the DIE descriptions. */
8552 output_compilation_unit_header (void)
8554 int ver = dwarf_version;
8556 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8557 dw2_asm_output_data (4, 0xffffffff,
8558 "Initial length escape value indicating 64-bit DWARF extension");
8559 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8560 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8561 "Length of Compilation Unit Info");
8562 dw2_asm_output_data (2, ver, "DWARF version number");
8563 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8564 debug_abbrev_section,
8565 "Offset Into Abbrev. Section");
8566 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8569 /* Output the compilation unit DIE and its children. */
8572 output_comp_unit (dw_die_ref die, int output_if_empty)
8574 const char *secname;
8577 /* Unless we are outputting main CU, we may throw away empty ones. */
8578 if (!output_if_empty && die->die_child == NULL)
8581 /* Even if there are no children of this DIE, we must output the information
8582 about the compilation unit. Otherwise, on an empty translation unit, we
8583 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8584 will then complain when examining the file. First mark all the DIEs in
8585 this CU so we know which get local refs. */
8588 build_abbrev_table (die);
8590 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8591 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8592 calc_die_sizes (die);
8594 oldsym = die->die_id.die_symbol;
8597 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8599 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8601 die->die_id.die_symbol = NULL;
8602 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8606 switch_to_section (debug_info_section);
8607 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
8608 info_section_emitted = true;
8611 /* Output debugging information. */
8612 output_compilation_unit_header ();
8615 /* Leave the marks on the main CU, so we can check them in
8620 die->die_id.die_symbol = oldsym;
8624 /* Output a comdat type unit DIE and its children. */
8627 output_comdat_type_unit (comdat_type_node *node)
8629 const char *secname;
8632 #if defined (OBJECT_FORMAT_ELF)
8636 /* First mark all the DIEs in this CU so we know which get local refs. */
8637 mark_dies (node->root_die);
8639 build_abbrev_table (node->root_die);
8641 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8642 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
8643 calc_die_sizes (node->root_die);
8645 #if defined (OBJECT_FORMAT_ELF)
8646 secname = ".debug_types";
8647 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
8648 sprintf (tmp, "wt.");
8649 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8650 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
8651 comdat_key = get_identifier (tmp);
8652 targetm.asm_out.named_section (secname,
8653 SECTION_DEBUG | SECTION_LINKONCE,
8656 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
8657 sprintf (tmp, ".gnu.linkonce.wt.");
8658 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8659 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
8661 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8664 /* Output debugging information. */
8665 output_compilation_unit_header ();
8666 output_signature (node->signature, "Type Signature");
8667 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
8668 "Offset to Type DIE");
8669 output_die (node->root_die);
8671 unmark_dies (node->root_die);
8674 /* Return the DWARF2/3 pubname associated with a decl. */
8677 dwarf2_name (tree decl, int scope)
8679 if (DECL_NAMELESS (decl))
8681 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8684 /* Add a new entry to .debug_pubnames if appropriate. */
8687 add_pubname_string (const char *str, dw_die_ref die)
8689 if (targetm.want_debug_pub_sections)
8694 e.name = xstrdup (str);
8695 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8700 add_pubname (tree decl, dw_die_ref die)
8702 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
8704 const char *name = dwarf2_name (decl, 1);
8706 add_pubname_string (name, die);
8710 /* Add a new entry to .debug_pubtypes if appropriate. */
8713 add_pubtype (tree decl, dw_die_ref die)
8717 if (!targetm.want_debug_pub_sections)
8721 if ((TREE_PUBLIC (decl)
8722 || is_cu_die (die->die_parent))
8723 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8728 if (TYPE_NAME (decl))
8730 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8731 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8732 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8733 && DECL_NAME (TYPE_NAME (decl)))
8734 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8736 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8741 e.name = dwarf2_name (decl, 1);
8743 e.name = xstrdup (e.name);
8746 /* If we don't have a name for the type, there's no point in adding
8748 if (e.name && e.name[0] != '\0')
8749 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8753 /* Output the public names table used to speed up access to externally
8754 visible names; or the public types table used to find type definitions. */
8757 output_pubnames (VEC (pubname_entry, gc) * names)
8760 unsigned long pubnames_length = size_of_pubnames (names);
8763 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8764 dw2_asm_output_data (4, 0xffffffff,
8765 "Initial length escape value indicating 64-bit DWARF extension");
8766 if (names == pubname_table)
8767 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8768 "Length of Public Names Info");
8770 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8771 "Length of Public Type Names Info");
8772 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8773 dw2_asm_output_data (2, 2, "DWARF Version");
8774 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8776 "Offset of Compilation Unit Info");
8777 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8778 "Compilation Unit Length");
8780 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
8782 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8783 if (names == pubname_table)
8784 gcc_assert (pub->die->die_mark);
8786 if (names != pubtype_table
8787 || pub->die->die_offset != 0
8788 || !flag_eliminate_unused_debug_types)
8790 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8793 dw2_asm_output_nstring (pub->name, -1, "external name");
8797 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8800 /* Output the information that goes into the .debug_aranges table.
8801 Namely, define the beginning and ending address range of the
8802 text section generated for this compilation unit. */
8805 output_aranges (unsigned long aranges_length)
8809 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8810 dw2_asm_output_data (4, 0xffffffff,
8811 "Initial length escape value indicating 64-bit DWARF extension");
8812 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8813 "Length of Address Ranges Info");
8814 /* Version number for aranges is still 2, even in DWARF3. */
8815 dw2_asm_output_data (2, 2, "DWARF Version");
8816 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8818 "Offset of Compilation Unit Info");
8819 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8820 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8822 /* We need to align to twice the pointer size here. */
8823 if (DWARF_ARANGES_PAD_SIZE)
8825 /* Pad using a 2 byte words so that padding is correct for any
8827 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8828 2 * DWARF2_ADDR_SIZE);
8829 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8830 dw2_asm_output_data (2, 0, NULL);
8833 /* It is necessary not to output these entries if the sections were
8834 not used; if the sections were not used, the length will be 0 and
8835 the address may end up as 0 if the section is discarded by ld
8836 --gc-sections, leaving an invalid (0, 0) entry that can be
8837 confused with the terminator. */
8838 if (text_section_used)
8840 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8841 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8842 text_section_label, "Length");
8844 if (cold_text_section_used)
8846 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8848 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8849 cold_text_section_label, "Length");
8852 if (have_multiple_function_sections)
8857 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
8859 if (!fde->in_std_section)
8861 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
8863 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
8864 fde->dw_fde_begin, "Length");
8866 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
8868 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
8870 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
8871 fde->dw_fde_second_begin, "Length");
8876 /* Output the terminator words. */
8877 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8878 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8881 /* Add a new entry to .debug_ranges. Return the offset at which it
8885 add_ranges_num (int num)
8887 unsigned int in_use = ranges_table_in_use;
8889 if (in_use == ranges_table_allocated)
8891 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8892 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8893 ranges_table_allocated);
8894 memset (ranges_table + ranges_table_in_use, 0,
8895 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8898 ranges_table[in_use].num = num;
8899 ranges_table_in_use = in_use + 1;
8901 return in_use * 2 * DWARF2_ADDR_SIZE;
8904 /* Add a new entry to .debug_ranges corresponding to a block, or a
8905 range terminator if BLOCK is NULL. */
8908 add_ranges (const_tree block)
8910 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8913 /* Add a new entry to .debug_ranges corresponding to a pair of
8917 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
8920 unsigned int in_use = ranges_by_label_in_use;
8921 unsigned int offset;
8923 if (in_use == ranges_by_label_allocated)
8925 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8926 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8928 ranges_by_label_allocated);
8929 memset (ranges_by_label + ranges_by_label_in_use, 0,
8930 RANGES_TABLE_INCREMENT
8931 * sizeof (struct dw_ranges_by_label_struct));
8934 ranges_by_label[in_use].begin = begin;
8935 ranges_by_label[in_use].end = end;
8936 ranges_by_label_in_use = in_use + 1;
8938 offset = add_ranges_num (-(int)in_use - 1);
8941 add_AT_range_list (die, DW_AT_ranges, offset);
8947 output_ranges (void)
8950 static const char *const start_fmt = "Offset %#x";
8951 const char *fmt = start_fmt;
8953 for (i = 0; i < ranges_table_in_use; i++)
8955 int block_num = ranges_table[i].num;
8959 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8960 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8962 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8963 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8965 /* If all code is in the text section, then the compilation
8966 unit base address defaults to DW_AT_low_pc, which is the
8967 base of the text section. */
8968 if (!have_multiple_function_sections)
8970 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8972 fmt, i * 2 * DWARF2_ADDR_SIZE);
8973 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8974 text_section_label, NULL);
8977 /* Otherwise, the compilation unit base address is zero,
8978 which allows us to use absolute addresses, and not worry
8979 about whether the target supports cross-section
8983 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8984 fmt, i * 2 * DWARF2_ADDR_SIZE);
8985 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8991 /* Negative block_num stands for an index into ranges_by_label. */
8992 else if (block_num < 0)
8994 int lab_idx = - block_num - 1;
8996 if (!have_multiple_function_sections)
9000 /* If we ever use add_ranges_by_labels () for a single
9001 function section, all we have to do is to take out
9003 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9004 ranges_by_label[lab_idx].begin,
9006 fmt, i * 2 * DWARF2_ADDR_SIZE);
9007 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9008 ranges_by_label[lab_idx].end,
9009 text_section_label, NULL);
9014 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9015 ranges_by_label[lab_idx].begin,
9016 fmt, i * 2 * DWARF2_ADDR_SIZE);
9017 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9018 ranges_by_label[lab_idx].end,
9024 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9025 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9031 /* Data structure containing information about input files. */
9034 const char *path; /* Complete file name. */
9035 const char *fname; /* File name part. */
9036 int length; /* Length of entire string. */
9037 struct dwarf_file_data * file_idx; /* Index in input file table. */
9038 int dir_idx; /* Index in directory table. */
9041 /* Data structure containing information about directories with source
9045 const char *path; /* Path including directory name. */
9046 int length; /* Path length. */
9047 int prefix; /* Index of directory entry which is a prefix. */
9048 int count; /* Number of files in this directory. */
9049 int dir_idx; /* Index of directory used as base. */
9052 /* Callback function for file_info comparison. We sort by looking at
9053 the directories in the path. */
9056 file_info_cmp (const void *p1, const void *p2)
9058 const struct file_info *const s1 = (const struct file_info *) p1;
9059 const struct file_info *const s2 = (const struct file_info *) p2;
9060 const unsigned char *cp1;
9061 const unsigned char *cp2;
9063 /* Take care of file names without directories. We need to make sure that
9064 we return consistent values to qsort since some will get confused if
9065 we return the same value when identical operands are passed in opposite
9066 orders. So if neither has a directory, return 0 and otherwise return
9067 1 or -1 depending on which one has the directory. */
9068 if ((s1->path == s1->fname || s2->path == s2->fname))
9069 return (s2->path == s2->fname) - (s1->path == s1->fname);
9071 cp1 = (const unsigned char *) s1->path;
9072 cp2 = (const unsigned char *) s2->path;
9078 /* Reached the end of the first path? If so, handle like above. */
9079 if ((cp1 == (const unsigned char *) s1->fname)
9080 || (cp2 == (const unsigned char *) s2->fname))
9081 return ((cp2 == (const unsigned char *) s2->fname)
9082 - (cp1 == (const unsigned char *) s1->fname));
9084 /* Character of current path component the same? */
9085 else if (*cp1 != *cp2)
9090 struct file_name_acquire_data
9092 struct file_info *files;
9097 /* Traversal function for the hash table. */
9100 file_name_acquire (void ** slot, void *data)
9102 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9103 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9104 struct file_info *fi;
9107 gcc_assert (fnad->max_files >= d->emitted_number);
9109 if (! d->emitted_number)
9112 gcc_assert (fnad->max_files != fnad->used_files);
9114 fi = fnad->files + fnad->used_files++;
9116 /* Skip all leading "./". */
9118 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9121 /* Create a new array entry. */
9123 fi->length = strlen (f);
9126 /* Search for the file name part. */
9127 f = strrchr (f, DIR_SEPARATOR);
9128 #if defined (DIR_SEPARATOR_2)
9130 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9134 if (f == NULL || f < g)
9140 fi->fname = f == NULL ? fi->path : f + 1;
9144 /* Output the directory table and the file name table. We try to minimize
9145 the total amount of memory needed. A heuristic is used to avoid large
9146 slowdowns with many input files. */
9149 output_file_names (void)
9151 struct file_name_acquire_data fnad;
9153 struct file_info *files;
9154 struct dir_info *dirs;
9162 if (!last_emitted_file)
9164 dw2_asm_output_data (1, 0, "End directory table");
9165 dw2_asm_output_data (1, 0, "End file name table");
9169 numfiles = last_emitted_file->emitted_number;
9171 /* Allocate the various arrays we need. */
9172 files = XALLOCAVEC (struct file_info, numfiles);
9173 dirs = XALLOCAVEC (struct dir_info, numfiles);
9176 fnad.used_files = 0;
9177 fnad.max_files = numfiles;
9178 htab_traverse (file_table, file_name_acquire, &fnad);
9179 gcc_assert (fnad.used_files == fnad.max_files);
9181 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9183 /* Find all the different directories used. */
9184 dirs[0].path = files[0].path;
9185 dirs[0].length = files[0].fname - files[0].path;
9186 dirs[0].prefix = -1;
9188 dirs[0].dir_idx = 0;
9189 files[0].dir_idx = 0;
9192 for (i = 1; i < numfiles; i++)
9193 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9194 && memcmp (dirs[ndirs - 1].path, files[i].path,
9195 dirs[ndirs - 1].length) == 0)
9197 /* Same directory as last entry. */
9198 files[i].dir_idx = ndirs - 1;
9199 ++dirs[ndirs - 1].count;
9205 /* This is a new directory. */
9206 dirs[ndirs].path = files[i].path;
9207 dirs[ndirs].length = files[i].fname - files[i].path;
9208 dirs[ndirs].count = 1;
9209 dirs[ndirs].dir_idx = ndirs;
9210 files[i].dir_idx = ndirs;
9212 /* Search for a prefix. */
9213 dirs[ndirs].prefix = -1;
9214 for (j = 0; j < ndirs; j++)
9215 if (dirs[j].length < dirs[ndirs].length
9216 && dirs[j].length > 1
9217 && (dirs[ndirs].prefix == -1
9218 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9219 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9220 dirs[ndirs].prefix = j;
9225 /* Now to the actual work. We have to find a subset of the directories which
9226 allow expressing the file name using references to the directory table
9227 with the least amount of characters. We do not do an exhaustive search
9228 where we would have to check out every combination of every single
9229 possible prefix. Instead we use a heuristic which provides nearly optimal
9230 results in most cases and never is much off. */
9231 saved = XALLOCAVEC (int, ndirs);
9232 savehere = XALLOCAVEC (int, ndirs);
9234 memset (saved, '\0', ndirs * sizeof (saved[0]));
9235 for (i = 0; i < ndirs; i++)
9240 /* We can always save some space for the current directory. But this
9241 does not mean it will be enough to justify adding the directory. */
9242 savehere[i] = dirs[i].length;
9243 total = (savehere[i] - saved[i]) * dirs[i].count;
9245 for (j = i + 1; j < ndirs; j++)
9248 if (saved[j] < dirs[i].length)
9250 /* Determine whether the dirs[i] path is a prefix of the
9255 while (k != -1 && k != (int) i)
9260 /* Yes it is. We can possibly save some memory by
9261 writing the filenames in dirs[j] relative to
9263 savehere[j] = dirs[i].length;
9264 total += (savehere[j] - saved[j]) * dirs[j].count;
9269 /* Check whether we can save enough to justify adding the dirs[i]
9271 if (total > dirs[i].length + 1)
9273 /* It's worthwhile adding. */
9274 for (j = i; j < ndirs; j++)
9275 if (savehere[j] > 0)
9277 /* Remember how much we saved for this directory so far. */
9278 saved[j] = savehere[j];
9280 /* Remember the prefix directory. */
9281 dirs[j].dir_idx = i;
9286 /* Emit the directory name table. */
9287 idx_offset = dirs[0].length > 0 ? 1 : 0;
9288 for (i = 1 - idx_offset; i < ndirs; i++)
9289 dw2_asm_output_nstring (dirs[i].path,
9291 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9292 "Directory Entry: %#x", i + idx_offset);
9294 dw2_asm_output_data (1, 0, "End directory table");
9296 /* We have to emit them in the order of emitted_number since that's
9297 used in the debug info generation. To do this efficiently we
9298 generate a back-mapping of the indices first. */
9299 backmap = XALLOCAVEC (int, numfiles);
9300 for (i = 0; i < numfiles; i++)
9301 backmap[files[i].file_idx->emitted_number - 1] = i;
9303 /* Now write all the file names. */
9304 for (i = 0; i < numfiles; i++)
9306 int file_idx = backmap[i];
9307 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9309 #ifdef VMS_DEBUGGING_INFO
9310 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9312 /* Setting these fields can lead to debugger miscomparisons,
9313 but VMS Debug requires them to be set correctly. */
9318 int maxfilelen = strlen (files[file_idx].path)
9319 + dirs[dir_idx].length
9320 + MAX_VMS_VERSION_LEN + 1;
9321 char *filebuf = XALLOCAVEC (char, maxfilelen);
9323 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9324 snprintf (filebuf, maxfilelen, "%s;%d",
9325 files[file_idx].path + dirs[dir_idx].length, ver);
9327 dw2_asm_output_nstring
9328 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
9330 /* Include directory index. */
9331 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9333 /* Modification time. */
9334 dw2_asm_output_data_uleb128
9335 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9339 /* File length in bytes. */
9340 dw2_asm_output_data_uleb128
9341 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9345 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9346 "File Entry: %#x", (unsigned) i + 1);
9348 /* Include directory index. */
9349 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9351 /* Modification time. */
9352 dw2_asm_output_data_uleb128 (0, NULL);
9354 /* File length in bytes. */
9355 dw2_asm_output_data_uleb128 (0, NULL);
9356 #endif /* VMS_DEBUGGING_INFO */
9359 dw2_asm_output_data (1, 0, "End file name table");
9363 /* Output one line number table into the .debug_line section. */
9366 output_one_line_info_table (dw_line_info_table *table)
9368 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9369 unsigned int current_line = 1;
9370 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
9371 dw_line_info_entry *ent;
9374 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
9376 switch (ent->opcode)
9378 case LI_set_address:
9379 /* ??? Unfortunately, we have little choice here currently, and
9380 must always use the most general form. GCC does not know the
9381 address delta itself, so we can't use DW_LNS_advance_pc. Many
9382 ports do have length attributes which will give an upper bound
9383 on the address range. We could perhaps use length attributes
9384 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9385 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
9387 /* This can handle any delta. This takes
9388 4+DWARF2_ADDR_SIZE bytes. */
9389 dw2_asm_output_data (1, 0, "set address %s", line_label);
9390 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9391 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9392 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9396 if (ent->val == current_line)
9398 /* We still need to start a new row, so output a copy insn. */
9399 dw2_asm_output_data (1, DW_LNS_copy,
9400 "copy line %u", current_line);
9404 int line_offset = ent->val - current_line;
9405 int line_delta = line_offset - DWARF_LINE_BASE;
9407 current_line = ent->val;
9408 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9410 /* This can handle deltas from -10 to 234, using the current
9411 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9412 This takes 1 byte. */
9413 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9414 "line %u", current_line);
9418 /* This can handle any delta. This takes at least 4 bytes,
9419 depending on the value being encoded. */
9420 dw2_asm_output_data (1, DW_LNS_advance_line,
9421 "advance to line %u", current_line);
9422 dw2_asm_output_data_sleb128 (line_offset, NULL);
9423 dw2_asm_output_data (1, DW_LNS_copy, NULL);
9429 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
9430 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9434 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
9435 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9438 case LI_negate_stmt:
9439 current_is_stmt = !current_is_stmt;
9440 dw2_asm_output_data (1, DW_LNS_negate_stmt,
9441 "is_stmt %d", current_is_stmt);
9444 case LI_set_prologue_end:
9445 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
9446 "set prologue end");
9449 case LI_set_epilogue_begin:
9450 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
9451 "set epilogue begin");
9454 case LI_set_discriminator:
9455 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
9456 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
9457 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
9458 dw2_asm_output_data_uleb128 (ent->val, NULL);
9463 /* Emit debug info for the address of the end of the table. */
9464 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
9465 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9466 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9467 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
9469 dw2_asm_output_data (1, 0, "end sequence");
9470 dw2_asm_output_data_uleb128 (1, NULL);
9471 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9474 /* Output the source line number correspondence information. This
9475 information goes into the .debug_line section. */
9478 output_line_info (void)
9480 char l1[20], l2[20], p1[20], p2[20];
9481 int ver = dwarf_version;
9482 bool saw_one = false;
9485 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9486 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9487 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9488 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9490 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9491 dw2_asm_output_data (4, 0xffffffff,
9492 "Initial length escape value indicating 64-bit DWARF extension");
9493 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9494 "Length of Source Line Info");
9495 ASM_OUTPUT_LABEL (asm_out_file, l1);
9497 dw2_asm_output_data (2, ver, "DWARF Version");
9498 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9499 ASM_OUTPUT_LABEL (asm_out_file, p1);
9501 /* Define the architecture-dependent minimum instruction length (in bytes).
9502 In this implementation of DWARF, this field is used for information
9503 purposes only. Since GCC generates assembly language, we have no
9504 a priori knowledge of how many instruction bytes are generated for each
9505 source line, and therefore can use only the DW_LNE_set_address and
9506 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9507 this as '1', which is "correct enough" for all architectures,
9508 and don't let the target override. */
9509 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9512 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
9513 "Maximum Operations Per Instruction");
9514 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9515 "Default is_stmt_start flag");
9516 dw2_asm_output_data (1, DWARF_LINE_BASE,
9517 "Line Base Value (Special Opcodes)");
9518 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9519 "Line Range Value (Special Opcodes)");
9520 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9521 "Special Opcode Base");
9523 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9528 case DW_LNS_advance_pc:
9529 case DW_LNS_advance_line:
9530 case DW_LNS_set_file:
9531 case DW_LNS_set_column:
9532 case DW_LNS_fixed_advance_pc:
9533 case DW_LNS_set_isa:
9541 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
9545 /* Write out the information about the files we use. */
9546 output_file_names ();
9547 ASM_OUTPUT_LABEL (asm_out_file, p2);
9549 if (separate_line_info)
9551 dw_line_info_table *table;
9554 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
9557 output_one_line_info_table (table);
9561 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
9563 output_one_line_info_table (cold_text_section_line_info);
9567 /* ??? Some Darwin linkers crash on a .debug_line section with no
9568 sequences. Further, merely a DW_LNE_end_sequence entry is not
9569 sufficient -- the address column must also be initialized.
9570 Make sure to output at least one set_address/end_sequence pair,
9571 choosing .text since that section is always present. */
9572 if (text_section_line_info->in_use || !saw_one)
9573 output_one_line_info_table (text_section_line_info);
9575 /* Output the marker for the end of the line number info. */
9576 ASM_OUTPUT_LABEL (asm_out_file, l2);
9579 /* Given a pointer to a tree node for some base type, return a pointer to
9580 a DIE that describes the given type.
9582 This routine must only be called for GCC type nodes that correspond to
9583 Dwarf base (fundamental) types. */
9586 base_type_die (tree type)
9588 dw_die_ref base_type_result;
9589 enum dwarf_type encoding;
9591 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9594 /* If this is a subtype that should not be emitted as a subrange type,
9595 use the base type. See subrange_type_for_debug_p. */
9596 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
9597 type = TREE_TYPE (type);
9599 switch (TREE_CODE (type))
9602 if ((dwarf_version >= 4 || !dwarf_strict)
9604 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9605 && DECL_IS_BUILTIN (TYPE_NAME (type))
9606 && DECL_NAME (TYPE_NAME (type)))
9608 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
9609 if (strcmp (name, "char16_t") == 0
9610 || strcmp (name, "char32_t") == 0)
9612 encoding = DW_ATE_UTF;
9616 if (TYPE_STRING_FLAG (type))
9618 if (TYPE_UNSIGNED (type))
9619 encoding = DW_ATE_unsigned_char;
9621 encoding = DW_ATE_signed_char;
9623 else if (TYPE_UNSIGNED (type))
9624 encoding = DW_ATE_unsigned;
9626 encoding = DW_ATE_signed;
9630 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9632 if (dwarf_version >= 3 || !dwarf_strict)
9633 encoding = DW_ATE_decimal_float;
9635 encoding = DW_ATE_lo_user;
9638 encoding = DW_ATE_float;
9641 case FIXED_POINT_TYPE:
9642 if (!(dwarf_version >= 3 || !dwarf_strict))
9643 encoding = DW_ATE_lo_user;
9644 else if (TYPE_UNSIGNED (type))
9645 encoding = DW_ATE_unsigned_fixed;
9647 encoding = DW_ATE_signed_fixed;
9650 /* Dwarf2 doesn't know anything about complex ints, so use
9651 a user defined type for it. */
9653 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9654 encoding = DW_ATE_complex_float;
9656 encoding = DW_ATE_lo_user;
9660 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9661 encoding = DW_ATE_boolean;
9665 /* No other TREE_CODEs are Dwarf fundamental types. */
9669 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
9671 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9672 int_size_in_bytes (type));
9673 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9675 return base_type_result;
9678 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9679 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9682 is_base_type (tree type)
9684 switch (TREE_CODE (type))
9690 case FIXED_POINT_TYPE:
9698 case QUAL_UNION_TYPE:
9703 case REFERENCE_TYPE:
9717 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9718 node, return the size in bits for the type if it is a constant, or else
9719 return the alignment for the type if the type's size is not constant, or
9720 else return BITS_PER_WORD if the type actually turns out to be an
9723 static inline unsigned HOST_WIDE_INT
9724 simple_type_size_in_bits (const_tree type)
9726 if (TREE_CODE (type) == ERROR_MARK)
9727 return BITS_PER_WORD;
9728 else if (TYPE_SIZE (type) == NULL_TREE)
9730 else if (host_integerp (TYPE_SIZE (type), 1))
9731 return tree_low_cst (TYPE_SIZE (type), 1);
9733 return TYPE_ALIGN (type);
9736 /* Similarly, but return a double_int instead of UHWI. */
9738 static inline double_int
9739 double_int_type_size_in_bits (const_tree type)
9741 if (TREE_CODE (type) == ERROR_MARK)
9742 return uhwi_to_double_int (BITS_PER_WORD);
9743 else if (TYPE_SIZE (type) == NULL_TREE)
9744 return double_int_zero;
9745 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
9746 return tree_to_double_int (TYPE_SIZE (type));
9748 return uhwi_to_double_int (TYPE_ALIGN (type));
9751 /* Given a pointer to a tree node for a subrange type, return a pointer
9752 to a DIE that describes the given type. */
9755 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
9757 dw_die_ref subrange_die;
9758 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9760 if (context_die == NULL)
9761 context_die = comp_unit_die ();
9763 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9765 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9767 /* The size of the subrange type and its base type do not match,
9768 so we need to generate a size attribute for the subrange type. */
9769 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9773 add_bound_info (subrange_die, DW_AT_lower_bound, low);
9775 add_bound_info (subrange_die, DW_AT_upper_bound, high);
9777 return subrange_die;
9780 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9781 entry that chains various modifiers in front of the given type. */
9784 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9785 dw_die_ref context_die)
9787 enum tree_code code = TREE_CODE (type);
9788 dw_die_ref mod_type_die;
9789 dw_die_ref sub_die = NULL;
9790 tree item_type = NULL;
9791 tree qualified_type;
9792 tree name, low, high;
9793 dw_die_ref mod_scope;
9795 if (code == ERROR_MARK)
9798 /* See if we already have the appropriately qualified variant of
9801 = get_qualified_type (type,
9802 ((is_const_type ? TYPE_QUAL_CONST : 0)
9803 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9805 if (qualified_type == sizetype
9806 && TYPE_NAME (qualified_type)
9807 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
9809 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
9811 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
9812 && TYPE_PRECISION (t)
9813 == TYPE_PRECISION (qualified_type)
9814 && TYPE_UNSIGNED (t)
9815 == TYPE_UNSIGNED (qualified_type));
9819 /* If we do, then we can just use its DIE, if it exists. */
9822 mod_type_die = lookup_type_die (qualified_type);
9824 return mod_type_die;
9827 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9829 /* Handle C typedef types. */
9830 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
9831 && !DECL_ARTIFICIAL (name))
9833 tree dtype = TREE_TYPE (name);
9835 if (qualified_type == dtype)
9837 /* For a named type, use the typedef. */
9838 gen_type_die (qualified_type, context_die);
9839 return lookup_type_die (qualified_type);
9841 else if (is_const_type < TYPE_READONLY (dtype)
9842 || is_volatile_type < TYPE_VOLATILE (dtype)
9843 || (is_const_type <= TYPE_READONLY (dtype)
9844 && is_volatile_type <= TYPE_VOLATILE (dtype)
9845 && DECL_ORIGINAL_TYPE (name) != type))
9846 /* cv-unqualified version of named type. Just use the unnamed
9847 type to which it refers. */
9848 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9849 is_const_type, is_volatile_type,
9851 /* Else cv-qualified version of named type; fall through. */
9854 mod_scope = scope_die_for (type, context_die);
9857 /* If both is_const_type and is_volatile_type, prefer the path
9858 which leads to a qualified type. */
9859 && (!is_volatile_type
9860 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
9861 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
9863 mod_type_die = new_die (DW_TAG_const_type, mod_scope, type);
9864 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9866 else if (is_volatile_type)
9868 mod_type_die = new_die (DW_TAG_volatile_type, mod_scope, type);
9869 sub_die = modified_type_die (type, is_const_type, 0, context_die);
9871 else if (code == POINTER_TYPE)
9873 mod_type_die = new_die (DW_TAG_pointer_type, mod_scope, type);
9874 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9875 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9876 item_type = TREE_TYPE (type);
9877 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
9878 add_AT_unsigned (mod_type_die, DW_AT_address_class,
9879 TYPE_ADDR_SPACE (item_type));
9881 else if (code == REFERENCE_TYPE)
9883 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
9884 mod_type_die = new_die (DW_TAG_rvalue_reference_type, mod_scope,
9887 mod_type_die = new_die (DW_TAG_reference_type, mod_scope, type);
9888 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9889 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9890 item_type = TREE_TYPE (type);
9891 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
9892 add_AT_unsigned (mod_type_die, DW_AT_address_class,
9893 TYPE_ADDR_SPACE (item_type));
9895 else if (code == INTEGER_TYPE
9896 && TREE_TYPE (type) != NULL_TREE
9897 && subrange_type_for_debug_p (type, &low, &high))
9899 mod_type_die = subrange_type_die (type, low, high, context_die);
9900 item_type = TREE_TYPE (type);
9902 else if (is_base_type (type))
9903 mod_type_die = base_type_die (type);
9906 gen_type_die (type, context_die);
9908 /* We have to get the type_main_variant here (and pass that to the
9909 `lookup_type_die' routine) because the ..._TYPE node we have
9910 might simply be a *copy* of some original type node (where the
9911 copy was created to help us keep track of typedef names) and
9912 that copy might have a different TYPE_UID from the original
9914 if (TREE_CODE (type) != VECTOR_TYPE)
9915 return lookup_type_die (type_main_variant (type));
9917 /* Vectors have the debugging information in the type,
9918 not the main variant. */
9919 return lookup_type_die (type);
9922 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9923 don't output a DW_TAG_typedef, since there isn't one in the
9924 user's program; just attach a DW_AT_name to the type.
9925 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
9926 if the base type already has the same name. */
9928 && ((TREE_CODE (name) != TYPE_DECL
9929 && (qualified_type == TYPE_MAIN_VARIANT (type)
9930 || (!is_const_type && !is_volatile_type)))
9931 || (TREE_CODE (name) == TYPE_DECL
9932 && TREE_TYPE (name) == qualified_type
9933 && DECL_NAME (name))))
9935 if (TREE_CODE (name) == TYPE_DECL)
9936 /* Could just call add_name_and_src_coords_attributes here,
9937 but since this is a builtin type it doesn't have any
9938 useful source coordinates anyway. */
9939 name = DECL_NAME (name);
9940 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9942 /* This probably indicates a bug. */
9943 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
9945 name = TYPE_NAME (type);
9947 && TREE_CODE (name) == TYPE_DECL)
9948 name = DECL_NAME (name);
9949 add_name_attribute (mod_type_die,
9950 name ? IDENTIFIER_POINTER (name) : "__unknown__");
9954 equate_type_number_to_die (qualified_type, mod_type_die);
9957 /* We must do this after the equate_type_number_to_die call, in case
9958 this is a recursive type. This ensures that the modified_type_die
9959 recursion will terminate even if the type is recursive. Recursive
9960 types are possible in Ada. */
9961 sub_die = modified_type_die (item_type,
9962 TYPE_READONLY (item_type),
9963 TYPE_VOLATILE (item_type),
9966 if (sub_die != NULL)
9967 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9969 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
9970 if (TYPE_ARTIFICIAL (type))
9971 add_AT_flag (mod_type_die, DW_AT_artificial, 1);
9973 return mod_type_die;
9976 /* Generate DIEs for the generic parameters of T.
9977 T must be either a generic type or a generic function.
9978 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
9981 gen_generic_params_dies (tree t)
9985 dw_die_ref die = NULL;
9987 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
9991 die = lookup_type_die (t);
9992 else if (DECL_P (t))
9993 die = lookup_decl_die (t);
9997 parms = lang_hooks.get_innermost_generic_parms (t);
9999 /* T has no generic parameter. It means T is neither a generic type
10000 or function. End of story. */
10003 parms_num = TREE_VEC_LENGTH (parms);
10004 args = lang_hooks.get_innermost_generic_args (t);
10005 for (i = 0; i < parms_num; i++)
10007 tree parm, arg, arg_pack_elems;
10009 parm = TREE_VEC_ELT (parms, i);
10010 arg = TREE_VEC_ELT (args, i);
10011 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
10012 gcc_assert (parm && TREE_VALUE (parm) && arg);
10014 if (parm && TREE_VALUE (parm) && arg)
10016 /* If PARM represents a template parameter pack,
10017 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10018 by DW_TAG_template_*_parameter DIEs for the argument
10019 pack elements of ARG. Note that ARG would then be
10020 an argument pack. */
10021 if (arg_pack_elems)
10022 template_parameter_pack_die (TREE_VALUE (parm),
10026 generic_parameter_die (TREE_VALUE (parm), arg,
10027 true /* Emit DW_AT_name */, die);
10032 /* Create and return a DIE for PARM which should be
10033 the representation of a generic type parameter.
10034 For instance, in the C++ front end, PARM would be a template parameter.
10035 ARG is the argument to PARM.
10036 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10038 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10039 as a child node. */
10042 generic_parameter_die (tree parm, tree arg,
10044 dw_die_ref parent_die)
10046 dw_die_ref tmpl_die = NULL;
10047 const char *name = NULL;
10049 if (!parm || !DECL_NAME (parm) || !arg)
10052 /* We support non-type generic parameters and arguments,
10053 type generic parameters and arguments, as well as
10054 generic generic parameters (a.k.a. template template parameters in C++)
10056 if (TREE_CODE (parm) == PARM_DECL)
10057 /* PARM is a nontype generic parameter */
10058 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
10059 else if (TREE_CODE (parm) == TYPE_DECL)
10060 /* PARM is a type generic parameter. */
10061 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
10062 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10063 /* PARM is a generic generic parameter.
10064 Its DIE is a GNU extension. It shall have a
10065 DW_AT_name attribute to represent the name of the template template
10066 parameter, and a DW_AT_GNU_template_name attribute to represent the
10067 name of the template template argument. */
10068 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
10071 gcc_unreachable ();
10077 /* If PARM is a generic parameter pack, it means we are
10078 emitting debug info for a template argument pack element.
10079 In other terms, ARG is a template argument pack element.
10080 In that case, we don't emit any DW_AT_name attribute for
10084 name = IDENTIFIER_POINTER (DECL_NAME (parm));
10086 add_AT_string (tmpl_die, DW_AT_name, name);
10089 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10091 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10092 TMPL_DIE should have a child DW_AT_type attribute that is set
10093 to the type of the argument to PARM, which is ARG.
10094 If PARM is a type generic parameter, TMPL_DIE should have a
10095 child DW_AT_type that is set to ARG. */
10096 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
10097 add_type_attribute (tmpl_die, tmpl_type, 0,
10098 TREE_THIS_VOLATILE (tmpl_type),
10103 /* So TMPL_DIE is a DIE representing a
10104 a generic generic template parameter, a.k.a template template
10105 parameter in C++ and arg is a template. */
10107 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10108 to the name of the argument. */
10109 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
10111 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
10114 if (TREE_CODE (parm) == PARM_DECL)
10115 /* So PARM is a non-type generic parameter.
10116 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10117 attribute of TMPL_DIE which value represents the value
10119 We must be careful here:
10120 The value of ARG might reference some function decls.
10121 We might currently be emitting debug info for a generic
10122 type and types are emitted before function decls, we don't
10123 know if the function decls referenced by ARG will actually be
10124 emitted after cgraph computations.
10125 So must defer the generation of the DW_AT_const_value to
10126 after cgraph is ready. */
10127 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
10133 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10134 PARM_PACK must be a template parameter pack. The returned DIE
10135 will be child DIE of PARENT_DIE. */
10138 template_parameter_pack_die (tree parm_pack,
10139 tree parm_pack_args,
10140 dw_die_ref parent_die)
10145 gcc_assert (parent_die && parm_pack);
10147 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
10148 add_name_and_src_coords_attributes (die, parm_pack);
10149 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
10150 generic_parameter_die (parm_pack,
10151 TREE_VEC_ELT (parm_pack_args, j),
10152 false /* Don't emit DW_AT_name */,
10157 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10158 an enumerated type. */
10161 type_is_enum (const_tree type)
10163 return TREE_CODE (type) == ENUMERAL_TYPE;
10166 /* Return the DBX register number described by a given RTL node. */
10168 static unsigned int
10169 dbx_reg_number (const_rtx rtl)
10171 unsigned regno = REGNO (rtl);
10173 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10175 #ifdef LEAF_REG_REMAP
10176 if (current_function_uses_only_leaf_regs)
10178 int leaf_reg = LEAF_REG_REMAP (regno);
10179 if (leaf_reg != -1)
10180 regno = (unsigned) leaf_reg;
10184 return DBX_REGISTER_NUMBER (regno);
10187 /* Optionally add a DW_OP_piece term to a location description expression.
10188 DW_OP_piece is only added if the location description expression already
10189 doesn't end with DW_OP_piece. */
10192 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10194 dw_loc_descr_ref loc;
10196 if (*list_head != NULL)
10198 /* Find the end of the chain. */
10199 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10202 if (loc->dw_loc_opc != DW_OP_piece)
10203 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10207 /* Return a location descriptor that designates a machine register or
10208 zero if there is none. */
10210 static dw_loc_descr_ref
10211 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10215 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10218 /* We only use "frame base" when we're sure we're talking about the
10219 post-prologue local stack frame. We do this by *not* running
10220 register elimination until this point, and recognizing the special
10221 argument pointer and soft frame pointer rtx's.
10222 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10223 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
10224 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
10226 dw_loc_descr_ref result = NULL;
10228 if (dwarf_version >= 4 || !dwarf_strict)
10230 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
10233 add_loc_descr (&result,
10234 new_loc_descr (DW_OP_stack_value, 0, 0));
10239 regs = targetm.dwarf_register_span (rtl);
10241 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10242 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10244 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10247 /* Return a location descriptor that designates a machine register for
10248 a given hard register number. */
10250 static dw_loc_descr_ref
10251 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10253 dw_loc_descr_ref reg_loc_descr;
10257 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10259 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10261 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10262 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10264 return reg_loc_descr;
10267 /* Given an RTL of a register, return a location descriptor that
10268 designates a value that spans more than one register. */
10270 static dw_loc_descr_ref
10271 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10272 enum var_init_status initialized)
10274 int nregs, size, i;
10276 dw_loc_descr_ref loc_result = NULL;
10279 #ifdef LEAF_REG_REMAP
10280 if (current_function_uses_only_leaf_regs)
10282 int leaf_reg = LEAF_REG_REMAP (reg);
10283 if (leaf_reg != -1)
10284 reg = (unsigned) leaf_reg;
10287 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10288 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10290 /* Simple, contiguous registers. */
10291 if (regs == NULL_RTX)
10293 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10298 dw_loc_descr_ref t;
10300 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10301 VAR_INIT_STATUS_INITIALIZED);
10302 add_loc_descr (&loc_result, t);
10303 add_loc_descr_op_piece (&loc_result, size);
10309 /* Now onto stupid register sets in non contiguous locations. */
10311 gcc_assert (GET_CODE (regs) == PARALLEL);
10313 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10316 for (i = 0; i < XVECLEN (regs, 0); ++i)
10318 dw_loc_descr_ref t;
10320 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10321 VAR_INIT_STATUS_INITIALIZED);
10322 add_loc_descr (&loc_result, t);
10323 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10324 add_loc_descr_op_piece (&loc_result, size);
10327 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10328 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10332 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
10334 /* Return a location descriptor that designates a constant i,
10335 as a compound operation from constant (i >> shift), constant shift
10338 static dw_loc_descr_ref
10339 int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
10341 dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
10342 add_loc_descr (&ret, int_loc_descriptor (shift));
10343 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
10347 /* Return a location descriptor that designates a constant. */
10349 static dw_loc_descr_ref
10350 int_loc_descriptor (HOST_WIDE_INT i)
10352 enum dwarf_location_atom op;
10354 /* Pick the smallest representation of a constant, rather than just
10355 defaulting to the LEB encoding. */
10358 int clz = clz_hwi (i);
10359 int ctz = ctz_hwi (i);
10361 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10362 else if (i <= 0xff)
10363 op = DW_OP_const1u;
10364 else if (i <= 0xffff)
10365 op = DW_OP_const2u;
10366 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
10367 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
10368 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10369 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10370 while DW_OP_const4u is 5 bytes. */
10371 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
10372 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10373 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
10374 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10375 while DW_OP_const4u is 5 bytes. */
10376 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
10377 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
10378 op = DW_OP_const4u;
10379 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10380 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
10381 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10382 while DW_OP_constu of constant >= 0x100000000 takes at least
10384 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
10385 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
10386 && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
10387 >= HOST_BITS_PER_WIDE_INT)
10388 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10389 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10390 while DW_OP_constu takes in this case at least 6 bytes. */
10391 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
10392 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
10393 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
10394 && size_of_uleb128 (i) > 6)
10395 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10396 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
10403 op = DW_OP_const1s;
10404 else if (i >= -0x8000)
10405 op = DW_OP_const2s;
10406 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
10408 if (size_of_int_loc_descriptor (i) < 5)
10410 dw_loc_descr_ref ret = int_loc_descriptor (-i);
10411 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
10414 op = DW_OP_const4s;
10418 if (size_of_int_loc_descriptor (i)
10419 < (unsigned long) 1 + size_of_sleb128 (i))
10421 dw_loc_descr_ref ret = int_loc_descriptor (-i);
10422 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
10429 return new_loc_descr (op, i, 0);
10432 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10433 without actually allocating it. */
10435 static unsigned long
10436 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
10438 return size_of_int_loc_descriptor (i >> shift)
10439 + size_of_int_loc_descriptor (shift)
10443 /* Return size_of_locs (int_loc_descriptor (i)) without
10444 actually allocating it. */
10446 static unsigned long
10447 size_of_int_loc_descriptor (HOST_WIDE_INT i)
10456 else if (i <= 0xff)
10458 else if (i <= 0xffff)
10462 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
10463 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
10464 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10466 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10467 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
10468 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10470 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
10472 s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
10473 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10474 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
10475 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10477 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
10478 && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
10479 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10481 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
10482 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
10484 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10493 else if (i >= -0x8000)
10495 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
10497 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
10499 s = size_of_int_loc_descriptor (-i) + 1;
10507 unsigned long r = 1 + size_of_sleb128 (i);
10508 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
10510 s = size_of_int_loc_descriptor (-i) + 1;
10519 /* Return loc description representing "address" of integer value.
10520 This can appear only as toplevel expression. */
10522 static dw_loc_descr_ref
10523 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
10526 dw_loc_descr_ref loc_result = NULL;
10528 if (!(dwarf_version >= 4 || !dwarf_strict))
10531 litsize = size_of_int_loc_descriptor (i);
10532 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10533 is more compact. For DW_OP_stack_value we need:
10534 litsize + 1 (DW_OP_stack_value)
10535 and for DW_OP_implicit_value:
10536 1 (DW_OP_implicit_value) + 1 (length) + size. */
10537 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
10539 loc_result = int_loc_descriptor (i);
10540 add_loc_descr (&loc_result,
10541 new_loc_descr (DW_OP_stack_value, 0, 0));
10545 loc_result = new_loc_descr (DW_OP_implicit_value,
10547 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
10548 loc_result->dw_loc_oprnd2.v.val_int = i;
10552 /* Return a location descriptor that designates a base+offset location. */
10554 static dw_loc_descr_ref
10555 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10556 enum var_init_status initialized)
10558 unsigned int regno;
10559 dw_loc_descr_ref result;
10560 dw_fde_ref fde = cfun->fde;
10562 /* We only use "frame base" when we're sure we're talking about the
10563 post-prologue local stack frame. We do this by *not* running
10564 register elimination until this point, and recognizing the special
10565 argument pointer and soft frame pointer rtx's. */
10566 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10568 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10572 if (GET_CODE (elim) == PLUS)
10574 offset += INTVAL (XEXP (elim, 1));
10575 elim = XEXP (elim, 0);
10577 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10578 && (elim == hard_frame_pointer_rtx
10579 || elim == stack_pointer_rtx))
10580 || elim == (frame_pointer_needed
10581 ? hard_frame_pointer_rtx
10582 : stack_pointer_rtx));
10584 /* If drap register is used to align stack, use frame
10585 pointer + offset to access stack variables. If stack
10586 is aligned without drap, use stack pointer + offset to
10587 access stack variables. */
10588 if (crtl->stack_realign_tried
10589 && reg == frame_pointer_rtx)
10592 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10593 ? HARD_FRAME_POINTER_REGNUM
10595 return new_reg_loc_descr (base_reg, offset);
10598 gcc_assert (frame_pointer_fb_offset_valid);
10599 offset += frame_pointer_fb_offset;
10600 return new_loc_descr (DW_OP_fbreg, offset, 0);
10604 regno = DWARF_FRAME_REGNUM (REGNO (reg));
10606 if (!optimize && fde
10607 && (fde->drap_reg == regno || fde->vdrap_reg == regno))
10609 /* Use cfa+offset to represent the location of arguments passed
10610 on the stack when drap is used to align stack.
10611 Only do this when not optimizing, for optimized code var-tracking
10612 is supposed to track where the arguments live and the register
10613 used as vdrap or drap in some spot might be used for something
10614 else in other part of the routine. */
10615 return new_loc_descr (DW_OP_fbreg, offset, 0);
10619 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10622 result = new_loc_descr (DW_OP_bregx, regno, offset);
10624 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10625 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10630 /* Return true if this RTL expression describes a base+offset calculation. */
10633 is_based_loc (const_rtx rtl)
10635 return (GET_CODE (rtl) == PLUS
10636 && ((REG_P (XEXP (rtl, 0))
10637 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10638 && CONST_INT_P (XEXP (rtl, 1)))));
10641 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10644 static dw_loc_descr_ref
10645 tls_mem_loc_descriptor (rtx mem)
10648 dw_loc_descr_ref loc_result;
10650 if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
10653 base = get_base_address (MEM_EXPR (mem));
10655 || TREE_CODE (base) != VAR_DECL
10656 || !DECL_THREAD_LOCAL_P (base))
10659 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
10660 if (loc_result == NULL)
10663 if (MEM_OFFSET (mem))
10664 loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
10669 /* Output debug info about reason why we failed to expand expression as dwarf
10673 expansion_failed (tree expr, rtx rtl, char const *reason)
10675 if (dump_file && (dump_flags & TDF_DETAILS))
10677 fprintf (dump_file, "Failed to expand as dwarf: ");
10679 print_generic_expr (dump_file, expr, dump_flags);
10682 fprintf (dump_file, "\n");
10683 print_rtl (dump_file, rtl);
10685 fprintf (dump_file, "\nReason: %s\n", reason);
10689 /* Helper function for const_ok_for_output, called either directly
10690 or via for_each_rtx. */
10693 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
10697 if (GET_CODE (rtl) == UNSPEC)
10699 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10700 we can't express it in the debug info. */
10701 #ifdef ENABLE_CHECKING
10702 /* Don't complain about TLS UNSPECs, those are just too hard to
10704 if (XVECLEN (rtl, 0) != 1
10705 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
10706 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
10707 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
10708 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
10709 inform (current_function_decl
10710 ? DECL_SOURCE_LOCATION (current_function_decl)
10711 : UNKNOWN_LOCATION,
10712 #if NUM_UNSPEC_VALUES > 0
10713 "non-delegitimized UNSPEC %s (%d) found in variable location",
10714 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
10715 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
10718 "non-delegitimized UNSPEC %d found in variable location",
10722 expansion_failed (NULL_TREE, rtl,
10723 "UNSPEC hasn't been delegitimized.\n");
10727 if (targetm.const_not_ok_for_debug_p (rtl))
10729 expansion_failed (NULL_TREE, rtl,
10730 "Expression rejected for debug by the backend.\n");
10734 if (GET_CODE (rtl) != SYMBOL_REF)
10737 if (CONSTANT_POOL_ADDRESS_P (rtl))
10740 get_pool_constant_mark (rtl, &marked);
10741 /* If all references to this pool constant were optimized away,
10742 it was not output and thus we can't represent it. */
10745 expansion_failed (NULL_TREE, rtl,
10746 "Constant was removed from constant pool.\n");
10751 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
10754 /* Avoid references to external symbols in debug info, on several targets
10755 the linker might even refuse to link when linking a shared library,
10756 and in many other cases the relocations for .debug_info/.debug_loc are
10757 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
10758 to be defined within the same shared library or executable are fine. */
10759 if (SYMBOL_REF_EXTERNAL_P (rtl))
10761 tree decl = SYMBOL_REF_DECL (rtl);
10763 if (decl == NULL || !targetm.binds_local_p (decl))
10765 expansion_failed (NULL_TREE, rtl,
10766 "Symbol not defined in current TU.\n");
10774 /* Return true if constant RTL can be emitted in DW_OP_addr or
10775 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
10776 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
10779 const_ok_for_output (rtx rtl)
10781 if (GET_CODE (rtl) == SYMBOL_REF)
10782 return const_ok_for_output_1 (&rtl, NULL) == 0;
10784 if (GET_CODE (rtl) == CONST)
10785 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
10790 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
10791 if possible, NULL otherwise. */
10794 base_type_for_mode (enum machine_mode mode, bool unsignedp)
10796 dw_die_ref type_die;
10797 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
10801 switch (TREE_CODE (type))
10809 type_die = lookup_type_die (type);
10811 type_die = modified_type_die (type, false, false, comp_unit_die ());
10812 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
10817 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
10818 type matching MODE, or, if MODE is narrower than or as wide as
10819 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
10822 static dw_loc_descr_ref
10823 convert_descriptor_to_mode (enum machine_mode mode, dw_loc_descr_ref op)
10825 enum machine_mode outer_mode = mode;
10826 dw_die_ref type_die;
10827 dw_loc_descr_ref cvt;
10829 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
10831 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
10834 type_die = base_type_for_mode (outer_mode, 1);
10835 if (type_die == NULL)
10837 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10838 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10839 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10840 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10841 add_loc_descr (&op, cvt);
10845 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
10847 static dw_loc_descr_ref
10848 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
10849 dw_loc_descr_ref op1)
10851 dw_loc_descr_ref ret = op0;
10852 add_loc_descr (&ret, op1);
10853 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10854 if (STORE_FLAG_VALUE != 1)
10856 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
10857 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
10862 /* Return location descriptor for signed comparison OP RTL. */
10864 static dw_loc_descr_ref
10865 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
10866 enum machine_mode mem_mode)
10868 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
10869 dw_loc_descr_ref op0, op1;
10872 if (op_mode == VOIDmode)
10873 op_mode = GET_MODE (XEXP (rtl, 1));
10874 if (op_mode == VOIDmode)
10878 && (GET_MODE_CLASS (op_mode) != MODE_INT
10879 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
10882 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
10883 VAR_INIT_STATUS_INITIALIZED);
10884 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
10885 VAR_INIT_STATUS_INITIALIZED);
10887 if (op0 == NULL || op1 == NULL)
10890 if (GET_MODE_CLASS (op_mode) != MODE_INT
10891 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
10892 return compare_loc_descriptor (op, op0, op1);
10894 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
10896 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
10897 dw_loc_descr_ref cvt;
10899 if (type_die == NULL)
10901 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10902 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10903 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10904 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10905 add_loc_descr (&op0, cvt);
10906 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10907 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10908 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10909 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10910 add_loc_descr (&op1, cvt);
10911 return compare_loc_descriptor (op, op0, op1);
10914 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
10915 /* For eq/ne, if the operands are known to be zero-extended,
10916 there is no need to do the fancy shifting up. */
10917 if (op == DW_OP_eq || op == DW_OP_ne)
10919 dw_loc_descr_ref last0, last1;
10920 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
10922 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
10924 /* deref_size zero extends, and for constants we can check
10925 whether they are zero extended or not. */
10926 if (((last0->dw_loc_opc == DW_OP_deref_size
10927 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
10928 || (CONST_INT_P (XEXP (rtl, 0))
10929 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
10930 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
10931 && ((last1->dw_loc_opc == DW_OP_deref_size
10932 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
10933 || (CONST_INT_P (XEXP (rtl, 1))
10934 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
10935 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
10936 return compare_loc_descriptor (op, op0, op1);
10938 /* EQ/NE comparison against constant in narrower type than
10939 DWARF2_ADDR_SIZE can be performed either as
10940 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
10943 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
10944 DW_OP_{eq,ne}. Pick whatever is shorter. */
10945 if (CONST_INT_P (XEXP (rtl, 1))
10946 && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
10947 && (size_of_int_loc_descriptor (shift) + 1
10948 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift)
10949 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
10950 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
10951 & GET_MODE_MASK (op_mode))))
10953 add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
10954 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10955 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
10956 & GET_MODE_MASK (op_mode));
10957 return compare_loc_descriptor (op, op0, op1);
10960 add_loc_descr (&op0, int_loc_descriptor (shift));
10961 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
10962 if (CONST_INT_P (XEXP (rtl, 1)))
10963 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
10966 add_loc_descr (&op1, int_loc_descriptor (shift));
10967 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
10969 return compare_loc_descriptor (op, op0, op1);
10972 /* Return location descriptor for unsigned comparison OP RTL. */
10974 static dw_loc_descr_ref
10975 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
10976 enum machine_mode mem_mode)
10978 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
10979 dw_loc_descr_ref op0, op1;
10981 if (op_mode == VOIDmode)
10982 op_mode = GET_MODE (XEXP (rtl, 1));
10983 if (op_mode == VOIDmode)
10985 if (GET_MODE_CLASS (op_mode) != MODE_INT)
10988 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
10991 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
10992 VAR_INIT_STATUS_INITIALIZED);
10993 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
10994 VAR_INIT_STATUS_INITIALIZED);
10996 if (op0 == NULL || op1 == NULL)
10999 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
11001 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
11002 dw_loc_descr_ref last0, last1;
11003 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
11005 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
11007 if (CONST_INT_P (XEXP (rtl, 0)))
11008 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
11009 /* deref_size zero extends, so no need to mask it again. */
11010 else if (last0->dw_loc_opc != DW_OP_deref_size
11011 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
11013 add_loc_descr (&op0, int_loc_descriptor (mask));
11014 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11016 if (CONST_INT_P (XEXP (rtl, 1)))
11017 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
11018 /* deref_size zero extends, so no need to mask it again. */
11019 else if (last1->dw_loc_opc != DW_OP_deref_size
11020 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
11022 add_loc_descr (&op1, int_loc_descriptor (mask));
11023 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11026 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
11028 HOST_WIDE_INT bias = 1;
11029 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11030 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11031 if (CONST_INT_P (XEXP (rtl, 1)))
11032 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
11033 + INTVAL (XEXP (rtl, 1)));
11035 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
11038 return compare_loc_descriptor (op, op0, op1);
11041 /* Return location descriptor for {U,S}{MIN,MAX}. */
11043 static dw_loc_descr_ref
11044 minmax_loc_descriptor (rtx rtl, enum machine_mode mode,
11045 enum machine_mode mem_mode)
11047 enum dwarf_location_atom op;
11048 dw_loc_descr_ref op0, op1, ret;
11049 dw_loc_descr_ref bra_node, drop_node;
11052 && (GET_MODE_CLASS (mode) != MODE_INT
11053 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
11056 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11057 VAR_INIT_STATUS_INITIALIZED);
11058 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11059 VAR_INIT_STATUS_INITIALIZED);
11061 if (op0 == NULL || op1 == NULL)
11064 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
11065 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
11066 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
11067 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
11069 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11071 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
11072 add_loc_descr (&op0, int_loc_descriptor (mask));
11073 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11074 add_loc_descr (&op1, int_loc_descriptor (mask));
11075 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11077 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
11079 HOST_WIDE_INT bias = 1;
11080 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11081 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11082 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11085 else if (GET_MODE_CLASS (mode) == MODE_INT
11086 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11088 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
11089 add_loc_descr (&op0, int_loc_descriptor (shift));
11090 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11091 add_loc_descr (&op1, int_loc_descriptor (shift));
11092 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11094 else if (GET_MODE_CLASS (mode) == MODE_INT
11095 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11097 dw_die_ref type_die = base_type_for_mode (mode, 0);
11098 dw_loc_descr_ref cvt;
11099 if (type_die == NULL)
11101 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11102 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11103 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11104 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11105 add_loc_descr (&op0, cvt);
11106 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11107 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11108 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11109 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11110 add_loc_descr (&op1, cvt);
11113 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
11118 add_loc_descr (&ret, op1);
11119 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11120 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11121 add_loc_descr (&ret, bra_node);
11122 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11123 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
11124 add_loc_descr (&ret, drop_node);
11125 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11126 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
11127 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
11128 && GET_MODE_CLASS (mode) == MODE_INT
11129 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11130 ret = convert_descriptor_to_mode (mode, ret);
11134 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11135 but after converting arguments to type_die, afterwards
11136 convert back to unsigned. */
11138 static dw_loc_descr_ref
11139 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
11140 enum machine_mode mode, enum machine_mode mem_mode)
11142 dw_loc_descr_ref cvt, op0, op1;
11144 if (type_die == NULL)
11146 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11147 VAR_INIT_STATUS_INITIALIZED);
11148 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11149 VAR_INIT_STATUS_INITIALIZED);
11150 if (op0 == NULL || op1 == NULL)
11152 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11153 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11154 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11155 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11156 add_loc_descr (&op0, cvt);
11157 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11158 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11159 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11160 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11161 add_loc_descr (&op1, cvt);
11162 add_loc_descr (&op0, op1);
11163 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
11164 return convert_descriptor_to_mode (mode, op0);
11167 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11168 const0 is DW_OP_lit0 or corresponding typed constant,
11169 const1 is DW_OP_lit1 or corresponding typed constant
11170 and constMSB is constant with just the MSB bit set
11172 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11173 L1: const0 DW_OP_swap
11174 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11175 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11180 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11181 L1: const0 DW_OP_swap
11182 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11183 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11188 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11189 L1: const1 DW_OP_swap
11190 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11191 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11195 static dw_loc_descr_ref
11196 clz_loc_descriptor (rtx rtl, enum machine_mode mode,
11197 enum machine_mode mem_mode)
11199 dw_loc_descr_ref op0, ret, tmp;
11200 HOST_WIDE_INT valv;
11201 dw_loc_descr_ref l1jump, l1label;
11202 dw_loc_descr_ref l2jump, l2label;
11203 dw_loc_descr_ref l3jump, l3label;
11204 dw_loc_descr_ref l4jump, l4label;
11207 if (GET_MODE_CLASS (mode) != MODE_INT
11208 || GET_MODE (XEXP (rtl, 0)) != mode
11209 || (GET_CODE (rtl) == CLZ
11210 && GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT))
11213 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11214 VAR_INIT_STATUS_INITIALIZED);
11218 if (GET_CODE (rtl) == CLZ)
11220 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11221 valv = GET_MODE_BITSIZE (mode);
11223 else if (GET_CODE (rtl) == FFS)
11225 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11226 valv = GET_MODE_BITSIZE (mode);
11227 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11228 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
11229 add_loc_descr (&ret, l1jump);
11230 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11231 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
11232 VAR_INIT_STATUS_INITIALIZED);
11235 add_loc_descr (&ret, tmp);
11236 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
11237 add_loc_descr (&ret, l4jump);
11238 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
11239 ? const1_rtx : const0_rtx,
11241 VAR_INIT_STATUS_INITIALIZED);
11242 if (l1label == NULL)
11244 add_loc_descr (&ret, l1label);
11245 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11246 l2label = new_loc_descr (DW_OP_dup, 0, 0);
11247 add_loc_descr (&ret, l2label);
11248 if (GET_CODE (rtl) != CLZ)
11250 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
11251 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
11252 << (GET_MODE_BITSIZE (mode) - 1));
11254 msb = immed_double_const (0, (unsigned HOST_WIDE_INT) 1
11255 << (GET_MODE_BITSIZE (mode)
11256 - HOST_BITS_PER_WIDE_INT - 1), mode);
11257 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
11258 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11259 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
11260 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
11262 tmp = mem_loc_descriptor (msb, mode, mem_mode,
11263 VAR_INIT_STATUS_INITIALIZED);
11266 add_loc_descr (&ret, tmp);
11267 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11268 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
11269 add_loc_descr (&ret, l3jump);
11270 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11271 VAR_INIT_STATUS_INITIALIZED);
11274 add_loc_descr (&ret, tmp);
11275 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
11276 ? DW_OP_shl : DW_OP_shr, 0, 0));
11277 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11278 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
11279 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11280 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
11281 add_loc_descr (&ret, l2jump);
11282 l3label = new_loc_descr (DW_OP_drop, 0, 0);
11283 add_loc_descr (&ret, l3label);
11284 l4label = new_loc_descr (DW_OP_nop, 0, 0);
11285 add_loc_descr (&ret, l4label);
11286 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11287 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11288 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11289 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11290 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11291 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
11292 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11293 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
11297 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11298 const1 is DW_OP_lit1 or corresponding typed constant):
11300 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11301 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11305 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11306 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11309 static dw_loc_descr_ref
11310 popcount_loc_descriptor (rtx rtl, enum machine_mode mode,
11311 enum machine_mode mem_mode)
11313 dw_loc_descr_ref op0, ret, tmp;
11314 dw_loc_descr_ref l1jump, l1label;
11315 dw_loc_descr_ref l2jump, l2label;
11317 if (GET_MODE_CLASS (mode) != MODE_INT
11318 || GET_MODE (XEXP (rtl, 0)) != mode)
11321 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11322 VAR_INIT_STATUS_INITIALIZED);
11326 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11327 VAR_INIT_STATUS_INITIALIZED);
11330 add_loc_descr (&ret, tmp);
11331 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11332 l1label = new_loc_descr (DW_OP_dup, 0, 0);
11333 add_loc_descr (&ret, l1label);
11334 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11335 add_loc_descr (&ret, l2jump);
11336 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11337 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11338 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11339 VAR_INIT_STATUS_INITIALIZED);
11342 add_loc_descr (&ret, tmp);
11343 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11344 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
11345 ? DW_OP_plus : DW_OP_xor, 0, 0));
11346 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11347 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11348 VAR_INIT_STATUS_INITIALIZED);
11349 add_loc_descr (&ret, tmp);
11350 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11351 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11352 add_loc_descr (&ret, l1jump);
11353 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11354 add_loc_descr (&ret, l2label);
11355 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11356 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11357 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11358 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11362 /* BSWAP (constS is initial shift count, either 56 or 24):
11364 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11365 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11366 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11367 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11368 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11370 static dw_loc_descr_ref
11371 bswap_loc_descriptor (rtx rtl, enum machine_mode mode,
11372 enum machine_mode mem_mode)
11374 dw_loc_descr_ref op0, ret, tmp;
11375 dw_loc_descr_ref l1jump, l1label;
11376 dw_loc_descr_ref l2jump, l2label;
11378 if (GET_MODE_CLASS (mode) != MODE_INT
11379 || BITS_PER_UNIT != 8
11380 || (GET_MODE_BITSIZE (mode) != 32
11381 && GET_MODE_BITSIZE (mode) != 64))
11384 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11385 VAR_INIT_STATUS_INITIALIZED);
11390 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11392 VAR_INIT_STATUS_INITIALIZED);
11395 add_loc_descr (&ret, tmp);
11396 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11397 VAR_INIT_STATUS_INITIALIZED);
11400 add_loc_descr (&ret, tmp);
11401 l1label = new_loc_descr (DW_OP_pick, 2, 0);
11402 add_loc_descr (&ret, l1label);
11403 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11405 VAR_INIT_STATUS_INITIALIZED);
11406 add_loc_descr (&ret, tmp);
11407 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
11408 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11409 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11410 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
11411 VAR_INIT_STATUS_INITIALIZED);
11414 add_loc_descr (&ret, tmp);
11415 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11416 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
11417 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11418 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11419 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11420 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11421 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11422 VAR_INIT_STATUS_INITIALIZED);
11423 add_loc_descr (&ret, tmp);
11424 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
11425 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11426 add_loc_descr (&ret, l2jump);
11427 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
11428 VAR_INIT_STATUS_INITIALIZED);
11429 add_loc_descr (&ret, tmp);
11430 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11431 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11432 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11433 add_loc_descr (&ret, l1jump);
11434 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11435 add_loc_descr (&ret, l2label);
11436 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11437 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11438 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11439 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11440 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11441 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11445 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11446 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11447 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11448 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11450 ROTATERT is similar:
11451 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11452 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11453 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11455 static dw_loc_descr_ref
11456 rotate_loc_descriptor (rtx rtl, enum machine_mode mode,
11457 enum machine_mode mem_mode)
11459 rtx rtlop1 = XEXP (rtl, 1);
11460 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
11463 if (GET_MODE_CLASS (mode) != MODE_INT)
11466 if (GET_MODE (rtlop1) != VOIDmode
11467 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
11468 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11469 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11470 VAR_INIT_STATUS_INITIALIZED);
11471 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11472 VAR_INIT_STATUS_INITIALIZED);
11473 if (op0 == NULL || op1 == NULL)
11475 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11476 for (i = 0; i < 2; i++)
11478 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
11479 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
11481 VAR_INIT_STATUS_INITIALIZED);
11482 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
11483 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11485 : HOST_BITS_PER_WIDE_INT == 64
11486 ? DW_OP_const8u : DW_OP_constu,
11487 GET_MODE_MASK (mode), 0);
11490 if (mask[i] == NULL)
11492 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
11495 add_loc_descr (&ret, op1);
11496 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11497 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11498 if (GET_CODE (rtl) == ROTATERT)
11500 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11501 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11502 GET_MODE_BITSIZE (mode), 0));
11504 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11505 if (mask[0] != NULL)
11506 add_loc_descr (&ret, mask[0]);
11507 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11508 if (mask[1] != NULL)
11510 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11511 add_loc_descr (&ret, mask[1]);
11512 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11514 if (GET_CODE (rtl) == ROTATE)
11516 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11517 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11518 GET_MODE_BITSIZE (mode), 0));
11520 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11521 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11525 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11526 for DEBUG_PARAMETER_REF RTL. */
11528 static dw_loc_descr_ref
11529 parameter_ref_descriptor (rtx rtl)
11531 dw_loc_descr_ref ret;
11536 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
11537 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
11538 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
11541 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11542 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
11543 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
11547 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
11548 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
11553 /* Helper function to get mode of MEM's address. */
11556 get_address_mode (rtx mem)
11558 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
11559 if (mode != VOIDmode)
11561 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
11564 /* The following routine converts the RTL for a variable or parameter
11565 (resident in memory) into an equivalent Dwarf representation of a
11566 mechanism for getting the address of that same variable onto the top of a
11567 hypothetical "address evaluation" stack.
11569 When creating memory location descriptors, we are effectively transforming
11570 the RTL for a memory-resident object into its Dwarf postfix expression
11571 equivalent. This routine recursively descends an RTL tree, turning
11572 it into Dwarf postfix code as it goes.
11574 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11576 MEM_MODE is the mode of the memory reference, needed to handle some
11577 autoincrement addressing modes.
11579 Return 0 if we can't represent the location. */
11582 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11583 enum machine_mode mem_mode,
11584 enum var_init_status initialized)
11586 dw_loc_descr_ref mem_loc_result = NULL;
11587 enum dwarf_location_atom op;
11588 dw_loc_descr_ref op0, op1;
11590 if (mode == VOIDmode)
11591 mode = GET_MODE (rtl);
11593 /* Note that for a dynamically sized array, the location we will generate a
11594 description of here will be the lowest numbered location which is
11595 actually within the array. That's *not* necessarily the same as the
11596 zeroth element of the array. */
11598 rtl = targetm.delegitimize_address (rtl);
11600 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
11603 switch (GET_CODE (rtl))
11608 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
11611 /* The case of a subreg may arise when we have a local (register)
11612 variable or a formal (register) parameter which doesn't quite fill
11613 up an entire register. For now, just assume that it is
11614 legitimate to make the Dwarf info refer to the whole register which
11615 contains the given subreg. */
11616 if (!subreg_lowpart_p (rtl))
11618 if (GET_MODE_CLASS (mode) == MODE_INT
11619 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
11620 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11621 #ifdef POINTERS_EXTEND_UNSIGNED
11622 || (mode == Pmode && mem_mode != VOIDmode)
11625 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
11627 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11628 GET_MODE (SUBREG_REG (rtl)),
11629 mem_mode, initialized);
11634 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11636 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
11637 && (GET_MODE_CLASS (mode) != MODE_INT
11638 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
11642 dw_die_ref type_die;
11643 dw_loc_descr_ref cvt;
11645 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11646 GET_MODE (SUBREG_REG (rtl)),
11647 mem_mode, initialized);
11648 if (mem_loc_result == NULL)
11650 type_die = base_type_for_mode (mode,
11651 GET_MODE_CLASS (mode) == MODE_INT);
11652 if (type_die == NULL)
11654 mem_loc_result = NULL;
11657 if (GET_MODE_SIZE (mode)
11658 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11659 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11661 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
11662 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11663 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11664 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11665 add_loc_descr (&mem_loc_result, cvt);
11670 if (GET_MODE_CLASS (mode) != MODE_INT
11671 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11672 #ifdef POINTERS_EXTEND_UNSIGNED
11673 && (mode != Pmode || mem_mode == VOIDmode)
11677 dw_die_ref type_die;
11681 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
11683 type_die = base_type_for_mode (mode,
11684 GET_MODE_CLASS (mode) == MODE_INT);
11685 if (type_die == NULL)
11687 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
11688 dbx_reg_number (rtl), 0);
11689 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
11690 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
11691 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
11694 /* Whenever a register number forms a part of the description of the
11695 method for calculating the (dynamic) address of a memory resident
11696 object, DWARF rules require the register number be referred to as
11697 a "base register". This distinction is not based in any way upon
11698 what category of register the hardware believes the given register
11699 belongs to. This is strictly DWARF terminology we're dealing with
11700 here. Note that in cases where the location of a memory-resident
11701 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11702 OP_CONST (0)) the actual DWARF location descriptor that we generate
11703 may just be OP_BASEREG (basereg). This may look deceptively like
11704 the object in question was allocated to a register (rather than in
11705 memory) so DWARF consumers need to be aware of the subtle
11706 distinction between OP_REG and OP_BASEREG. */
11707 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
11708 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
11709 else if (stack_realign_drap
11711 && crtl->args.internal_arg_pointer == rtl
11712 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
11714 /* If RTL is internal_arg_pointer, which has been optimized
11715 out, use DRAP instead. */
11716 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
11717 VAR_INIT_STATUS_INITIALIZED);
11723 if (GET_MODE_CLASS (mode) != MODE_INT)
11725 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
11726 mem_mode, VAR_INIT_STATUS_INITIALIZED);
11729 else if (GET_CODE (rtl) == ZERO_EXTEND
11730 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11731 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
11732 < HOST_BITS_PER_WIDE_INT
11733 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11734 to expand zero extend as two shifts instead of
11736 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
11738 enum machine_mode imode = GET_MODE (XEXP (rtl, 0));
11739 mem_loc_result = op0;
11740 add_loc_descr (&mem_loc_result,
11741 int_loc_descriptor (GET_MODE_MASK (imode)));
11742 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
11744 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11746 int shift = DWARF2_ADDR_SIZE
11747 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11748 shift *= BITS_PER_UNIT;
11749 if (GET_CODE (rtl) == SIGN_EXTEND)
11753 mem_loc_result = op0;
11754 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11755 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11756 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11757 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11759 else if (!dwarf_strict)
11761 dw_die_ref type_die1, type_die2;
11762 dw_loc_descr_ref cvt;
11764 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
11765 GET_CODE (rtl) == ZERO_EXTEND);
11766 if (type_die1 == NULL)
11768 type_die2 = base_type_for_mode (mode, 1);
11769 if (type_die2 == NULL)
11771 mem_loc_result = op0;
11772 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11773 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11774 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
11775 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11776 add_loc_descr (&mem_loc_result, cvt);
11777 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11778 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11779 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
11780 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11781 add_loc_descr (&mem_loc_result, cvt);
11787 rtx new_rtl = avoid_constant_pool_reference (rtl);
11788 if (new_rtl != rtl)
11790 mem_loc_result = mem_loc_descriptor (new_rtl, mode, mem_mode,
11792 if (mem_loc_result != NULL)
11793 return mem_loc_result;
11796 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
11797 get_address_mode (rtl), mode,
11798 VAR_INIT_STATUS_INITIALIZED);
11799 if (mem_loc_result == NULL)
11800 mem_loc_result = tls_mem_loc_descriptor (rtl);
11801 if (mem_loc_result != NULL)
11803 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11804 || GET_MODE_CLASS (mode) != MODE_INT)
11806 dw_die_ref type_die;
11807 dw_loc_descr_ref deref;
11812 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
11813 if (type_die == NULL)
11815 deref = new_loc_descr (DW_OP_GNU_deref_type,
11816 GET_MODE_SIZE (mode), 0);
11817 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
11818 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
11819 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
11820 add_loc_descr (&mem_loc_result, deref);
11822 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
11823 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
11825 add_loc_descr (&mem_loc_result,
11826 new_loc_descr (DW_OP_deref_size,
11827 GET_MODE_SIZE (mode), 0));
11832 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
11835 /* Some ports can transform a symbol ref into a label ref, because
11836 the symbol ref is too far away and has to be dumped into a constant
11840 if (GET_MODE_CLASS (mode) != MODE_INT
11841 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11842 #ifdef POINTERS_EXTEND_UNSIGNED
11843 && (mode != Pmode || mem_mode == VOIDmode)
11847 if (GET_CODE (rtl) == SYMBOL_REF
11848 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11850 dw_loc_descr_ref temp;
11852 /* If this is not defined, we have no way to emit the data. */
11853 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
11856 /* We used to emit DW_OP_addr here, but that's wrong, since
11857 DW_OP_addr should be relocated by the debug info consumer,
11858 while DW_OP_GNU_push_tls_address operand should not. */
11859 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
11860 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
11861 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
11862 temp->dw_loc_oprnd1.v.val_addr = rtl;
11863 temp->dtprel = true;
11865 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
11866 add_loc_descr (&mem_loc_result, temp);
11871 if (!const_ok_for_output (rtl))
11875 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
11876 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
11877 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
11878 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11884 case DEBUG_IMPLICIT_PTR:
11885 expansion_failed (NULL_TREE, rtl,
11886 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11892 if (REG_P (ENTRY_VALUE_EXP (rtl)))
11894 if (GET_MODE_CLASS (mode) != MODE_INT
11895 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11896 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
11897 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11900 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
11901 VAR_INIT_STATUS_INITIALIZED);
11903 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
11904 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
11906 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
11907 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11908 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
11912 gcc_unreachable ();
11915 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
11916 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
11917 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
11920 case DEBUG_PARAMETER_REF:
11921 mem_loc_result = parameter_ref_descriptor (rtl);
11925 /* Extract the PLUS expression nested inside and fall into
11926 PLUS code below. */
11927 rtl = XEXP (rtl, 1);
11932 /* Turn these into a PLUS expression and fall into the PLUS code
11934 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
11935 GEN_INT (GET_CODE (rtl) == PRE_INC
11936 ? GET_MODE_UNIT_SIZE (mem_mode)
11937 : -GET_MODE_UNIT_SIZE (mem_mode)));
11939 /* ... fall through ... */
11943 if (is_based_loc (rtl)
11944 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11945 && GET_MODE_CLASS (mode) == MODE_INT)
11946 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
11947 INTVAL (XEXP (rtl, 1)),
11948 VAR_INIT_STATUS_INITIALIZED);
11951 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11952 VAR_INIT_STATUS_INITIALIZED);
11953 if (mem_loc_result == 0)
11956 if (CONST_INT_P (XEXP (rtl, 1))
11957 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11958 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
11961 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11962 VAR_INIT_STATUS_INITIALIZED);
11965 add_loc_descr (&mem_loc_result, op1);
11966 add_loc_descr (&mem_loc_result,
11967 new_loc_descr (DW_OP_plus, 0, 0));
11972 /* If a pseudo-reg is optimized away, it is possible for it to
11973 be replaced with a MEM containing a multiply or shift. */
11984 && GET_MODE_CLASS (mode) == MODE_INT
11985 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11987 mem_loc_result = typed_binop (DW_OP_div, rtl,
11988 base_type_for_mode (mode, 0),
12012 if (GET_MODE_CLASS (mode) != MODE_INT)
12014 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12015 VAR_INIT_STATUS_INITIALIZED);
12017 rtx rtlop1 = XEXP (rtl, 1);
12018 if (GET_MODE (rtlop1) != VOIDmode
12019 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
12020 < GET_MODE_BITSIZE (mode))
12021 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
12022 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
12023 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 (op, 0, 0));
12047 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12048 VAR_INIT_STATUS_INITIALIZED);
12049 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12050 VAR_INIT_STATUS_INITIALIZED);
12052 if (op0 == 0 || op1 == 0)
12055 mem_loc_result = op0;
12056 add_loc_descr (&mem_loc_result, op1);
12057 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12061 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
12063 mem_loc_result = typed_binop (DW_OP_mod, rtl,
12064 base_type_for_mode (mode, 0),
12069 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12070 VAR_INIT_STATUS_INITIALIZED);
12071 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12072 VAR_INIT_STATUS_INITIALIZED);
12074 if (op0 == 0 || op1 == 0)
12077 mem_loc_result = op0;
12078 add_loc_descr (&mem_loc_result, op1);
12079 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
12080 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
12081 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
12082 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
12083 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
12087 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
12089 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
12094 mem_loc_result = typed_binop (DW_OP_div, rtl,
12095 base_type_for_mode (mode, 1),
12113 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12114 VAR_INIT_STATUS_INITIALIZED);
12119 mem_loc_result = op0;
12120 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12124 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12125 #ifdef POINTERS_EXTEND_UNSIGNED
12127 && mem_mode != VOIDmode
12128 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
12132 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
12136 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
12137 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
12139 dw_die_ref type_die = base_type_for_mode (mode, 1);
12140 enum machine_mode amode;
12141 if (type_die == NULL)
12143 amode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
12145 if (INTVAL (rtl) >= 0
12146 && amode != BLKmode
12147 && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
12148 /* const DW_OP_GNU_convert <XXX> vs.
12149 DW_OP_GNU_const_type <XXX, 1, const>. */
12150 && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
12151 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode))
12153 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
12154 op0 = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12155 op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12156 op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12157 op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
12158 add_loc_descr (&mem_loc_result, op0);
12159 return mem_loc_result;
12161 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
12163 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12164 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12165 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
12166 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
12167 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
12170 mem_loc_result->dw_loc_oprnd2.val_class
12171 = dw_val_class_const_double;
12172 mem_loc_result->dw_loc_oprnd2.v.val_double
12173 = shwi_to_double_int (INTVAL (rtl));
12181 dw_die_ref type_die;
12183 /* Note that a CONST_DOUBLE rtx could represent either an integer
12184 or a floating-point constant. A CONST_DOUBLE is used whenever
12185 the constant requires more than one word in order to be
12186 adequately represented. We output CONST_DOUBLEs as blocks. */
12187 if (mode == VOIDmode
12188 || (GET_MODE (rtl) == VOIDmode
12189 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
12191 type_die = base_type_for_mode (mode,
12192 GET_MODE_CLASS (mode) == MODE_INT);
12193 if (type_die == NULL)
12195 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
12196 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12197 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12198 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
12199 if (SCALAR_FLOAT_MODE_P (mode))
12201 unsigned int length = GET_MODE_SIZE (mode);
12202 unsigned char *array
12203 = (unsigned char*) ggc_alloc_atomic (length);
12205 insert_float (rtl, array);
12206 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12207 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12208 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12209 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12213 mem_loc_result->dw_loc_oprnd2.val_class
12214 = dw_val_class_const_double;
12215 mem_loc_result->dw_loc_oprnd2.v.val_double
12216 = rtx_to_double_int (rtl);
12222 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
12226 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12230 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12234 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12238 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12242 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
12246 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12250 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12254 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12258 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12263 if (GET_MODE_CLASS (mode) != MODE_INT)
12268 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
12273 if (CONST_INT_P (XEXP (rtl, 1))
12274 && CONST_INT_P (XEXP (rtl, 2))
12275 && ((unsigned) INTVAL (XEXP (rtl, 1))
12276 + (unsigned) INTVAL (XEXP (rtl, 2))
12277 <= GET_MODE_BITSIZE (mode))
12278 && GET_MODE_CLASS (mode) == MODE_INT
12279 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12280 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
12283 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12284 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12287 if (GET_CODE (rtl) == SIGN_EXTRACT)
12291 mem_loc_result = op0;
12292 size = INTVAL (XEXP (rtl, 1));
12293 shift = INTVAL (XEXP (rtl, 2));
12294 if (BITS_BIG_ENDIAN)
12295 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
12297 if (shift + size != (int) DWARF2_ADDR_SIZE)
12299 add_loc_descr (&mem_loc_result,
12300 int_loc_descriptor (DWARF2_ADDR_SIZE
12302 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
12304 if (size != (int) DWARF2_ADDR_SIZE)
12306 add_loc_descr (&mem_loc_result,
12307 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
12308 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12315 dw_loc_descr_ref op2, bra_node, drop_node;
12316 op0 = mem_loc_descriptor (XEXP (rtl, 0),
12317 GET_MODE (XEXP (rtl, 0)) == VOIDmode
12318 ? word_mode : GET_MODE (XEXP (rtl, 0)),
12319 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12320 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12321 VAR_INIT_STATUS_INITIALIZED);
12322 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
12323 VAR_INIT_STATUS_INITIALIZED);
12324 if (op0 == NULL || op1 == NULL || op2 == NULL)
12327 mem_loc_result = op1;
12328 add_loc_descr (&mem_loc_result, op2);
12329 add_loc_descr (&mem_loc_result, op0);
12330 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12331 add_loc_descr (&mem_loc_result, bra_node);
12332 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
12333 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
12334 add_loc_descr (&mem_loc_result, drop_node);
12335 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12336 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
12341 case FLOAT_TRUNCATE:
12343 case UNSIGNED_FLOAT:
12348 dw_die_ref type_die;
12349 dw_loc_descr_ref cvt;
12351 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12352 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12355 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
12356 && (GET_CODE (rtl) == FLOAT
12357 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
12358 <= DWARF2_ADDR_SIZE))
12360 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12361 GET_CODE (rtl) == UNSIGNED_FLOAT);
12362 if (type_die == NULL)
12364 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12365 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12366 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12367 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12368 add_loc_descr (&op0, cvt);
12370 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
12371 if (type_die == NULL)
12373 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12374 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12375 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12376 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12377 add_loc_descr (&op0, cvt);
12378 if (GET_MODE_CLASS (mode) == MODE_INT
12379 && (GET_CODE (rtl) == FIX
12380 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
12382 op0 = convert_descriptor_to_mode (mode, op0);
12386 mem_loc_result = op0;
12393 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
12398 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
12402 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
12407 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
12412 /* In theory, we could implement the above. */
12413 /* DWARF cannot represent the unsigned compare operations
12438 case FRACT_CONVERT:
12439 case UNSIGNED_FRACT_CONVERT:
12441 case UNSIGNED_SAT_FRACT:
12447 case VEC_DUPLICATE:
12451 case STRICT_LOW_PART:
12455 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12456 can't express it in the debug info. This can happen e.g. with some
12461 resolve_one_addr (&rtl, NULL);
12465 #ifdef ENABLE_CHECKING
12466 print_rtl (stderr, rtl);
12467 gcc_unreachable ();
12473 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12474 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12476 return mem_loc_result;
12479 /* Return a descriptor that describes the concatenation of two locations.
12480 This is typically a complex variable. */
12482 static dw_loc_descr_ref
12483 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
12485 dw_loc_descr_ref cc_loc_result = NULL;
12486 dw_loc_descr_ref x0_ref
12487 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12488 dw_loc_descr_ref x1_ref
12489 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12491 if (x0_ref == 0 || x1_ref == 0)
12494 cc_loc_result = x0_ref;
12495 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
12497 add_loc_descr (&cc_loc_result, x1_ref);
12498 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
12500 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
12501 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12503 return cc_loc_result;
12506 /* Return a descriptor that describes the concatenation of N
12509 static dw_loc_descr_ref
12510 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
12513 dw_loc_descr_ref cc_loc_result = NULL;
12514 unsigned int n = XVECLEN (concatn, 0);
12516 for (i = 0; i < n; ++i)
12518 dw_loc_descr_ref ref;
12519 rtx x = XVECEXP (concatn, 0, i);
12521 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12525 add_loc_descr (&cc_loc_result, ref);
12526 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
12529 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12530 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12532 return cc_loc_result;
12535 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12536 for DEBUG_IMPLICIT_PTR RTL. */
12538 static dw_loc_descr_ref
12539 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
12541 dw_loc_descr_ref ret;
12546 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
12547 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
12548 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
12549 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
12550 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
12551 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
12554 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12555 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
12556 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
12560 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
12561 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
12566 /* Output a proper Dwarf location descriptor for a variable or parameter
12567 which is either allocated in a register or in a memory location. For a
12568 register, we just generate an OP_REG and the register number. For a
12569 memory location we provide a Dwarf postfix expression describing how to
12570 generate the (dynamic) address of the object onto the address stack.
12572 MODE is mode of the decl if this loc_descriptor is going to be used in
12573 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12574 allowed, VOIDmode otherwise.
12576 If we don't know how to describe it, return 0. */
12578 static dw_loc_descr_ref
12579 loc_descriptor (rtx rtl, enum machine_mode mode,
12580 enum var_init_status initialized)
12582 dw_loc_descr_ref loc_result = NULL;
12584 switch (GET_CODE (rtl))
12587 /* The case of a subreg may arise when we have a local (register)
12588 variable or a formal (register) parameter which doesn't quite fill
12589 up an entire register. For now, just assume that it is
12590 legitimate to make the Dwarf info refer to the whole register which
12591 contains the given subreg. */
12592 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
12593 loc_result = loc_descriptor (SUBREG_REG (rtl),
12594 GET_MODE (SUBREG_REG (rtl)), initialized);
12600 loc_result = reg_loc_descriptor (rtl, initialized);
12604 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
12605 GET_MODE (rtl), initialized);
12606 if (loc_result == NULL)
12607 loc_result = tls_mem_loc_descriptor (rtl);
12608 if (loc_result == NULL)
12610 rtx new_rtl = avoid_constant_pool_reference (rtl);
12611 if (new_rtl != rtl)
12612 loc_result = loc_descriptor (new_rtl, mode, initialized);
12617 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
12622 loc_result = concatn_loc_descriptor (rtl, initialized);
12627 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
12629 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
12630 if (GET_CODE (loc) == EXPR_LIST)
12631 loc = XEXP (loc, 0);
12632 loc_result = loc_descriptor (loc, mode, initialized);
12636 rtl = XEXP (rtl, 1);
12641 rtvec par_elems = XVEC (rtl, 0);
12642 int num_elem = GET_NUM_ELEM (par_elems);
12643 enum machine_mode mode;
12646 /* Create the first one, so we have something to add to. */
12647 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
12648 VOIDmode, initialized);
12649 if (loc_result == NULL)
12651 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
12652 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12653 for (i = 1; i < num_elem; i++)
12655 dw_loc_descr_ref temp;
12657 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
12658 VOIDmode, initialized);
12661 add_loc_descr (&loc_result, temp);
12662 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
12663 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12669 if (mode != VOIDmode && mode != BLKmode)
12670 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
12675 if (mode == VOIDmode)
12676 mode = GET_MODE (rtl);
12678 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12680 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12682 /* Note that a CONST_DOUBLE rtx could represent either an integer
12683 or a floating-point constant. A CONST_DOUBLE is used whenever
12684 the constant requires more than one word in order to be
12685 adequately represented. We output CONST_DOUBLEs as blocks. */
12686 loc_result = new_loc_descr (DW_OP_implicit_value,
12687 GET_MODE_SIZE (mode), 0);
12688 if (SCALAR_FLOAT_MODE_P (mode))
12690 unsigned int length = GET_MODE_SIZE (mode);
12691 unsigned char *array
12692 = (unsigned char*) ggc_alloc_atomic (length);
12694 insert_float (rtl, array);
12695 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12696 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12697 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12698 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12702 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
12703 loc_result->dw_loc_oprnd2.v.val_double
12704 = rtx_to_double_int (rtl);
12710 if (mode == VOIDmode)
12711 mode = GET_MODE (rtl);
12713 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12715 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
12716 unsigned int length = CONST_VECTOR_NUNITS (rtl);
12717 unsigned char *array = (unsigned char *)
12718 ggc_alloc_atomic (length * elt_size);
12722 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12723 switch (GET_MODE_CLASS (mode))
12725 case MODE_VECTOR_INT:
12726 for (i = 0, p = array; i < length; i++, p += elt_size)
12728 rtx elt = CONST_VECTOR_ELT (rtl, i);
12729 double_int val = rtx_to_double_int (elt);
12731 if (elt_size <= sizeof (HOST_WIDE_INT))
12732 insert_int (double_int_to_shwi (val), elt_size, p);
12735 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
12736 insert_double (val, p);
12741 case MODE_VECTOR_FLOAT:
12742 for (i = 0, p = array; i < length; i++, p += elt_size)
12744 rtx elt = CONST_VECTOR_ELT (rtl, i);
12745 insert_float (elt, p);
12750 gcc_unreachable ();
12753 loc_result = new_loc_descr (DW_OP_implicit_value,
12754 length * elt_size, 0);
12755 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12756 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
12757 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
12758 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12763 if (mode == VOIDmode
12764 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
12765 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
12766 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
12768 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
12773 if (!const_ok_for_output (rtl))
12776 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
12777 && (dwarf_version >= 4 || !dwarf_strict))
12779 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
12780 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
12781 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
12782 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
12783 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12787 case DEBUG_IMPLICIT_PTR:
12788 loc_result = implicit_ptr_descriptor (rtl, 0);
12792 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
12793 && CONST_INT_P (XEXP (rtl, 1)))
12796 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
12802 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
12803 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
12804 && dwarf_version >= 4)
12805 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
12807 /* Value expression. */
12808 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
12810 add_loc_descr (&loc_result,
12811 new_loc_descr (DW_OP_stack_value, 0, 0));
12819 /* We need to figure out what section we should use as the base for the
12820 address ranges where a given location is valid.
12821 1. If this particular DECL has a section associated with it, use that.
12822 2. If this function has a section associated with it, use that.
12823 3. Otherwise, use the text section.
12824 XXX: If you split a variable across multiple sections, we won't notice. */
12826 static const char *
12827 secname_for_decl (const_tree decl)
12829 const char *secname;
12831 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
12833 tree sectree = DECL_SECTION_NAME (decl);
12834 secname = TREE_STRING_POINTER (sectree);
12836 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
12838 tree sectree = DECL_SECTION_NAME (current_function_decl);
12839 secname = TREE_STRING_POINTER (sectree);
12841 else if (cfun && in_cold_section_p)
12842 secname = crtl->subsections.cold_section_label;
12844 secname = text_section_label;
12849 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12852 decl_by_reference_p (tree decl)
12854 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
12855 || TREE_CODE (decl) == VAR_DECL)
12856 && DECL_BY_REFERENCE (decl));
12859 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12862 static dw_loc_descr_ref
12863 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
12864 enum var_init_status initialized)
12866 int have_address = 0;
12867 dw_loc_descr_ref descr;
12868 enum machine_mode mode;
12870 if (want_address != 2)
12872 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12874 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
12876 varloc = PAT_VAR_LOCATION_LOC (varloc);
12877 if (GET_CODE (varloc) == EXPR_LIST)
12878 varloc = XEXP (varloc, 0);
12879 mode = GET_MODE (varloc);
12880 if (MEM_P (varloc))
12882 rtx addr = XEXP (varloc, 0);
12883 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
12884 mode, initialized);
12889 rtx x = avoid_constant_pool_reference (varloc);
12891 descr = mem_loc_descriptor (x, mode, VOIDmode,
12896 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
12903 if (GET_CODE (varloc) == VAR_LOCATION)
12904 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
12906 mode = DECL_MODE (loc);
12907 descr = loc_descriptor (varloc, mode, initialized);
12914 if (want_address == 2 && !have_address
12915 && (dwarf_version >= 4 || !dwarf_strict))
12917 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
12919 expansion_failed (loc, NULL_RTX,
12920 "DWARF address size mismatch");
12923 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
12926 /* Show if we can't fill the request for an address. */
12927 if (want_address && !have_address)
12929 expansion_failed (loc, NULL_RTX,
12930 "Want address and only have value");
12934 /* If we've got an address and don't want one, dereference. */
12935 if (!want_address && have_address)
12937 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
12938 enum dwarf_location_atom op;
12940 if (size > DWARF2_ADDR_SIZE || size == -1)
12942 expansion_failed (loc, NULL_RTX,
12943 "DWARF address size mismatch");
12946 else if (size == DWARF2_ADDR_SIZE)
12949 op = DW_OP_deref_size;
12951 add_loc_descr (&descr, new_loc_descr (op, size, 0));
12957 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
12958 if it is not possible. */
12960 static dw_loc_descr_ref
12961 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
12963 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
12964 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
12965 else if (dwarf_version >= 3 || !dwarf_strict)
12966 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
12971 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12972 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
12974 static dw_loc_descr_ref
12975 dw_sra_loc_expr (tree decl, rtx loc)
12978 unsigned int padsize = 0;
12979 dw_loc_descr_ref descr, *descr_tail;
12980 unsigned HOST_WIDE_INT decl_size;
12982 enum var_init_status initialized;
12984 if (DECL_SIZE (decl) == NULL
12985 || !host_integerp (DECL_SIZE (decl), 1))
12988 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
12990 descr_tail = &descr;
12992 for (p = loc; p; p = XEXP (p, 1))
12994 unsigned int bitsize = decl_piece_bitsize (p);
12995 rtx loc_note = *decl_piece_varloc_ptr (p);
12996 dw_loc_descr_ref cur_descr;
12997 dw_loc_descr_ref *tail, last = NULL;
12998 unsigned int opsize = 0;
13000 if (loc_note == NULL_RTX
13001 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
13003 padsize += bitsize;
13006 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
13007 varloc = NOTE_VAR_LOCATION (loc_note);
13008 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
13009 if (cur_descr == NULL)
13011 padsize += bitsize;
13015 /* Check that cur_descr either doesn't use
13016 DW_OP_*piece operations, or their sum is equal
13017 to bitsize. Otherwise we can't embed it. */
13018 for (tail = &cur_descr; *tail != NULL;
13019 tail = &(*tail)->dw_loc_next)
13020 if ((*tail)->dw_loc_opc == DW_OP_piece)
13022 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
13026 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
13028 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
13032 if (last != NULL && opsize != bitsize)
13034 padsize += bitsize;
13038 /* If there is a hole, add DW_OP_*piece after empty DWARF
13039 expression, which means that those bits are optimized out. */
13042 if (padsize > decl_size)
13044 decl_size -= padsize;
13045 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
13046 if (*descr_tail == NULL)
13048 descr_tail = &(*descr_tail)->dw_loc_next;
13051 *descr_tail = cur_descr;
13053 if (bitsize > decl_size)
13055 decl_size -= bitsize;
13058 HOST_WIDE_INT offset = 0;
13059 if (GET_CODE (varloc) == VAR_LOCATION
13060 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
13062 varloc = PAT_VAR_LOCATION_LOC (varloc);
13063 if (GET_CODE (varloc) == EXPR_LIST)
13064 varloc = XEXP (varloc, 0);
13068 if (GET_CODE (varloc) == CONST
13069 || GET_CODE (varloc) == SIGN_EXTEND
13070 || GET_CODE (varloc) == ZERO_EXTEND)
13071 varloc = XEXP (varloc, 0);
13072 else if (GET_CODE (varloc) == SUBREG)
13073 varloc = SUBREG_REG (varloc);
13078 /* DW_OP_bit_size offset should be zero for register
13079 or implicit location descriptions and empty location
13080 descriptions, but for memory addresses needs big endian
13082 if (MEM_P (varloc))
13084 unsigned HOST_WIDE_INT memsize
13085 = MEM_SIZE (varloc) * BITS_PER_UNIT;
13086 if (memsize != bitsize)
13088 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
13089 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
13091 if (memsize < bitsize)
13093 if (BITS_BIG_ENDIAN)
13094 offset = memsize - bitsize;
13098 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
13099 if (*descr_tail == NULL)
13101 descr_tail = &(*descr_tail)->dw_loc_next;
13105 /* If there were any non-empty expressions, add padding till the end of
13107 if (descr != NULL && decl_size != 0)
13109 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
13110 if (*descr_tail == NULL)
13116 /* Return the dwarf representation of the location list LOC_LIST of
13117 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13120 static dw_loc_list_ref
13121 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
13123 const char *endname, *secname;
13125 enum var_init_status initialized;
13126 struct var_loc_node *node;
13127 dw_loc_descr_ref descr;
13128 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13129 dw_loc_list_ref list = NULL;
13130 dw_loc_list_ref *listp = &list;
13132 /* Now that we know what section we are using for a base,
13133 actually construct the list of locations.
13134 The first location information is what is passed to the
13135 function that creates the location list, and the remaining
13136 locations just get added on to that list.
13137 Note that we only know the start address for a location
13138 (IE location changes), so to build the range, we use
13139 the range [current location start, next location start].
13140 This means we have to special case the last node, and generate
13141 a range of [last location start, end of function label]. */
13143 secname = secname_for_decl (decl);
13145 for (node = loc_list->first; node; node = node->next)
13146 if (GET_CODE (node->loc) == EXPR_LIST
13147 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
13149 if (GET_CODE (node->loc) == EXPR_LIST)
13151 /* This requires DW_OP_{,bit_}piece, which is not usable
13152 inside DWARF expressions. */
13153 if (want_address != 2)
13155 descr = dw_sra_loc_expr (decl, node->loc);
13161 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
13162 varloc = NOTE_VAR_LOCATION (node->loc);
13163 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
13167 bool range_across_switch = false;
13168 /* If section switch happens in between node->label
13169 and node->next->label (or end of function) and
13170 we can't emit it as a single entry list,
13171 emit two ranges, first one ending at the end
13172 of first partition and second one starting at the
13173 beginning of second partition. */
13174 if (node == loc_list->last_before_switch
13175 && (node != loc_list->first || loc_list->first->next)
13176 && current_function_decl)
13178 endname = cfun->fde->dw_fde_end;
13179 range_across_switch = true;
13181 /* The variable has a location between NODE->LABEL and
13182 NODE->NEXT->LABEL. */
13183 else if (node->next)
13184 endname = node->next->label;
13185 /* If the variable has a location at the last label
13186 it keeps its location until the end of function. */
13187 else if (!current_function_decl)
13188 endname = text_end_label;
13191 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13192 current_function_funcdef_no);
13193 endname = ggc_strdup (label_id);
13196 *listp = new_loc_list (descr, node->label, endname, secname);
13197 if (TREE_CODE (decl) == PARM_DECL
13198 && node == loc_list->first
13199 && GET_CODE (node->loc) == NOTE
13200 && strcmp (node->label, endname) == 0)
13201 (*listp)->force = true;
13202 listp = &(*listp)->dw_loc_next;
13204 if (range_across_switch)
13206 if (GET_CODE (node->loc) == EXPR_LIST)
13207 descr = dw_sra_loc_expr (decl, node->loc);
13210 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
13211 varloc = NOTE_VAR_LOCATION (node->loc);
13212 descr = dw_loc_list_1 (decl, varloc, want_address,
13215 gcc_assert (descr);
13216 /* The variable has a location between NODE->LABEL and
13217 NODE->NEXT->LABEL. */
13219 endname = node->next->label;
13221 endname = cfun->fde->dw_fde_second_end;
13222 *listp = new_loc_list (descr,
13223 cfun->fde->dw_fde_second_begin,
13225 listp = &(*listp)->dw_loc_next;
13230 /* Try to avoid the overhead of a location list emitting a location
13231 expression instead, but only if we didn't have more than one
13232 location entry in the first place. If some entries were not
13233 representable, we don't want to pretend a single entry that was
13234 applies to the entire scope in which the variable is
13236 if (list && loc_list->first->next)
13242 /* Return if the loc_list has only single element and thus can be represented
13243 as location description. */
13246 single_element_loc_list_p (dw_loc_list_ref list)
13248 gcc_assert (!list->dw_loc_next || list->ll_symbol);
13249 return !list->ll_symbol;
13252 /* To each location in list LIST add loc descr REF. */
13255 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
13257 dw_loc_descr_ref copy;
13258 add_loc_descr (&list->expr, ref);
13259 list = list->dw_loc_next;
13262 copy = ggc_alloc_dw_loc_descr_node ();
13263 memcpy (copy, ref, sizeof (dw_loc_descr_node));
13264 add_loc_descr (&list->expr, copy);
13265 while (copy->dw_loc_next)
13267 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
13268 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
13269 copy->dw_loc_next = new_copy;
13272 list = list->dw_loc_next;
13276 /* Given two lists RET and LIST
13277 produce location list that is result of adding expression in LIST
13278 to expression in RET on each possition in program.
13279 Might be destructive on both RET and LIST.
13281 TODO: We handle only simple cases of RET or LIST having at most one
13282 element. General case would inolve sorting the lists in program order
13283 and merging them that will need some additional work.
13284 Adding that will improve quality of debug info especially for SRA-ed
13288 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
13297 if (!list->dw_loc_next)
13299 add_loc_descr_to_each (*ret, list->expr);
13302 if (!(*ret)->dw_loc_next)
13304 add_loc_descr_to_each (list, (*ret)->expr);
13308 expansion_failed (NULL_TREE, NULL_RTX,
13309 "Don't know how to merge two non-trivial"
13310 " location lists.\n");
13315 /* LOC is constant expression. Try a luck, look it up in constant
13316 pool and return its loc_descr of its address. */
13318 static dw_loc_descr_ref
13319 cst_pool_loc_descr (tree loc)
13321 /* Get an RTL for this, if something has been emitted. */
13322 rtx rtl = lookup_constant_def (loc);
13324 if (!rtl || !MEM_P (rtl))
13329 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
13331 /* TODO: We might get more coverage if we was actually delaying expansion
13332 of all expressions till end of compilation when constant pools are fully
13334 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
13336 expansion_failed (loc, NULL_RTX,
13337 "CST value in contant pool but not marked.");
13340 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
13341 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
13344 /* Return dw_loc_list representing address of addr_expr LOC
13345 by looking for innder INDIRECT_REF expression and turing it
13346 into simple arithmetics. */
13348 static dw_loc_list_ref
13349 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
13352 HOST_WIDE_INT bitsize, bitpos, bytepos;
13353 enum machine_mode mode;
13355 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13356 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13358 obj = get_inner_reference (TREE_OPERAND (loc, 0),
13359 &bitsize, &bitpos, &offset, &mode,
13360 &unsignedp, &volatilep, false);
13362 if (bitpos % BITS_PER_UNIT)
13364 expansion_failed (loc, NULL_RTX, "bitfield access");
13367 if (!INDIRECT_REF_P (obj))
13369 expansion_failed (obj,
13370 NULL_RTX, "no indirect ref in inner refrence");
13373 if (!offset && !bitpos)
13374 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
13376 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
13377 && (dwarf_version >= 4 || !dwarf_strict))
13379 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
13384 /* Variable offset. */
13385 list_ret1 = loc_list_from_tree (offset, 0);
13386 if (list_ret1 == 0)
13388 add_loc_list (&list_ret, list_ret1);
13391 add_loc_descr_to_each (list_ret,
13392 new_loc_descr (DW_OP_plus, 0, 0));
13394 bytepos = bitpos / BITS_PER_UNIT;
13396 add_loc_descr_to_each (list_ret,
13397 new_loc_descr (DW_OP_plus_uconst,
13399 else if (bytepos < 0)
13400 loc_list_plus_const (list_ret, bytepos);
13401 add_loc_descr_to_each (list_ret,
13402 new_loc_descr (DW_OP_stack_value, 0, 0));
13408 /* Generate Dwarf location list representing LOC.
13409 If WANT_ADDRESS is false, expression computing LOC will be computed
13410 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13411 if WANT_ADDRESS is 2, expression computing address useable in location
13412 will be returned (i.e. DW_OP_reg can be used
13413 to refer to register values). */
13415 static dw_loc_list_ref
13416 loc_list_from_tree (tree loc, int want_address)
13418 dw_loc_descr_ref ret = NULL, ret1 = NULL;
13419 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13420 int have_address = 0;
13421 enum dwarf_location_atom op;
13423 /* ??? Most of the time we do not take proper care for sign/zero
13424 extending the values properly. Hopefully this won't be a real
13427 switch (TREE_CODE (loc))
13430 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
13433 case PLACEHOLDER_EXPR:
13434 /* This case involves extracting fields from an object to determine the
13435 position of other fields. We don't try to encode this here. The
13436 only user of this is Ada, which encodes the needed information using
13437 the names of types. */
13438 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
13442 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
13443 /* There are no opcodes for these operations. */
13446 case PREINCREMENT_EXPR:
13447 case PREDECREMENT_EXPR:
13448 case POSTINCREMENT_EXPR:
13449 case POSTDECREMENT_EXPR:
13450 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
13451 /* There are no opcodes for these operations. */
13455 /* If we already want an address, see if there is INDIRECT_REF inside
13456 e.g. for &this->field. */
13459 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
13460 (loc, want_address == 2);
13463 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
13464 && (ret = cst_pool_loc_descr (loc)))
13467 /* Otherwise, process the argument and look for the address. */
13468 if (!list_ret && !ret)
13469 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
13473 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
13479 if (DECL_THREAD_LOCAL_P (loc))
13482 enum dwarf_location_atom first_op;
13483 enum dwarf_location_atom second_op;
13484 bool dtprel = false;
13486 if (targetm.have_tls)
13488 /* If this is not defined, we have no way to emit the
13490 if (!targetm.asm_out.output_dwarf_dtprel)
13493 /* The way DW_OP_GNU_push_tls_address is specified, we
13494 can only look up addresses of objects in the current
13495 module. We used DW_OP_addr as first op, but that's
13496 wrong, because DW_OP_addr is relocated by the debug
13497 info consumer, while DW_OP_GNU_push_tls_address
13498 operand shouldn't be. */
13499 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
13501 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
13503 second_op = DW_OP_GNU_push_tls_address;
13507 if (!targetm.emutls.debug_form_tls_address
13508 || !(dwarf_version >= 3 || !dwarf_strict))
13510 /* We stuffed the control variable into the DECL_VALUE_EXPR
13511 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13512 no longer appear in gimple code. We used the control
13513 variable in specific so that we could pick it up here. */
13514 loc = DECL_VALUE_EXPR (loc);
13515 first_op = DW_OP_addr;
13516 second_op = DW_OP_form_tls_address;
13519 rtl = rtl_for_decl_location (loc);
13520 if (rtl == NULL_RTX)
13525 rtl = XEXP (rtl, 0);
13526 if (! CONSTANT_P (rtl))
13529 ret = new_loc_descr (first_op, 0, 0);
13530 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13531 ret->dw_loc_oprnd1.v.val_addr = rtl;
13532 ret->dtprel = dtprel;
13534 ret1 = new_loc_descr (second_op, 0, 0);
13535 add_loc_descr (&ret, ret1);
13544 if (DECL_HAS_VALUE_EXPR_P (loc))
13545 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
13549 case FUNCTION_DECL:
13552 var_loc_list *loc_list = lookup_decl_loc (loc);
13554 if (loc_list && loc_list->first)
13556 list_ret = dw_loc_list (loc_list, loc, want_address);
13557 have_address = want_address != 0;
13560 rtl = rtl_for_decl_location (loc);
13561 if (rtl == NULL_RTX)
13563 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
13566 else if (CONST_INT_P (rtl))
13568 HOST_WIDE_INT val = INTVAL (rtl);
13569 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13570 val &= GET_MODE_MASK (DECL_MODE (loc));
13571 ret = int_loc_descriptor (val);
13573 else if (GET_CODE (rtl) == CONST_STRING)
13575 expansion_failed (loc, NULL_RTX, "CONST_STRING");
13578 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
13580 ret = new_loc_descr (DW_OP_addr, 0, 0);
13581 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13582 ret->dw_loc_oprnd1.v.val_addr = rtl;
13586 enum machine_mode mode, mem_mode;
13588 /* Certain constructs can only be represented at top-level. */
13589 if (want_address == 2)
13591 ret = loc_descriptor (rtl, VOIDmode,
13592 VAR_INIT_STATUS_INITIALIZED);
13597 mode = GET_MODE (rtl);
13598 mem_mode = VOIDmode;
13602 mode = get_address_mode (rtl);
13603 rtl = XEXP (rtl, 0);
13606 ret = mem_loc_descriptor (rtl, mode, mem_mode,
13607 VAR_INIT_STATUS_INITIALIZED);
13610 expansion_failed (loc, rtl,
13611 "failed to produce loc descriptor for rtl");
13618 if (!integer_zerop (TREE_OPERAND (loc, 1)))
13622 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13626 case COMPOUND_EXPR:
13627 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
13630 case VIEW_CONVERT_EXPR:
13633 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
13635 case COMPONENT_REF:
13636 case BIT_FIELD_REF:
13638 case ARRAY_RANGE_REF:
13639 case REALPART_EXPR:
13640 case IMAGPART_EXPR:
13643 HOST_WIDE_INT bitsize, bitpos, bytepos;
13644 enum machine_mode mode;
13646 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13648 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
13649 &unsignedp, &volatilep, false);
13651 gcc_assert (obj != loc);
13653 list_ret = loc_list_from_tree (obj,
13655 && !bitpos && !offset ? 2 : 1);
13656 /* TODO: We can extract value of the small expression via shifting even
13657 for nonzero bitpos. */
13660 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
13662 expansion_failed (loc, NULL_RTX,
13663 "bitfield access");
13667 if (offset != NULL_TREE)
13669 /* Variable offset. */
13670 list_ret1 = loc_list_from_tree (offset, 0);
13671 if (list_ret1 == 0)
13673 add_loc_list (&list_ret, list_ret1);
13676 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
13679 bytepos = bitpos / BITS_PER_UNIT;
13681 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
13682 else if (bytepos < 0)
13683 loc_list_plus_const (list_ret, bytepos);
13690 if ((want_address || !host_integerp (loc, 0))
13691 && (ret = cst_pool_loc_descr (loc)))
13693 else if (want_address == 2
13694 && host_integerp (loc, 0)
13695 && (ret = address_of_int_loc_descriptor
13696 (int_size_in_bytes (TREE_TYPE (loc)),
13697 tree_low_cst (loc, 0))))
13699 else if (host_integerp (loc, 0))
13700 ret = int_loc_descriptor (tree_low_cst (loc, 0));
13703 expansion_failed (loc, NULL_RTX,
13704 "Integer operand is not host integer");
13713 if ((ret = cst_pool_loc_descr (loc)))
13716 /* We can construct small constants here using int_loc_descriptor. */
13717 expansion_failed (loc, NULL_RTX,
13718 "constructor or constant not in constant pool");
13721 case TRUTH_AND_EXPR:
13722 case TRUTH_ANDIF_EXPR:
13727 case TRUTH_XOR_EXPR:
13732 case TRUTH_OR_EXPR:
13733 case TRUTH_ORIF_EXPR:
13738 case FLOOR_DIV_EXPR:
13739 case CEIL_DIV_EXPR:
13740 case ROUND_DIV_EXPR:
13741 case TRUNC_DIV_EXPR:
13742 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13751 case FLOOR_MOD_EXPR:
13752 case CEIL_MOD_EXPR:
13753 case ROUND_MOD_EXPR:
13754 case TRUNC_MOD_EXPR:
13755 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13760 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13761 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
13762 if (list_ret == 0 || list_ret1 == 0)
13765 add_loc_list (&list_ret, list_ret1);
13768 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
13769 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
13770 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
13771 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
13772 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
13784 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
13787 case POINTER_PLUS_EXPR:
13789 if (host_integerp (TREE_OPERAND (loc, 1), 0))
13791 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13795 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
13803 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13810 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13817 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13824 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13839 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13840 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
13841 if (list_ret == 0 || list_ret1 == 0)
13844 add_loc_list (&list_ret, list_ret1);
13847 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
13850 case TRUTH_NOT_EXPR:
13864 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13868 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
13874 const enum tree_code code =
13875 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
13877 loc = build3 (COND_EXPR, TREE_TYPE (loc),
13878 build2 (code, integer_type_node,
13879 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
13880 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
13883 /* ... fall through ... */
13887 dw_loc_descr_ref lhs
13888 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
13889 dw_loc_list_ref rhs
13890 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
13891 dw_loc_descr_ref bra_node, jump_node, tmp;
13893 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13894 if (list_ret == 0 || lhs == 0 || rhs == 0)
13897 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
13898 add_loc_descr_to_each (list_ret, bra_node);
13900 add_loc_list (&list_ret, rhs);
13901 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
13902 add_loc_descr_to_each (list_ret, jump_node);
13904 add_loc_descr_to_each (list_ret, lhs);
13905 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13906 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
13908 /* ??? Need a node to point the skip at. Use a nop. */
13909 tmp = new_loc_descr (DW_OP_nop, 0, 0);
13910 add_loc_descr_to_each (list_ret, tmp);
13911 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13912 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
13916 case FIX_TRUNC_EXPR:
13920 /* Leave front-end specific codes as simply unknown. This comes
13921 up, for instance, with the C STMT_EXPR. */
13922 if ((unsigned int) TREE_CODE (loc)
13923 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
13925 expansion_failed (loc, NULL_RTX,
13926 "language specific tree node");
13930 #ifdef ENABLE_CHECKING
13931 /* Otherwise this is a generic code; we should just lists all of
13932 these explicitly. We forgot one. */
13933 gcc_unreachable ();
13935 /* In a release build, we want to degrade gracefully: better to
13936 generate incomplete debugging information than to crash. */
13941 if (!ret && !list_ret)
13944 if (want_address == 2 && !have_address
13945 && (dwarf_version >= 4 || !dwarf_strict))
13947 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
13949 expansion_failed (loc, NULL_RTX,
13950 "DWARF address size mismatch");
13954 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
13956 add_loc_descr_to_each (list_ret,
13957 new_loc_descr (DW_OP_stack_value, 0, 0));
13960 /* Show if we can't fill the request for an address. */
13961 if (want_address && !have_address)
13963 expansion_failed (loc, NULL_RTX,
13964 "Want address and only have value");
13968 gcc_assert (!ret || !list_ret);
13970 /* If we've got an address and don't want one, dereference. */
13971 if (!want_address && have_address)
13973 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
13975 if (size > DWARF2_ADDR_SIZE || size == -1)
13977 expansion_failed (loc, NULL_RTX,
13978 "DWARF address size mismatch");
13981 else if (size == DWARF2_ADDR_SIZE)
13984 op = DW_OP_deref_size;
13987 add_loc_descr (&ret, new_loc_descr (op, size, 0));
13989 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
13992 list_ret = new_loc_list (ret, NULL, NULL, NULL);
13997 /* Same as above but return only single location expression. */
13998 static dw_loc_descr_ref
13999 loc_descriptor_from_tree (tree loc, int want_address)
14001 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
14004 if (ret->dw_loc_next)
14006 expansion_failed (loc, NULL_RTX,
14007 "Location list where only loc descriptor needed");
14013 /* Given a value, round it up to the lowest multiple of `boundary'
14014 which is not less than the value itself. */
14016 static inline HOST_WIDE_INT
14017 ceiling (HOST_WIDE_INT value, unsigned int boundary)
14019 return (((value + boundary - 1) / boundary) * boundary);
14022 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14023 pointer to the declared type for the relevant field variable, or return
14024 `integer_type_node' if the given node turns out to be an
14025 ERROR_MARK node. */
14028 field_type (const_tree decl)
14032 if (TREE_CODE (decl) == ERROR_MARK)
14033 return integer_type_node;
14035 type = DECL_BIT_FIELD_TYPE (decl);
14036 if (type == NULL_TREE)
14037 type = TREE_TYPE (decl);
14042 /* Given a pointer to a tree node, return the alignment in bits for
14043 it, or else return BITS_PER_WORD if the node actually turns out to
14044 be an ERROR_MARK node. */
14046 static inline unsigned
14047 simple_type_align_in_bits (const_tree type)
14049 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
14052 static inline unsigned
14053 simple_decl_align_in_bits (const_tree decl)
14055 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
14058 /* Return the result of rounding T up to ALIGN. */
14060 static inline double_int
14061 round_up_to_align (double_int t, unsigned int align)
14063 double_int alignd = uhwi_to_double_int (align);
14064 t = double_int_add (t, alignd);
14065 t = double_int_add (t, double_int_minus_one);
14066 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
14067 t = double_int_mul (t, alignd);
14071 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14072 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14073 or return 0 if we are unable to determine what that offset is, either
14074 because the argument turns out to be a pointer to an ERROR_MARK node, or
14075 because the offset is actually variable. (We can't handle the latter case
14078 static HOST_WIDE_INT
14079 field_byte_offset (const_tree decl)
14081 double_int object_offset_in_bits;
14082 double_int object_offset_in_bytes;
14083 double_int bitpos_int;
14085 if (TREE_CODE (decl) == ERROR_MARK)
14088 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
14090 /* We cannot yet cope with fields whose positions are variable, so
14091 for now, when we see such things, we simply return 0. Someday, we may
14092 be able to handle such cases, but it will be damn difficult. */
14093 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
14096 bitpos_int = tree_to_double_int (bit_position (decl));
14098 #ifdef PCC_BITFIELD_TYPE_MATTERS
14099 if (PCC_BITFIELD_TYPE_MATTERS)
14102 tree field_size_tree;
14103 double_int deepest_bitpos;
14104 double_int field_size_in_bits;
14105 unsigned int type_align_in_bits;
14106 unsigned int decl_align_in_bits;
14107 double_int type_size_in_bits;
14109 type = field_type (decl);
14110 type_size_in_bits = double_int_type_size_in_bits (type);
14111 type_align_in_bits = simple_type_align_in_bits (type);
14113 field_size_tree = DECL_SIZE (decl);
14115 /* The size could be unspecified if there was an error, or for
14116 a flexible array member. */
14117 if (!field_size_tree)
14118 field_size_tree = bitsize_zero_node;
14120 /* If the size of the field is not constant, use the type size. */
14121 if (TREE_CODE (field_size_tree) == INTEGER_CST)
14122 field_size_in_bits = tree_to_double_int (field_size_tree);
14124 field_size_in_bits = type_size_in_bits;
14126 decl_align_in_bits = simple_decl_align_in_bits (decl);
14128 /* The GCC front-end doesn't make any attempt to keep track of the
14129 starting bit offset (relative to the start of the containing
14130 structure type) of the hypothetical "containing object" for a
14131 bit-field. Thus, when computing the byte offset value for the
14132 start of the "containing object" of a bit-field, we must deduce
14133 this information on our own. This can be rather tricky to do in
14134 some cases. For example, handling the following structure type
14135 definition when compiling for an i386/i486 target (which only
14136 aligns long long's to 32-bit boundaries) can be very tricky:
14138 struct S { int field1; long long field2:31; };
14140 Fortunately, there is a simple rule-of-thumb which can be used
14141 in such cases. When compiling for an i386/i486, GCC will
14142 allocate 8 bytes for the structure shown above. It decides to
14143 do this based upon one simple rule for bit-field allocation.
14144 GCC allocates each "containing object" for each bit-field at
14145 the first (i.e. lowest addressed) legitimate alignment boundary
14146 (based upon the required minimum alignment for the declared
14147 type of the field) which it can possibly use, subject to the
14148 condition that there is still enough available space remaining
14149 in the containing object (when allocated at the selected point)
14150 to fully accommodate all of the bits of the bit-field itself.
14152 This simple rule makes it obvious why GCC allocates 8 bytes for
14153 each object of the structure type shown above. When looking
14154 for a place to allocate the "containing object" for `field2',
14155 the compiler simply tries to allocate a 64-bit "containing
14156 object" at each successive 32-bit boundary (starting at zero)
14157 until it finds a place to allocate that 64- bit field such that
14158 at least 31 contiguous (and previously unallocated) bits remain
14159 within that selected 64 bit field. (As it turns out, for the
14160 example above, the compiler finds it is OK to allocate the
14161 "containing object" 64-bit field at bit-offset zero within the
14164 Here we attempt to work backwards from the limited set of facts
14165 we're given, and we try to deduce from those facts, where GCC
14166 must have believed that the containing object started (within
14167 the structure type). The value we deduce is then used (by the
14168 callers of this routine) to generate DW_AT_location and
14169 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14170 the case of DW_AT_location, regular fields as well). */
14172 /* Figure out the bit-distance from the start of the structure to
14173 the "deepest" bit of the bit-field. */
14174 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
14176 /* This is the tricky part. Use some fancy footwork to deduce
14177 where the lowest addressed bit of the containing object must
14179 object_offset_in_bits
14180 = double_int_sub (deepest_bitpos, type_size_in_bits);
14182 /* Round up to type_align by default. This works best for
14184 object_offset_in_bits
14185 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
14187 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
14189 object_offset_in_bits
14190 = double_int_sub (deepest_bitpos, type_size_in_bits);
14192 /* Round up to decl_align instead. */
14193 object_offset_in_bits
14194 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
14198 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14199 object_offset_in_bits = bitpos_int;
14201 object_offset_in_bytes
14202 = double_int_div (object_offset_in_bits,
14203 uhwi_to_double_int (BITS_PER_UNIT), true,
14205 return double_int_to_shwi (object_offset_in_bytes);
14208 /* The following routines define various Dwarf attributes and any data
14209 associated with them. */
14211 /* Add a location description attribute value to a DIE.
14213 This emits location attributes suitable for whole variables and
14214 whole parameters. Note that the location attributes for struct fields are
14215 generated by the routine `data_member_location_attribute' below. */
14218 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
14219 dw_loc_list_ref descr)
14223 if (single_element_loc_list_p (descr))
14224 add_AT_loc (die, attr_kind, descr->expr);
14226 add_AT_loc_list (die, attr_kind, descr);
14229 /* Add DW_AT_accessibility attribute to DIE if needed. */
14232 add_accessibility_attribute (dw_die_ref die, tree decl)
14234 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14235 children, otherwise the default is DW_ACCESS_public. In DWARF2
14236 the default has always been DW_ACCESS_public. */
14237 if (TREE_PROTECTED (decl))
14238 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14239 else if (TREE_PRIVATE (decl))
14241 if (dwarf_version == 2
14242 || die->die_parent == NULL
14243 || die->die_parent->die_tag != DW_TAG_class_type)
14244 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
14246 else if (dwarf_version > 2
14248 && die->die_parent->die_tag == DW_TAG_class_type)
14249 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14252 /* Attach the specialized form of location attribute used for data members of
14253 struct and union types. In the special case of a FIELD_DECL node which
14254 represents a bit-field, the "offset" part of this special location
14255 descriptor must indicate the distance in bytes from the lowest-addressed
14256 byte of the containing struct or union type to the lowest-addressed byte of
14257 the "containing object" for the bit-field. (See the `field_byte_offset'
14260 For any given bit-field, the "containing object" is a hypothetical object
14261 (of some integral or enum type) within which the given bit-field lives. The
14262 type of this hypothetical "containing object" is always the same as the
14263 declared type of the individual bit-field itself (for GCC anyway... the
14264 DWARF spec doesn't actually mandate this). Note that it is the size (in
14265 bytes) of the hypothetical "containing object" which will be given in the
14266 DW_AT_byte_size attribute for this bit-field. (See the
14267 `byte_size_attribute' function below.) It is also used when calculating the
14268 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14269 function below.) */
14272 add_data_member_location_attribute (dw_die_ref die, tree decl)
14274 HOST_WIDE_INT offset;
14275 dw_loc_descr_ref loc_descr = 0;
14277 if (TREE_CODE (decl) == TREE_BINFO)
14279 /* We're working on the TAG_inheritance for a base class. */
14280 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
14282 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14283 aren't at a fixed offset from all (sub)objects of the same
14284 type. We need to extract the appropriate offset from our
14285 vtable. The following dwarf expression means
14287 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14289 This is specific to the V3 ABI, of course. */
14291 dw_loc_descr_ref tmp;
14293 /* Make a copy of the object address. */
14294 tmp = new_loc_descr (DW_OP_dup, 0, 0);
14295 add_loc_descr (&loc_descr, tmp);
14297 /* Extract the vtable address. */
14298 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14299 add_loc_descr (&loc_descr, tmp);
14301 /* Calculate the address of the offset. */
14302 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
14303 gcc_assert (offset < 0);
14305 tmp = int_loc_descriptor (-offset);
14306 add_loc_descr (&loc_descr, tmp);
14307 tmp = new_loc_descr (DW_OP_minus, 0, 0);
14308 add_loc_descr (&loc_descr, tmp);
14310 /* Extract the offset. */
14311 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14312 add_loc_descr (&loc_descr, tmp);
14314 /* Add it to the object address. */
14315 tmp = new_loc_descr (DW_OP_plus, 0, 0);
14316 add_loc_descr (&loc_descr, tmp);
14319 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
14322 offset = field_byte_offset (decl);
14326 if (dwarf_version > 2)
14328 /* Don't need to output a location expression, just the constant. */
14330 add_AT_int (die, DW_AT_data_member_location, offset);
14332 add_AT_unsigned (die, DW_AT_data_member_location, offset);
14337 enum dwarf_location_atom op;
14339 /* The DWARF2 standard says that we should assume that the structure
14340 address is already on the stack, so we can specify a structure
14341 field address by using DW_OP_plus_uconst. */
14343 #ifdef MIPS_DEBUGGING_INFO
14344 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
14345 operator correctly. It works only if we leave the offset on the
14349 op = DW_OP_plus_uconst;
14352 loc_descr = new_loc_descr (op, offset, 0);
14356 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
14359 /* Writes integer values to dw_vec_const array. */
14362 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
14366 *dest++ = val & 0xff;
14372 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14374 static HOST_WIDE_INT
14375 extract_int (const unsigned char *src, unsigned int size)
14377 HOST_WIDE_INT val = 0;
14383 val |= *--src & 0xff;
14389 /* Writes double_int values to dw_vec_const array. */
14392 insert_double (double_int val, unsigned char *dest)
14394 unsigned char *p0 = dest;
14395 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
14397 if (WORDS_BIG_ENDIAN)
14403 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
14404 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
14407 /* Writes floating point values to dw_vec_const array. */
14410 insert_float (const_rtx rtl, unsigned char *array)
14412 REAL_VALUE_TYPE rv;
14416 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
14417 real_to_target (val, &rv, GET_MODE (rtl));
14419 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14420 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
14422 insert_int (val[i], 4, array);
14427 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14428 does not have a "location" either in memory or in a register. These
14429 things can arise in GNU C when a constant is passed as an actual parameter
14430 to an inlined function. They can also arise in C++ where declared
14431 constants do not necessarily get memory "homes". */
14434 add_const_value_attribute (dw_die_ref die, rtx rtl)
14436 switch (GET_CODE (rtl))
14440 HOST_WIDE_INT val = INTVAL (rtl);
14443 add_AT_int (die, DW_AT_const_value, val);
14445 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
14450 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14451 floating-point constant. A CONST_DOUBLE is used whenever the
14452 constant requires more than one word in order to be adequately
14455 enum machine_mode mode = GET_MODE (rtl);
14457 if (SCALAR_FLOAT_MODE_P (mode))
14459 unsigned int length = GET_MODE_SIZE (mode);
14460 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
14462 insert_float (rtl, array);
14463 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
14466 add_AT_double (die, DW_AT_const_value,
14467 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
14473 enum machine_mode mode = GET_MODE (rtl);
14474 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
14475 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14476 unsigned char *array = (unsigned char *) ggc_alloc_atomic
14477 (length * elt_size);
14481 switch (GET_MODE_CLASS (mode))
14483 case MODE_VECTOR_INT:
14484 for (i = 0, p = array; i < length; i++, p += elt_size)
14486 rtx elt = CONST_VECTOR_ELT (rtl, i);
14487 double_int val = rtx_to_double_int (elt);
14489 if (elt_size <= sizeof (HOST_WIDE_INT))
14490 insert_int (double_int_to_shwi (val), elt_size, p);
14493 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14494 insert_double (val, p);
14499 case MODE_VECTOR_FLOAT:
14500 for (i = 0, p = array; i < length; i++, p += elt_size)
14502 rtx elt = CONST_VECTOR_ELT (rtl, i);
14503 insert_float (elt, p);
14508 gcc_unreachable ();
14511 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
14516 if (dwarf_version >= 4 || !dwarf_strict)
14518 dw_loc_descr_ref loc_result;
14519 resolve_one_addr (&rtl, NULL);
14521 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14522 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14523 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14524 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14525 add_AT_loc (die, DW_AT_location, loc_result);
14526 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14532 if (CONSTANT_P (XEXP (rtl, 0)))
14533 return add_const_value_attribute (die, XEXP (rtl, 0));
14536 if (!const_ok_for_output (rtl))
14539 if (dwarf_version >= 4 || !dwarf_strict)
14544 /* In cases where an inlined instance of an inline function is passed
14545 the address of an `auto' variable (which is local to the caller) we
14546 can get a situation where the DECL_RTL of the artificial local
14547 variable (for the inlining) which acts as a stand-in for the
14548 corresponding formal parameter (of the inline function) will look
14549 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14550 exactly a compile-time constant expression, but it isn't the address
14551 of the (artificial) local variable either. Rather, it represents the
14552 *value* which the artificial local variable always has during its
14553 lifetime. We currently have no way to represent such quasi-constant
14554 values in Dwarf, so for now we just punt and generate nothing. */
14562 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
14563 && MEM_READONLY_P (rtl)
14564 && GET_MODE (rtl) == BLKmode)
14566 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
14572 /* No other kinds of rtx should be possible here. */
14573 gcc_unreachable ();
14578 /* Determine whether the evaluation of EXPR references any variables
14579 or functions which aren't otherwise used (and therefore may not be
14582 reference_to_unused (tree * tp, int * walk_subtrees,
14583 void * data ATTRIBUTE_UNUSED)
14585 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
14586 *walk_subtrees = 0;
14588 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
14589 && ! TREE_ASM_WRITTEN (*tp))
14591 /* ??? The C++ FE emits debug information for using decls, so
14592 putting gcc_unreachable here falls over. See PR31899. For now
14593 be conservative. */
14594 else if (!cgraph_global_info_ready
14595 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
14597 else if (TREE_CODE (*tp) == VAR_DECL)
14599 struct varpool_node *node = varpool_get_node (*tp);
14600 if (!node || !node->needed)
14603 else if (TREE_CODE (*tp) == FUNCTION_DECL
14604 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
14606 /* The call graph machinery must have finished analyzing,
14607 optimizing and gimplifying the CU by now.
14608 So if *TP has no call graph node associated
14609 to it, it means *TP will not be emitted. */
14610 if (!cgraph_get_node (*tp))
14613 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
14619 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14620 for use in a later add_const_value_attribute call. */
14623 rtl_for_decl_init (tree init, tree type)
14625 rtx rtl = NULL_RTX;
14629 /* If a variable is initialized with a string constant without embedded
14630 zeros, build CONST_STRING. */
14631 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
14633 tree enttype = TREE_TYPE (type);
14634 tree domain = TYPE_DOMAIN (type);
14635 enum machine_mode mode = TYPE_MODE (enttype);
14637 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
14639 && integer_zerop (TYPE_MIN_VALUE (domain))
14640 && compare_tree_int (TYPE_MAX_VALUE (domain),
14641 TREE_STRING_LENGTH (init) - 1) == 0
14642 && ((size_t) TREE_STRING_LENGTH (init)
14643 == strlen (TREE_STRING_POINTER (init)) + 1))
14645 rtl = gen_rtx_CONST_STRING (VOIDmode,
14646 ggc_strdup (TREE_STRING_POINTER (init)));
14647 rtl = gen_rtx_MEM (BLKmode, rtl);
14648 MEM_READONLY_P (rtl) = 1;
14651 /* Other aggregates, and complex values, could be represented using
14653 else if (AGGREGATE_TYPE_P (type)
14654 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
14655 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
14656 || TREE_CODE (type) == COMPLEX_TYPE)
14658 /* Vectors only work if their mode is supported by the target.
14659 FIXME: generic vectors ought to work too. */
14660 else if (TREE_CODE (type) == VECTOR_TYPE
14661 && !VECTOR_MODE_P (TYPE_MODE (type)))
14663 /* If the initializer is something that we know will expand into an
14664 immediate RTL constant, expand it now. We must be careful not to
14665 reference variables which won't be output. */
14666 else if (initializer_constant_valid_p (init, type)
14667 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
14669 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14671 if (TREE_CODE (type) == VECTOR_TYPE)
14672 switch (TREE_CODE (init))
14677 if (TREE_CONSTANT (init))
14679 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
14680 bool constant_p = true;
14682 unsigned HOST_WIDE_INT ix;
14684 /* Even when ctor is constant, it might contain non-*_CST
14685 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14686 belong into VECTOR_CST nodes. */
14687 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
14688 if (!CONSTANT_CLASS_P (value))
14690 constant_p = false;
14696 init = build_vector_from_ctor (type, elts);
14706 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
14708 /* If expand_expr returns a MEM, it wasn't immediate. */
14709 gcc_assert (!rtl || !MEM_P (rtl));
14715 /* Generate RTL for the variable DECL to represent its location. */
14718 rtl_for_decl_location (tree decl)
14722 /* Here we have to decide where we are going to say the parameter "lives"
14723 (as far as the debugger is concerned). We only have a couple of
14724 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14726 DECL_RTL normally indicates where the parameter lives during most of the
14727 activation of the function. If optimization is enabled however, this
14728 could be either NULL or else a pseudo-reg. Both of those cases indicate
14729 that the parameter doesn't really live anywhere (as far as the code
14730 generation parts of GCC are concerned) during most of the function's
14731 activation. That will happen (for example) if the parameter is never
14732 referenced within the function.
14734 We could just generate a location descriptor here for all non-NULL
14735 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14736 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14737 where DECL_RTL is NULL or is a pseudo-reg.
14739 Note however that we can only get away with using DECL_INCOMING_RTL as
14740 a backup substitute for DECL_RTL in certain limited cases. In cases
14741 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14742 we can be sure that the parameter was passed using the same type as it is
14743 declared to have within the function, and that its DECL_INCOMING_RTL
14744 points us to a place where a value of that type is passed.
14746 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14747 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14748 because in these cases DECL_INCOMING_RTL points us to a value of some
14749 type which is *different* from the type of the parameter itself. Thus,
14750 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14751 such cases, the debugger would end up (for example) trying to fetch a
14752 `float' from a place which actually contains the first part of a
14753 `double'. That would lead to really incorrect and confusing
14754 output at debug-time.
14756 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14757 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14758 are a couple of exceptions however. On little-endian machines we can
14759 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14760 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14761 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14762 when (on a little-endian machine) a non-prototyped function has a
14763 parameter declared to be of type `short' or `char'. In such cases,
14764 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14765 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14766 passed `int' value. If the debugger then uses that address to fetch
14767 a `short' or a `char' (on a little-endian machine) the result will be
14768 the correct data, so we allow for such exceptional cases below.
14770 Note that our goal here is to describe the place where the given formal
14771 parameter lives during most of the function's activation (i.e. between the
14772 end of the prologue and the start of the epilogue). We'll do that as best
14773 as we can. Note however that if the given formal parameter is modified
14774 sometime during the execution of the function, then a stack backtrace (at
14775 debug-time) will show the function as having been called with the *new*
14776 value rather than the value which was originally passed in. This happens
14777 rarely enough that it is not a major problem, but it *is* a problem, and
14778 I'd like to fix it.
14780 A future version of dwarf2out.c may generate two additional attributes for
14781 any given DW_TAG_formal_parameter DIE which will describe the "passed
14782 type" and the "passed location" for the given formal parameter in addition
14783 to the attributes we now generate to indicate the "declared type" and the
14784 "active location" for each parameter. This additional set of attributes
14785 could be used by debuggers for stack backtraces. Separately, note that
14786 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
14787 This happens (for example) for inlined-instances of inline function formal
14788 parameters which are never referenced. This really shouldn't be
14789 happening. All PARM_DECL nodes should get valid non-NULL
14790 DECL_INCOMING_RTL values. FIXME. */
14792 /* Use DECL_RTL as the "location" unless we find something better. */
14793 rtl = DECL_RTL_IF_SET (decl);
14795 /* When generating abstract instances, ignore everything except
14796 constants, symbols living in memory, and symbols living in
14797 fixed registers. */
14798 if (! reload_completed)
14801 && (CONSTANT_P (rtl)
14803 && CONSTANT_P (XEXP (rtl, 0)))
14805 && TREE_CODE (decl) == VAR_DECL
14806 && TREE_STATIC (decl))))
14808 rtl = targetm.delegitimize_address (rtl);
14813 else if (TREE_CODE (decl) == PARM_DECL)
14815 if (rtl == NULL_RTX
14816 || is_pseudo_reg (rtl)
14818 && is_pseudo_reg (XEXP (rtl, 0))
14819 && DECL_INCOMING_RTL (decl)
14820 && MEM_P (DECL_INCOMING_RTL (decl))
14821 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
14823 tree declared_type = TREE_TYPE (decl);
14824 tree passed_type = DECL_ARG_TYPE (decl);
14825 enum machine_mode dmode = TYPE_MODE (declared_type);
14826 enum machine_mode pmode = TYPE_MODE (passed_type);
14828 /* This decl represents a formal parameter which was optimized out.
14829 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
14830 all cases where (rtl == NULL_RTX) just below. */
14831 if (dmode == pmode)
14832 rtl = DECL_INCOMING_RTL (decl);
14833 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
14834 && SCALAR_INT_MODE_P (dmode)
14835 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
14836 && DECL_INCOMING_RTL (decl))
14838 rtx inc = DECL_INCOMING_RTL (decl);
14841 else if (MEM_P (inc))
14843 if (BYTES_BIG_ENDIAN)
14844 rtl = adjust_address_nv (inc, dmode,
14845 GET_MODE_SIZE (pmode)
14846 - GET_MODE_SIZE (dmode));
14853 /* If the parm was passed in registers, but lives on the stack, then
14854 make a big endian correction if the mode of the type of the
14855 parameter is not the same as the mode of the rtl. */
14856 /* ??? This is the same series of checks that are made in dbxout.c before
14857 we reach the big endian correction code there. It isn't clear if all
14858 of these checks are necessary here, but keeping them all is the safe
14860 else if (MEM_P (rtl)
14861 && XEXP (rtl, 0) != const0_rtx
14862 && ! CONSTANT_P (XEXP (rtl, 0))
14863 /* Not passed in memory. */
14864 && !MEM_P (DECL_INCOMING_RTL (decl))
14865 /* Not passed by invisible reference. */
14866 && (!REG_P (XEXP (rtl, 0))
14867 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
14868 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
14869 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
14870 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
14873 /* Big endian correction check. */
14874 && BYTES_BIG_ENDIAN
14875 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
14876 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
14879 int offset = (UNITS_PER_WORD
14880 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
14882 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
14883 plus_constant (XEXP (rtl, 0), offset));
14886 else if (TREE_CODE (decl) == VAR_DECL
14889 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
14890 && BYTES_BIG_ENDIAN)
14892 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
14893 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
14895 /* If a variable is declared "register" yet is smaller than
14896 a register, then if we store the variable to memory, it
14897 looks like we're storing a register-sized value, when in
14898 fact we are not. We need to adjust the offset of the
14899 storage location to reflect the actual value's bytes,
14900 else gdb will not be able to display it. */
14902 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
14903 plus_constant (XEXP (rtl, 0), rsize-dsize));
14906 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
14907 and will have been substituted directly into all expressions that use it.
14908 C does not have such a concept, but C++ and other languages do. */
14909 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
14910 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
14913 rtl = targetm.delegitimize_address (rtl);
14915 /* If we don't look past the constant pool, we risk emitting a
14916 reference to a constant pool entry that isn't referenced from
14917 code, and thus is not emitted. */
14919 rtl = avoid_constant_pool_reference (rtl);
14921 /* Try harder to get a rtl. If this symbol ends up not being emitted
14922 in the current CU, resolve_addr will remove the expression referencing
14924 if (rtl == NULL_RTX
14925 && TREE_CODE (decl) == VAR_DECL
14926 && !DECL_EXTERNAL (decl)
14927 && TREE_STATIC (decl)
14928 && DECL_NAME (decl)
14929 && !DECL_HARD_REGISTER (decl)
14930 && DECL_MODE (decl) != VOIDmode)
14932 rtl = make_decl_rtl_for_debug (decl);
14934 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
14935 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
14942 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
14943 returned. If so, the decl for the COMMON block is returned, and the
14944 value is the offset into the common block for the symbol. */
14947 fortran_common (tree decl, HOST_WIDE_INT *value)
14949 tree val_expr, cvar;
14950 enum machine_mode mode;
14951 HOST_WIDE_INT bitsize, bitpos;
14953 int volatilep = 0, unsignedp = 0;
14955 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
14956 it does not have a value (the offset into the common area), or if it
14957 is thread local (as opposed to global) then it isn't common, and shouldn't
14958 be handled as such. */
14959 if (TREE_CODE (decl) != VAR_DECL
14960 || !TREE_STATIC (decl)
14961 || !DECL_HAS_VALUE_EXPR_P (decl)
14965 val_expr = DECL_VALUE_EXPR (decl);
14966 if (TREE_CODE (val_expr) != COMPONENT_REF)
14969 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
14970 &mode, &unsignedp, &volatilep, true);
14972 if (cvar == NULL_TREE
14973 || TREE_CODE (cvar) != VAR_DECL
14974 || DECL_ARTIFICIAL (cvar)
14975 || !TREE_PUBLIC (cvar))
14979 if (offset != NULL)
14981 if (!host_integerp (offset, 0))
14983 *value = tree_low_cst (offset, 0);
14986 *value += bitpos / BITS_PER_UNIT;
14991 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
14992 data attribute for a variable or a parameter. We generate the
14993 DW_AT_const_value attribute only in those cases where the given variable
14994 or parameter does not have a true "location" either in memory or in a
14995 register. This can happen (for example) when a constant is passed as an
14996 actual argument in a call to an inline function. (It's possible that
14997 these things can crop up in other ways also.) Note that one type of
14998 constant value which can be passed into an inlined function is a constant
14999 pointer. This can happen for example if an actual argument in an inlined
15000 function call evaluates to a compile-time constant address.
15002 CACHE_P is true if it is worth caching the location list for DECL,
15003 so that future calls can reuse it rather than regenerate it from scratch.
15004 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15005 since we will need to refer to them each time the function is inlined. */
15008 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
15009 enum dwarf_attribute attr)
15012 dw_loc_list_ref list;
15013 var_loc_list *loc_list;
15014 cached_dw_loc_list *cache;
15017 if (TREE_CODE (decl) == ERROR_MARK)
15020 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
15021 || TREE_CODE (decl) == RESULT_DECL);
15023 /* Try to get some constant RTL for this decl, and use that as the value of
15026 rtl = rtl_for_decl_location (decl);
15027 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
15028 && add_const_value_attribute (die, rtl))
15031 /* See if we have single element location list that is equivalent to
15032 a constant value. That way we are better to use add_const_value_attribute
15033 rather than expanding constant value equivalent. */
15034 loc_list = lookup_decl_loc (decl);
15037 && loc_list->first->next == NULL
15038 && NOTE_P (loc_list->first->loc)
15039 && NOTE_VAR_LOCATION (loc_list->first->loc)
15040 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
15042 struct var_loc_node *node;
15044 node = loc_list->first;
15045 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
15046 if (GET_CODE (rtl) == EXPR_LIST)
15047 rtl = XEXP (rtl, 0);
15048 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
15049 && add_const_value_attribute (die, rtl))
15052 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15053 list several times. See if we've already cached the contents. */
15055 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
15059 cache = (cached_dw_loc_list *)
15060 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
15062 list = cache->loc_list;
15066 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
15067 /* It is usually worth caching this result if the decl is from
15068 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15069 if (cache_p && list && list->dw_loc_next)
15071 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
15072 DECL_UID (decl), INSERT);
15073 cache = ggc_alloc_cleared_cached_dw_loc_list ();
15074 cache->decl_id = DECL_UID (decl);
15075 cache->loc_list = list;
15081 add_AT_location_description (die, attr, list);
15084 /* None of that worked, so it must not really have a location;
15085 try adding a constant value attribute from the DECL_INITIAL. */
15086 return tree_add_const_value_attribute_for_decl (die, decl);
15089 /* Add VARIABLE and DIE into deferred locations list. */
15092 defer_location (tree variable, dw_die_ref die)
15094 deferred_locations entry;
15095 entry.variable = variable;
15097 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
15100 /* Helper function for tree_add_const_value_attribute. Natively encode
15101 initializer INIT into an array. Return true if successful. */
15104 native_encode_initializer (tree init, unsigned char *array, int size)
15108 if (init == NULL_TREE)
15112 switch (TREE_CODE (init))
15115 type = TREE_TYPE (init);
15116 if (TREE_CODE (type) == ARRAY_TYPE)
15118 tree enttype = TREE_TYPE (type);
15119 enum machine_mode mode = TYPE_MODE (enttype);
15121 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
15123 if (int_size_in_bytes (type) != size)
15125 if (size > TREE_STRING_LENGTH (init))
15127 memcpy (array, TREE_STRING_POINTER (init),
15128 TREE_STRING_LENGTH (init));
15129 memset (array + TREE_STRING_LENGTH (init),
15130 '\0', size - TREE_STRING_LENGTH (init));
15133 memcpy (array, TREE_STRING_POINTER (init), size);
15138 type = TREE_TYPE (init);
15139 if (int_size_in_bytes (type) != size)
15141 if (TREE_CODE (type) == ARRAY_TYPE)
15143 HOST_WIDE_INT min_index;
15144 unsigned HOST_WIDE_INT cnt;
15145 int curpos = 0, fieldsize;
15146 constructor_elt *ce;
15148 if (TYPE_DOMAIN (type) == NULL_TREE
15149 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
15152 fieldsize = int_size_in_bytes (TREE_TYPE (type));
15153 if (fieldsize <= 0)
15156 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
15157 memset (array, '\0', size);
15158 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
15160 tree val = ce->value;
15161 tree index = ce->index;
15163 if (index && TREE_CODE (index) == RANGE_EXPR)
15164 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
15167 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
15172 if (!native_encode_initializer (val, array + pos, fieldsize))
15175 curpos = pos + fieldsize;
15176 if (index && TREE_CODE (index) == RANGE_EXPR)
15178 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
15179 - tree_low_cst (TREE_OPERAND (index, 0), 0);
15180 while (count-- > 0)
15183 memcpy (array + curpos, array + pos, fieldsize);
15184 curpos += fieldsize;
15187 gcc_assert (curpos <= size);
15191 else if (TREE_CODE (type) == RECORD_TYPE
15192 || TREE_CODE (type) == UNION_TYPE)
15194 tree field = NULL_TREE;
15195 unsigned HOST_WIDE_INT cnt;
15196 constructor_elt *ce;
15198 if (int_size_in_bytes (type) != size)
15201 if (TREE_CODE (type) == RECORD_TYPE)
15202 field = TYPE_FIELDS (type);
15204 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
15206 tree val = ce->value;
15207 int pos, fieldsize;
15209 if (ce->index != 0)
15215 if (field == NULL_TREE || DECL_BIT_FIELD (field))
15218 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
15219 && TYPE_DOMAIN (TREE_TYPE (field))
15220 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
15222 else if (DECL_SIZE_UNIT (field) == NULL_TREE
15223 || !host_integerp (DECL_SIZE_UNIT (field), 0))
15225 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
15226 pos = int_byte_position (field);
15227 gcc_assert (pos + fieldsize <= size);
15229 && !native_encode_initializer (val, array + pos, fieldsize))
15235 case VIEW_CONVERT_EXPR:
15236 case NON_LVALUE_EXPR:
15237 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
15239 return native_encode_expr (init, array, size) == size;
15243 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15244 attribute is the const value T. */
15247 tree_add_const_value_attribute (dw_die_ref die, tree t)
15250 tree type = TREE_TYPE (t);
15253 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
15257 gcc_assert (!DECL_P (init));
15259 rtl = rtl_for_decl_init (init, type);
15261 return add_const_value_attribute (die, rtl);
15262 /* If the host and target are sane, try harder. */
15263 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
15264 && initializer_constant_valid_p (init, type))
15266 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
15267 if (size > 0 && (int) size == size)
15269 unsigned char *array = (unsigned char *)
15270 ggc_alloc_cleared_atomic (size);
15272 if (native_encode_initializer (init, array, size))
15274 add_AT_vec (die, DW_AT_const_value, size, 1, array);
15282 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15283 attribute is the const value of T, where T is an integral constant
15284 variable with static storage duration
15285 (so it can't be a PARM_DECL or a RESULT_DECL). */
15288 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
15292 || (TREE_CODE (decl) != VAR_DECL
15293 && TREE_CODE (decl) != CONST_DECL)
15294 || (TREE_CODE (decl) == VAR_DECL
15295 && !TREE_STATIC (decl)))
15298 if (TREE_READONLY (decl)
15299 && ! TREE_THIS_VOLATILE (decl)
15300 && DECL_INITIAL (decl))
15305 /* Don't add DW_AT_const_value if abstract origin already has one. */
15306 if (get_AT (var_die, DW_AT_const_value))
15309 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
15312 /* Convert the CFI instructions for the current function into a
15313 location list. This is used for DW_AT_frame_base when we targeting
15314 a dwarf2 consumer that does not support the dwarf3
15315 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15318 static dw_loc_list_ref
15319 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
15323 dw_loc_list_ref list, *list_tail;
15325 dw_cfa_location last_cfa, next_cfa;
15326 const char *start_label, *last_label, *section;
15327 dw_cfa_location remember;
15330 gcc_assert (fde != NULL);
15332 section = secname_for_decl (current_function_decl);
15336 memset (&next_cfa, 0, sizeof (next_cfa));
15337 next_cfa.reg = INVALID_REGNUM;
15338 remember = next_cfa;
15340 start_label = fde->dw_fde_begin;
15342 /* ??? Bald assumption that the CIE opcode list does not contain
15343 advance opcodes. */
15344 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
15345 lookup_cfa_1 (cfi, &next_cfa, &remember);
15347 last_cfa = next_cfa;
15348 last_label = start_label;
15350 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
15352 /* If the first partition contained no CFI adjustments, the
15353 CIE opcodes apply to the whole first partition. */
15354 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15355 fde->dw_fde_begin, fde->dw_fde_end, section);
15356 list_tail =&(*list_tail)->dw_loc_next;
15357 start_label = last_label = fde->dw_fde_second_begin;
15360 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
15362 switch (cfi->dw_cfi_opc)
15364 case DW_CFA_set_loc:
15365 case DW_CFA_advance_loc1:
15366 case DW_CFA_advance_loc2:
15367 case DW_CFA_advance_loc4:
15368 if (!cfa_equal_p (&last_cfa, &next_cfa))
15370 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15371 start_label, last_label, section);
15373 list_tail = &(*list_tail)->dw_loc_next;
15374 last_cfa = next_cfa;
15375 start_label = last_label;
15377 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
15380 case DW_CFA_advance_loc:
15381 /* The encoding is complex enough that we should never emit this. */
15382 gcc_unreachable ();
15385 lookup_cfa_1 (cfi, &next_cfa, &remember);
15388 if (ix + 1 == fde->dw_fde_switch_cfi_index)
15390 if (!cfa_equal_p (&last_cfa, &next_cfa))
15392 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15393 start_label, last_label, section);
15395 list_tail = &(*list_tail)->dw_loc_next;
15396 last_cfa = next_cfa;
15397 start_label = last_label;
15399 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15400 start_label, fde->dw_fde_end, section);
15401 list_tail = &(*list_tail)->dw_loc_next;
15402 start_label = last_label = fde->dw_fde_second_begin;
15406 if (!cfa_equal_p (&last_cfa, &next_cfa))
15408 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15409 start_label, last_label, section);
15410 list_tail = &(*list_tail)->dw_loc_next;
15411 start_label = last_label;
15414 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
15416 fde->dw_fde_second_begin
15417 ? fde->dw_fde_second_end : fde->dw_fde_end,
15420 if (list && list->dw_loc_next)
15426 /* Compute a displacement from the "steady-state frame pointer" to the
15427 frame base (often the same as the CFA), and store it in
15428 frame_pointer_fb_offset. OFFSET is added to the displacement
15429 before the latter is negated. */
15432 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
15436 #ifdef FRAME_POINTER_CFA_OFFSET
15437 reg = frame_pointer_rtx;
15438 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
15440 reg = arg_pointer_rtx;
15441 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
15444 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
15445 if (GET_CODE (elim) == PLUS)
15447 offset += INTVAL (XEXP (elim, 1));
15448 elim = XEXP (elim, 0);
15451 frame_pointer_fb_offset = -offset;
15453 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15454 in which to eliminate. This is because it's stack pointer isn't
15455 directly accessible as a register within the ISA. To work around
15456 this, assume that while we cannot provide a proper value for
15457 frame_pointer_fb_offset, we won't need one either. */
15458 frame_pointer_fb_offset_valid
15459 = ((SUPPORTS_STACK_ALIGNMENT
15460 && (elim == hard_frame_pointer_rtx
15461 || elim == stack_pointer_rtx))
15462 || elim == (frame_pointer_needed
15463 ? hard_frame_pointer_rtx
15464 : stack_pointer_rtx));
15467 /* Generate a DW_AT_name attribute given some string value to be included as
15468 the value of the attribute. */
15471 add_name_attribute (dw_die_ref die, const char *name_string)
15473 if (name_string != NULL && *name_string != 0)
15475 if (demangle_name_func)
15476 name_string = (*demangle_name_func) (name_string);
15478 add_AT_string (die, DW_AT_name, name_string);
15482 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15483 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15484 of TYPE accordingly.
15486 ??? This is a temporary measure until after we're able to generate
15487 regular DWARF for the complex Ada type system. */
15490 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
15491 dw_die_ref context_die)
15494 dw_die_ref dtype_die;
15496 if (!lang_hooks.types.descriptive_type)
15499 dtype = lang_hooks.types.descriptive_type (type);
15503 dtype_die = lookup_type_die (dtype);
15506 gen_type_die (dtype, context_die);
15507 dtype_die = lookup_type_die (dtype);
15508 gcc_assert (dtype_die);
15511 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
15514 /* Generate a DW_AT_comp_dir attribute for DIE. */
15517 add_comp_dir_attribute (dw_die_ref die)
15519 const char *wd = get_src_pwd ();
15525 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
15529 wdlen = strlen (wd);
15530 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
15532 wd1 [wdlen] = DIR_SEPARATOR;
15533 wd1 [wdlen + 1] = 0;
15537 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
15540 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15544 lower_bound_default (void)
15546 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
15551 case DW_LANG_C_plus_plus:
15553 case DW_LANG_ObjC_plus_plus:
15556 case DW_LANG_Fortran77:
15557 case DW_LANG_Fortran90:
15558 case DW_LANG_Fortran95:
15562 case DW_LANG_Python:
15563 return dwarf_version >= 4 ? 0 : -1;
15564 case DW_LANG_Ada95:
15565 case DW_LANG_Ada83:
15566 case DW_LANG_Cobol74:
15567 case DW_LANG_Cobol85:
15568 case DW_LANG_Pascal83:
15569 case DW_LANG_Modula2:
15571 return dwarf_version >= 4 ? 1 : -1;
15577 /* Given a tree node describing an array bound (either lower or upper) output
15578 a representation for that bound. */
15581 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
15583 switch (TREE_CODE (bound))
15588 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15591 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
15594 /* Use the default if possible. */
15595 if (bound_attr == DW_AT_lower_bound
15596 && host_integerp (bound, 0)
15597 && (dflt = lower_bound_default ()) != -1
15598 && tree_low_cst (bound, 0) == dflt)
15601 /* Otherwise represent the bound as an unsigned value with the
15602 precision of its type. The precision and signedness of the
15603 type will be necessary to re-interpret it unambiguously. */
15604 else if (prec < HOST_BITS_PER_WIDE_INT)
15606 unsigned HOST_WIDE_INT mask
15607 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
15608 add_AT_unsigned (subrange_die, bound_attr,
15609 TREE_INT_CST_LOW (bound) & mask);
15611 else if (prec == HOST_BITS_PER_WIDE_INT
15612 || TREE_INT_CST_HIGH (bound) == 0)
15613 add_AT_unsigned (subrange_die, bound_attr,
15614 TREE_INT_CST_LOW (bound));
15616 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
15617 TREE_INT_CST_LOW (bound));
15622 case VIEW_CONVERT_EXPR:
15623 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
15633 dw_die_ref decl_die = lookup_decl_die (bound);
15635 /* ??? Can this happen, or should the variable have been bound
15636 first? Probably it can, since I imagine that we try to create
15637 the types of parameters in the order in which they exist in
15638 the list, and won't have created a forward reference to a
15639 later parameter. */
15640 if (decl_die != NULL)
15642 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15650 /* Otherwise try to create a stack operation procedure to
15651 evaluate the value of the array bound. */
15653 dw_die_ref ctx, decl_die;
15654 dw_loc_list_ref list;
15656 list = loc_list_from_tree (bound, 2);
15657 if (list == NULL || single_element_loc_list_p (list))
15659 /* If DW_AT_*bound is not a reference nor constant, it is
15660 a DWARF expression rather than location description.
15661 For that loc_list_from_tree (bound, 0) is needed.
15662 If that fails to give a single element list,
15663 fall back to outputting this as a reference anyway. */
15664 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
15665 if (list2 && single_element_loc_list_p (list2))
15667 add_AT_loc (subrange_die, bound_attr, list2->expr);
15674 if (current_function_decl == 0)
15675 ctx = comp_unit_die ();
15677 ctx = lookup_decl_die (current_function_decl);
15679 decl_die = new_die (DW_TAG_variable, ctx, bound);
15680 add_AT_flag (decl_die, DW_AT_artificial, 1);
15681 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
15682 add_AT_location_description (decl_die, DW_AT_location, list);
15683 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15689 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15690 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15691 Note that the block of subscript information for an array type also
15692 includes information about the element type of the given array type. */
15695 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
15697 unsigned dimension_number;
15699 dw_die_ref subrange_die;
15701 for (dimension_number = 0;
15702 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
15703 type = TREE_TYPE (type), dimension_number++)
15705 tree domain = TYPE_DOMAIN (type);
15707 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
15710 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15711 and (in GNU C only) variable bounds. Handle all three forms
15713 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
15716 /* We have an array type with specified bounds. */
15717 lower = TYPE_MIN_VALUE (domain);
15718 upper = TYPE_MAX_VALUE (domain);
15720 /* Define the index type. */
15721 if (TREE_TYPE (domain))
15723 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15724 TREE_TYPE field. We can't emit debug info for this
15725 because it is an unnamed integral type. */
15726 if (TREE_CODE (domain) == INTEGER_TYPE
15727 && TYPE_NAME (domain) == NULL_TREE
15728 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
15729 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
15732 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
15736 /* ??? If upper is NULL, the array has unspecified length,
15737 but it does have a lower bound. This happens with Fortran
15739 Since the debugger is definitely going to need to know N
15740 to produce useful results, go ahead and output the lower
15741 bound solo, and hope the debugger can cope. */
15743 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
15745 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
15748 /* Otherwise we have an array type with an unspecified length. The
15749 DWARF-2 spec does not say how to handle this; let's just leave out the
15755 add_byte_size_attribute (dw_die_ref die, tree tree_node)
15759 switch (TREE_CODE (tree_node))
15764 case ENUMERAL_TYPE:
15767 case QUAL_UNION_TYPE:
15768 size = int_size_in_bytes (tree_node);
15771 /* For a data member of a struct or union, the DW_AT_byte_size is
15772 generally given as the number of bytes normally allocated for an
15773 object of the *declared* type of the member itself. This is true
15774 even for bit-fields. */
15775 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
15778 gcc_unreachable ();
15781 /* Note that `size' might be -1 when we get to this point. If it is, that
15782 indicates that the byte size of the entity in question is variable. We
15783 have no good way of expressing this fact in Dwarf at the present time,
15784 so just let the -1 pass on through. */
15785 add_AT_unsigned (die, DW_AT_byte_size, size);
15788 /* For a FIELD_DECL node which represents a bit-field, output an attribute
15789 which specifies the distance in bits from the highest order bit of the
15790 "containing object" for the bit-field to the highest order bit of the
15793 For any given bit-field, the "containing object" is a hypothetical object
15794 (of some integral or enum type) within which the given bit-field lives. The
15795 type of this hypothetical "containing object" is always the same as the
15796 declared type of the individual bit-field itself. The determination of the
15797 exact location of the "containing object" for a bit-field is rather
15798 complicated. It's handled by the `field_byte_offset' function (above).
15800 Note that it is the size (in bytes) of the hypothetical "containing object"
15801 which will be given in the DW_AT_byte_size attribute for this bit-field.
15802 (See `byte_size_attribute' above). */
15805 add_bit_offset_attribute (dw_die_ref die, tree decl)
15807 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
15808 tree type = DECL_BIT_FIELD_TYPE (decl);
15809 HOST_WIDE_INT bitpos_int;
15810 HOST_WIDE_INT highest_order_object_bit_offset;
15811 HOST_WIDE_INT highest_order_field_bit_offset;
15812 HOST_WIDE_INT bit_offset;
15814 /* Must be a field and a bit field. */
15815 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
15817 /* We can't yet handle bit-fields whose offsets are variable, so if we
15818 encounter such things, just return without generating any attribute
15819 whatsoever. Likewise for variable or too large size. */
15820 if (! host_integerp (bit_position (decl), 0)
15821 || ! host_integerp (DECL_SIZE (decl), 1))
15824 bitpos_int = int_bit_position (decl);
15826 /* Note that the bit offset is always the distance (in bits) from the
15827 highest-order bit of the "containing object" to the highest-order bit of
15828 the bit-field itself. Since the "high-order end" of any object or field
15829 is different on big-endian and little-endian machines, the computation
15830 below must take account of these differences. */
15831 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
15832 highest_order_field_bit_offset = bitpos_int;
15834 if (! BYTES_BIG_ENDIAN)
15836 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
15837 highest_order_object_bit_offset += simple_type_size_in_bits (type);
15841 = (! BYTES_BIG_ENDIAN
15842 ? highest_order_object_bit_offset - highest_order_field_bit_offset
15843 : highest_order_field_bit_offset - highest_order_object_bit_offset);
15845 if (bit_offset < 0)
15846 add_AT_int (die, DW_AT_bit_offset, bit_offset);
15848 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
15851 /* For a FIELD_DECL node which represents a bit field, output an attribute
15852 which specifies the length in bits of the given field. */
15855 add_bit_size_attribute (dw_die_ref die, tree decl)
15857 /* Must be a field and a bit field. */
15858 gcc_assert (TREE_CODE (decl) == FIELD_DECL
15859 && DECL_BIT_FIELD_TYPE (decl));
15861 if (host_integerp (DECL_SIZE (decl), 1))
15862 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
15865 /* If the compiled language is ANSI C, then add a 'prototyped'
15866 attribute, if arg types are given for the parameters of a function. */
15869 add_prototyped_attribute (dw_die_ref die, tree func_type)
15871 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
15872 && prototype_p (func_type))
15873 add_AT_flag (die, DW_AT_prototyped, 1);
15876 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
15877 by looking in either the type declaration or object declaration
15880 static inline dw_die_ref
15881 add_abstract_origin_attribute (dw_die_ref die, tree origin)
15883 dw_die_ref origin_die = NULL;
15885 if (TREE_CODE (origin) != FUNCTION_DECL)
15887 /* We may have gotten separated from the block for the inlined
15888 function, if we're in an exception handler or some such; make
15889 sure that the abstract function has been written out.
15891 Doing this for nested functions is wrong, however; functions are
15892 distinct units, and our context might not even be inline. */
15896 fn = TYPE_STUB_DECL (fn);
15898 fn = decl_function_context (fn);
15900 dwarf2out_abstract_function (fn);
15903 if (DECL_P (origin))
15904 origin_die = lookup_decl_die (origin);
15905 else if (TYPE_P (origin))
15906 origin_die = lookup_type_die (origin);
15908 /* XXX: Functions that are never lowered don't always have correct block
15909 trees (in the case of java, they simply have no block tree, in some other
15910 languages). For these functions, there is nothing we can really do to
15911 output correct debug info for inlined functions in all cases. Rather
15912 than die, we'll just produce deficient debug info now, in that we will
15913 have variables without a proper abstract origin. In the future, when all
15914 functions are lowered, we should re-add a gcc_assert (origin_die)
15918 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
15922 /* We do not currently support the pure_virtual attribute. */
15925 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
15927 if (DECL_VINDEX (func_decl))
15929 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
15931 if (host_integerp (DECL_VINDEX (func_decl), 0))
15932 add_AT_loc (die, DW_AT_vtable_elem_location,
15933 new_loc_descr (DW_OP_constu,
15934 tree_low_cst (DECL_VINDEX (func_decl), 0),
15937 /* GNU extension: Record what type this method came from originally. */
15938 if (debug_info_level > DINFO_LEVEL_TERSE
15939 && DECL_CONTEXT (func_decl))
15940 add_AT_die_ref (die, DW_AT_containing_type,
15941 lookup_type_die (DECL_CONTEXT (func_decl)));
15945 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
15946 given decl. This used to be a vendor extension until after DWARF 4
15947 standardized it. */
15950 add_linkage_attr (dw_die_ref die, tree decl)
15952 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15954 /* Mimic what assemble_name_raw does with a leading '*'. */
15955 if (name[0] == '*')
15958 if (dwarf_version >= 4)
15959 add_AT_string (die, DW_AT_linkage_name, name);
15961 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
15964 /* Add source coordinate attributes for the given decl. */
15967 add_src_coords_attributes (dw_die_ref die, tree decl)
15969 expanded_location s;
15971 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
15973 s = expand_location (DECL_SOURCE_LOCATION (decl));
15974 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
15975 add_AT_unsigned (die, DW_AT_decl_line, s.line);
15978 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
15981 add_linkage_name (dw_die_ref die, tree decl)
15983 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
15984 && TREE_PUBLIC (decl)
15985 && !DECL_ABSTRACT (decl)
15986 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
15987 && die->die_tag != DW_TAG_member)
15989 /* Defer until we have an assembler name set. */
15990 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
15992 limbo_die_node *asm_name;
15994 asm_name = ggc_alloc_cleared_limbo_die_node ();
15995 asm_name->die = die;
15996 asm_name->created_for = decl;
15997 asm_name->next = deferred_asm_name;
15998 deferred_asm_name = asm_name;
16000 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
16001 add_linkage_attr (die, decl);
16005 /* Add a DW_AT_name attribute and source coordinate attribute for the
16006 given decl, but only if it actually has a name. */
16009 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
16013 decl_name = DECL_NAME (decl);
16014 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
16016 const char *name = dwarf2_name (decl, 0);
16018 add_name_attribute (die, name);
16019 if (! DECL_ARTIFICIAL (decl))
16020 add_src_coords_attributes (die, decl);
16022 add_linkage_name (die, decl);
16025 #ifdef VMS_DEBUGGING_INFO
16026 /* Get the function's name, as described by its RTL. This may be different
16027 from the DECL_NAME name used in the source file. */
16028 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
16030 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
16031 XEXP (DECL_RTL (decl), 0));
16032 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
16034 #endif /* VMS_DEBUGGING_INFO */
16037 #ifdef VMS_DEBUGGING_INFO
16038 /* Output the debug main pointer die for VMS */
16041 dwarf2out_vms_debug_main_pointer (void)
16043 char label[MAX_ARTIFICIAL_LABEL_BYTES];
16046 /* Allocate the VMS debug main subprogram die. */
16047 die = ggc_alloc_cleared_die_node ();
16048 die->die_tag = DW_TAG_subprogram;
16049 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
16050 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
16051 current_function_funcdef_no);
16052 add_AT_lbl_id (die, DW_AT_entry_pc, label);
16054 /* Make it the first child of comp_unit_die (). */
16055 die->die_parent = comp_unit_die ();
16056 if (comp_unit_die ()->die_child)
16058 die->die_sib = comp_unit_die ()->die_child->die_sib;
16059 comp_unit_die ()->die_child->die_sib = die;
16063 die->die_sib = die;
16064 comp_unit_die ()->die_child = die;
16067 #endif /* VMS_DEBUGGING_INFO */
16069 /* Push a new declaration scope. */
16072 push_decl_scope (tree scope)
16074 VEC_safe_push (tree, gc, decl_scope_table, scope);
16077 /* Pop a declaration scope. */
16080 pop_decl_scope (void)
16082 VEC_pop (tree, decl_scope_table);
16085 /* walk_tree helper function for uses_local_type, below. */
16088 uses_local_type_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
16091 *walk_subtrees = 0;
16094 tree name = TYPE_NAME (*tp);
16095 if (name && DECL_P (name) && decl_function_context (name))
16101 /* If TYPE involves a function-local type (including a local typedef to a
16102 non-local type), returns that type; otherwise returns NULL_TREE. */
16105 uses_local_type (tree type)
16107 tree used = walk_tree_without_duplicates (&type, uses_local_type_r, NULL);
16111 /* Return the DIE for the scope that immediately contains this type.
16112 Non-named types that do not involve a function-local type get global
16113 scope. Named types nested in namespaces or other types get their
16114 containing scope. All other types (i.e. function-local named types) get
16115 the current active scope. */
16118 scope_die_for (tree t, dw_die_ref context_die)
16120 dw_die_ref scope_die = NULL;
16121 tree containing_scope;
16123 /* Non-types always go in the current scope. */
16124 gcc_assert (TYPE_P (t));
16126 /* Use the scope of the typedef, rather than the scope of the type
16128 if (TYPE_NAME (t) && DECL_P (TYPE_NAME (t)))
16129 containing_scope = DECL_CONTEXT (TYPE_NAME (t));
16131 containing_scope = TYPE_CONTEXT (t);
16133 /* Use the containing namespace if there is one. */
16134 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
16136 if (context_die == lookup_decl_die (containing_scope))
16138 else if (debug_info_level > DINFO_LEVEL_TERSE)
16139 context_die = get_context_die (containing_scope);
16141 containing_scope = NULL_TREE;
16144 /* Ignore function type "scopes" from the C frontend. They mean that
16145 a tagged type is local to a parmlist of a function declarator, but
16146 that isn't useful to DWARF. */
16147 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
16148 containing_scope = NULL_TREE;
16150 if (SCOPE_FILE_SCOPE_P (containing_scope))
16152 /* If T uses a local type keep it local as well, to avoid references
16153 to function-local DIEs from outside the function. */
16154 if (current_function_decl && uses_local_type (t))
16155 scope_die = context_die;
16157 scope_die = comp_unit_die ();
16159 else if (TYPE_P (containing_scope))
16161 /* For types, we can just look up the appropriate DIE. */
16162 if (debug_info_level > DINFO_LEVEL_TERSE)
16163 scope_die = get_context_die (containing_scope);
16166 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
16167 if (scope_die == NULL)
16168 scope_die = comp_unit_die ();
16172 scope_die = context_die;
16177 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16180 local_scope_p (dw_die_ref context_die)
16182 for (; context_die; context_die = context_die->die_parent)
16183 if (context_die->die_tag == DW_TAG_inlined_subroutine
16184 || context_die->die_tag == DW_TAG_subprogram)
16190 /* Returns nonzero if CONTEXT_DIE is a class. */
16193 class_scope_p (dw_die_ref context_die)
16195 return (context_die
16196 && (context_die->die_tag == DW_TAG_structure_type
16197 || context_die->die_tag == DW_TAG_class_type
16198 || context_die->die_tag == DW_TAG_interface_type
16199 || context_die->die_tag == DW_TAG_union_type));
16202 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16203 whether or not to treat a DIE in this context as a declaration. */
16206 class_or_namespace_scope_p (dw_die_ref context_die)
16208 return (class_scope_p (context_die)
16209 || (context_die && context_die->die_tag == DW_TAG_namespace));
16212 /* Many forms of DIEs require a "type description" attribute. This
16213 routine locates the proper "type descriptor" die for the type given
16214 by 'type', and adds a DW_AT_type attribute below the given die. */
16217 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
16218 int decl_volatile, dw_die_ref context_die)
16220 enum tree_code code = TREE_CODE (type);
16221 dw_die_ref type_die = NULL;
16223 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16224 or fixed-point type, use the inner type. This is because we have no
16225 support for unnamed types in base_type_die. This can happen if this is
16226 an Ada subrange type. Correct solution is emit a subrange type die. */
16227 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
16228 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
16229 type = TREE_TYPE (type), code = TREE_CODE (type);
16231 if (code == ERROR_MARK
16232 /* Handle a special case. For functions whose return type is void, we
16233 generate *no* type attribute. (Note that no object may have type
16234 `void', so this only applies to function return types). */
16235 || code == VOID_TYPE)
16238 type_die = modified_type_die (type,
16239 decl_const || TYPE_READONLY (type),
16240 decl_volatile || TYPE_VOLATILE (type),
16243 if (type_die != NULL)
16244 add_AT_die_ref (object_die, DW_AT_type, type_die);
16247 /* Given an object die, add the calling convention attribute for the
16248 function call type. */
16250 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
16252 enum dwarf_calling_convention value = DW_CC_normal;
16254 value = ((enum dwarf_calling_convention)
16255 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
16258 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
16260 /* DWARF 2 doesn't provide a way to identify a program's source-level
16261 entry point. DW_AT_calling_convention attributes are only meant
16262 to describe functions' calling conventions. However, lacking a
16263 better way to signal the Fortran main program, we used this for
16264 a long time, following existing custom. Now, DWARF 4 has
16265 DW_AT_main_subprogram, which we add below, but some tools still
16266 rely on the old way, which we thus keep. */
16267 value = DW_CC_program;
16269 if (dwarf_version >= 4 || !dwarf_strict)
16270 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
16273 /* Only add the attribute if the backend requests it, and
16274 is not DW_CC_normal. */
16275 if (value && (value != DW_CC_normal))
16276 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
16279 /* Given a tree pointer to a struct, class, union, or enum type node, return
16280 a pointer to the (string) tag name for the given type, or zero if the type
16281 was declared without a tag. */
16283 static const char *
16284 type_tag (const_tree type)
16286 const char *name = 0;
16288 if (TYPE_NAME (type) != 0)
16292 /* Find the IDENTIFIER_NODE for the type name. */
16293 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
16294 && !TYPE_NAMELESS (type))
16295 t = TYPE_NAME (type);
16297 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16298 a TYPE_DECL node, regardless of whether or not a `typedef' was
16300 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16301 && ! DECL_IGNORED_P (TYPE_NAME (type)))
16303 /* We want to be extra verbose. Don't call dwarf_name if
16304 DECL_NAME isn't set. The default hook for decl_printable_name
16305 doesn't like that, and in this context it's correct to return
16306 0, instead of "<anonymous>" or the like. */
16307 if (DECL_NAME (TYPE_NAME (type))
16308 && !DECL_NAMELESS (TYPE_NAME (type)))
16309 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
16312 /* Now get the name as a string, or invent one. */
16313 if (!name && t != 0)
16314 name = IDENTIFIER_POINTER (t);
16317 return (name == 0 || *name == '\0') ? 0 : name;
16320 /* Return the type associated with a data member, make a special check
16321 for bit field types. */
16324 member_declared_type (const_tree member)
16326 return (DECL_BIT_FIELD_TYPE (member)
16327 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
16330 /* Get the decl's label, as described by its RTL. This may be different
16331 from the DECL_NAME name used in the source file. */
16334 static const char *
16335 decl_start_label (tree decl)
16338 const char *fnname;
16340 x = DECL_RTL (decl);
16341 gcc_assert (MEM_P (x));
16344 gcc_assert (GET_CODE (x) == SYMBOL_REF);
16346 fnname = XSTR (x, 0);
16351 /* These routines generate the internal representation of the DIE's for
16352 the compilation unit. Debugging information is collected by walking
16353 the declaration trees passed in from dwarf2out_decl(). */
16356 gen_array_type_die (tree type, dw_die_ref context_die)
16358 dw_die_ref scope_die = scope_die_for (type, context_die);
16359 dw_die_ref array_die;
16361 /* GNU compilers represent multidimensional array types as sequences of one
16362 dimensional array types whose element types are themselves array types.
16363 We sometimes squish that down to a single array_type DIE with multiple
16364 subscripts in the Dwarf debugging info. The draft Dwarf specification
16365 say that we are allowed to do this kind of compression in C, because
16366 there is no difference between an array of arrays and a multidimensional
16367 array. We don't do this for Ada to remain as close as possible to the
16368 actual representation, which is especially important against the language
16369 flexibilty wrt arrays of variable size. */
16371 bool collapse_nested_arrays = !is_ada ();
16374 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16375 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16376 if (TYPE_STRING_FLAG (type)
16377 && TREE_CODE (type) == ARRAY_TYPE
16379 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
16381 HOST_WIDE_INT size;
16383 array_die = new_die (DW_TAG_string_type, scope_die, type);
16384 add_name_attribute (array_die, type_tag (type));
16385 equate_type_number_to_die (type, array_die);
16386 size = int_size_in_bytes (type);
16388 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16389 else if (TYPE_DOMAIN (type) != NULL_TREE
16390 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
16391 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
16393 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
16394 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
16396 size = int_size_in_bytes (TREE_TYPE (szdecl));
16397 if (loc && size > 0)
16399 add_AT_location_description (array_die, DW_AT_string_length, loc);
16400 if (size != DWARF2_ADDR_SIZE)
16401 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16407 /* ??? The SGI dwarf reader fails for array of array of enum types
16408 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
16409 array type comes before the outer array type. We thus call gen_type_die
16410 before we new_die and must prevent nested array types collapsing for this
16413 #ifdef MIPS_DEBUGGING_INFO
16414 gen_type_die (TREE_TYPE (type), context_die);
16415 collapse_nested_arrays = false;
16418 array_die = new_die (DW_TAG_array_type, scope_die, type);
16419 add_name_attribute (array_die, type_tag (type));
16420 equate_type_number_to_die (type, array_die);
16422 if (TREE_CODE (type) == VECTOR_TYPE)
16423 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
16425 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16427 && TREE_CODE (type) == ARRAY_TYPE
16428 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
16429 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
16430 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16433 /* We default the array ordering. SDB will probably do
16434 the right things even if DW_AT_ordering is not present. It's not even
16435 an issue until we start to get into multidimensional arrays anyway. If
16436 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16437 then we'll have to put the DW_AT_ordering attribute back in. (But if
16438 and when we find out that we need to put these in, we will only do so
16439 for multidimensional arrays. */
16440 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
16443 #ifdef MIPS_DEBUGGING_INFO
16444 /* The SGI compilers handle arrays of unknown bound by setting
16445 AT_declaration and not emitting any subrange DIEs. */
16446 if (TREE_CODE (type) == ARRAY_TYPE
16447 && ! TYPE_DOMAIN (type))
16448 add_AT_flag (array_die, DW_AT_declaration, 1);
16451 if (TREE_CODE (type) == VECTOR_TYPE)
16453 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16454 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
16455 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
16456 add_bound_info (subrange_die, DW_AT_upper_bound,
16457 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
16460 add_subscript_info (array_die, type, collapse_nested_arrays);
16462 /* Add representation of the type of the elements of this array type and
16463 emit the corresponding DIE if we haven't done it already. */
16464 element_type = TREE_TYPE (type);
16465 if (collapse_nested_arrays)
16466 while (TREE_CODE (element_type) == ARRAY_TYPE)
16468 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
16470 element_type = TREE_TYPE (element_type);
16473 #ifndef MIPS_DEBUGGING_INFO
16474 gen_type_die (element_type, context_die);
16477 add_type_attribute (array_die, element_type, 0, 0, context_die);
16479 add_gnat_descriptive_type_attribute (array_die, type, context_die);
16480 if (TYPE_ARTIFICIAL (type))
16481 add_AT_flag (array_die, DW_AT_artificial, 1);
16483 if (get_AT (array_die, DW_AT_name))
16484 add_pubtype (type, array_die);
16487 static dw_loc_descr_ref
16488 descr_info_loc (tree val, tree base_decl)
16490 HOST_WIDE_INT size;
16491 dw_loc_descr_ref loc, loc2;
16492 enum dwarf_location_atom op;
16494 if (val == base_decl)
16495 return new_loc_descr (DW_OP_push_object_address, 0, 0);
16497 switch (TREE_CODE (val))
16500 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16502 return loc_descriptor_from_tree (val, 0);
16504 if (host_integerp (val, 0))
16505 return int_loc_descriptor (tree_low_cst (val, 0));
16508 size = int_size_in_bytes (TREE_TYPE (val));
16511 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16514 if (size == DWARF2_ADDR_SIZE)
16515 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
16517 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
16519 case POINTER_PLUS_EXPR:
16521 if (host_integerp (TREE_OPERAND (val, 1), 1)
16522 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
16525 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16528 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
16534 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16537 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
16540 add_loc_descr (&loc, loc2);
16541 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
16563 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
16564 tree val, tree base_decl)
16566 dw_loc_descr_ref loc;
16568 if (host_integerp (val, 0))
16570 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
16574 loc = descr_info_loc (val, base_decl);
16578 add_AT_loc (die, attr, loc);
16581 /* This routine generates DIE for array with hidden descriptor, details
16582 are filled into *info by a langhook. */
16585 gen_descr_array_type_die (tree type, struct array_descr_info *info,
16586 dw_die_ref context_die)
16588 dw_die_ref scope_die = scope_die_for (type, context_die);
16589 dw_die_ref array_die;
16592 array_die = new_die (DW_TAG_array_type, scope_die, type);
16593 add_name_attribute (array_die, type_tag (type));
16594 equate_type_number_to_die (type, array_die);
16596 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16598 && info->ndimensions >= 2)
16599 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16601 if (info->data_location)
16602 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
16604 if (info->associated)
16605 add_descr_info_field (array_die, DW_AT_associated, info->associated,
16607 if (info->allocated)
16608 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
16611 for (dim = 0; dim < info->ndimensions; dim++)
16613 dw_die_ref subrange_die
16614 = new_die (DW_TAG_subrange_type, array_die, NULL);
16616 if (info->dimen[dim].lower_bound)
16618 /* If it is the default value, omit it. */
16621 if (host_integerp (info->dimen[dim].lower_bound, 0)
16622 && (dflt = lower_bound_default ()) != -1
16623 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
16626 add_descr_info_field (subrange_die, DW_AT_lower_bound,
16627 info->dimen[dim].lower_bound,
16630 if (info->dimen[dim].upper_bound)
16631 add_descr_info_field (subrange_die, DW_AT_upper_bound,
16632 info->dimen[dim].upper_bound,
16634 if (info->dimen[dim].stride)
16635 add_descr_info_field (subrange_die, DW_AT_byte_stride,
16636 info->dimen[dim].stride,
16640 gen_type_die (info->element_type, context_die);
16641 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
16643 if (get_AT (array_die, DW_AT_name))
16644 add_pubtype (type, array_die);
16649 gen_entry_point_die (tree decl, dw_die_ref context_die)
16651 tree origin = decl_ultimate_origin (decl);
16652 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
16654 if (origin != NULL)
16655 add_abstract_origin_attribute (decl_die, origin);
16658 add_name_and_src_coords_attributes (decl_die, decl);
16659 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
16660 0, 0, context_die);
16663 if (DECL_ABSTRACT (decl))
16664 equate_decl_number_to_die (decl, decl_die);
16666 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
16670 /* Walk through the list of incomplete types again, trying once more to
16671 emit full debugging info for them. */
16674 retry_incomplete_types (void)
16678 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
16679 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
16680 DINFO_USAGE_DIR_USE))
16681 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
16684 /* Determine what tag to use for a record type. */
16686 static enum dwarf_tag
16687 record_type_tag (tree type)
16689 if (! lang_hooks.types.classify_record)
16690 return DW_TAG_structure_type;
16692 switch (lang_hooks.types.classify_record (type))
16694 case RECORD_IS_STRUCT:
16695 return DW_TAG_structure_type;
16697 case RECORD_IS_CLASS:
16698 return DW_TAG_class_type;
16700 case RECORD_IS_INTERFACE:
16701 if (dwarf_version >= 3 || !dwarf_strict)
16702 return DW_TAG_interface_type;
16703 return DW_TAG_structure_type;
16706 gcc_unreachable ();
16710 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16711 include all of the information about the enumeration values also. Each
16712 enumerated type name/value is listed as a child of the enumerated type
16716 gen_enumeration_type_die (tree type, dw_die_ref context_die)
16718 dw_die_ref type_die = lookup_type_die (type);
16720 if (type_die == NULL)
16722 type_die = new_die (DW_TAG_enumeration_type,
16723 scope_die_for (type, context_die), type);
16724 equate_type_number_to_die (type, type_die);
16725 add_name_attribute (type_die, type_tag (type));
16726 if (dwarf_version >= 4 || !dwarf_strict)
16728 if (ENUM_IS_SCOPED (type))
16729 add_AT_flag (type_die, DW_AT_enum_class, 1);
16730 if (ENUM_IS_OPAQUE (type))
16731 add_AT_flag (type_die, DW_AT_declaration, 1);
16734 else if (! TYPE_SIZE (type))
16737 remove_AT (type_die, DW_AT_declaration);
16739 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16740 given enum type is incomplete, do not generate the DW_AT_byte_size
16741 attribute or the DW_AT_element_list attribute. */
16742 if (TYPE_SIZE (type))
16746 TREE_ASM_WRITTEN (type) = 1;
16747 add_byte_size_attribute (type_die, type);
16748 if (TYPE_STUB_DECL (type) != NULL_TREE)
16750 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
16751 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
16754 /* If the first reference to this type was as the return type of an
16755 inline function, then it may not have a parent. Fix this now. */
16756 if (type_die->die_parent == NULL)
16757 add_child_die (scope_die_for (type, context_die), type_die);
16759 for (link = TYPE_VALUES (type);
16760 link != NULL; link = TREE_CHAIN (link))
16762 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
16763 tree value = TREE_VALUE (link);
16765 add_name_attribute (enum_die,
16766 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
16768 if (TREE_CODE (value) == CONST_DECL)
16769 value = DECL_INITIAL (value);
16771 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
16772 /* DWARF2 does not provide a way of indicating whether or
16773 not enumeration constants are signed or unsigned. GDB
16774 always assumes the values are signed, so we output all
16775 values as if they were signed. That means that
16776 enumeration constants with very large unsigned values
16777 will appear to have negative values in the debugger. */
16778 add_AT_int (enum_die, DW_AT_const_value,
16779 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
16782 add_gnat_descriptive_type_attribute (type_die, type, context_die);
16783 if (TYPE_ARTIFICIAL (type))
16784 add_AT_flag (type_die, DW_AT_artificial, 1);
16787 add_AT_flag (type_die, DW_AT_declaration, 1);
16789 if (get_AT (type_die, DW_AT_name))
16790 add_pubtype (type, type_die);
16795 /* Generate a DIE to represent either a real live formal parameter decl or to
16796 represent just the type of some formal parameter position in some function
16799 Note that this routine is a bit unusual because its argument may be a
16800 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
16801 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
16802 node. If it's the former then this function is being called to output a
16803 DIE to represent a formal parameter object (or some inlining thereof). If
16804 it's the latter, then this function is only being called to output a
16805 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
16806 argument type of some subprogram type.
16807 If EMIT_NAME_P is true, name and source coordinate attributes
16811 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
16812 dw_die_ref context_die)
16814 tree node_or_origin = node ? node : origin;
16815 tree ultimate_origin;
16816 dw_die_ref parm_die
16817 = new_die (DW_TAG_formal_parameter, context_die, node);
16819 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
16821 case tcc_declaration:
16822 ultimate_origin = decl_ultimate_origin (node_or_origin);
16823 if (node || ultimate_origin)
16824 origin = ultimate_origin;
16825 if (origin != NULL)
16826 add_abstract_origin_attribute (parm_die, origin);
16827 else if (emit_name_p)
16828 add_name_and_src_coords_attributes (parm_die, node);
16830 || (! DECL_ABSTRACT (node_or_origin)
16831 && variably_modified_type_p (TREE_TYPE (node_or_origin),
16832 decl_function_context
16833 (node_or_origin))))
16835 tree type = TREE_TYPE (node_or_origin);
16836 if (decl_by_reference_p (node_or_origin))
16837 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
16840 add_type_attribute (parm_die, type,
16841 TREE_READONLY (node_or_origin),
16842 TREE_THIS_VOLATILE (node_or_origin),
16845 if (origin == NULL && DECL_ARTIFICIAL (node))
16846 add_AT_flag (parm_die, DW_AT_artificial, 1);
16848 if (node && node != origin)
16849 equate_decl_number_to_die (node, parm_die);
16850 if (! DECL_ABSTRACT (node_or_origin))
16851 add_location_or_const_value_attribute (parm_die, node_or_origin,
16852 node == NULL, DW_AT_location);
16857 /* We were called with some kind of a ..._TYPE node. */
16858 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
16862 gcc_unreachable ();
16868 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
16869 children DW_TAG_formal_parameter DIEs representing the arguments of the
16872 PARM_PACK must be a function parameter pack.
16873 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
16874 must point to the subsequent arguments of the function PACK_ARG belongs to.
16875 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
16876 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
16877 following the last one for which a DIE was generated. */
16880 gen_formal_parameter_pack_die (tree parm_pack,
16882 dw_die_ref subr_die,
16886 dw_die_ref parm_pack_die;
16888 gcc_assert (parm_pack
16889 && lang_hooks.function_parameter_pack_p (parm_pack)
16892 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
16893 add_src_coords_attributes (parm_pack_die, parm_pack);
16895 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
16897 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
16900 gen_formal_parameter_die (arg, NULL,
16901 false /* Don't emit name attribute. */,
16906 return parm_pack_die;
16909 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
16910 at the end of an (ANSI prototyped) formal parameters list. */
16913 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
16915 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
16918 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
16919 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
16920 parameters as specified in some function type specification (except for
16921 those which appear as part of a function *definition*). */
16924 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
16927 tree formal_type = NULL;
16928 tree first_parm_type;
16931 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
16933 arg = DECL_ARGUMENTS (function_or_method_type);
16934 function_or_method_type = TREE_TYPE (function_or_method_type);
16939 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
16941 /* Make our first pass over the list of formal parameter types and output a
16942 DW_TAG_formal_parameter DIE for each one. */
16943 for (link = first_parm_type; link; )
16945 dw_die_ref parm_die;
16947 formal_type = TREE_VALUE (link);
16948 if (formal_type == void_type_node)
16951 /* Output a (nameless) DIE to represent the formal parameter itself. */
16952 parm_die = gen_formal_parameter_die (formal_type, NULL,
16953 true /* Emit name attribute. */,
16955 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
16956 && link == first_parm_type)
16958 add_AT_flag (parm_die, DW_AT_artificial, 1);
16959 if (dwarf_version >= 3 || !dwarf_strict)
16960 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
16962 else if (arg && DECL_ARTIFICIAL (arg))
16963 add_AT_flag (parm_die, DW_AT_artificial, 1);
16965 link = TREE_CHAIN (link);
16967 arg = DECL_CHAIN (arg);
16970 /* If this function type has an ellipsis, add a
16971 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
16972 if (formal_type != void_type_node)
16973 gen_unspecified_parameters_die (function_or_method_type, context_die);
16975 /* Make our second (and final) pass over the list of formal parameter types
16976 and output DIEs to represent those types (as necessary). */
16977 for (link = TYPE_ARG_TYPES (function_or_method_type);
16978 link && TREE_VALUE (link);
16979 link = TREE_CHAIN (link))
16980 gen_type_die (TREE_VALUE (link), context_die);
16983 /* We want to generate the DIE for TYPE so that we can generate the
16984 die for MEMBER, which has been defined; we will need to refer back
16985 to the member declaration nested within TYPE. If we're trying to
16986 generate minimal debug info for TYPE, processing TYPE won't do the
16987 trick; we need to attach the member declaration by hand. */
16990 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
16992 gen_type_die (type, context_die);
16994 /* If we're trying to avoid duplicate debug info, we may not have
16995 emitted the member decl for this function. Emit it now. */
16996 if (TYPE_STUB_DECL (type)
16997 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
16998 && ! lookup_decl_die (member))
17000 dw_die_ref type_die;
17001 gcc_assert (!decl_ultimate_origin (member));
17003 push_decl_scope (type);
17004 type_die = lookup_type_die_strip_naming_typedef (type);
17005 if (TREE_CODE (member) == FUNCTION_DECL)
17006 gen_subprogram_die (member, type_die);
17007 else if (TREE_CODE (member) == FIELD_DECL)
17009 /* Ignore the nameless fields that are used to skip bits but handle
17010 C++ anonymous unions and structs. */
17011 if (DECL_NAME (member) != NULL_TREE
17012 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
17013 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
17015 gen_type_die (member_declared_type (member), type_die);
17016 gen_field_die (member, type_die);
17020 gen_variable_die (member, NULL_TREE, type_die);
17026 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17027 may later generate inlined and/or out-of-line instances of. */
17030 dwarf2out_abstract_function (tree decl)
17032 dw_die_ref old_die;
17036 htab_t old_decl_loc_table;
17037 htab_t old_cached_dw_loc_list_table;
17038 int old_call_site_count, old_tail_call_site_count;
17039 struct call_arg_loc_node *old_call_arg_locations;
17041 /* Make sure we have the actual abstract inline, not a clone. */
17042 decl = DECL_ORIGIN (decl);
17044 old_die = lookup_decl_die (decl);
17045 if (old_die && get_AT (old_die, DW_AT_inline))
17046 /* We've already generated the abstract instance. */
17049 /* We can be called while recursively when seeing block defining inlined subroutine
17050 DIE. Be sure to not clobber the outer location table nor use it or we would
17051 get locations in abstract instantces. */
17052 old_decl_loc_table = decl_loc_table;
17053 decl_loc_table = NULL;
17054 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
17055 cached_dw_loc_list_table = NULL;
17056 old_call_arg_locations = call_arg_locations;
17057 call_arg_locations = NULL;
17058 old_call_site_count = call_site_count;
17059 call_site_count = -1;
17060 old_tail_call_site_count = tail_call_site_count;
17061 tail_call_site_count = -1;
17063 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17064 we don't get confused by DECL_ABSTRACT. */
17065 if (debug_info_level > DINFO_LEVEL_TERSE)
17067 context = decl_class_context (decl);
17069 gen_type_die_for_member
17070 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
17073 /* Pretend we've just finished compiling this function. */
17074 save_fn = current_function_decl;
17075 current_function_decl = decl;
17076 push_cfun (DECL_STRUCT_FUNCTION (decl));
17078 was_abstract = DECL_ABSTRACT (decl);
17079 set_decl_abstract_flags (decl, 1);
17080 dwarf2out_decl (decl);
17081 if (! was_abstract)
17082 set_decl_abstract_flags (decl, 0);
17084 current_function_decl = save_fn;
17085 decl_loc_table = old_decl_loc_table;
17086 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
17087 call_arg_locations = old_call_arg_locations;
17088 call_site_count = old_call_site_count;
17089 tail_call_site_count = old_tail_call_site_count;
17093 /* Helper function of premark_used_types() which gets called through
17096 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17097 marked as unused by prune_unused_types. */
17100 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
17105 type = (tree) *slot;
17106 die = lookup_type_die (type);
17108 die->die_perennial_p = 1;
17112 /* Helper function of premark_types_used_by_global_vars which gets called
17113 through htab_traverse.
17115 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17116 marked as unused by prune_unused_types. The DIE of the type is marked
17117 only if the global variable using the type will actually be emitted. */
17120 premark_types_used_by_global_vars_helper (void **slot,
17121 void *data ATTRIBUTE_UNUSED)
17123 struct types_used_by_vars_entry *entry;
17126 entry = (struct types_used_by_vars_entry *) *slot;
17127 gcc_assert (entry->type != NULL
17128 && entry->var_decl != NULL);
17129 die = lookup_type_die (entry->type);
17132 /* Ask cgraph if the global variable really is to be emitted.
17133 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17134 struct varpool_node *node = varpool_get_node (entry->var_decl);
17135 if (node && node->needed)
17137 die->die_perennial_p = 1;
17138 /* Keep the parent DIEs as well. */
17139 while ((die = die->die_parent) && die->die_perennial_p == 0)
17140 die->die_perennial_p = 1;
17146 /* Mark all members of used_types_hash as perennial. */
17149 premark_used_types (void)
17151 if (cfun && cfun->used_types_hash)
17152 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
17155 /* Mark all members of types_used_by_vars_entry as perennial. */
17158 premark_types_used_by_global_vars (void)
17160 if (types_used_by_vars_hash)
17161 htab_traverse (types_used_by_vars_hash,
17162 premark_types_used_by_global_vars_helper, NULL);
17165 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17166 for CA_LOC call arg loc node. */
17169 gen_call_site_die (tree decl, dw_die_ref subr_die,
17170 struct call_arg_loc_node *ca_loc)
17172 dw_die_ref stmt_die = NULL, die;
17173 tree block = ca_loc->block;
17176 && block != DECL_INITIAL (decl)
17177 && TREE_CODE (block) == BLOCK)
17179 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
17180 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
17183 block = BLOCK_SUPERCONTEXT (block);
17185 if (stmt_die == NULL)
17186 stmt_die = subr_die;
17187 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
17188 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
17189 if (ca_loc->tail_call_p)
17190 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
17191 if (ca_loc->symbol_ref)
17193 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
17195 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
17197 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
17202 /* Generate a DIE to represent a declared function (either file-scope or
17206 gen_subprogram_die (tree decl, dw_die_ref context_die)
17208 tree origin = decl_ultimate_origin (decl);
17209 dw_die_ref subr_die;
17211 dw_die_ref old_die = lookup_decl_die (decl);
17212 int declaration = (current_function_decl != decl
17213 || class_or_namespace_scope_p (context_die));
17215 premark_used_types ();
17217 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17218 started to generate the abstract instance of an inline, decided to output
17219 its containing class, and proceeded to emit the declaration of the inline
17220 from the member list for the class. If so, DECLARATION takes priority;
17221 we'll get back to the abstract instance when done with the class. */
17223 /* The class-scope declaration DIE must be the primary DIE. */
17224 if (origin && declaration && class_or_namespace_scope_p (context_die))
17227 gcc_assert (!old_die);
17230 /* Now that the C++ front end lazily declares artificial member fns, we
17231 might need to retrofit the declaration into its class. */
17232 if (!declaration && !origin && !old_die
17233 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
17234 && !class_or_namespace_scope_p (context_die)
17235 && debug_info_level > DINFO_LEVEL_TERSE)
17236 old_die = force_decl_die (decl);
17238 if (origin != NULL)
17240 gcc_assert (!declaration || local_scope_p (context_die));
17242 /* Fixup die_parent for the abstract instance of a nested
17243 inline function. */
17244 if (old_die && old_die->die_parent == NULL)
17245 add_child_die (context_die, old_die);
17247 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17248 add_abstract_origin_attribute (subr_die, origin);
17249 /* This is where the actual code for a cloned function is.
17250 Let's emit linkage name attribute for it. This helps
17251 debuggers to e.g, set breakpoints into
17252 constructors/destructors when the user asks "break
17254 add_linkage_name (subr_die, decl);
17258 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17259 struct dwarf_file_data * file_index = lookup_filename (s.file);
17261 if (!get_AT_flag (old_die, DW_AT_declaration)
17262 /* We can have a normal definition following an inline one in the
17263 case of redefinition of GNU C extern inlines.
17264 It seems reasonable to use AT_specification in this case. */
17265 && !get_AT (old_die, DW_AT_inline))
17267 /* Detect and ignore this case, where we are trying to output
17268 something we have already output. */
17272 /* If the definition comes from the same place as the declaration,
17273 maybe use the old DIE. We always want the DIE for this function
17274 that has the *_pc attributes to be under comp_unit_die so the
17275 debugger can find it. We also need to do this for abstract
17276 instances of inlines, since the spec requires the out-of-line copy
17277 to have the same parent. For local class methods, this doesn't
17278 apply; we just use the old DIE. */
17279 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
17280 && (DECL_ARTIFICIAL (decl)
17281 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
17282 && (get_AT_unsigned (old_die, DW_AT_decl_line)
17283 == (unsigned) s.line))))
17285 subr_die = old_die;
17287 /* Clear out the declaration attribute and the formal parameters.
17288 Do not remove all children, because it is possible that this
17289 declaration die was forced using force_decl_die(). In such
17290 cases die that forced declaration die (e.g. TAG_imported_module)
17291 is one of the children that we do not want to remove. */
17292 remove_AT (subr_die, DW_AT_declaration);
17293 remove_AT (subr_die, DW_AT_object_pointer);
17294 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
17298 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17299 add_AT_specification (subr_die, old_die);
17300 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
17301 add_AT_file (subr_die, DW_AT_decl_file, file_index);
17302 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
17303 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
17308 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17310 if (TREE_PUBLIC (decl))
17311 add_AT_flag (subr_die, DW_AT_external, 1);
17313 add_name_and_src_coords_attributes (subr_die, decl);
17314 if (debug_info_level > DINFO_LEVEL_TERSE)
17316 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
17317 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
17318 0, 0, context_die);
17321 add_pure_or_virtual_attribute (subr_die, decl);
17322 if (DECL_ARTIFICIAL (decl))
17323 add_AT_flag (subr_die, DW_AT_artificial, 1);
17325 add_accessibility_attribute (subr_die, decl);
17330 if (!old_die || !get_AT (old_die, DW_AT_inline))
17332 add_AT_flag (subr_die, DW_AT_declaration, 1);
17334 /* If this is an explicit function declaration then generate
17335 a DW_AT_explicit attribute. */
17336 if (lang_hooks.decls.function_decl_explicit_p (decl)
17337 && (dwarf_version >= 3 || !dwarf_strict))
17338 add_AT_flag (subr_die, DW_AT_explicit, 1);
17340 /* The first time we see a member function, it is in the context of
17341 the class to which it belongs. We make sure of this by emitting
17342 the class first. The next time is the definition, which is
17343 handled above. The two may come from the same source text.
17345 Note that force_decl_die() forces function declaration die. It is
17346 later reused to represent definition. */
17347 equate_decl_number_to_die (decl, subr_die);
17350 else if (DECL_ABSTRACT (decl))
17352 if (DECL_DECLARED_INLINE_P (decl))
17354 if (cgraph_function_possibly_inlined_p (decl))
17355 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
17357 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
17361 if (cgraph_function_possibly_inlined_p (decl))
17362 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
17364 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
17367 if (DECL_DECLARED_INLINE_P (decl)
17368 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
17369 add_AT_flag (subr_die, DW_AT_artificial, 1);
17371 equate_decl_number_to_die (decl, subr_die);
17373 else if (!DECL_EXTERNAL (decl))
17375 HOST_WIDE_INT cfa_fb_offset;
17377 if (!old_die || !get_AT (old_die, DW_AT_inline))
17378 equate_decl_number_to_die (decl, subr_die);
17380 if (!flag_reorder_blocks_and_partition)
17382 dw_fde_ref fde = cfun->fde;
17383 if (fde->dw_fde_begin)
17385 /* We have already generated the labels. */
17386 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17387 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17391 /* Create start/end labels and add the range. */
17392 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
17393 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
17394 current_function_funcdef_no);
17395 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
17396 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
17397 current_function_funcdef_no);
17398 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
17401 #if VMS_DEBUGGING_INFO
17402 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17403 Section 2.3 Prologue and Epilogue Attributes:
17404 When a breakpoint is set on entry to a function, it is generally
17405 desirable for execution to be suspended, not on the very first
17406 instruction of the function, but rather at a point after the
17407 function's frame has been set up, after any language defined local
17408 declaration processing has been completed, and before execution of
17409 the first statement of the function begins. Debuggers generally
17410 cannot properly determine where this point is. Similarly for a
17411 breakpoint set on exit from a function. The prologue and epilogue
17412 attributes allow a compiler to communicate the location(s) to use. */
17415 if (fde->dw_fde_vms_end_prologue)
17416 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
17417 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
17419 if (fde->dw_fde_vms_begin_epilogue)
17420 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
17421 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
17425 add_pubname (decl, subr_die);
17429 /* Generate pubnames entries for the split function code ranges. */
17430 dw_fde_ref fde = cfun->fde;
17432 if (fde->dw_fde_second_begin)
17434 if (dwarf_version >= 3 || !dwarf_strict)
17436 /* We should use ranges for non-contiguous code section
17437 addresses. Use the actual code range for the initial
17438 section, since the HOT/COLD labels might precede an
17439 alignment offset. */
17440 bool range_list_added = false;
17441 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
17442 fde->dw_fde_end, &range_list_added);
17443 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
17444 fde->dw_fde_second_end,
17445 &range_list_added);
17446 add_pubname (decl, subr_die);
17447 if (range_list_added)
17452 /* There is no real support in DW2 for this .. so we make
17453 a work-around. First, emit the pub name for the segment
17454 containing the function label. Then make and emit a
17455 simplified subprogram DIE for the second segment with the
17456 name pre-fixed by __hot/cold_sect_of_. We use the same
17457 linkage name for the second die so that gdb will find both
17458 sections when given "b foo". */
17459 const char *name = NULL;
17460 tree decl_name = DECL_NAME (decl);
17461 dw_die_ref seg_die;
17463 /* Do the 'primary' section. */
17464 add_AT_lbl_id (subr_die, DW_AT_low_pc,
17465 fde->dw_fde_begin);
17466 add_AT_lbl_id (subr_die, DW_AT_high_pc,
17469 add_pubname (decl, subr_die);
17471 /* Build a minimal DIE for the secondary section. */
17472 seg_die = new_die (DW_TAG_subprogram,
17473 subr_die->die_parent, decl);
17475 if (TREE_PUBLIC (decl))
17476 add_AT_flag (seg_die, DW_AT_external, 1);
17478 if (decl_name != NULL
17479 && IDENTIFIER_POINTER (decl_name) != NULL)
17481 name = dwarf2_name (decl, 1);
17482 if (! DECL_ARTIFICIAL (decl))
17483 add_src_coords_attributes (seg_die, decl);
17485 add_linkage_name (seg_die, decl);
17487 gcc_assert (name != NULL);
17488 add_pure_or_virtual_attribute (seg_die, decl);
17489 if (DECL_ARTIFICIAL (decl))
17490 add_AT_flag (seg_die, DW_AT_artificial, 1);
17492 name = concat ("__second_sect_of_", name, NULL);
17493 add_AT_lbl_id (seg_die, DW_AT_low_pc,
17494 fde->dw_fde_second_begin);
17495 add_AT_lbl_id (seg_die, DW_AT_high_pc,
17496 fde->dw_fde_second_end);
17497 add_name_attribute (seg_die, name);
17498 add_pubname_string (name, seg_die);
17503 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17504 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17505 add_pubname (decl, subr_die);
17509 #ifdef MIPS_DEBUGGING_INFO
17510 /* Add a reference to the FDE for this routine. */
17511 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, cfun->fde->fde_index);
17514 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
17516 /* We define the "frame base" as the function's CFA. This is more
17517 convenient for several reasons: (1) It's stable across the prologue
17518 and epilogue, which makes it better than just a frame pointer,
17519 (2) With dwarf3, there exists a one-byte encoding that allows us
17520 to reference the .debug_frame data by proxy, but failing that,
17521 (3) We can at least reuse the code inspection and interpretation
17522 code that determines the CFA position at various points in the
17524 if (dwarf_version >= 3)
17526 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
17527 add_AT_loc (subr_die, DW_AT_frame_base, op);
17531 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
17532 if (list->dw_loc_next)
17533 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
17535 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
17538 /* Compute a displacement from the "steady-state frame pointer" to
17539 the CFA. The former is what all stack slots and argument slots
17540 will reference in the rtl; the later is what we've told the
17541 debugger about. We'll need to adjust all frame_base references
17542 by this displacement. */
17543 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
17545 if (cfun->static_chain_decl)
17546 add_AT_location_description (subr_die, DW_AT_static_link,
17547 loc_list_from_tree (cfun->static_chain_decl, 2));
17550 /* Generate child dies for template paramaters. */
17551 if (debug_info_level > DINFO_LEVEL_TERSE)
17552 gen_generic_params_dies (decl);
17554 /* Now output descriptions of the arguments for this function. This gets
17555 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17556 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17557 `...' at the end of the formal parameter list. In order to find out if
17558 there was a trailing ellipsis or not, we must instead look at the type
17559 associated with the FUNCTION_DECL. This will be a node of type
17560 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17561 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17562 an ellipsis at the end. */
17564 /* In the case where we are describing a mere function declaration, all we
17565 need to do here (and all we *can* do here) is to describe the *types* of
17566 its formal parameters. */
17567 if (debug_info_level <= DINFO_LEVEL_TERSE)
17569 else if (declaration)
17570 gen_formal_types_die (decl, subr_die);
17573 /* Generate DIEs to represent all known formal parameters. */
17574 tree parm = DECL_ARGUMENTS (decl);
17575 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
17576 tree generic_decl_parm = generic_decl
17577 ? DECL_ARGUMENTS (generic_decl)
17580 /* Now we want to walk the list of parameters of the function and
17581 emit their relevant DIEs.
17583 We consider the case of DECL being an instance of a generic function
17584 as well as it being a normal function.
17586 If DECL is an instance of a generic function we walk the
17587 parameters of the generic function declaration _and_ the parameters of
17588 DECL itself. This is useful because we want to emit specific DIEs for
17589 function parameter packs and those are declared as part of the
17590 generic function declaration. In that particular case,
17591 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17592 That DIE has children DIEs representing the set of arguments
17593 of the pack. Note that the set of pack arguments can be empty.
17594 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17597 Otherwise, we just consider the parameters of DECL. */
17598 while (generic_decl_parm || parm)
17600 if (generic_decl_parm
17601 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
17602 gen_formal_parameter_pack_die (generic_decl_parm,
17607 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
17609 if (parm == DECL_ARGUMENTS (decl)
17610 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
17612 && (dwarf_version >= 3 || !dwarf_strict))
17613 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
17615 parm = DECL_CHAIN (parm);
17618 if (generic_decl_parm)
17619 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
17622 /* Decide whether we need an unspecified_parameters DIE at the end.
17623 There are 2 more cases to do this for: 1) the ansi ... declaration -
17624 this is detectable when the end of the arg list is not a
17625 void_type_node 2) an unprototyped function declaration (not a
17626 definition). This just means that we have no info about the
17627 parameters at all. */
17628 if (prototype_p (TREE_TYPE (decl)))
17630 /* This is the prototyped case, check for.... */
17631 if (stdarg_p (TREE_TYPE (decl)))
17632 gen_unspecified_parameters_die (decl, subr_die);
17634 else if (DECL_INITIAL (decl) == NULL_TREE)
17635 gen_unspecified_parameters_die (decl, subr_die);
17638 /* Output Dwarf info for all of the stuff within the body of the function
17639 (if it has one - it may be just a declaration). */
17640 outer_scope = DECL_INITIAL (decl);
17642 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17643 a function. This BLOCK actually represents the outermost binding contour
17644 for the function, i.e. the contour in which the function's formal
17645 parameters and labels get declared. Curiously, it appears that the front
17646 end doesn't actually put the PARM_DECL nodes for the current function onto
17647 the BLOCK_VARS list for this outer scope, but are strung off of the
17648 DECL_ARGUMENTS list for the function instead.
17650 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17651 the LABEL_DECL nodes for the function however, and we output DWARF info
17652 for those in decls_for_scope. Just within the `outer_scope' there will be
17653 a BLOCK node representing the function's outermost pair of curly braces,
17654 and any blocks used for the base and member initializers of a C++
17655 constructor function. */
17656 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
17658 int call_site_note_count = 0;
17659 int tail_call_site_note_count = 0;
17661 /* Emit a DW_TAG_variable DIE for a named return value. */
17662 if (DECL_NAME (DECL_RESULT (decl)))
17663 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
17665 current_function_has_inlines = 0;
17666 decls_for_scope (outer_scope, subr_die, 0);
17668 if (call_arg_locations && !dwarf_strict)
17670 struct call_arg_loc_node *ca_loc;
17671 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
17673 dw_die_ref die = NULL;
17674 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
17677 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
17678 arg; arg = next_arg)
17680 dw_loc_descr_ref reg, val;
17681 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
17682 dw_die_ref cdie, tdie = NULL;
17684 next_arg = XEXP (arg, 1);
17685 if (REG_P (XEXP (XEXP (arg, 0), 0))
17687 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
17688 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
17689 && REGNO (XEXP (XEXP (arg, 0), 0))
17690 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
17691 next_arg = XEXP (next_arg, 1);
17692 if (mode == VOIDmode)
17694 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
17695 if (mode == VOIDmode)
17696 mode = GET_MODE (XEXP (arg, 0));
17698 if (mode == VOIDmode || mode == BLKmode)
17700 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
17702 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17703 tloc = XEXP (XEXP (arg, 0), 1);
17706 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
17707 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
17709 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17710 tlocc = XEXP (XEXP (arg, 0), 1);
17714 if (REG_P (XEXP (XEXP (arg, 0), 0)))
17715 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
17716 VAR_INIT_STATUS_INITIALIZED);
17717 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
17719 rtx mem = XEXP (XEXP (arg, 0), 0);
17720 reg = mem_loc_descriptor (XEXP (mem, 0),
17721 get_address_mode (mem),
17723 VAR_INIT_STATUS_INITIALIZED);
17725 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
17726 == DEBUG_PARAMETER_REF)
17729 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
17730 tdie = lookup_decl_die (tdecl);
17737 && GET_CODE (XEXP (XEXP (arg, 0), 0))
17738 != DEBUG_PARAMETER_REF)
17740 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
17742 VAR_INIT_STATUS_INITIALIZED);
17746 die = gen_call_site_die (decl, subr_die, ca_loc);
17747 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
17750 add_AT_loc (cdie, DW_AT_location, reg);
17751 else if (tdie != NULL)
17752 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
17753 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
17754 if (next_arg != XEXP (arg, 1))
17756 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
17757 if (mode == VOIDmode)
17758 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
17759 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
17762 VAR_INIT_STATUS_INITIALIZED);
17764 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
17768 && (ca_loc->symbol_ref || tloc))
17769 die = gen_call_site_die (decl, subr_die, ca_loc);
17770 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
17772 dw_loc_descr_ref tval = NULL;
17774 if (tloc != NULL_RTX)
17775 tval = mem_loc_descriptor (tloc,
17776 GET_MODE (tloc) == VOIDmode
17777 ? Pmode : GET_MODE (tloc),
17779 VAR_INIT_STATUS_INITIALIZED);
17781 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
17782 else if (tlocc != NULL_RTX)
17784 tval = mem_loc_descriptor (tlocc,
17785 GET_MODE (tlocc) == VOIDmode
17786 ? Pmode : GET_MODE (tlocc),
17788 VAR_INIT_STATUS_INITIALIZED);
17790 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
17796 call_site_note_count++;
17797 if (ca_loc->tail_call_p)
17798 tail_call_site_note_count++;
17802 call_arg_locations = NULL;
17803 call_arg_loc_last = NULL;
17804 if (tail_call_site_count >= 0
17805 && tail_call_site_count == tail_call_site_note_count
17808 if (call_site_count >= 0
17809 && call_site_count == call_site_note_count)
17810 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
17812 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
17814 call_site_count = -1;
17815 tail_call_site_count = -1;
17817 /* Add the calling convention attribute if requested. */
17818 add_calling_convention_attribute (subr_die, decl);
17822 /* Returns a hash value for X (which really is a die_struct). */
17825 common_block_die_table_hash (const void *x)
17827 const_dw_die_ref d = (const_dw_die_ref) x;
17828 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
17831 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17832 as decl_id and die_parent of die_struct Y. */
17835 common_block_die_table_eq (const void *x, const void *y)
17837 const_dw_die_ref d = (const_dw_die_ref) x;
17838 const_dw_die_ref e = (const_dw_die_ref) y;
17839 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
17842 /* Generate a DIE to represent a declared data object.
17843 Either DECL or ORIGIN must be non-null. */
17846 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
17850 tree decl_or_origin = decl ? decl : origin;
17851 tree ultimate_origin;
17852 dw_die_ref var_die;
17853 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
17854 dw_die_ref origin_die;
17855 bool declaration = (DECL_EXTERNAL (decl_or_origin)
17856 || class_or_namespace_scope_p (context_die));
17857 bool specialization_p = false;
17859 ultimate_origin = decl_ultimate_origin (decl_or_origin);
17860 if (decl || ultimate_origin)
17861 origin = ultimate_origin;
17862 com_decl = fortran_common (decl_or_origin, &off);
17864 /* Symbol in common gets emitted as a child of the common block, in the form
17865 of a data member. */
17868 dw_die_ref com_die;
17869 dw_loc_list_ref loc;
17870 die_node com_die_arg;
17872 var_die = lookup_decl_die (decl_or_origin);
17875 if (get_AT (var_die, DW_AT_location) == NULL)
17877 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
17882 /* Optimize the common case. */
17883 if (single_element_loc_list_p (loc)
17884 && loc->expr->dw_loc_opc == DW_OP_addr
17885 && loc->expr->dw_loc_next == NULL
17886 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
17888 loc->expr->dw_loc_oprnd1.v.val_addr
17889 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
17891 loc_list_plus_const (loc, off);
17893 add_AT_location_description (var_die, DW_AT_location, loc);
17894 remove_AT (var_die, DW_AT_declaration);
17900 if (common_block_die_table == NULL)
17901 common_block_die_table
17902 = htab_create_ggc (10, common_block_die_table_hash,
17903 common_block_die_table_eq, NULL);
17905 com_die_arg.decl_id = DECL_UID (com_decl);
17906 com_die_arg.die_parent = context_die;
17907 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
17908 loc = loc_list_from_tree (com_decl, 2);
17909 if (com_die == NULL)
17912 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
17915 com_die = new_die (DW_TAG_common_block, context_die, decl);
17916 add_name_and_src_coords_attributes (com_die, com_decl);
17919 add_AT_location_description (com_die, DW_AT_location, loc);
17920 /* Avoid sharing the same loc descriptor between
17921 DW_TAG_common_block and DW_TAG_variable. */
17922 loc = loc_list_from_tree (com_decl, 2);
17924 else if (DECL_EXTERNAL (decl))
17925 add_AT_flag (com_die, DW_AT_declaration, 1);
17926 add_pubname_string (cnam, com_die); /* ??? needed? */
17927 com_die->decl_id = DECL_UID (com_decl);
17928 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
17929 *slot = (void *) com_die;
17931 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
17933 add_AT_location_description (com_die, DW_AT_location, loc);
17934 loc = loc_list_from_tree (com_decl, 2);
17935 remove_AT (com_die, DW_AT_declaration);
17937 var_die = new_die (DW_TAG_variable, com_die, decl);
17938 add_name_and_src_coords_attributes (var_die, decl);
17939 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
17940 TREE_THIS_VOLATILE (decl), context_die);
17941 add_AT_flag (var_die, DW_AT_external, 1);
17946 /* Optimize the common case. */
17947 if (single_element_loc_list_p (loc)
17948 && loc->expr->dw_loc_opc == DW_OP_addr
17949 && loc->expr->dw_loc_next == NULL
17950 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
17951 loc->expr->dw_loc_oprnd1.v.val_addr
17952 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
17954 loc_list_plus_const (loc, off);
17956 add_AT_location_description (var_die, DW_AT_location, loc);
17958 else if (DECL_EXTERNAL (decl))
17959 add_AT_flag (var_die, DW_AT_declaration, 1);
17960 equate_decl_number_to_die (decl, var_die);
17964 /* If the compiler emitted a definition for the DECL declaration
17965 and if we already emitted a DIE for it, don't emit a second
17966 DIE for it again. Allow re-declarations of DECLs that are
17967 inside functions, though. */
17968 if (old_die && declaration && !local_scope_p (context_die))
17971 /* For static data members, the declaration in the class is supposed
17972 to have DW_TAG_member tag; the specification should still be
17973 DW_TAG_variable referencing the DW_TAG_member DIE. */
17974 if (declaration && class_scope_p (context_die))
17975 var_die = new_die (DW_TAG_member, context_die, decl);
17977 var_die = new_die (DW_TAG_variable, context_die, decl);
17980 if (origin != NULL)
17981 origin_die = add_abstract_origin_attribute (var_die, origin);
17983 /* Loop unrolling can create multiple blocks that refer to the same
17984 static variable, so we must test for the DW_AT_declaration flag.
17986 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17987 copy decls and set the DECL_ABSTRACT flag on them instead of
17990 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17992 ??? The declare_in_namespace support causes us to get two DIEs for one
17993 variable, both of which are declarations. We want to avoid considering
17994 one to be a specification, so we must test that this DIE is not a
17996 else if (old_die && TREE_STATIC (decl) && ! declaration
17997 && get_AT_flag (old_die, DW_AT_declaration) == 1)
17999 /* This is a definition of a C++ class level static. */
18000 add_AT_specification (var_die, old_die);
18001 specialization_p = true;
18002 if (DECL_NAME (decl))
18004 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
18005 struct dwarf_file_data * file_index = lookup_filename (s.file);
18007 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
18008 add_AT_file (var_die, DW_AT_decl_file, file_index);
18010 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
18011 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
18013 if (old_die->die_tag == DW_TAG_member)
18014 add_linkage_name (var_die, decl);
18018 add_name_and_src_coords_attributes (var_die, decl);
18020 if ((origin == NULL && !specialization_p)
18022 && !DECL_ABSTRACT (decl_or_origin)
18023 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
18024 decl_function_context
18025 (decl_or_origin))))
18027 tree type = TREE_TYPE (decl_or_origin);
18029 if (decl_by_reference_p (decl_or_origin))
18030 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
18032 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
18033 TREE_THIS_VOLATILE (decl_or_origin), context_die);
18036 if (origin == NULL && !specialization_p)
18038 if (TREE_PUBLIC (decl))
18039 add_AT_flag (var_die, DW_AT_external, 1);
18041 if (DECL_ARTIFICIAL (decl))
18042 add_AT_flag (var_die, DW_AT_artificial, 1);
18044 add_accessibility_attribute (var_die, decl);
18048 add_AT_flag (var_die, DW_AT_declaration, 1);
18050 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
18051 equate_decl_number_to_die (decl, var_die);
18054 && (! DECL_ABSTRACT (decl_or_origin)
18055 /* Local static vars are shared between all clones/inlines,
18056 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18058 || (TREE_CODE (decl_or_origin) == VAR_DECL
18059 && TREE_STATIC (decl_or_origin)
18060 && DECL_RTL_SET_P (decl_or_origin)))
18061 /* When abstract origin already has DW_AT_location attribute, no need
18062 to add it again. */
18063 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
18065 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
18066 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
18067 defer_location (decl_or_origin, var_die);
18069 add_location_or_const_value_attribute (var_die, decl_or_origin,
18070 decl == NULL, DW_AT_location);
18071 add_pubname (decl_or_origin, var_die);
18074 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
18077 /* Generate a DIE to represent a named constant. */
18080 gen_const_die (tree decl, dw_die_ref context_die)
18082 dw_die_ref const_die;
18083 tree type = TREE_TYPE (decl);
18085 const_die = new_die (DW_TAG_constant, context_die, decl);
18086 add_name_and_src_coords_attributes (const_die, decl);
18087 add_type_attribute (const_die, type, 1, 0, context_die);
18088 if (TREE_PUBLIC (decl))
18089 add_AT_flag (const_die, DW_AT_external, 1);
18090 if (DECL_ARTIFICIAL (decl))
18091 add_AT_flag (const_die, DW_AT_artificial, 1);
18092 tree_add_const_value_attribute_for_decl (const_die, decl);
18095 /* Generate a DIE to represent a label identifier. */
18098 gen_label_die (tree decl, dw_die_ref context_die)
18100 tree origin = decl_ultimate_origin (decl);
18101 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
18103 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18105 if (origin != NULL)
18106 add_abstract_origin_attribute (lbl_die, origin);
18108 add_name_and_src_coords_attributes (lbl_die, decl);
18110 if (DECL_ABSTRACT (decl))
18111 equate_decl_number_to_die (decl, lbl_die);
18114 insn = DECL_RTL_IF_SET (decl);
18116 /* Deleted labels are programmer specified labels which have been
18117 eliminated because of various optimizations. We still emit them
18118 here so that it is possible to put breakpoints on them. */
18122 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
18124 /* When optimization is enabled (via -O) some parts of the compiler
18125 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18126 represent source-level labels which were explicitly declared by
18127 the user. This really shouldn't be happening though, so catch
18128 it if it ever does happen. */
18129 gcc_assert (!INSN_DELETED_P (insn));
18131 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
18132 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
18136 && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL
18137 && CODE_LABEL_NUMBER (insn) != -1)
18139 ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn));
18140 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
18145 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18146 attributes to the DIE for a block STMT, to describe where the inlined
18147 function was called from. This is similar to add_src_coords_attributes. */
18150 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
18152 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
18154 if (dwarf_version >= 3 || !dwarf_strict)
18156 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
18157 add_AT_unsigned (die, DW_AT_call_line, s.line);
18162 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18163 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18166 add_high_low_attributes (tree stmt, dw_die_ref die)
18168 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18170 if (BLOCK_FRAGMENT_CHAIN (stmt)
18171 && (dwarf_version >= 3 || !dwarf_strict))
18175 if (inlined_function_outer_scope_p (stmt))
18177 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
18178 BLOCK_NUMBER (stmt));
18179 add_AT_lbl_id (die, DW_AT_entry_pc, label);
18182 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
18184 chain = BLOCK_FRAGMENT_CHAIN (stmt);
18187 add_ranges (chain);
18188 chain = BLOCK_FRAGMENT_CHAIN (chain);
18195 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
18196 BLOCK_NUMBER (stmt));
18197 add_AT_lbl_id (die, DW_AT_low_pc, label);
18198 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
18199 BLOCK_NUMBER (stmt));
18200 add_AT_lbl_id (die, DW_AT_high_pc, label);
18204 /* Generate a DIE for a lexical block. */
18207 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
18209 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
18211 if (call_arg_locations)
18213 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
18214 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
18215 BLOCK_NUMBER (stmt) + 1);
18216 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
18219 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
18220 add_high_low_attributes (stmt, stmt_die);
18222 decls_for_scope (stmt, stmt_die, depth);
18225 /* Generate a DIE for an inlined subprogram. */
18228 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
18232 /* The instance of function that is effectively being inlined shall not
18234 gcc_assert (! BLOCK_ABSTRACT (stmt));
18236 decl = block_ultimate_origin (stmt);
18238 /* Emit info for the abstract instance first, if we haven't yet. We
18239 must emit this even if the block is abstract, otherwise when we
18240 emit the block below (or elsewhere), we may end up trying to emit
18241 a die whose origin die hasn't been emitted, and crashing. */
18242 dwarf2out_abstract_function (decl);
18244 if (! BLOCK_ABSTRACT (stmt))
18246 dw_die_ref subr_die
18247 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
18249 if (call_arg_locations)
18251 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
18252 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
18253 BLOCK_NUMBER (stmt) + 1);
18254 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
18256 add_abstract_origin_attribute (subr_die, decl);
18257 if (TREE_ASM_WRITTEN (stmt))
18258 add_high_low_attributes (stmt, subr_die);
18259 add_call_src_coords_attributes (stmt, subr_die);
18261 decls_for_scope (stmt, subr_die, depth);
18262 current_function_has_inlines = 1;
18266 /* Generate a DIE for a field in a record, or structure. */
18269 gen_field_die (tree decl, dw_die_ref context_die)
18271 dw_die_ref decl_die;
18273 if (TREE_TYPE (decl) == error_mark_node)
18276 decl_die = new_die (DW_TAG_member, context_die, decl);
18277 add_name_and_src_coords_attributes (decl_die, decl);
18278 add_type_attribute (decl_die, member_declared_type (decl),
18279 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
18282 if (DECL_BIT_FIELD_TYPE (decl))
18284 add_byte_size_attribute (decl_die, decl);
18285 add_bit_size_attribute (decl_die, decl);
18286 add_bit_offset_attribute (decl_die, decl);
18289 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
18290 add_data_member_location_attribute (decl_die, decl);
18292 if (DECL_ARTIFICIAL (decl))
18293 add_AT_flag (decl_die, DW_AT_artificial, 1);
18295 add_accessibility_attribute (decl_die, decl);
18297 /* Equate decl number to die, so that we can look up this decl later on. */
18298 equate_decl_number_to_die (decl, decl_die);
18302 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18303 Use modified_type_die instead.
18304 We keep this code here just in case these types of DIEs may be needed to
18305 represent certain things in other languages (e.g. Pascal) someday. */
18308 gen_pointer_type_die (tree type, dw_die_ref context_die)
18311 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
18313 equate_type_number_to_die (type, ptr_die);
18314 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18315 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18318 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18319 Use modified_type_die instead.
18320 We keep this code here just in case these types of DIEs may be needed to
18321 represent certain things in other languages (e.g. Pascal) someday. */
18324 gen_reference_type_die (tree type, dw_die_ref context_die)
18326 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
18328 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
18329 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
18331 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
18333 equate_type_number_to_die (type, ref_die);
18334 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
18335 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18339 /* Generate a DIE for a pointer to a member type. */
18342 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
18345 = new_die (DW_TAG_ptr_to_member_type,
18346 scope_die_for (type, context_die), type);
18348 equate_type_number_to_die (type, ptr_die);
18349 add_AT_die_ref (ptr_die, DW_AT_containing_type,
18350 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
18351 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18354 typedef const char *dchar_p; /* For DEF_VEC_P. */
18355 DEF_VEC_P(dchar_p);
18356 DEF_VEC_ALLOC_P(dchar_p,heap);
18358 static char *producer_string;
18360 /* Return a heap allocated producer string including command line options
18361 if -grecord-gcc-switches. */
18364 gen_producer_string (void)
18367 VEC(dchar_p, heap) *switches = NULL;
18368 const char *language_string = lang_hooks.name;
18369 char *producer, *tail;
18371 size_t len = dwarf_record_gcc_switches ? 0 : 3;
18372 size_t plen = strlen (language_string) + 1 + strlen (version_string);
18374 for (j = 1; dwarf_record_gcc_switches && j < save_decoded_options_count; j++)
18375 switch (save_decoded_options[j].opt_index)
18382 case OPT_auxbase_strip:
18391 case OPT_SPECIAL_unknown:
18392 case OPT_SPECIAL_ignore:
18393 case OPT_SPECIAL_program_name:
18394 case OPT_SPECIAL_input_file:
18395 case OPT_grecord_gcc_switches:
18396 case OPT_gno_record_gcc_switches:
18397 case OPT__output_pch_:
18398 case OPT_fdiagnostics_show_location_:
18399 case OPT_fdiagnostics_show_option:
18400 case OPT_fverbose_asm:
18402 case OPT__sysroot_:
18404 case OPT_nostdinc__:
18405 /* Ignore these. */
18408 gcc_checking_assert (save_decoded_options[j].canonical_option[0][0]
18410 switch (save_decoded_options[j].canonical_option[0][1])
18417 if (strncmp (save_decoded_options[j].canonical_option[0] + 2,
18424 VEC_safe_push (dchar_p, heap, switches,
18425 save_decoded_options[j].orig_option_with_args_text);
18426 len += strlen (save_decoded_options[j].orig_option_with_args_text) + 1;
18430 producer = XNEWVEC (char, plen + 1 + len + 1);
18432 sprintf (tail, "%s %s", language_string, version_string);
18435 if (!dwarf_record_gcc_switches)
18437 #ifdef MIPS_DEBUGGING_INFO
18438 /* The MIPS/SGI compilers place the 'cc' command line options in the
18439 producer string. The SGI debugger looks for -g, -g1, -g2, or -g3;
18440 if they do not appear in the producer string, the debugger reaches
18441 the conclusion that the object file is stripped and has no debugging
18442 information. To get the MIPS/SGI debugger to believe that there is
18443 debugging information in the object file, we add a -g to the producer
18445 if (debug_info_level > DINFO_LEVEL_TERSE)
18447 memcpy (tail, " -g", 3);
18453 FOR_EACH_VEC_ELT (dchar_p, switches, j, p)
18457 memcpy (tail + 1, p, len);
18462 VEC_free (dchar_p, heap, switches);
18466 /* Generate the DIE for the compilation unit. */
18469 gen_compile_unit_die (const char *filename)
18472 const char *language_string = lang_hooks.name;
18475 die = new_die (DW_TAG_compile_unit, NULL, NULL);
18479 add_name_attribute (die, filename);
18480 /* Don't add cwd for <built-in>. */
18481 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
18482 add_comp_dir_attribute (die);
18485 if (producer_string == NULL)
18486 producer_string = gen_producer_string ();
18487 add_AT_string (die, DW_AT_producer, producer_string);
18489 /* If our producer is LTO try to figure out a common language to use
18490 from the global list of translation units. */
18491 if (strcmp (language_string, "GNU GIMPLE") == 0)
18495 const char *common_lang = NULL;
18497 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
18499 if (!TRANSLATION_UNIT_LANGUAGE (t))
18502 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
18503 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
18505 else if (strncmp (common_lang, "GNU C", 5) == 0
18506 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
18507 /* Mixing C and C++ is ok, use C++ in that case. */
18508 common_lang = "GNU C++";
18511 /* Fall back to C. */
18512 common_lang = NULL;
18518 language_string = common_lang;
18521 language = DW_LANG_C89;
18522 if (strcmp (language_string, "GNU C++") == 0)
18523 language = DW_LANG_C_plus_plus;
18524 else if (strcmp (language_string, "GNU F77") == 0)
18525 language = DW_LANG_Fortran77;
18526 else if (strcmp (language_string, "GNU Pascal") == 0)
18527 language = DW_LANG_Pascal83;
18528 else if (dwarf_version >= 3 || !dwarf_strict)
18530 if (strcmp (language_string, "GNU Ada") == 0)
18531 language = DW_LANG_Ada95;
18532 else if (strcmp (language_string, "GNU Fortran") == 0)
18533 language = DW_LANG_Fortran95;
18534 else if (strcmp (language_string, "GNU Java") == 0)
18535 language = DW_LANG_Java;
18536 else if (strcmp (language_string, "GNU Objective-C") == 0)
18537 language = DW_LANG_ObjC;
18538 else if (strcmp (language_string, "GNU Objective-C++") == 0)
18539 language = DW_LANG_ObjC_plus_plus;
18540 else if (dwarf_version >= 5 || !dwarf_strict)
18542 if (strcmp (language_string, "GNU Go") == 0)
18543 language = DW_LANG_Go;
18547 add_AT_unsigned (die, DW_AT_language, language);
18551 case DW_LANG_Fortran77:
18552 case DW_LANG_Fortran90:
18553 case DW_LANG_Fortran95:
18554 /* Fortran has case insensitive identifiers and the front-end
18555 lowercases everything. */
18556 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
18559 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18565 /* Generate the DIE for a base class. */
18568 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
18570 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
18572 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
18573 add_data_member_location_attribute (die, binfo);
18575 if (BINFO_VIRTUAL_P (binfo))
18576 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18578 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18579 children, otherwise the default is DW_ACCESS_public. In DWARF2
18580 the default has always been DW_ACCESS_private. */
18581 if (access == access_public_node)
18583 if (dwarf_version == 2
18584 || context_die->die_tag == DW_TAG_class_type)
18585 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
18587 else if (access == access_protected_node)
18588 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
18589 else if (dwarf_version > 2
18590 && context_die->die_tag != DW_TAG_class_type)
18591 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
18594 /* Generate a DIE for a class member. */
18597 gen_member_die (tree type, dw_die_ref context_die)
18600 tree binfo = TYPE_BINFO (type);
18603 /* If this is not an incomplete type, output descriptions of each of its
18604 members. Note that as we output the DIEs necessary to represent the
18605 members of this record or union type, we will also be trying to output
18606 DIEs to represent the *types* of those members. However the `type'
18607 function (above) will specifically avoid generating type DIEs for member
18608 types *within* the list of member DIEs for this (containing) type except
18609 for those types (of members) which are explicitly marked as also being
18610 members of this (containing) type themselves. The g++ front- end can
18611 force any given type to be treated as a member of some other (containing)
18612 type by setting the TYPE_CONTEXT of the given (member) type to point to
18613 the TREE node representing the appropriate (containing) type. */
18615 /* First output info about the base classes. */
18618 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
18622 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
18623 gen_inheritance_die (base,
18624 (accesses ? VEC_index (tree, accesses, i)
18625 : access_public_node), context_die);
18628 /* Now output info about the data members and type members. */
18629 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
18631 /* If we thought we were generating minimal debug info for TYPE
18632 and then changed our minds, some of the member declarations
18633 may have already been defined. Don't define them again, but
18634 do put them in the right order. */
18636 child = lookup_decl_die (member);
18638 splice_child_die (context_die, child);
18640 gen_decl_die (member, NULL, context_die);
18643 /* Now output info about the function members (if any). */
18644 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
18646 /* Don't include clones in the member list. */
18647 if (DECL_ABSTRACT_ORIGIN (member))
18650 child = lookup_decl_die (member);
18652 splice_child_die (context_die, child);
18654 gen_decl_die (member, NULL, context_die);
18658 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18659 is set, we pretend that the type was never defined, so we only get the
18660 member DIEs needed by later specification DIEs. */
18663 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
18664 enum debug_info_usage usage)
18666 dw_die_ref type_die = lookup_type_die (type);
18667 dw_die_ref scope_die = 0;
18669 int complete = (TYPE_SIZE (type)
18670 && (! TYPE_STUB_DECL (type)
18671 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
18672 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
18673 complete = complete && should_emit_struct_debug (type, usage);
18675 if (type_die && ! complete)
18678 if (TYPE_CONTEXT (type) != NULL_TREE
18679 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18680 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
18683 scope_die = scope_die_for (type, context_die);
18685 if (! type_die || (nested && is_cu_die (scope_die)))
18686 /* First occurrence of type or toplevel definition of nested class. */
18688 dw_die_ref old_die = type_die;
18690 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
18691 ? record_type_tag (type) : DW_TAG_union_type,
18693 equate_type_number_to_die (type, type_die);
18695 add_AT_specification (type_die, old_die);
18697 add_name_attribute (type_die, type_tag (type));
18700 remove_AT (type_die, DW_AT_declaration);
18702 /* Generate child dies for template paramaters. */
18703 if (debug_info_level > DINFO_LEVEL_TERSE
18704 && COMPLETE_TYPE_P (type))
18705 schedule_generic_params_dies_gen (type);
18707 /* If this type has been completed, then give it a byte_size attribute and
18708 then give a list of members. */
18709 if (complete && !ns_decl)
18711 /* Prevent infinite recursion in cases where the type of some member of
18712 this type is expressed in terms of this type itself. */
18713 TREE_ASM_WRITTEN (type) = 1;
18714 add_byte_size_attribute (type_die, type);
18715 if (TYPE_STUB_DECL (type) != NULL_TREE)
18717 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18718 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18721 /* If the first reference to this type was as the return type of an
18722 inline function, then it may not have a parent. Fix this now. */
18723 if (type_die->die_parent == NULL)
18724 add_child_die (scope_die, type_die);
18726 push_decl_scope (type);
18727 gen_member_die (type, type_die);
18730 add_gnat_descriptive_type_attribute (type_die, type, context_die);
18731 if (TYPE_ARTIFICIAL (type))
18732 add_AT_flag (type_die, DW_AT_artificial, 1);
18734 /* GNU extension: Record what type our vtable lives in. */
18735 if (TYPE_VFIELD (type))
18737 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
18739 gen_type_die (vtype, context_die);
18740 add_AT_die_ref (type_die, DW_AT_containing_type,
18741 lookup_type_die (vtype));
18746 add_AT_flag (type_die, DW_AT_declaration, 1);
18748 /* We don't need to do this for function-local types. */
18749 if (TYPE_STUB_DECL (type)
18750 && ! decl_function_context (TYPE_STUB_DECL (type)))
18751 VEC_safe_push (tree, gc, incomplete_types, type);
18754 if (get_AT (type_die, DW_AT_name))
18755 add_pubtype (type, type_die);
18758 /* Generate a DIE for a subroutine _type_. */
18761 gen_subroutine_type_die (tree type, dw_die_ref context_die)
18763 tree return_type = TREE_TYPE (type);
18764 dw_die_ref subr_die
18765 = new_die (DW_TAG_subroutine_type,
18766 scope_die_for (type, context_die), type);
18768 equate_type_number_to_die (type, subr_die);
18769 add_prototyped_attribute (subr_die, type);
18770 add_type_attribute (subr_die, return_type, 0, 0, context_die);
18771 gen_formal_types_die (type, subr_die);
18773 if (get_AT (subr_die, DW_AT_name))
18774 add_pubtype (type, subr_die);
18777 /* Generate a DIE for a type definition. */
18780 gen_typedef_die (tree decl, dw_die_ref context_die)
18782 dw_die_ref type_die;
18785 if (TREE_ASM_WRITTEN (decl))
18788 TREE_ASM_WRITTEN (decl) = 1;
18789 type_die = new_die (DW_TAG_typedef, context_die, decl);
18790 origin = decl_ultimate_origin (decl);
18791 if (origin != NULL)
18792 add_abstract_origin_attribute (type_die, origin);
18797 add_name_and_src_coords_attributes (type_die, decl);
18798 if (DECL_ORIGINAL_TYPE (decl))
18800 type = DECL_ORIGINAL_TYPE (decl);
18802 gcc_assert (type != TREE_TYPE (decl));
18803 equate_type_number_to_die (TREE_TYPE (decl), type_die);
18807 type = TREE_TYPE (decl);
18809 if (is_naming_typedef_decl (TYPE_NAME (type)))
18811 /* Here, we are in the case of decl being a typedef naming
18812 an anonymous type, e.g:
18813 typedef struct {...} foo;
18814 In that case TREE_TYPE (decl) is not a typedef variant
18815 type and TYPE_NAME of the anonymous type is set to the
18816 TYPE_DECL of the typedef. This construct is emitted by
18819 TYPE is the anonymous struct named by the typedef
18820 DECL. As we need the DW_AT_type attribute of the
18821 DW_TAG_typedef to point to the DIE of TYPE, let's
18822 generate that DIE right away. add_type_attribute
18823 called below will then pick (via lookup_type_die) that
18824 anonymous struct DIE. */
18825 if (!TREE_ASM_WRITTEN (type))
18826 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
18828 /* This is a GNU Extension. We are adding a
18829 DW_AT_linkage_name attribute to the DIE of the
18830 anonymous struct TYPE. The value of that attribute
18831 is the name of the typedef decl naming the anonymous
18832 struct. This greatly eases the work of consumers of
18833 this debug info. */
18834 add_linkage_attr (lookup_type_die (type), decl);
18838 add_type_attribute (type_die, type, TREE_READONLY (decl),
18839 TREE_THIS_VOLATILE (decl), context_die);
18841 if (is_naming_typedef_decl (decl))
18842 /* We want that all subsequent calls to lookup_type_die with
18843 TYPE in argument yield the DW_TAG_typedef we have just
18845 equate_type_number_to_die (type, type_die);
18847 add_accessibility_attribute (type_die, decl);
18850 if (DECL_ABSTRACT (decl))
18851 equate_decl_number_to_die (decl, type_die);
18853 if (get_AT (type_die, DW_AT_name))
18854 add_pubtype (decl, type_die);
18857 /* Generate a DIE for a struct, class, enum or union type. */
18860 gen_tagged_type_die (tree type,
18861 dw_die_ref context_die,
18862 enum debug_info_usage usage)
18866 if (type == NULL_TREE
18867 || !is_tagged_type (type))
18870 /* If this is a nested type whose containing class hasn't been written
18871 out yet, writing it out will cover this one, too. This does not apply
18872 to instantiations of member class templates; they need to be added to
18873 the containing class as they are generated. FIXME: This hurts the
18874 idea of combining type decls from multiple TUs, since we can't predict
18875 what set of template instantiations we'll get. */
18876 if (TYPE_CONTEXT (type)
18877 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18878 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
18880 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
18882 if (TREE_ASM_WRITTEN (type))
18885 /* If that failed, attach ourselves to the stub. */
18886 push_decl_scope (TYPE_CONTEXT (type));
18887 context_die = lookup_type_die (TYPE_CONTEXT (type));
18890 else if (TYPE_CONTEXT (type) != NULL_TREE
18891 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
18893 /* If this type is local to a function that hasn't been written
18894 out yet, use a NULL context for now; it will be fixed up in
18895 decls_for_scope. */
18896 context_die = lookup_decl_die (TYPE_CONTEXT (type));
18897 /* A declaration DIE doesn't count; nested types need to go in the
18899 if (context_die && is_declaration_die (context_die))
18900 context_die = NULL;
18905 context_die = declare_in_namespace (type, context_die);
18909 if (TREE_CODE (type) == ENUMERAL_TYPE)
18911 /* This might have been written out by the call to
18912 declare_in_namespace. */
18913 if (!TREE_ASM_WRITTEN (type))
18914 gen_enumeration_type_die (type, context_die);
18917 gen_struct_or_union_type_die (type, context_die, usage);
18922 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18923 it up if it is ever completed. gen_*_type_die will set it for us
18924 when appropriate. */
18927 /* Generate a type description DIE. */
18930 gen_type_die_with_usage (tree type, dw_die_ref context_die,
18931 enum debug_info_usage usage)
18933 struct array_descr_info info;
18935 if (type == NULL_TREE || type == error_mark_node)
18938 if (TYPE_NAME (type) != NULL_TREE
18939 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18940 && is_redundant_typedef (TYPE_NAME (type))
18941 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
18942 /* The DECL of this type is a typedef we don't want to emit debug
18943 info for but we want debug info for its underlying typedef.
18944 This can happen for e.g, the injected-class-name of a C++
18946 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
18948 /* If TYPE is a typedef type variant, let's generate debug info
18949 for the parent typedef which TYPE is a type of. */
18950 if (typedef_variant_p (type))
18952 if (TREE_ASM_WRITTEN (type))
18955 /* Prevent broken recursion; we can't hand off to the same type. */
18956 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
18958 /* Give typedefs the right scope. */
18959 context_die = scope_die_for (type, context_die);
18961 TREE_ASM_WRITTEN (type) = 1;
18963 gen_decl_die (TYPE_NAME (type), NULL, context_die);
18967 /* If type is an anonymous tagged type named by a typedef, let's
18968 generate debug info for the typedef. */
18969 if (is_naming_typedef_decl (TYPE_NAME (type)))
18971 /* Use the DIE of the containing namespace as the parent DIE of
18972 the type description DIE we want to generate. */
18973 if (DECL_CONTEXT (TYPE_NAME (type))
18974 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
18975 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
18977 gen_decl_die (TYPE_NAME (type), NULL, context_die);
18981 /* If this is an array type with hidden descriptor, handle it first. */
18982 if (!TREE_ASM_WRITTEN (type)
18983 && lang_hooks.types.get_array_descr_info
18984 && lang_hooks.types.get_array_descr_info (type, &info)
18985 && (dwarf_version >= 3 || !dwarf_strict))
18987 gen_descr_array_type_die (type, &info, context_die);
18988 TREE_ASM_WRITTEN (type) = 1;
18992 /* We are going to output a DIE to represent the unqualified version
18993 of this type (i.e. without any const or volatile qualifiers) so
18994 get the main variant (i.e. the unqualified version) of this type
18995 now. (Vectors are special because the debugging info is in the
18996 cloned type itself). */
18997 if (TREE_CODE (type) != VECTOR_TYPE)
18998 type = type_main_variant (type);
19000 if (TREE_ASM_WRITTEN (type))
19003 switch (TREE_CODE (type))
19009 case REFERENCE_TYPE:
19010 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19011 ensures that the gen_type_die recursion will terminate even if the
19012 type is recursive. Recursive types are possible in Ada. */
19013 /* ??? We could perhaps do this for all types before the switch
19015 TREE_ASM_WRITTEN (type) = 1;
19017 /* For these types, all that is required is that we output a DIE (or a
19018 set of DIEs) to represent the "basis" type. */
19019 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19020 DINFO_USAGE_IND_USE);
19024 /* This code is used for C++ pointer-to-data-member types.
19025 Output a description of the relevant class type. */
19026 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
19027 DINFO_USAGE_IND_USE);
19029 /* Output a description of the type of the object pointed to. */
19030 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19031 DINFO_USAGE_IND_USE);
19033 /* Now output a DIE to represent this pointer-to-data-member type
19035 gen_ptr_to_mbr_type_die (type, context_die);
19038 case FUNCTION_TYPE:
19039 /* Force out return type (in case it wasn't forced out already). */
19040 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19041 DINFO_USAGE_DIR_USE);
19042 gen_subroutine_type_die (type, context_die);
19046 /* Force out return type (in case it wasn't forced out already). */
19047 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19048 DINFO_USAGE_DIR_USE);
19049 gen_subroutine_type_die (type, context_die);
19053 gen_array_type_die (type, context_die);
19057 gen_array_type_die (type, context_die);
19060 case ENUMERAL_TYPE:
19063 case QUAL_UNION_TYPE:
19064 gen_tagged_type_die (type, context_die, usage);
19070 case FIXED_POINT_TYPE:
19073 /* No DIEs needed for fundamental types. */
19078 /* Just use DW_TAG_unspecified_type. */
19080 dw_die_ref type_die = lookup_type_die (type);
19081 if (type_die == NULL)
19083 tree name = TYPE_NAME (type);
19084 if (TREE_CODE (name) == TYPE_DECL)
19085 name = DECL_NAME (name);
19086 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
19087 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
19088 equate_type_number_to_die (type, type_die);
19094 gcc_unreachable ();
19097 TREE_ASM_WRITTEN (type) = 1;
19101 gen_type_die (tree type, dw_die_ref context_die)
19103 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
19106 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19107 things which are local to the given block. */
19110 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
19112 int must_output_die = 0;
19115 /* Ignore blocks that are NULL. */
19116 if (stmt == NULL_TREE)
19119 inlined_func = inlined_function_outer_scope_p (stmt);
19121 /* If the block is one fragment of a non-contiguous block, do not
19122 process the variables, since they will have been done by the
19123 origin block. Do process subblocks. */
19124 if (BLOCK_FRAGMENT_ORIGIN (stmt))
19128 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
19129 gen_block_die (sub, context_die, depth + 1);
19134 /* Determine if we need to output any Dwarf DIEs at all to represent this
19137 /* The outer scopes for inlinings *must* always be represented. We
19138 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19139 must_output_die = 1;
19142 /* Determine if this block directly contains any "significant"
19143 local declarations which we will need to output DIEs for. */
19144 if (debug_info_level > DINFO_LEVEL_TERSE)
19145 /* We are not in terse mode so *any* local declaration counts
19146 as being a "significant" one. */
19147 must_output_die = ((BLOCK_VARS (stmt) != NULL
19148 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
19149 && (TREE_USED (stmt)
19150 || TREE_ASM_WRITTEN (stmt)
19151 || BLOCK_ABSTRACT (stmt)));
19152 else if ((TREE_USED (stmt)
19153 || TREE_ASM_WRITTEN (stmt)
19154 || BLOCK_ABSTRACT (stmt))
19155 && !dwarf2out_ignore_block (stmt))
19156 must_output_die = 1;
19159 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19160 DIE for any block which contains no significant local declarations at
19161 all. Rather, in such cases we just call `decls_for_scope' so that any
19162 needed Dwarf info for any sub-blocks will get properly generated. Note
19163 that in terse mode, our definition of what constitutes a "significant"
19164 local declaration gets restricted to include only inlined function
19165 instances and local (nested) function definitions. */
19166 if (must_output_die)
19170 /* If STMT block is abstract, that means we have been called
19171 indirectly from dwarf2out_abstract_function.
19172 That function rightfully marks the descendent blocks (of
19173 the abstract function it is dealing with) as being abstract,
19174 precisely to prevent us from emitting any
19175 DW_TAG_inlined_subroutine DIE as a descendent
19176 of an abstract function instance. So in that case, we should
19177 not call gen_inlined_subroutine_die.
19179 Later though, when cgraph asks dwarf2out to emit info
19180 for the concrete instance of the function decl into which
19181 the concrete instance of STMT got inlined, the later will lead
19182 to the generation of a DW_TAG_inlined_subroutine DIE. */
19183 if (! BLOCK_ABSTRACT (stmt))
19184 gen_inlined_subroutine_die (stmt, context_die, depth);
19187 gen_lexical_block_die (stmt, context_die, depth);
19190 decls_for_scope (stmt, context_die, depth);
19193 /* Process variable DECL (or variable with origin ORIGIN) within
19194 block STMT and add it to CONTEXT_DIE. */
19196 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
19199 tree decl_or_origin = decl ? decl : origin;
19201 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
19202 die = lookup_decl_die (decl_or_origin);
19203 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
19204 && TYPE_DECL_IS_STUB (decl_or_origin))
19205 die = lookup_type_die (TREE_TYPE (decl_or_origin));
19209 if (die != NULL && die->die_parent == NULL)
19210 add_child_die (context_die, die);
19211 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
19212 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
19213 stmt, context_die);
19215 gen_decl_die (decl, origin, context_die);
19218 /* Generate all of the decls declared within a given scope and (recursively)
19219 all of its sub-blocks. */
19222 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
19228 /* Ignore NULL blocks. */
19229 if (stmt == NULL_TREE)
19232 /* Output the DIEs to represent all of the data objects and typedefs
19233 declared directly within this block but not within any nested
19234 sub-blocks. Also, nested function and tag DIEs have been
19235 generated with a parent of NULL; fix that up now. */
19236 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
19237 process_scope_var (stmt, decl, NULL_TREE, context_die);
19238 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
19239 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
19242 /* If we're at -g1, we're not interested in subblocks. */
19243 if (debug_info_level <= DINFO_LEVEL_TERSE)
19246 /* Output the DIEs to represent all sub-blocks (and the items declared
19247 therein) of this block. */
19248 for (subblocks = BLOCK_SUBBLOCKS (stmt);
19250 subblocks = BLOCK_CHAIN (subblocks))
19251 gen_block_die (subblocks, context_die, depth + 1);
19254 /* Is this a typedef we can avoid emitting? */
19257 is_redundant_typedef (const_tree decl)
19259 if (TYPE_DECL_IS_STUB (decl))
19262 if (DECL_ARTIFICIAL (decl)
19263 && DECL_CONTEXT (decl)
19264 && is_tagged_type (DECL_CONTEXT (decl))
19265 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
19266 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
19267 /* Also ignore the artificial member typedef for the class name. */
19273 /* Return TRUE if TYPE is a typedef that names a type for linkage
19274 purposes. This kind of typedefs is produced by the C++ FE for
19277 typedef struct {...} foo;
19279 In that case, there is no typedef variant type produced for foo.
19280 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19284 is_naming_typedef_decl (const_tree decl)
19286 if (decl == NULL_TREE
19287 || TREE_CODE (decl) != TYPE_DECL
19288 || !is_tagged_type (TREE_TYPE (decl))
19289 || DECL_IS_BUILTIN (decl)
19290 || is_redundant_typedef (decl)
19291 /* It looks like Ada produces TYPE_DECLs that are very similar
19292 to C++ naming typedefs but that have different
19293 semantics. Let's be specific to c++ for now. */
19297 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
19298 && TYPE_NAME (TREE_TYPE (decl)) == decl
19299 && (TYPE_STUB_DECL (TREE_TYPE (decl))
19300 != TYPE_NAME (TREE_TYPE (decl))));
19303 /* Returns the DIE for a context. */
19305 static inline dw_die_ref
19306 get_context_die (tree context)
19310 /* Find die that represents this context. */
19311 if (TYPE_P (context))
19313 context = TYPE_MAIN_VARIANT (context);
19314 return strip_naming_typedef (context, force_type_die (context));
19317 return force_decl_die (context);
19319 return comp_unit_die ();
19322 /* Returns the DIE for decl. A DIE will always be returned. */
19325 force_decl_die (tree decl)
19327 dw_die_ref decl_die;
19328 unsigned saved_external_flag;
19329 tree save_fn = NULL_TREE;
19330 decl_die = lookup_decl_die (decl);
19333 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
19335 decl_die = lookup_decl_die (decl);
19339 switch (TREE_CODE (decl))
19341 case FUNCTION_DECL:
19342 /* Clear current_function_decl, so that gen_subprogram_die thinks
19343 that this is a declaration. At this point, we just want to force
19344 declaration die. */
19345 save_fn = current_function_decl;
19346 current_function_decl = NULL_TREE;
19347 gen_subprogram_die (decl, context_die);
19348 current_function_decl = save_fn;
19352 /* Set external flag to force declaration die. Restore it after
19353 gen_decl_die() call. */
19354 saved_external_flag = DECL_EXTERNAL (decl);
19355 DECL_EXTERNAL (decl) = 1;
19356 gen_decl_die (decl, NULL, context_die);
19357 DECL_EXTERNAL (decl) = saved_external_flag;
19360 case NAMESPACE_DECL:
19361 if (dwarf_version >= 3 || !dwarf_strict)
19362 dwarf2out_decl (decl);
19364 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19365 decl_die = comp_unit_die ();
19368 case TRANSLATION_UNIT_DECL:
19369 decl_die = comp_unit_die ();
19373 gcc_unreachable ();
19376 /* We should be able to find the DIE now. */
19378 decl_die = lookup_decl_die (decl);
19379 gcc_assert (decl_die);
19385 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19386 always returned. */
19389 force_type_die (tree type)
19391 dw_die_ref type_die;
19393 type_die = lookup_type_die (type);
19396 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
19398 type_die = modified_type_die (type, TYPE_READONLY (type),
19399 TYPE_VOLATILE (type), context_die);
19400 gcc_assert (type_die);
19405 /* Force out any required namespaces to be able to output DECL,
19406 and return the new context_die for it, if it's changed. */
19409 setup_namespace_context (tree thing, dw_die_ref context_die)
19411 tree context = (DECL_P (thing)
19412 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
19413 if (context && TREE_CODE (context) == NAMESPACE_DECL)
19414 /* Force out the namespace. */
19415 context_die = force_decl_die (context);
19417 return context_die;
19420 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19421 type) within its namespace, if appropriate.
19423 For compatibility with older debuggers, namespace DIEs only contain
19424 declarations; all definitions are emitted at CU scope. */
19427 declare_in_namespace (tree thing, dw_die_ref context_die)
19429 dw_die_ref ns_context;
19431 if (debug_info_level <= DINFO_LEVEL_TERSE)
19432 return context_die;
19434 /* If this decl is from an inlined function, then don't try to emit it in its
19435 namespace, as we will get confused. It would have already been emitted
19436 when the abstract instance of the inline function was emitted anyways. */
19437 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
19438 return context_die;
19440 ns_context = setup_namespace_context (thing, context_die);
19442 if (ns_context != context_die)
19446 if (DECL_P (thing))
19447 gen_decl_die (thing, NULL, ns_context);
19449 gen_type_die (thing, ns_context);
19451 return context_die;
19454 /* Generate a DIE for a namespace or namespace alias. */
19457 gen_namespace_die (tree decl, dw_die_ref context_die)
19459 dw_die_ref namespace_die;
19461 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19462 they are an alias of. */
19463 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
19465 /* Output a real namespace or module. */
19466 context_die = setup_namespace_context (decl, comp_unit_die ());
19467 namespace_die = new_die (is_fortran ()
19468 ? DW_TAG_module : DW_TAG_namespace,
19469 context_die, decl);
19470 /* For Fortran modules defined in different CU don't add src coords. */
19471 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
19473 const char *name = dwarf2_name (decl, 0);
19475 add_name_attribute (namespace_die, name);
19478 add_name_and_src_coords_attributes (namespace_die, decl);
19479 if (DECL_EXTERNAL (decl))
19480 add_AT_flag (namespace_die, DW_AT_declaration, 1);
19481 equate_decl_number_to_die (decl, namespace_die);
19485 /* Output a namespace alias. */
19487 /* Force out the namespace we are an alias of, if necessary. */
19488 dw_die_ref origin_die
19489 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
19491 if (DECL_FILE_SCOPE_P (decl)
19492 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
19493 context_die = setup_namespace_context (decl, comp_unit_die ());
19494 /* Now create the namespace alias DIE. */
19495 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
19496 add_name_and_src_coords_attributes (namespace_die, decl);
19497 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
19498 equate_decl_number_to_die (decl, namespace_die);
19502 /* Generate Dwarf debug information for a decl described by DECL.
19503 The return value is currently only meaningful for PARM_DECLs,
19504 for all other decls it returns NULL. */
19507 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
19509 tree decl_or_origin = decl ? decl : origin;
19510 tree class_origin = NULL, ultimate_origin;
19512 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
19515 switch (TREE_CODE (decl_or_origin))
19521 if (!is_fortran () && !is_ada ())
19523 /* The individual enumerators of an enum type get output when we output
19524 the Dwarf representation of the relevant enum type itself. */
19528 /* Emit its type. */
19529 gen_type_die (TREE_TYPE (decl), context_die);
19531 /* And its containing namespace. */
19532 context_die = declare_in_namespace (decl, context_die);
19534 gen_const_die (decl, context_die);
19537 case FUNCTION_DECL:
19538 /* Don't output any DIEs to represent mere function declarations,
19539 unless they are class members or explicit block externs. */
19540 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
19541 && DECL_FILE_SCOPE_P (decl_or_origin)
19542 && (current_function_decl == NULL_TREE
19543 || DECL_ARTIFICIAL (decl_or_origin)))
19548 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19549 on local redeclarations of global functions. That seems broken. */
19550 if (current_function_decl != decl)
19551 /* This is only a declaration. */;
19554 /* If we're emitting a clone, emit info for the abstract instance. */
19555 if (origin || DECL_ORIGIN (decl) != decl)
19556 dwarf2out_abstract_function (origin
19557 ? DECL_ORIGIN (origin)
19558 : DECL_ABSTRACT_ORIGIN (decl));
19560 /* If we're emitting an out-of-line copy of an inline function,
19561 emit info for the abstract instance and set up to refer to it. */
19562 else if (cgraph_function_possibly_inlined_p (decl)
19563 && ! DECL_ABSTRACT (decl)
19564 && ! class_or_namespace_scope_p (context_die)
19565 /* dwarf2out_abstract_function won't emit a die if this is just
19566 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19567 that case, because that works only if we have a die. */
19568 && DECL_INITIAL (decl) != NULL_TREE)
19570 dwarf2out_abstract_function (decl);
19571 set_decl_origin_self (decl);
19574 /* Otherwise we're emitting the primary DIE for this decl. */
19575 else if (debug_info_level > DINFO_LEVEL_TERSE)
19577 /* Before we describe the FUNCTION_DECL itself, make sure that we
19578 have its containing type. */
19580 origin = decl_class_context (decl);
19581 if (origin != NULL_TREE)
19582 gen_type_die (origin, context_die);
19584 /* And its return type. */
19585 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
19587 /* And its virtual context. */
19588 if (DECL_VINDEX (decl) != NULL_TREE)
19589 gen_type_die (DECL_CONTEXT (decl), context_die);
19591 /* Make sure we have a member DIE for decl. */
19592 if (origin != NULL_TREE)
19593 gen_type_die_for_member (origin, decl, context_die);
19595 /* And its containing namespace. */
19596 context_die = declare_in_namespace (decl, context_die);
19599 /* Now output a DIE to represent the function itself. */
19601 gen_subprogram_die (decl, context_die);
19605 /* If we are in terse mode, don't generate any DIEs to represent any
19606 actual typedefs. */
19607 if (debug_info_level <= DINFO_LEVEL_TERSE)
19610 /* In the special case of a TYPE_DECL node representing the declaration
19611 of some type tag, if the given TYPE_DECL is marked as having been
19612 instantiated from some other (original) TYPE_DECL node (e.g. one which
19613 was generated within the original definition of an inline function) we
19614 used to generate a special (abbreviated) DW_TAG_structure_type,
19615 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19616 should be actually referencing those DIEs, as variable DIEs with that
19617 type would be emitted already in the abstract origin, so it was always
19618 removed during unused type prunning. Don't add anything in this
19620 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
19623 if (is_redundant_typedef (decl))
19624 gen_type_die (TREE_TYPE (decl), context_die);
19626 /* Output a DIE to represent the typedef itself. */
19627 gen_typedef_die (decl, context_die);
19631 if (debug_info_level >= DINFO_LEVEL_NORMAL)
19632 gen_label_die (decl, context_die);
19637 /* If we are in terse mode, don't generate any DIEs to represent any
19638 variable declarations or definitions. */
19639 if (debug_info_level <= DINFO_LEVEL_TERSE)
19642 /* Output any DIEs that are needed to specify the type of this data
19644 if (decl_by_reference_p (decl_or_origin))
19645 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19647 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19649 /* And its containing type. */
19650 class_origin = decl_class_context (decl_or_origin);
19651 if (class_origin != NULL_TREE)
19652 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
19654 /* And its containing namespace. */
19655 context_die = declare_in_namespace (decl_or_origin, context_die);
19657 /* Now output the DIE to represent the data object itself. This gets
19658 complicated because of the possibility that the VAR_DECL really
19659 represents an inlined instance of a formal parameter for an inline
19661 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19662 if (ultimate_origin != NULL_TREE
19663 && TREE_CODE (ultimate_origin) == PARM_DECL)
19664 gen_formal_parameter_die (decl, origin,
19665 true /* Emit name attribute. */,
19668 gen_variable_die (decl, origin, context_die);
19672 /* Ignore the nameless fields that are used to skip bits but handle C++
19673 anonymous unions and structs. */
19674 if (DECL_NAME (decl) != NULL_TREE
19675 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
19676 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
19678 gen_type_die (member_declared_type (decl), context_die);
19679 gen_field_die (decl, context_die);
19684 if (DECL_BY_REFERENCE (decl_or_origin))
19685 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19687 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19688 return gen_formal_parameter_die (decl, origin,
19689 true /* Emit name attribute. */,
19692 case NAMESPACE_DECL:
19693 case IMPORTED_DECL:
19694 if (dwarf_version >= 3 || !dwarf_strict)
19695 gen_namespace_die (decl, context_die);
19699 /* Probably some frontend-internal decl. Assume we don't care. */
19700 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
19707 /* Output debug information for global decl DECL. Called from toplev.c after
19708 compilation proper has finished. */
19711 dwarf2out_global_decl (tree decl)
19713 /* Output DWARF2 information for file-scope tentative data object
19714 declarations, file-scope (extern) function declarations (which
19715 had no corresponding body) and file-scope tagged type declarations
19716 and definitions which have not yet been forced out. */
19717 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
19718 dwarf2out_decl (decl);
19721 /* Output debug information for type decl DECL. Called from toplev.c
19722 and from language front ends (to record built-in types). */
19724 dwarf2out_type_decl (tree decl, int local)
19727 dwarf2out_decl (decl);
19730 /* Output debug information for imported module or decl DECL.
19731 NAME is non-NULL name in the lexical block if the decl has been renamed.
19732 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19733 that DECL belongs to.
19734 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19736 dwarf2out_imported_module_or_decl_1 (tree decl,
19738 tree lexical_block,
19739 dw_die_ref lexical_block_die)
19741 expanded_location xloc;
19742 dw_die_ref imported_die = NULL;
19743 dw_die_ref at_import_die;
19745 if (TREE_CODE (decl) == IMPORTED_DECL)
19747 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
19748 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
19752 xloc = expand_location (input_location);
19754 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
19756 at_import_die = force_type_die (TREE_TYPE (decl));
19757 /* For namespace N { typedef void T; } using N::T; base_type_die
19758 returns NULL, but DW_TAG_imported_declaration requires
19759 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19760 if (!at_import_die)
19762 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
19763 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
19764 at_import_die = lookup_type_die (TREE_TYPE (decl));
19765 gcc_assert (at_import_die);
19770 at_import_die = lookup_decl_die (decl);
19771 if (!at_import_die)
19773 /* If we're trying to avoid duplicate debug info, we may not have
19774 emitted the member decl for this field. Emit it now. */
19775 if (TREE_CODE (decl) == FIELD_DECL)
19777 tree type = DECL_CONTEXT (decl);
19779 if (TYPE_CONTEXT (type)
19780 && TYPE_P (TYPE_CONTEXT (type))
19781 && !should_emit_struct_debug (TYPE_CONTEXT (type),
19782 DINFO_USAGE_DIR_USE))
19784 gen_type_die_for_member (type, decl,
19785 get_context_die (TYPE_CONTEXT (type)));
19787 at_import_die = force_decl_die (decl);
19791 if (TREE_CODE (decl) == NAMESPACE_DECL)
19793 if (dwarf_version >= 3 || !dwarf_strict)
19794 imported_die = new_die (DW_TAG_imported_module,
19801 imported_die = new_die (DW_TAG_imported_declaration,
19805 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
19806 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
19808 add_AT_string (imported_die, DW_AT_name,
19809 IDENTIFIER_POINTER (name));
19810 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
19813 /* Output debug information for imported module or decl DECL.
19814 NAME is non-NULL name in context if the decl has been renamed.
19815 CHILD is true if decl is one of the renamed decls as part of
19816 importing whole module. */
19819 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
19822 /* dw_die_ref at_import_die; */
19823 dw_die_ref scope_die;
19825 if (debug_info_level <= DINFO_LEVEL_TERSE)
19830 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19831 We need decl DIE for reference and scope die. First, get DIE for the decl
19834 /* Get the scope die for decl context. Use comp_unit_die for global module
19835 or decl. If die is not found for non globals, force new die. */
19837 && TYPE_P (context)
19838 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
19841 if (!(dwarf_version >= 3 || !dwarf_strict))
19844 scope_die = get_context_die (context);
19848 gcc_assert (scope_die->die_child);
19849 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
19850 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
19851 scope_die = scope_die->die_child;
19854 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19855 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
19859 /* Write the debugging output for DECL. */
19862 dwarf2out_decl (tree decl)
19864 dw_die_ref context_die = comp_unit_die ();
19866 switch (TREE_CODE (decl))
19871 case FUNCTION_DECL:
19872 /* What we would really like to do here is to filter out all mere
19873 file-scope declarations of file-scope functions which are never
19874 referenced later within this translation unit (and keep all of ones
19875 that *are* referenced later on) but we aren't clairvoyant, so we have
19876 no idea which functions will be referenced in the future (i.e. later
19877 on within the current translation unit). So here we just ignore all
19878 file-scope function declarations which are not also definitions. If
19879 and when the debugger needs to know something about these functions,
19880 it will have to hunt around and find the DWARF information associated
19881 with the definition of the function.
19883 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19884 nodes represent definitions and which ones represent mere
19885 declarations. We have to check DECL_INITIAL instead. That's because
19886 the C front-end supports some weird semantics for "extern inline"
19887 function definitions. These can get inlined within the current
19888 translation unit (and thus, we need to generate Dwarf info for their
19889 abstract instances so that the Dwarf info for the concrete inlined
19890 instances can have something to refer to) but the compiler never
19891 generates any out-of-lines instances of such things (despite the fact
19892 that they *are* definitions).
19894 The important point is that the C front-end marks these "extern
19895 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19896 them anyway. Note that the C++ front-end also plays some similar games
19897 for inline function definitions appearing within include files which
19898 also contain `#pragma interface' pragmas. */
19899 if (DECL_INITIAL (decl) == NULL_TREE)
19902 /* If we're a nested function, initially use a parent of NULL; if we're
19903 a plain function, this will be fixed up in decls_for_scope. If
19904 we're a method, it will be ignored, since we already have a DIE. */
19905 if (decl_function_context (decl)
19906 /* But if we're in terse mode, we don't care about scope. */
19907 && debug_info_level > DINFO_LEVEL_TERSE)
19908 context_die = NULL;
19912 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19913 declaration and if the declaration was never even referenced from
19914 within this entire compilation unit. We suppress these DIEs in
19915 order to save space in the .debug section (by eliminating entries
19916 which are probably useless). Note that we must not suppress
19917 block-local extern declarations (whether used or not) because that
19918 would screw-up the debugger's name lookup mechanism and cause it to
19919 miss things which really ought to be in scope at a given point. */
19920 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
19923 /* For local statics lookup proper context die. */
19924 if (TREE_STATIC (decl)
19925 && DECL_CONTEXT (decl)
19926 && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL)
19927 context_die = lookup_decl_die (DECL_CONTEXT (decl));
19929 /* If we are in terse mode, don't generate any DIEs to represent any
19930 variable declarations or definitions. */
19931 if (debug_info_level <= DINFO_LEVEL_TERSE)
19936 if (debug_info_level <= DINFO_LEVEL_TERSE)
19938 if (!is_fortran () && !is_ada ())
19940 if (TREE_STATIC (decl) && decl_function_context (decl))
19941 context_die = lookup_decl_die (DECL_CONTEXT (decl));
19944 case NAMESPACE_DECL:
19945 case IMPORTED_DECL:
19946 if (debug_info_level <= DINFO_LEVEL_TERSE)
19948 if (lookup_decl_die (decl) != NULL)
19953 /* Don't emit stubs for types unless they are needed by other DIEs. */
19954 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
19957 /* Don't bother trying to generate any DIEs to represent any of the
19958 normal built-in types for the language we are compiling. */
19959 if (DECL_IS_BUILTIN (decl))
19962 /* If we are in terse mode, don't generate any DIEs for types. */
19963 if (debug_info_level <= DINFO_LEVEL_TERSE)
19966 /* If we're a function-scope tag, initially use a parent of NULL;
19967 this will be fixed up in decls_for_scope. */
19968 if (decl_function_context (decl))
19969 context_die = NULL;
19977 gen_decl_die (decl, NULL, context_die);
19980 /* Write the debugging output for DECL. */
19983 dwarf2out_function_decl (tree decl)
19985 dwarf2out_decl (decl);
19986 call_arg_locations = NULL;
19987 call_arg_loc_last = NULL;
19988 call_site_count = -1;
19989 tail_call_site_count = -1;
19990 VEC_free (dw_die_ref, heap, block_map);
19991 htab_empty (decl_loc_table);
19992 htab_empty (cached_dw_loc_list_table);
19995 /* Output a marker (i.e. a label) for the beginning of the generated code for
19996 a lexical block. */
19999 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
20000 unsigned int blocknum)
20002 switch_to_section (current_function_section ());
20003 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
20006 /* Output a marker (i.e. a label) for the end of the generated code for a
20010 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
20012 switch_to_section (current_function_section ());
20013 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
20016 /* Returns nonzero if it is appropriate not to emit any debugging
20017 information for BLOCK, because it doesn't contain any instructions.
20019 Don't allow this for blocks with nested functions or local classes
20020 as we would end up with orphans, and in the presence of scheduling
20021 we may end up calling them anyway. */
20024 dwarf2out_ignore_block (const_tree block)
20029 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
20030 if (TREE_CODE (decl) == FUNCTION_DECL
20031 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
20033 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
20035 decl = BLOCK_NONLOCALIZED_VAR (block, i);
20036 if (TREE_CODE (decl) == FUNCTION_DECL
20037 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
20044 /* Hash table routines for file_hash. */
20047 file_table_eq (const void *p1_p, const void *p2_p)
20049 const struct dwarf_file_data *const p1 =
20050 (const struct dwarf_file_data *) p1_p;
20051 const char *const p2 = (const char *) p2_p;
20052 return filename_cmp (p1->filename, p2) == 0;
20056 file_table_hash (const void *p_p)
20058 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
20059 return htab_hash_string (p->filename);
20062 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20063 dwarf2out.c) and return its "index". The index of each (known) filename is
20064 just a unique number which is associated with only that one filename. We
20065 need such numbers for the sake of generating labels (in the .debug_sfnames
20066 section) and references to those files numbers (in the .debug_srcinfo
20067 and.debug_macinfo sections). If the filename given as an argument is not
20068 found in our current list, add it to the list and assign it the next
20069 available unique index number. In order to speed up searches, we remember
20070 the index of the filename was looked up last. This handles the majority of
20073 static struct dwarf_file_data *
20074 lookup_filename (const char *file_name)
20077 struct dwarf_file_data * created;
20079 /* Check to see if the file name that was searched on the previous
20080 call matches this file name. If so, return the index. */
20081 if (file_table_last_lookup
20082 && (file_name == file_table_last_lookup->filename
20083 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
20084 return file_table_last_lookup;
20086 /* Didn't match the previous lookup, search the table. */
20087 slot = htab_find_slot_with_hash (file_table, file_name,
20088 htab_hash_string (file_name), INSERT);
20090 return (struct dwarf_file_data *) *slot;
20092 created = ggc_alloc_dwarf_file_data ();
20093 created->filename = file_name;
20094 created->emitted_number = 0;
20099 /* If the assembler will construct the file table, then translate the compiler
20100 internal file table number into the assembler file table number, and emit
20101 a .file directive if we haven't already emitted one yet. The file table
20102 numbers are different because we prune debug info for unused variables and
20103 types, which may include filenames. */
20106 maybe_emit_file (struct dwarf_file_data * fd)
20108 if (! fd->emitted_number)
20110 if (last_emitted_file)
20111 fd->emitted_number = last_emitted_file->emitted_number + 1;
20113 fd->emitted_number = 1;
20114 last_emitted_file = fd;
20116 if (DWARF2_ASM_LINE_DEBUG_INFO)
20118 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
20119 output_quoted_string (asm_out_file,
20120 remap_debug_filename (fd->filename));
20121 fputc ('\n', asm_out_file);
20125 return fd->emitted_number;
20128 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20129 That generation should happen after function debug info has been
20130 generated. The value of the attribute is the constant value of ARG. */
20133 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
20135 die_arg_entry entry;
20140 if (!tmpl_value_parm_die_table)
20141 tmpl_value_parm_die_table
20142 = VEC_alloc (die_arg_entry, gc, 32);
20146 VEC_safe_push (die_arg_entry, gc,
20147 tmpl_value_parm_die_table,
20151 /* Return TRUE if T is an instance of generic type, FALSE
20155 generic_type_p (tree t)
20157 if (t == NULL_TREE || !TYPE_P (t))
20159 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
20162 /* Schedule the generation of the generic parameter dies for the
20163 instance of generic type T. The proper generation itself is later
20164 done by gen_scheduled_generic_parms_dies. */
20167 schedule_generic_params_dies_gen (tree t)
20169 if (!generic_type_p (t))
20172 if (generic_type_instances == NULL)
20173 generic_type_instances = VEC_alloc (tree, gc, 256);
20175 VEC_safe_push (tree, gc, generic_type_instances, t);
20178 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20179 by append_entry_to_tmpl_value_parm_die_table. This function must
20180 be called after function DIEs have been generated. */
20183 gen_remaining_tmpl_value_param_die_attribute (void)
20185 if (tmpl_value_parm_die_table)
20190 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
20191 tree_add_const_value_attribute (e->die, e->arg);
20195 /* Generate generic parameters DIEs for instances of generic types
20196 that have been previously scheduled by
20197 schedule_generic_params_dies_gen. This function must be called
20198 after all the types of the CU have been laid out. */
20201 gen_scheduled_generic_parms_dies (void)
20206 if (generic_type_instances == NULL)
20209 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
20210 gen_generic_params_dies (t);
20214 /* Replace DW_AT_name for the decl with name. */
20217 dwarf2out_set_name (tree decl, tree name)
20223 die = TYPE_SYMTAB_DIE (decl);
20227 dname = dwarf2_name (name, 0);
20231 attr = get_AT (die, DW_AT_name);
20234 struct indirect_string_node *node;
20236 node = find_AT_string (dname);
20237 /* replace the string. */
20238 attr->dw_attr_val.v.val_str = node;
20242 add_name_attribute (die, dname);
20245 /* Called by the final INSN scan whenever we see a var location. We
20246 use it to drop labels in the right places, and throw the location in
20247 our lookup table. */
20250 dwarf2out_var_location (rtx loc_note)
20252 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
20253 struct var_loc_node *newloc;
20254 rtx next_real, next_note;
20255 static const char *last_label;
20256 static const char *last_postcall_label;
20257 static bool last_in_cold_section_p;
20258 static rtx expected_next_loc_note;
20262 if (!NOTE_P (loc_note))
20264 if (CALL_P (loc_note))
20267 if (SIBLING_CALL_P (loc_note))
20268 tail_call_site_count++;
20273 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
20274 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
20277 /* Optimize processing a large consecutive sequence of location
20278 notes so we don't spend too much time in next_real_insn. If the
20279 next insn is another location note, remember the next_real_insn
20280 calculation for next time. */
20281 next_real = cached_next_real_insn;
20284 if (expected_next_loc_note != loc_note)
20285 next_real = NULL_RTX;
20288 next_note = NEXT_INSN (loc_note);
20290 || INSN_DELETED_P (next_note)
20291 || GET_CODE (next_note) != NOTE
20292 || (NOTE_KIND (next_note) != NOTE_INSN_VAR_LOCATION
20293 && NOTE_KIND (next_note) != NOTE_INSN_CALL_ARG_LOCATION))
20294 next_note = NULL_RTX;
20297 next_real = next_real_insn (loc_note);
20301 expected_next_loc_note = next_note;
20302 cached_next_real_insn = next_real;
20305 cached_next_real_insn = NULL_RTX;
20307 /* If there are no instructions which would be affected by this note,
20308 don't do anything. */
20310 && next_real == NULL_RTX
20311 && !NOTE_DURING_CALL_P (loc_note))
20314 if (next_real == NULL_RTX)
20315 next_real = get_last_insn ();
20317 /* If there were any real insns between note we processed last time
20318 and this note (or if it is the first note), clear
20319 last_{,postcall_}label so that they are not reused this time. */
20320 if (last_var_location_insn == NULL_RTX
20321 || last_var_location_insn != next_real
20322 || last_in_cold_section_p != in_cold_section_p)
20325 last_postcall_label = NULL;
20330 decl = NOTE_VAR_LOCATION_DECL (loc_note);
20331 newloc = add_var_loc_to_decl (decl, loc_note,
20332 NOTE_DURING_CALL_P (loc_note)
20333 ? last_postcall_label : last_label);
20334 if (newloc == NULL)
20343 /* If there were no real insns between note we processed last time
20344 and this note, use the label we emitted last time. Otherwise
20345 create a new label and emit it. */
20346 if (last_label == NULL)
20348 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
20349 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
20351 last_label = ggc_strdup (loclabel);
20356 struct call_arg_loc_node *ca_loc
20357 = ggc_alloc_cleared_call_arg_loc_node ();
20358 rtx prev = prev_real_insn (loc_note), x;
20359 ca_loc->call_arg_loc_note = loc_note;
20360 ca_loc->next = NULL;
20361 ca_loc->label = last_label;
20364 || (NONJUMP_INSN_P (prev)
20365 && GET_CODE (PATTERN (prev)) == SEQUENCE
20366 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
20367 if (!CALL_P (prev))
20368 prev = XVECEXP (PATTERN (prev), 0, 0);
20369 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
20370 x = PATTERN (prev);
20371 if (GET_CODE (x) == PARALLEL)
20372 x = XVECEXP (x, 0, 0);
20373 if (GET_CODE (x) == SET)
20375 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
20377 x = XEXP (XEXP (x, 0), 0);
20378 if (GET_CODE (x) == SYMBOL_REF
20379 && SYMBOL_REF_DECL (x)
20380 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
20381 ca_loc->symbol_ref = x;
20383 ca_loc->block = insn_scope (prev);
20384 if (call_arg_locations)
20385 call_arg_loc_last->next = ca_loc;
20387 call_arg_locations = ca_loc;
20388 call_arg_loc_last = ca_loc;
20390 else if (!NOTE_DURING_CALL_P (loc_note))
20391 newloc->label = last_label;
20394 if (!last_postcall_label)
20396 sprintf (loclabel, "%s-1", last_label);
20397 last_postcall_label = ggc_strdup (loclabel);
20399 newloc->label = last_postcall_label;
20402 last_var_location_insn = next_real;
20403 last_in_cold_section_p = in_cold_section_p;
20406 /* Note in one location list that text section has changed. */
20409 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
20411 var_loc_list *list = (var_loc_list *) *slot;
20413 list->last_before_switch
20414 = list->last->next ? list->last->next : list->last;
20418 /* Note in all location lists that text section has changed. */
20421 var_location_switch_text_section (void)
20423 if (decl_loc_table == NULL)
20426 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
20429 /* Create a new line number table. */
20431 static dw_line_info_table *
20432 new_line_info_table (void)
20434 dw_line_info_table *table;
20436 table = ggc_alloc_cleared_dw_line_info_table_struct ();
20437 table->file_num = 1;
20438 table->line_num = 1;
20439 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
20444 /* Lookup the "current" table into which we emit line info, so
20445 that we don't have to do it for every source line. */
20448 set_cur_line_info_table (section *sec)
20450 dw_line_info_table *table;
20452 if (sec == text_section)
20453 table = text_section_line_info;
20454 else if (sec == cold_text_section)
20456 table = cold_text_section_line_info;
20459 cold_text_section_line_info = table = new_line_info_table ();
20460 table->end_label = cold_end_label;
20465 const char *end_label;
20467 if (flag_reorder_blocks_and_partition)
20469 if (in_cold_section_p)
20470 end_label = crtl->subsections.cold_section_end_label;
20472 end_label = crtl->subsections.hot_section_end_label;
20476 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20477 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
20478 current_function_funcdef_no);
20479 end_label = ggc_strdup (label);
20482 table = new_line_info_table ();
20483 table->end_label = end_label;
20485 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
20488 if (DWARF2_ASM_LINE_DEBUG_INFO)
20489 table->is_stmt = (cur_line_info_table
20490 ? cur_line_info_table->is_stmt
20491 : DWARF_LINE_DEFAULT_IS_STMT_START);
20492 cur_line_info_table = table;
20496 /* We need to reset the locations at the beginning of each
20497 function. We can't do this in the end_function hook, because the
20498 declarations that use the locations won't have been output when
20499 that hook is called. Also compute have_multiple_function_sections here. */
20502 dwarf2out_begin_function (tree fun)
20504 section *sec = function_section (fun);
20506 if (sec != text_section)
20507 have_multiple_function_sections = true;
20509 if (flag_reorder_blocks_and_partition && !cold_text_section)
20511 gcc_assert (current_function_decl == fun);
20512 cold_text_section = unlikely_text_section ();
20513 switch_to_section (cold_text_section);
20514 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
20515 switch_to_section (sec);
20518 dwarf2out_note_section_used ();
20519 call_site_count = 0;
20520 tail_call_site_count = 0;
20522 set_cur_line_info_table (sec);
20525 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20528 push_dw_line_info_entry (dw_line_info_table *table,
20529 enum dw_line_info_opcode opcode, unsigned int val)
20531 dw_line_info_entry e;
20534 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
20537 /* Output a label to mark the beginning of a source code line entry
20538 and record information relating to this source line, in
20539 'line_info_table' for later output of the .debug_line section. */
20540 /* ??? The discriminator parameter ought to be unsigned. */
20543 dwarf2out_source_line (unsigned int line, const char *filename,
20544 int discriminator, bool is_stmt)
20546 unsigned int file_num;
20547 dw_line_info_table *table;
20549 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
20552 /* The discriminator column was added in dwarf4. Simplify the below
20553 by simply removing it if we're not supposed to output it. */
20554 if (dwarf_version < 4 && dwarf_strict)
20557 table = cur_line_info_table;
20558 file_num = maybe_emit_file (lookup_filename (filename));
20560 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20561 the debugger has used the second (possibly duplicate) line number
20562 at the beginning of the function to mark the end of the prologue.
20563 We could eliminate any other duplicates within the function. For
20564 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20565 that second line number entry. */
20566 /* Recall that this end-of-prologue indication is *not* the same thing
20567 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20568 to which the hook corresponds, follows the last insn that was
20569 emitted by gen_prologue. What we need is to preceed the first insn
20570 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20571 insn that corresponds to something the user wrote. These may be
20572 very different locations once scheduling is enabled. */
20574 if (0 && file_num == table->file_num
20575 && line == table->line_num
20576 && discriminator == table->discrim_num
20577 && is_stmt == table->is_stmt)
20580 switch_to_section (current_function_section ());
20582 /* If requested, emit something human-readable. */
20583 if (flag_debug_asm)
20584 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
20586 if (DWARF2_ASM_LINE_DEBUG_INFO)
20588 /* Emit the .loc directive understood by GNU as. */
20589 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
20590 file_num, line, is_stmt, discriminator */
20591 fputs ("\t.loc ", asm_out_file);
20592 fprint_ul (asm_out_file, file_num);
20593 putc (' ', asm_out_file);
20594 fprint_ul (asm_out_file, line);
20595 putc (' ', asm_out_file);
20596 putc ('0', asm_out_file);
20598 if (is_stmt != table->is_stmt)
20600 fputs (" is_stmt ", asm_out_file);
20601 putc (is_stmt ? '1' : '0', asm_out_file);
20603 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
20605 gcc_assert (discriminator > 0);
20606 fputs (" discriminator ", asm_out_file);
20607 fprint_ul (asm_out_file, (unsigned long) discriminator);
20609 putc ('\n', asm_out_file);
20613 unsigned int label_num = ++line_info_label_num;
20615 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
20617 push_dw_line_info_entry (table, LI_set_address, label_num);
20618 if (file_num != table->file_num)
20619 push_dw_line_info_entry (table, LI_set_file, file_num);
20620 if (discriminator != table->discrim_num)
20621 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
20622 if (is_stmt != table->is_stmt)
20623 push_dw_line_info_entry (table, LI_negate_stmt, 0);
20624 push_dw_line_info_entry (table, LI_set_line, line);
20627 table->file_num = file_num;
20628 table->line_num = line;
20629 table->discrim_num = discriminator;
20630 table->is_stmt = is_stmt;
20631 table->in_use = true;
20634 /* Record the beginning of a new source file. */
20637 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
20639 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20641 /* Record the beginning of the file for break_out_includes. */
20642 dw_die_ref bincl_die;
20644 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
20645 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
20648 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20651 e.code = DW_MACINFO_start_file;
20653 e.info = ggc_strdup (filename);
20654 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20658 /* Record the end of a source file. */
20661 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
20663 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20664 /* Record the end of the file for break_out_includes. */
20665 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
20667 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20670 e.code = DW_MACINFO_end_file;
20673 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20677 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20678 the tail part of the directive line, i.e. the part which is past the
20679 initial whitespace, #, whitespace, directive-name, whitespace part. */
20682 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
20683 const char *buffer ATTRIBUTE_UNUSED)
20685 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20688 /* Insert a dummy first entry to be able to optimize the whole
20689 predefined macro block using DW_MACRO_GNU_transparent_include. */
20690 if (VEC_empty (macinfo_entry, macinfo_table) && lineno <= 1)
20695 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20697 e.code = DW_MACINFO_define;
20699 e.info = ggc_strdup (buffer);
20700 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20704 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20705 the tail part of the directive line, i.e. the part which is past the
20706 initial whitespace, #, whitespace, directive-name, whitespace part. */
20709 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
20710 const char *buffer ATTRIBUTE_UNUSED)
20712 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20715 /* Insert a dummy first entry to be able to optimize the whole
20716 predefined macro block using DW_MACRO_GNU_transparent_include. */
20717 if (VEC_empty (macinfo_entry, macinfo_table) && lineno <= 1)
20722 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20724 e.code = DW_MACINFO_undef;
20726 e.info = ggc_strdup (buffer);
20727 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20731 /* Routines to manipulate hash table of CUs. */
20734 htab_macinfo_hash (const void *of)
20736 const macinfo_entry *const entry =
20737 (const macinfo_entry *) of;
20739 return htab_hash_string (entry->info);
20743 htab_macinfo_eq (const void *of1, const void *of2)
20745 const macinfo_entry *const entry1 = (const macinfo_entry *) of1;
20746 const macinfo_entry *const entry2 = (const macinfo_entry *) of2;
20748 return !strcmp (entry1->info, entry2->info);
20751 /* Output a single .debug_macinfo entry. */
20754 output_macinfo_op (macinfo_entry *ref)
20758 struct indirect_string_node *node;
20759 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20760 struct dwarf_file_data *fd;
20764 case DW_MACINFO_start_file:
20765 fd = lookup_filename (ref->info);
20766 file_num = maybe_emit_file (fd);
20767 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
20768 dw2_asm_output_data_uleb128 (ref->lineno,
20769 "Included from line number %lu",
20770 (unsigned long) ref->lineno);
20771 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
20773 case DW_MACINFO_end_file:
20774 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
20776 case DW_MACINFO_define:
20777 case DW_MACINFO_undef:
20778 len = strlen (ref->info) + 1;
20780 && len > DWARF_OFFSET_SIZE
20781 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
20782 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
20784 ref->code = ref->code == DW_MACINFO_define
20785 ? DW_MACRO_GNU_define_indirect
20786 : DW_MACRO_GNU_undef_indirect;
20787 output_macinfo_op (ref);
20790 dw2_asm_output_data (1, ref->code,
20791 ref->code == DW_MACINFO_define
20792 ? "Define macro" : "Undefine macro");
20793 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20794 (unsigned long) ref->lineno);
20795 dw2_asm_output_nstring (ref->info, -1, "The macro");
20797 case DW_MACRO_GNU_define_indirect:
20798 case DW_MACRO_GNU_undef_indirect:
20799 node = find_AT_string (ref->info);
20800 if (node->form != DW_FORM_strp)
20803 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
20804 ++dw2_string_counter;
20805 node->label = xstrdup (label);
20806 node->form = DW_FORM_strp;
20808 dw2_asm_output_data (1, ref->code,
20809 ref->code == DW_MACRO_GNU_define_indirect
20810 ? "Define macro indirect"
20811 : "Undefine macro indirect");
20812 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20813 (unsigned long) ref->lineno);
20814 dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
20815 debug_str_section, "The macro: \"%s\"",
20818 case DW_MACRO_GNU_transparent_include:
20819 dw2_asm_output_data (1, ref->code, "Transparent include");
20820 ASM_GENERATE_INTERNAL_LABEL (label,
20821 DEBUG_MACRO_SECTION_LABEL, ref->lineno);
20822 dw2_asm_output_offset (DWARF_OFFSET_SIZE, label, NULL, NULL);
20825 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
20826 ASM_COMMENT_START, (unsigned long) ref->code);
20831 /* Attempt to make a sequence of define/undef macinfo ops shareable with
20832 other compilation unit .debug_macinfo sections. IDX is the first
20833 index of a define/undef, return the number of ops that should be
20834 emitted in a comdat .debug_macinfo section and emit
20835 a DW_MACRO_GNU_transparent_include entry referencing it.
20836 If the define/undef entry should be emitted normally, return 0. */
20839 optimize_macinfo_range (unsigned int idx, VEC (macinfo_entry, gc) *files,
20840 htab_t *macinfo_htab)
20842 macinfo_entry *first, *second, *cur, *inc;
20843 char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
20844 unsigned char checksum[16];
20845 struct md5_ctx ctx;
20846 char *grp_name, *tail;
20848 unsigned int i, count, encoded_filename_len, linebuf_len;
20851 first = VEC_index (macinfo_entry, macinfo_table, idx);
20852 second = VEC_index (macinfo_entry, macinfo_table, idx + 1);
20854 /* Optimize only if there are at least two consecutive define/undef ops,
20855 and either all of them are before first DW_MACINFO_start_file
20856 with lineno {0,1} (i.e. predefined macro block), or all of them are
20857 in some included header file. */
20858 if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
20860 if (VEC_empty (macinfo_entry, files))
20862 if (first->lineno > 1 || second->lineno > 1)
20865 else if (first->lineno == 0)
20868 /* Find the last define/undef entry that can be grouped together
20869 with first and at the same time compute md5 checksum of their
20870 codes, linenumbers and strings. */
20871 md5_init_ctx (&ctx);
20872 for (i = idx; VEC_iterate (macinfo_entry, macinfo_table, i, cur); i++)
20873 if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
20875 else if (VEC_empty (macinfo_entry, files) && cur->lineno > 1)
20879 unsigned char code = cur->code;
20880 md5_process_bytes (&code, 1, &ctx);
20881 checksum_uleb128 (cur->lineno, &ctx);
20882 md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
20884 md5_finish_ctx (&ctx, checksum);
20887 /* From the containing include filename (if any) pick up just
20888 usable characters from its basename. */
20889 if (VEC_empty (macinfo_entry, files))
20892 base = lbasename (VEC_last (macinfo_entry, files)->info);
20893 for (encoded_filename_len = 0, i = 0; base[i]; i++)
20894 if (ISIDNUM (base[i]) || base[i] == '.')
20895 encoded_filename_len++;
20896 /* Count . at the end. */
20897 if (encoded_filename_len)
20898 encoded_filename_len++;
20900 sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
20901 linebuf_len = strlen (linebuf);
20903 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
20904 grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
20906 memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4);
20907 tail = grp_name + 4;
20908 if (encoded_filename_len)
20910 for (i = 0; base[i]; i++)
20911 if (ISIDNUM (base[i]) || base[i] == '.')
20915 memcpy (tail, linebuf, linebuf_len);
20916 tail += linebuf_len;
20918 for (i = 0; i < 16; i++)
20919 sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
20921 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
20922 in the empty vector entry before the first define/undef. */
20923 inc = VEC_index (macinfo_entry, macinfo_table, idx - 1);
20924 inc->code = DW_MACRO_GNU_transparent_include;
20926 inc->info = ggc_strdup (grp_name);
20927 if (*macinfo_htab == NULL)
20928 *macinfo_htab = htab_create (10, htab_macinfo_hash, htab_macinfo_eq, NULL);
20929 /* Avoid emitting duplicates. */
20930 slot = htab_find_slot (*macinfo_htab, inc, INSERT);
20935 /* If such an entry has been used before, just emit
20936 a DW_MACRO_GNU_transparent_include op. */
20937 inc = (macinfo_entry *) *slot;
20938 output_macinfo_op (inc);
20939 /* And clear all macinfo_entry in the range to avoid emitting them
20940 in the second pass. */
20942 VEC_iterate (macinfo_entry, macinfo_table, i, cur)
20943 && i < idx + count;
20953 inc->lineno = htab_elements (*macinfo_htab);
20954 output_macinfo_op (inc);
20959 /* Output macinfo section(s). */
20962 output_macinfo (void)
20965 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
20966 macinfo_entry *ref;
20967 VEC (macinfo_entry, gc) *files = NULL;
20968 htab_t macinfo_htab = NULL;
20973 /* output_macinfo* uses these interchangeably. */
20974 gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_GNU_define
20975 && (int) DW_MACINFO_undef == (int) DW_MACRO_GNU_undef
20976 && (int) DW_MACINFO_start_file == (int) DW_MACRO_GNU_start_file
20977 && (int) DW_MACINFO_end_file == (int) DW_MACRO_GNU_end_file);
20979 /* For .debug_macro emit the section header. */
20982 dw2_asm_output_data (2, 4, "DWARF macro version number");
20983 if (DWARF_OFFSET_SIZE == 8)
20984 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
20986 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
20987 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_line_section_label,
20988 debug_line_section, NULL);
20991 /* In the first loop, it emits the primary .debug_macinfo section
20992 and after each emitted op the macinfo_entry is cleared.
20993 If a longer range of define/undef ops can be optimized using
20994 DW_MACRO_GNU_transparent_include, the
20995 DW_MACRO_GNU_transparent_include op is emitted and kept in
20996 the vector before the first define/undef in the range and the
20997 whole range of define/undef ops is not emitted and kept. */
20998 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
21002 case DW_MACINFO_start_file:
21003 VEC_safe_push (macinfo_entry, gc, files, ref);
21005 case DW_MACINFO_end_file:
21006 if (!VEC_empty (macinfo_entry, files))
21007 VEC_pop (macinfo_entry, files);
21009 case DW_MACINFO_define:
21010 case DW_MACINFO_undef:
21012 && HAVE_COMDAT_GROUP
21013 && VEC_length (macinfo_entry, files) != 1
21016 && VEC_index (macinfo_entry, macinfo_table, i - 1)->code == 0)
21018 unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
21027 /* A dummy entry may be inserted at the beginning to be able
21028 to optimize the whole block of predefined macros. */
21034 output_macinfo_op (ref);
21039 if (macinfo_htab == NULL)
21042 htab_delete (macinfo_htab);
21044 /* If any DW_MACRO_GNU_transparent_include were used, on those
21045 DW_MACRO_GNU_transparent_include entries terminate the
21046 current chain and switch to a new comdat .debug_macinfo
21047 section and emit the define/undef entries within it. */
21048 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
21053 case DW_MACRO_GNU_transparent_include:
21055 char label[MAX_ARTIFICIAL_LABEL_BYTES];
21056 tree comdat_key = get_identifier (ref->info);
21057 /* Terminate the previous .debug_macinfo section. */
21058 dw2_asm_output_data (1, 0, "End compilation unit");
21059 targetm.asm_out.named_section (DEBUG_MACRO_SECTION,
21061 | SECTION_LINKONCE,
21063 ASM_GENERATE_INTERNAL_LABEL (label,
21064 DEBUG_MACRO_SECTION_LABEL,
21066 ASM_OUTPUT_LABEL (asm_out_file, label);
21069 dw2_asm_output_data (2, 4, "DWARF macro version number");
21070 if (DWARF_OFFSET_SIZE == 8)
21071 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21073 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21076 case DW_MACINFO_define:
21077 case DW_MACINFO_undef:
21078 output_macinfo_op (ref);
21083 gcc_unreachable ();
21087 /* Set up for Dwarf output at the start of compilation. */
21090 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
21092 /* Allocate the file_table. */
21093 file_table = htab_create_ggc (50, file_table_hash,
21094 file_table_eq, NULL);
21096 /* Allocate the decl_die_table. */
21097 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
21098 decl_die_table_eq, NULL);
21100 /* Allocate the decl_loc_table. */
21101 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
21102 decl_loc_table_eq, NULL);
21104 /* Allocate the cached_dw_loc_list_table. */
21105 cached_dw_loc_list_table
21106 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
21107 cached_dw_loc_list_table_eq, NULL);
21109 /* Allocate the initial hunk of the decl_scope_table. */
21110 decl_scope_table = VEC_alloc (tree, gc, 256);
21112 /* Allocate the initial hunk of the abbrev_die_table. */
21113 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
21114 (ABBREV_DIE_TABLE_INCREMENT);
21115 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
21116 /* Zero-th entry is allocated, but unused. */
21117 abbrev_die_table_in_use = 1;
21119 /* Allocate the pubtypes and pubnames vectors. */
21120 pubname_table = VEC_alloc (pubname_entry, gc, 32);
21121 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
21123 incomplete_types = VEC_alloc (tree, gc, 64);
21125 used_rtx_array = VEC_alloc (rtx, gc, 32);
21127 debug_info_section = get_section (DEBUG_INFO_SECTION,
21128 SECTION_DEBUG, NULL);
21129 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
21130 SECTION_DEBUG, NULL);
21131 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
21132 SECTION_DEBUG, NULL);
21133 debug_macinfo_section = get_section (dwarf_strict
21134 ? DEBUG_MACINFO_SECTION
21135 : DEBUG_MACRO_SECTION,
21136 SECTION_DEBUG, NULL);
21137 debug_line_section = get_section (DEBUG_LINE_SECTION,
21138 SECTION_DEBUG, NULL);
21139 debug_loc_section = get_section (DEBUG_LOC_SECTION,
21140 SECTION_DEBUG, NULL);
21141 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
21142 SECTION_DEBUG, NULL);
21143 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
21144 SECTION_DEBUG, NULL);
21145 debug_str_section = get_section (DEBUG_STR_SECTION,
21146 DEBUG_STR_SECTION_FLAGS, NULL);
21147 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
21148 SECTION_DEBUG, NULL);
21149 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
21150 SECTION_DEBUG, NULL);
21152 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
21153 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
21154 DEBUG_ABBREV_SECTION_LABEL, 0);
21155 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
21156 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
21157 COLD_TEXT_SECTION_LABEL, 0);
21158 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
21160 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
21161 DEBUG_INFO_SECTION_LABEL, 0);
21162 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
21163 DEBUG_LINE_SECTION_LABEL, 0);
21164 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
21165 DEBUG_RANGES_SECTION_LABEL, 0);
21166 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
21168 ? DEBUG_MACINFO_SECTION_LABEL
21169 : DEBUG_MACRO_SECTION_LABEL, 0);
21171 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21172 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
21174 switch_to_section (text_section);
21175 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
21177 /* Make sure the line number table for .text always exists. */
21178 text_section_line_info = new_line_info_table ();
21179 text_section_line_info->end_label = text_end_label;
21182 /* Called before cgraph_optimize starts outputtting functions, variables
21183 and toplevel asms into assembly. */
21186 dwarf2out_assembly_start (void)
21188 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21189 && dwarf2out_do_cfi_asm ()
21190 && (!(flag_unwind_tables || flag_exceptions)
21191 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
21192 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
21195 /* A helper function for dwarf2out_finish called through
21196 htab_traverse. Emit one queued .debug_str string. */
21199 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
21201 struct indirect_string_node *node = (struct indirect_string_node *) *h;
21203 if (node->form == DW_FORM_strp)
21205 switch_to_section (debug_str_section);
21206 ASM_OUTPUT_LABEL (asm_out_file, node->label);
21207 assemble_string (node->str, strlen (node->str) + 1);
21213 #if ENABLE_ASSERT_CHECKING
21214 /* Verify that all marks are clear. */
21217 verify_marks_clear (dw_die_ref die)
21221 gcc_assert (! die->die_mark);
21222 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
21224 #endif /* ENABLE_ASSERT_CHECKING */
21226 /* Clear the marks for a die and its children.
21227 Be cool if the mark isn't set. */
21230 prune_unmark_dies (dw_die_ref die)
21236 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
21239 /* Given DIE that we're marking as used, find any other dies
21240 it references as attributes and mark them as used. */
21243 prune_unused_types_walk_attribs (dw_die_ref die)
21248 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21250 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
21252 /* A reference to another DIE.
21253 Make sure that it will get emitted.
21254 If it was broken out into a comdat group, don't follow it. */
21255 if (! use_debug_types
21256 || a->dw_attr == DW_AT_specification
21257 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
21258 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
21260 /* Set the string's refcount to 0 so that prune_unused_types_mark
21261 accounts properly for it. */
21262 if (AT_class (a) == dw_val_class_str)
21263 a->dw_attr_val.v.val_str->refcount = 0;
21267 /* Mark the generic parameters and arguments children DIEs of DIE. */
21270 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
21274 if (die == NULL || die->die_child == NULL)
21276 c = die->die_child;
21279 switch (c->die_tag)
21281 case DW_TAG_template_type_param:
21282 case DW_TAG_template_value_param:
21283 case DW_TAG_GNU_template_template_param:
21284 case DW_TAG_GNU_template_parameter_pack:
21285 prune_unused_types_mark (c, 1);
21291 } while (c && c != die->die_child);
21294 /* Mark DIE as being used. If DOKIDS is true, then walk down
21295 to DIE's children. */
21298 prune_unused_types_mark (dw_die_ref die, int dokids)
21302 if (die->die_mark == 0)
21304 /* We haven't done this node yet. Mark it as used. */
21306 /* If this is the DIE of a generic type instantiation,
21307 mark the children DIEs that describe its generic parms and
21309 prune_unused_types_mark_generic_parms_dies (die);
21311 /* We also have to mark its parents as used.
21312 (But we don't want to mark our parents' kids due to this.) */
21313 if (die->die_parent)
21314 prune_unused_types_mark (die->die_parent, 0);
21316 /* Mark any referenced nodes. */
21317 prune_unused_types_walk_attribs (die);
21319 /* If this node is a specification,
21320 also mark the definition, if it exists. */
21321 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
21322 prune_unused_types_mark (die->die_definition, 1);
21325 if (dokids && die->die_mark != 2)
21327 /* We need to walk the children, but haven't done so yet.
21328 Remember that we've walked the kids. */
21331 /* If this is an array type, we need to make sure our
21332 kids get marked, even if they're types. If we're
21333 breaking out types into comdat sections, do this
21334 for all type definitions. */
21335 if (die->die_tag == DW_TAG_array_type
21336 || (use_debug_types
21337 && is_type_die (die) && ! is_declaration_die (die)))
21338 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
21340 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21344 /* For local classes, look if any static member functions were emitted
21345 and if so, mark them. */
21348 prune_unused_types_walk_local_classes (dw_die_ref die)
21352 if (die->die_mark == 2)
21355 switch (die->die_tag)
21357 case DW_TAG_structure_type:
21358 case DW_TAG_union_type:
21359 case DW_TAG_class_type:
21362 case DW_TAG_subprogram:
21363 if (!get_AT_flag (die, DW_AT_declaration)
21364 || die->die_definition != NULL)
21365 prune_unused_types_mark (die, 1);
21372 /* Mark children. */
21373 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
21376 /* Walk the tree DIE and mark types that we actually use. */
21379 prune_unused_types_walk (dw_die_ref die)
21383 /* Don't do anything if this node is already marked and
21384 children have been marked as well. */
21385 if (die->die_mark == 2)
21388 switch (die->die_tag)
21390 case DW_TAG_structure_type:
21391 case DW_TAG_union_type:
21392 case DW_TAG_class_type:
21393 if (die->die_perennial_p)
21396 for (c = die->die_parent; c; c = c->die_parent)
21397 if (c->die_tag == DW_TAG_subprogram)
21400 /* Finding used static member functions inside of classes
21401 is needed just for local classes, because for other classes
21402 static member function DIEs with DW_AT_specification
21403 are emitted outside of the DW_TAG_*_type. If we ever change
21404 it, we'd need to call this even for non-local classes. */
21406 prune_unused_types_walk_local_classes (die);
21408 /* It's a type node --- don't mark it. */
21411 case DW_TAG_const_type:
21412 case DW_TAG_packed_type:
21413 case DW_TAG_pointer_type:
21414 case DW_TAG_reference_type:
21415 case DW_TAG_rvalue_reference_type:
21416 case DW_TAG_volatile_type:
21417 case DW_TAG_typedef:
21418 case DW_TAG_array_type:
21419 case DW_TAG_interface_type:
21420 case DW_TAG_friend:
21421 case DW_TAG_variant_part:
21422 case DW_TAG_enumeration_type:
21423 case DW_TAG_subroutine_type:
21424 case DW_TAG_string_type:
21425 case DW_TAG_set_type:
21426 case DW_TAG_subrange_type:
21427 case DW_TAG_ptr_to_member_type:
21428 case DW_TAG_file_type:
21429 if (die->die_perennial_p)
21432 /* It's a type node --- don't mark it. */
21436 /* Mark everything else. */
21440 if (die->die_mark == 0)
21444 /* Now, mark any dies referenced from here. */
21445 prune_unused_types_walk_attribs (die);
21450 /* Mark children. */
21451 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21454 /* Increment the string counts on strings referred to from DIE's
21458 prune_unused_types_update_strings (dw_die_ref die)
21463 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21464 if (AT_class (a) == dw_val_class_str)
21466 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
21468 /* Avoid unnecessarily putting strings that are used less than
21469 twice in the hash table. */
21471 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
21474 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
21475 htab_hash_string (s->str),
21477 gcc_assert (*slot == NULL);
21483 /* Remove from the tree DIE any dies that aren't marked. */
21486 prune_unused_types_prune (dw_die_ref die)
21490 gcc_assert (die->die_mark);
21491 prune_unused_types_update_strings (die);
21493 if (! die->die_child)
21496 c = die->die_child;
21498 dw_die_ref prev = c;
21499 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
21500 if (c == die->die_child)
21502 /* No marked children between 'prev' and the end of the list. */
21504 /* No marked children at all. */
21505 die->die_child = NULL;
21508 prev->die_sib = c->die_sib;
21509 die->die_child = prev;
21514 if (c != prev->die_sib)
21516 prune_unused_types_prune (c);
21517 } while (c != die->die_child);
21520 /* Remove dies representing declarations that we never use. */
21523 prune_unused_types (void)
21526 limbo_die_node *node;
21527 comdat_type_node *ctnode;
21529 dw_die_ref base_type;
21531 #if ENABLE_ASSERT_CHECKING
21532 /* All the marks should already be clear. */
21533 verify_marks_clear (comp_unit_die ());
21534 for (node = limbo_die_list; node; node = node->next)
21535 verify_marks_clear (node->die);
21536 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21537 verify_marks_clear (ctnode->root_die);
21538 #endif /* ENABLE_ASSERT_CHECKING */
21540 /* Mark types that are used in global variables. */
21541 premark_types_used_by_global_vars ();
21543 /* Set the mark on nodes that are actually used. */
21544 prune_unused_types_walk (comp_unit_die ());
21545 for (node = limbo_die_list; node; node = node->next)
21546 prune_unused_types_walk (node->die);
21547 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21549 prune_unused_types_walk (ctnode->root_die);
21550 prune_unused_types_mark (ctnode->type_die, 1);
21553 /* Also set the mark on nodes referenced from the
21555 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
21556 prune_unused_types_mark (pub->die, 1);
21557 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21558 prune_unused_types_mark (base_type, 1);
21560 if (debug_str_hash)
21561 htab_empty (debug_str_hash);
21562 prune_unused_types_prune (comp_unit_die ());
21563 for (node = limbo_die_list; node; node = node->next)
21564 prune_unused_types_prune (node->die);
21565 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21566 prune_unused_types_prune (ctnode->root_die);
21568 /* Leave the marks clear. */
21569 prune_unmark_dies (comp_unit_die ());
21570 for (node = limbo_die_list; node; node = node->next)
21571 prune_unmark_dies (node->die);
21572 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21573 prune_unmark_dies (ctnode->root_die);
21576 /* Set the parameter to true if there are any relative pathnames in
21579 file_table_relative_p (void ** slot, void *param)
21581 bool *p = (bool *) param;
21582 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
21583 if (!IS_ABSOLUTE_PATH (d->filename))
21591 /* Routines to manipulate hash table of comdat type units. */
21594 htab_ct_hash (const void *of)
21597 const comdat_type_node *const type_node = (const comdat_type_node *) of;
21599 memcpy (&h, type_node->signature, sizeof (h));
21604 htab_ct_eq (const void *of1, const void *of2)
21606 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
21607 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
21609 return (! memcmp (type_node_1->signature, type_node_2->signature,
21610 DWARF_TYPE_SIGNATURE_SIZE));
21613 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21614 to the location it would have been added, should we know its
21615 DECL_ASSEMBLER_NAME when we added other attributes. This will
21616 probably improve compactness of debug info, removing equivalent
21617 abbrevs, and hide any differences caused by deferring the
21618 computation of the assembler name, triggered by e.g. PCH. */
21621 move_linkage_attr (dw_die_ref die)
21623 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
21624 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
21626 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
21627 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
21631 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
21633 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
21637 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
21639 VEC_pop (dw_attr_node, die->die_attr);
21640 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
21644 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21645 referenced from typed stack ops and count how often they are used. */
21648 mark_base_types (dw_loc_descr_ref loc)
21650 dw_die_ref base_type = NULL;
21652 for (; loc; loc = loc->dw_loc_next)
21654 switch (loc->dw_loc_opc)
21656 case DW_OP_GNU_regval_type:
21657 case DW_OP_GNU_deref_type:
21658 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
21660 case DW_OP_GNU_convert:
21661 case DW_OP_GNU_reinterpret:
21662 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
21665 case DW_OP_GNU_const_type:
21666 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
21668 case DW_OP_GNU_entry_value:
21669 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
21674 gcc_assert (base_type->die_parent == comp_unit_die ());
21675 if (base_type->die_mark)
21676 base_type->die_mark++;
21679 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
21680 base_type->die_mark = 1;
21685 /* Comparison function for sorting marked base types. */
21688 base_type_cmp (const void *x, const void *y)
21690 dw_die_ref dx = *(const dw_die_ref *) x;
21691 dw_die_ref dy = *(const dw_die_ref *) y;
21692 unsigned int byte_size1, byte_size2;
21693 unsigned int encoding1, encoding2;
21694 if (dx->die_mark > dy->die_mark)
21696 if (dx->die_mark < dy->die_mark)
21698 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
21699 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
21700 if (byte_size1 < byte_size2)
21702 if (byte_size1 > byte_size2)
21704 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
21705 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
21706 if (encoding1 < encoding2)
21708 if (encoding1 > encoding2)
21713 /* Move base types marked by mark_base_types as early as possible
21714 in the CU, sorted by decreasing usage count both to make the
21715 uleb128 references as small as possible and to make sure they
21716 will have die_offset already computed by calc_die_sizes when
21717 sizes of typed stack loc ops is computed. */
21720 move_marked_base_types (void)
21723 dw_die_ref base_type, die, c;
21725 if (VEC_empty (dw_die_ref, base_types))
21728 /* Sort by decreasing usage count, they will be added again in that
21730 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
21731 die = comp_unit_die ();
21732 c = die->die_child;
21735 dw_die_ref prev = c;
21737 while (c->die_mark)
21739 remove_child_with_prev (c, prev);
21740 /* As base types got marked, there must be at least
21741 one node other than DW_TAG_base_type. */
21742 gcc_assert (c != c->die_sib);
21746 while (c != die->die_child);
21747 gcc_assert (die->die_child);
21748 c = die->die_child;
21749 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21751 base_type->die_mark = 0;
21752 base_type->die_sib = c->die_sib;
21753 c->die_sib = base_type;
21758 /* Helper function for resolve_addr, attempt to resolve
21759 one CONST_STRING, return non-zero if not successful. Similarly verify that
21760 SYMBOL_REFs refer to variables emitted in the current CU. */
21763 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
21767 if (GET_CODE (rtl) == CONST_STRING)
21769 size_t len = strlen (XSTR (rtl, 0)) + 1;
21770 tree t = build_string (len, XSTR (rtl, 0));
21771 tree tlen = size_int (len - 1);
21773 = build_array_type (char_type_node, build_index_type (tlen));
21774 rtl = lookup_constant_def (t);
21775 if (!rtl || !MEM_P (rtl))
21777 rtl = XEXP (rtl, 0);
21778 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
21783 if (GET_CODE (rtl) == SYMBOL_REF
21784 && SYMBOL_REF_DECL (rtl))
21786 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
21788 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
21791 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
21795 if (GET_CODE (rtl) == CONST
21796 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
21802 /* Helper function for resolve_addr, handle one location
21803 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21804 the location list couldn't be resolved. */
21807 resolve_addr_in_expr (dw_loc_descr_ref loc)
21809 dw_loc_descr_ref keep = NULL;
21810 for (; loc; loc = loc->dw_loc_next)
21811 switch (loc->dw_loc_opc)
21814 if (resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21817 case DW_OP_const4u:
21818 case DW_OP_const8u:
21820 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21823 case DW_OP_plus_uconst:
21824 if (size_of_loc_descr (loc)
21825 > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
21827 && loc->dw_loc_oprnd1.v.val_unsigned > 0)
21829 dw_loc_descr_ref repl
21830 = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
21831 add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
21832 add_loc_descr (&repl, loc->dw_loc_next);
21836 case DW_OP_implicit_value:
21837 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
21838 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL))
21841 case DW_OP_GNU_implicit_pointer:
21842 case DW_OP_GNU_parameter_ref:
21843 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
21846 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
21849 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
21850 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
21851 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
21854 case DW_OP_GNU_const_type:
21855 case DW_OP_GNU_regval_type:
21856 case DW_OP_GNU_deref_type:
21857 case DW_OP_GNU_convert:
21858 case DW_OP_GNU_reinterpret:
21859 while (loc->dw_loc_next
21860 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
21862 dw_die_ref base1, base2;
21863 unsigned enc1, enc2, size1, size2;
21864 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21865 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21866 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
21867 else if (loc->dw_loc_oprnd1.val_class
21868 == dw_val_class_unsigned_const)
21871 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
21872 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
21873 == dw_val_class_unsigned_const)
21875 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
21876 gcc_assert (base1->die_tag == DW_TAG_base_type
21877 && base2->die_tag == DW_TAG_base_type);
21878 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
21879 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
21880 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
21881 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
21883 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
21884 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
21888 /* Optimize away next DW_OP_GNU_convert after
21889 adjusting LOC's base type die reference. */
21890 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21891 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21892 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
21894 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
21895 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
21898 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21899 point typed stack entry. */
21900 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
21901 keep = loc->dw_loc_next;
21911 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21912 an address in .rodata section if the string literal is emitted there,
21913 or remove the containing location list or replace DW_AT_const_value
21914 with DW_AT_location and empty location expression, if it isn't found
21915 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21916 to something that has been emitted in the current CU. */
21919 resolve_addr (dw_die_ref die)
21923 dw_loc_list_ref *curr, *start, loc;
21926 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21927 switch (AT_class (a))
21929 case dw_val_class_loc_list:
21930 start = curr = AT_loc_list_ptr (a);
21933 /* The same list can be referenced more than once. See if we have
21934 already recorded the result from a previous pass. */
21936 *curr = loc->dw_loc_next;
21937 else if (!loc->resolved_addr)
21939 /* As things stand, we do not expect or allow one die to
21940 reference a suffix of another die's location list chain.
21941 References must be identical or completely separate.
21942 There is therefore no need to cache the result of this
21943 pass on any list other than the first; doing so
21944 would lead to unnecessary writes. */
21947 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
21948 if (!resolve_addr_in_expr ((*curr)->expr))
21950 dw_loc_list_ref next = (*curr)->dw_loc_next;
21951 if (next && (*curr)->ll_symbol)
21953 gcc_assert (!next->ll_symbol);
21954 next->ll_symbol = (*curr)->ll_symbol;
21960 mark_base_types ((*curr)->expr);
21961 curr = &(*curr)->dw_loc_next;
21965 loc->resolved_addr = 1;
21969 loc->dw_loc_next = *start;
21974 remove_AT (die, a->dw_attr);
21978 case dw_val_class_loc:
21980 dw_loc_descr_ref l = AT_loc (a);
21981 /* For -gdwarf-2 don't attempt to optimize
21982 DW_AT_data_member_location containing
21983 DW_OP_plus_uconst - older consumers might
21984 rely on it being that op instead of a more complex,
21985 but shorter, location description. */
21986 if ((dwarf_version > 2
21987 || a->dw_attr != DW_AT_data_member_location
21989 || l->dw_loc_opc != DW_OP_plus_uconst
21990 || l->dw_loc_next != NULL)
21991 && !resolve_addr_in_expr (l))
21993 remove_AT (die, a->dw_attr);
21997 mark_base_types (l);
22000 case dw_val_class_addr:
22001 if (a->dw_attr == DW_AT_const_value
22002 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
22004 remove_AT (die, a->dw_attr);
22007 if (die->die_tag == DW_TAG_GNU_call_site
22008 && a->dw_attr == DW_AT_abstract_origin)
22010 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
22011 dw_die_ref tdie = lookup_decl_die (tdecl);
22013 && DECL_EXTERNAL (tdecl)
22014 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
22016 force_decl_die (tdecl);
22017 tdie = lookup_decl_die (tdecl);
22021 a->dw_attr_val.val_class = dw_val_class_die_ref;
22022 a->dw_attr_val.v.val_die_ref.die = tdie;
22023 a->dw_attr_val.v.val_die_ref.external = 0;
22027 remove_AT (die, a->dw_attr);
22036 FOR_EACH_CHILD (die, c, resolve_addr (c));
22039 /* Helper routines for optimize_location_lists.
22040 This pass tries to share identical local lists in .debug_loc
22043 /* Iteratively hash operands of LOC opcode. */
22045 static inline hashval_t
22046 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
22048 dw_val_ref val1 = &loc->dw_loc_oprnd1;
22049 dw_val_ref val2 = &loc->dw_loc_oprnd2;
22051 switch (loc->dw_loc_opc)
22053 case DW_OP_const4u:
22054 case DW_OP_const8u:
22058 case DW_OP_const1u:
22059 case DW_OP_const1s:
22060 case DW_OP_const2u:
22061 case DW_OP_const2s:
22062 case DW_OP_const4s:
22063 case DW_OP_const8s:
22067 case DW_OP_plus_uconst:
22103 case DW_OP_deref_size:
22104 case DW_OP_xderef_size:
22105 hash = iterative_hash_object (val1->v.val_int, hash);
22112 gcc_assert (val1->val_class == dw_val_class_loc);
22113 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
22114 hash = iterative_hash_object (offset, hash);
22117 case DW_OP_implicit_value:
22118 hash = iterative_hash_object (val1->v.val_unsigned, hash);
22119 switch (val2->val_class)
22121 case dw_val_class_const:
22122 hash = iterative_hash_object (val2->v.val_int, hash);
22124 case dw_val_class_vec:
22126 unsigned int elt_size = val2->v.val_vec.elt_size;
22127 unsigned int len = val2->v.val_vec.length;
22129 hash = iterative_hash_object (elt_size, hash);
22130 hash = iterative_hash_object (len, hash);
22131 hash = iterative_hash (val2->v.val_vec.array,
22132 len * elt_size, hash);
22135 case dw_val_class_const_double:
22136 hash = iterative_hash_object (val2->v.val_double.low, hash);
22137 hash = iterative_hash_object (val2->v.val_double.high, hash);
22139 case dw_val_class_addr:
22140 hash = iterative_hash_rtx (val2->v.val_addr, hash);
22143 gcc_unreachable ();
22147 case DW_OP_bit_piece:
22148 hash = iterative_hash_object (val1->v.val_int, hash);
22149 hash = iterative_hash_object (val2->v.val_int, hash);
22155 unsigned char dtprel = 0xd1;
22156 hash = iterative_hash_object (dtprel, hash);
22158 hash = iterative_hash_rtx (val1->v.val_addr, hash);
22160 case DW_OP_GNU_implicit_pointer:
22161 hash = iterative_hash_object (val2->v.val_int, hash);
22163 case DW_OP_GNU_entry_value:
22164 hash = hash_loc_operands (val1->v.val_loc, hash);
22166 case DW_OP_GNU_regval_type:
22167 case DW_OP_GNU_deref_type:
22169 unsigned int byte_size
22170 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
22171 unsigned int encoding
22172 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
22173 hash = iterative_hash_object (val1->v.val_int, hash);
22174 hash = iterative_hash_object (byte_size, hash);
22175 hash = iterative_hash_object (encoding, hash);
22178 case DW_OP_GNU_convert:
22179 case DW_OP_GNU_reinterpret:
22180 if (val1->val_class == dw_val_class_unsigned_const)
22182 hash = iterative_hash_object (val1->v.val_unsigned, hash);
22186 case DW_OP_GNU_const_type:
22188 unsigned int byte_size
22189 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
22190 unsigned int encoding
22191 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
22192 hash = iterative_hash_object (byte_size, hash);
22193 hash = iterative_hash_object (encoding, hash);
22194 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
22196 hash = iterative_hash_object (val2->val_class, hash);
22197 switch (val2->val_class)
22199 case dw_val_class_const:
22200 hash = iterative_hash_object (val2->v.val_int, hash);
22202 case dw_val_class_vec:
22204 unsigned int elt_size = val2->v.val_vec.elt_size;
22205 unsigned int len = val2->v.val_vec.length;
22207 hash = iterative_hash_object (elt_size, hash);
22208 hash = iterative_hash_object (len, hash);
22209 hash = iterative_hash (val2->v.val_vec.array,
22210 len * elt_size, hash);
22213 case dw_val_class_const_double:
22214 hash = iterative_hash_object (val2->v.val_double.low, hash);
22215 hash = iterative_hash_object (val2->v.val_double.high, hash);
22218 gcc_unreachable ();
22224 /* Other codes have no operands. */
22230 /* Iteratively hash the whole DWARF location expression LOC. */
22232 static inline hashval_t
22233 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
22235 dw_loc_descr_ref l;
22236 bool sizes_computed = false;
22237 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22238 size_of_locs (loc);
22240 for (l = loc; l != NULL; l = l->dw_loc_next)
22242 enum dwarf_location_atom opc = l->dw_loc_opc;
22243 hash = iterative_hash_object (opc, hash);
22244 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
22246 size_of_locs (loc);
22247 sizes_computed = true;
22249 hash = hash_loc_operands (l, hash);
22254 /* Compute hash of the whole location list LIST_HEAD. */
22257 hash_loc_list (dw_loc_list_ref list_head)
22259 dw_loc_list_ref curr = list_head;
22260 hashval_t hash = 0;
22262 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
22264 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
22265 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
22267 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
22269 hash = hash_locs (curr->expr, hash);
22271 list_head->hash = hash;
22274 /* Return true if X and Y opcodes have the same operands. */
22277 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
22279 dw_val_ref valx1 = &x->dw_loc_oprnd1;
22280 dw_val_ref valx2 = &x->dw_loc_oprnd2;
22281 dw_val_ref valy1 = &y->dw_loc_oprnd1;
22282 dw_val_ref valy2 = &y->dw_loc_oprnd2;
22284 switch (x->dw_loc_opc)
22286 case DW_OP_const4u:
22287 case DW_OP_const8u:
22291 case DW_OP_const1u:
22292 case DW_OP_const1s:
22293 case DW_OP_const2u:
22294 case DW_OP_const2s:
22295 case DW_OP_const4s:
22296 case DW_OP_const8s:
22300 case DW_OP_plus_uconst:
22336 case DW_OP_deref_size:
22337 case DW_OP_xderef_size:
22338 return valx1->v.val_int == valy1->v.val_int;
22341 gcc_assert (valx1->val_class == dw_val_class_loc
22342 && valy1->val_class == dw_val_class_loc
22343 && x->dw_loc_addr == y->dw_loc_addr);
22344 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
22345 case DW_OP_implicit_value:
22346 if (valx1->v.val_unsigned != valy1->v.val_unsigned
22347 || valx2->val_class != valy2->val_class)
22349 switch (valx2->val_class)
22351 case dw_val_class_const:
22352 return valx2->v.val_int == valy2->v.val_int;
22353 case dw_val_class_vec:
22354 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22355 && valx2->v.val_vec.length == valy2->v.val_vec.length
22356 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22357 valx2->v.val_vec.elt_size
22358 * valx2->v.val_vec.length) == 0;
22359 case dw_val_class_const_double:
22360 return valx2->v.val_double.low == valy2->v.val_double.low
22361 && valx2->v.val_double.high == valy2->v.val_double.high;
22362 case dw_val_class_addr:
22363 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
22365 gcc_unreachable ();
22368 case DW_OP_bit_piece:
22369 return valx1->v.val_int == valy1->v.val_int
22370 && valx2->v.val_int == valy2->v.val_int;
22373 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
22374 case DW_OP_GNU_implicit_pointer:
22375 return valx1->val_class == dw_val_class_die_ref
22376 && valx1->val_class == valy1->val_class
22377 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
22378 && valx2->v.val_int == valy2->v.val_int;
22379 case DW_OP_GNU_entry_value:
22380 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
22381 case DW_OP_GNU_const_type:
22382 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
22383 || valx2->val_class != valy2->val_class)
22385 switch (valx2->val_class)
22387 case dw_val_class_const:
22388 return valx2->v.val_int == valy2->v.val_int;
22389 case dw_val_class_vec:
22390 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22391 && valx2->v.val_vec.length == valy2->v.val_vec.length
22392 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22393 valx2->v.val_vec.elt_size
22394 * valx2->v.val_vec.length) == 0;
22395 case dw_val_class_const_double:
22396 return valx2->v.val_double.low == valy2->v.val_double.low
22397 && valx2->v.val_double.high == valy2->v.val_double.high;
22399 gcc_unreachable ();
22401 case DW_OP_GNU_regval_type:
22402 case DW_OP_GNU_deref_type:
22403 return valx1->v.val_int == valy1->v.val_int
22404 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
22405 case DW_OP_GNU_convert:
22406 case DW_OP_GNU_reinterpret:
22407 if (valx1->val_class != valy1->val_class)
22409 if (valx1->val_class == dw_val_class_unsigned_const)
22410 return valx1->v.val_unsigned == valy1->v.val_unsigned;
22411 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
22412 case DW_OP_GNU_parameter_ref:
22413 return valx1->val_class == dw_val_class_die_ref
22414 && valx1->val_class == valy1->val_class
22415 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
22417 /* Other codes have no operands. */
22422 /* Return true if DWARF location expressions X and Y are the same. */
22425 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
22427 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
22428 if (x->dw_loc_opc != y->dw_loc_opc
22429 || x->dtprel != y->dtprel
22430 || !compare_loc_operands (x, y))
22432 return x == NULL && y == NULL;
22435 /* Return precomputed hash of location list X. */
22438 loc_list_hash (const void *x)
22440 return ((const struct dw_loc_list_struct *) x)->hash;
22443 /* Return 1 if location lists X and Y are the same. */
22446 loc_list_eq (const void *x, const void *y)
22448 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
22449 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
22452 if (a->hash != b->hash)
22454 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
22455 if (strcmp (a->begin, b->begin) != 0
22456 || strcmp (a->end, b->end) != 0
22457 || (a->section == NULL) != (b->section == NULL)
22458 || (a->section && strcmp (a->section, b->section) != 0)
22459 || !compare_locs (a->expr, b->expr))
22461 return a == NULL && b == NULL;
22464 /* Recursively optimize location lists referenced from DIE
22465 children and share them whenever possible. */
22468 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
22475 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22476 if (AT_class (a) == dw_val_class_loc_list)
22478 dw_loc_list_ref list = AT_loc_list (a);
22479 /* TODO: perform some optimizations here, before hashing
22480 it and storing into the hash table. */
22481 hash_loc_list (list);
22482 slot = htab_find_slot_with_hash (htab, list, list->hash,
22485 *slot = (void *) list;
22487 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
22490 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
22493 /* Optimize location lists referenced from DIE
22494 children and share them whenever possible. */
22497 optimize_location_lists (dw_die_ref die)
22499 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
22500 optimize_location_lists_1 (die, htab);
22501 htab_delete (htab);
22504 /* Output stuff that dwarf requires at the end of every file,
22505 and generate the DWARF-2 debugging info. */
22508 dwarf2out_finish (const char *filename)
22510 limbo_die_node *node, *next_node;
22511 comdat_type_node *ctnode;
22512 htab_t comdat_type_table;
22515 /* PCH might result in DW_AT_producer string being restored from the
22516 header compilation, fix it up if needed. */
22517 dw_attr_ref producer = get_AT (comp_unit_die (), DW_AT_producer);
22518 if (strcmp (AT_string (producer), producer_string) != 0)
22520 struct indirect_string_node *node = find_AT_string (producer_string);
22521 producer->dw_attr_val.v.val_str = node;
22524 gen_scheduled_generic_parms_dies ();
22525 gen_remaining_tmpl_value_param_die_attribute ();
22527 /* Add the name for the main input file now. We delayed this from
22528 dwarf2out_init to avoid complications with PCH. */
22529 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
22530 if (!IS_ABSOLUTE_PATH (filename))
22531 add_comp_dir_attribute (comp_unit_die ());
22532 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
22535 htab_traverse (file_table, file_table_relative_p, &p);
22537 add_comp_dir_attribute (comp_unit_die ());
22540 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
22542 add_location_or_const_value_attribute (
22543 VEC_index (deferred_locations, deferred_locations_list, i)->die,
22544 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
22549 /* Traverse the limbo die list, and add parent/child links. The only
22550 dies without parents that should be here are concrete instances of
22551 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22552 For concrete instances, we can get the parent die from the abstract
22554 for (node = limbo_die_list; node; node = next_node)
22556 dw_die_ref die = node->die;
22557 next_node = node->next;
22559 if (die->die_parent == NULL)
22561 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
22563 if (origin && origin->die_parent)
22564 add_child_die (origin->die_parent, die);
22565 else if (is_cu_die (die))
22567 else if (seen_error ())
22568 /* It's OK to be confused by errors in the input. */
22569 add_child_die (comp_unit_die (), die);
22572 /* In certain situations, the lexical block containing a
22573 nested function can be optimized away, which results
22574 in the nested function die being orphaned. Likewise
22575 with the return type of that nested function. Force
22576 this to be a child of the containing function.
22578 It may happen that even the containing function got fully
22579 inlined and optimized out. In that case we are lost and
22580 assign the empty child. This should not be big issue as
22581 the function is likely unreachable too. */
22582 gcc_assert (node->created_for);
22584 if (DECL_P (node->created_for))
22585 origin = get_context_die (DECL_CONTEXT (node->created_for));
22586 else if (TYPE_P (node->created_for))
22587 origin = scope_die_for (node->created_for, comp_unit_die ());
22589 origin = comp_unit_die ();
22591 add_child_die (origin, die);
22596 limbo_die_list = NULL;
22598 #if ENABLE_ASSERT_CHECKING
22600 dw_die_ref die = comp_unit_die (), c;
22601 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
22604 resolve_addr (comp_unit_die ());
22605 move_marked_base_types ();
22607 for (node = deferred_asm_name; node; node = node->next)
22609 tree decl = node->created_for;
22610 /* When generating LTO bytecode we can not generate new assembler
22611 names at this point and all important decls got theirs via
22613 if ((!flag_generate_lto || DECL_ASSEMBLER_NAME_SET_P (decl))
22614 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22616 add_linkage_attr (node->die, decl);
22617 move_linkage_attr (node->die);
22621 deferred_asm_name = NULL;
22623 /* Walk through the list of incomplete types again, trying once more to
22624 emit full debugging info for them. */
22625 retry_incomplete_types ();
22627 if (flag_eliminate_unused_debug_types)
22628 prune_unused_types ();
22630 /* Generate separate CUs for each of the include files we've seen.
22631 They will go into limbo_die_list. */
22632 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22633 break_out_includes (comp_unit_die ());
22635 /* Generate separate COMDAT sections for type DIEs. */
22636 if (use_debug_types)
22638 break_out_comdat_types (comp_unit_die ());
22640 /* Each new type_unit DIE was added to the limbo die list when created.
22641 Since these have all been added to comdat_type_list, clear the
22643 limbo_die_list = NULL;
22645 /* For each new comdat type unit, copy declarations for incomplete
22646 types to make the new unit self-contained (i.e., no direct
22647 references to the main compile unit). */
22648 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22649 copy_decls_for_unworthy_types (ctnode->root_die);
22650 copy_decls_for_unworthy_types (comp_unit_die ());
22652 /* In the process of copying declarations from one unit to another,
22653 we may have left some declarations behind that are no longer
22654 referenced. Prune them. */
22655 prune_unused_types ();
22658 /* Traverse the DIE's and add add sibling attributes to those DIE's
22659 that have children. */
22660 add_sibling_attributes (comp_unit_die ());
22661 for (node = limbo_die_list; node; node = node->next)
22662 add_sibling_attributes (node->die);
22663 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22664 add_sibling_attributes (ctnode->root_die);
22666 /* Output a terminator label for the .text section. */
22667 switch_to_section (text_section);
22668 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
22669 if (cold_text_section)
22671 switch_to_section (cold_text_section);
22672 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
22675 /* We can only use the low/high_pc attributes if all of the code was
22677 if (!have_multiple_function_sections
22678 || (dwarf_version < 3 && dwarf_strict))
22680 /* Don't add if the CU has no associated code. */
22681 if (text_section_used)
22683 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
22684 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
22691 bool range_list_added = false;
22693 if (text_section_used)
22694 add_ranges_by_labels (comp_unit_die (), text_section_label,
22695 text_end_label, &range_list_added);
22696 if (cold_text_section_used)
22697 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
22698 cold_end_label, &range_list_added);
22700 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
22702 if (!fde->in_std_section)
22703 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
22704 fde->dw_fde_end, &range_list_added);
22705 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
22706 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
22707 fde->dw_fde_second_end, &range_list_added);
22710 if (range_list_added)
22712 /* We need to give .debug_loc and .debug_ranges an appropriate
22713 "base address". Use zero so that these addresses become
22714 absolute. Historically, we've emitted the unexpected
22715 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22716 Emit both to give time for other tools to adapt. */
22717 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
22718 if (! dwarf_strict && dwarf_version < 4)
22719 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
22725 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22726 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
22727 debug_line_section_label);
22730 add_AT_macptr (comp_unit_die (),
22731 dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros,
22732 macinfo_section_label);
22734 if (have_location_lists)
22735 optimize_location_lists (comp_unit_die ());
22737 /* Output all of the compilation units. We put the main one last so that
22738 the offsets are available to output_pubnames. */
22739 for (node = limbo_die_list; node; node = node->next)
22740 output_comp_unit (node->die, 0);
22742 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
22743 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22745 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
22747 /* Don't output duplicate types. */
22748 if (*slot != HTAB_EMPTY_ENTRY)
22751 /* Add a pointer to the line table for the main compilation unit
22752 so that the debugger can make sense of DW_AT_decl_file
22754 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22755 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
22756 debug_line_section_label);
22758 output_comdat_type_unit (ctnode);
22761 htab_delete (comdat_type_table);
22763 /* Output the main compilation unit if non-empty or if .debug_macinfo
22764 or .debug_macro will be emitted. */
22765 output_comp_unit (comp_unit_die (), have_macinfo);
22767 /* Output the abbreviation table. */
22768 if (abbrev_die_table_in_use != 1)
22770 switch_to_section (debug_abbrev_section);
22771 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
22772 output_abbrev_section ();
22775 /* Output location list section if necessary. */
22776 if (have_location_lists)
22778 /* Output the location lists info. */
22779 switch_to_section (debug_loc_section);
22780 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
22781 DEBUG_LOC_SECTION_LABEL, 0);
22782 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
22783 output_location_lists (comp_unit_die ());
22786 /* Output public names table if necessary. */
22787 if (!VEC_empty (pubname_entry, pubname_table))
22789 gcc_assert (info_section_emitted);
22790 switch_to_section (debug_pubnames_section);
22791 output_pubnames (pubname_table);
22794 /* Output public types table if necessary. */
22795 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22796 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22797 simply won't look for the section. */
22798 if (!VEC_empty (pubname_entry, pubtype_table))
22800 bool empty = false;
22802 if (flag_eliminate_unused_debug_types)
22804 /* The pubtypes table might be emptied by pruning unused items. */
22808 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
22809 if (p->die->die_offset != 0)
22817 gcc_assert (info_section_emitted);
22818 switch_to_section (debug_pubtypes_section);
22819 output_pubnames (pubtype_table);
22823 /* Output the address range information if a CU (.debug_info section)
22824 was emitted. We output an empty table even if we had no functions
22825 to put in it. This because the consumer has no way to tell the
22826 difference between an empty table that we omitted and failure to
22827 generate a table that would have contained data. */
22828 if (info_section_emitted)
22830 unsigned long aranges_length = size_of_aranges ();
22832 switch_to_section (debug_aranges_section);
22833 output_aranges (aranges_length);
22836 /* Output ranges section if necessary. */
22837 if (ranges_table_in_use)
22839 switch_to_section (debug_ranges_section);
22840 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
22844 /* Have to end the macro section. */
22847 switch_to_section (debug_macinfo_section);
22848 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
22850 dw2_asm_output_data (1, 0, "End compilation unit");
22853 /* Output the source line correspondence table. We must do this
22854 even if there is no line information. Otherwise, on an empty
22855 translation unit, we will generate a present, but empty,
22856 .debug_info section. IRIX 6.5 `nm' will then complain when
22857 examining the file. This is done late so that any filenames
22858 used by the debug_info section are marked as 'used'. */
22859 switch_to_section (debug_line_section);
22860 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
22861 if (! DWARF2_ASM_LINE_DEBUG_INFO)
22862 output_line_info ();
22864 /* If we emitted any DW_FORM_strp form attribute, output the string
22866 if (debug_str_hash)
22867 htab_traverse (debug_str_hash, output_indirect_string, NULL);
22870 #include "gt-dwarf2out.h"