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
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"
98 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
99 static rtx last_var_location_insn;
101 #ifdef VMS_DEBUGGING_INFO
102 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
104 /* Define this macro to be a nonzero value if the directory specifications
105 which are output in the debug info should end with a separator. */
106 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
107 /* Define this macro to evaluate to a nonzero value if GCC should refrain
108 from generating indirect strings in DWARF2 debug information, for instance
109 if your target is stuck with an old version of GDB that is unable to
110 process them properly or uses VMS Debug. */
111 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
113 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
114 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
117 /* ??? Poison these here until it can be done generically. They've been
118 totally replaced in this file; make sure it stays that way. */
119 #undef DWARF2_UNWIND_INFO
120 #undef DWARF2_FRAME_INFO
121 #if (GCC_VERSION >= 3000)
122 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
125 /* The size of the target's pointer type. */
127 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
130 /* Array of RTXes referenced by the debugging information, which therefore
131 must be kept around forever. */
132 static GTY(()) VEC(rtx,gc) *used_rtx_array;
134 /* A pointer to the base of a list of incomplete types which might be
135 completed at some later time. incomplete_types_list needs to be a
136 VEC(tree,gc) because we want to tell the garbage collector about
138 static GTY(()) VEC(tree,gc) *incomplete_types;
140 /* A pointer to the base of a table of references to declaration
141 scopes. This table is a display which tracks the nesting
142 of declaration scopes at the current scope and containing
143 scopes. This table is used to find the proper place to
144 define type declaration DIE's. */
145 static GTY(()) VEC(tree,gc) *decl_scope_table;
147 /* Pointers to various DWARF2 sections. */
148 static GTY(()) section *debug_info_section;
149 static GTY(()) section *debug_abbrev_section;
150 static GTY(()) section *debug_aranges_section;
151 static GTY(()) section *debug_macinfo_section;
152 static GTY(()) section *debug_line_section;
153 static GTY(()) section *debug_loc_section;
154 static GTY(()) section *debug_pubnames_section;
155 static GTY(()) section *debug_pubtypes_section;
156 static GTY(()) section *debug_str_section;
157 static GTY(()) section *debug_ranges_section;
158 static GTY(()) section *debug_frame_section;
160 /* Maximum size (in bytes) of an artificially generated label. */
161 #define MAX_ARTIFICIAL_LABEL_BYTES 30
163 /* According to the (draft) DWARF 3 specification, the initial length
164 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
165 bytes are 0xffffffff, followed by the length stored in the next 8
168 However, the SGI/MIPS ABI uses an initial length which is equal to
169 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
171 #ifndef DWARF_INITIAL_LENGTH_SIZE
172 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
175 /* Round SIZE up to the nearest BOUNDARY. */
176 #define DWARF_ROUND(SIZE,BOUNDARY) \
177 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
179 /* CIE identifier. */
180 #if HOST_BITS_PER_WIDE_INT >= 64
181 #define DWARF_CIE_ID \
182 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
184 #define DWARF_CIE_ID DW_CIE_ID
187 DEF_VEC_P (dw_fde_ref);
188 DEF_VEC_ALLOC_P (dw_fde_ref, gc);
190 /* A vector for a table that contains frame description
191 information for each routine. */
192 static GTY(()) VEC(dw_fde_ref, gc) *fde_vec;
194 struct GTY(()) indirect_string_node {
196 unsigned int refcount;
197 enum dwarf_form form;
201 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
203 static GTY(()) int dw2_string_counter;
205 /* True if the compilation unit places functions in more than one section. */
206 static GTY(()) bool have_multiple_function_sections = false;
208 /* Whether the default text and cold text sections have been used at all. */
210 static GTY(()) bool text_section_used = false;
211 static GTY(()) bool cold_text_section_used = false;
213 /* The default cold text section. */
214 static GTY(()) section *cold_text_section;
216 /* Forward declarations for functions defined in this file. */
218 static char *stripattributes (const char *);
219 static void output_call_frame_info (int);
220 static void dwarf2out_note_section_used (void);
222 /* Personality decl of current unit. Used only when assembler does not support
224 static GTY(()) rtx current_unit_personality;
226 /* Data and reference forms for relocatable data. */
227 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
228 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
230 #ifndef DEBUG_FRAME_SECTION
231 #define DEBUG_FRAME_SECTION ".debug_frame"
234 #ifndef FUNC_BEGIN_LABEL
235 #define FUNC_BEGIN_LABEL "LFB"
238 #ifndef FUNC_END_LABEL
239 #define FUNC_END_LABEL "LFE"
242 #ifndef PROLOGUE_END_LABEL
243 #define PROLOGUE_END_LABEL "LPE"
246 #ifndef EPILOGUE_BEGIN_LABEL
247 #define EPILOGUE_BEGIN_LABEL "LEB"
250 #ifndef FRAME_BEGIN_LABEL
251 #define FRAME_BEGIN_LABEL "Lframe"
253 #define CIE_AFTER_SIZE_LABEL "LSCIE"
254 #define CIE_END_LABEL "LECIE"
255 #define FDE_LABEL "LSFDE"
256 #define FDE_AFTER_SIZE_LABEL "LASFDE"
257 #define FDE_END_LABEL "LEFDE"
258 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
259 #define LINE_NUMBER_END_LABEL "LELT"
260 #define LN_PROLOG_AS_LABEL "LASLTP"
261 #define LN_PROLOG_END_LABEL "LELTP"
262 #define DIE_LABEL_PREFIX "DW"
264 /* Match the base name of a file to the base name of a compilation unit. */
267 matches_main_base (const char *path)
269 /* Cache the last query. */
270 static const char *last_path = NULL;
271 static int last_match = 0;
272 if (path != last_path)
275 int length = base_of_path (path, &base);
277 last_match = (length == main_input_baselength
278 && memcmp (base, main_input_basename, length) == 0);
283 #ifdef DEBUG_DEBUG_STRUCT
286 dump_struct_debug (tree type, enum debug_info_usage usage,
287 enum debug_struct_file criterion, int generic,
288 int matches, int result)
290 /* Find the type name. */
291 tree type_decl = TYPE_STUB_DECL (type);
293 const char *name = 0;
294 if (TREE_CODE (t) == TYPE_DECL)
297 name = IDENTIFIER_POINTER (t);
299 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
301 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
302 matches ? "bas" : "hdr",
303 generic ? "gen" : "ord",
304 usage == DINFO_USAGE_DFN ? ";" :
305 usage == DINFO_USAGE_DIR_USE ? "." : "*",
307 (void*) type_decl, name);
310 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
311 dump_struct_debug (type, usage, criterion, generic, matches, result)
315 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
321 should_emit_struct_debug (tree type, enum debug_info_usage usage)
323 enum debug_struct_file criterion;
325 bool generic = lang_hooks.types.generic_p (type);
328 criterion = debug_struct_generic[usage];
330 criterion = debug_struct_ordinary[usage];
332 if (criterion == DINFO_STRUCT_FILE_NONE)
333 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
334 if (criterion == DINFO_STRUCT_FILE_ANY)
335 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
337 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
339 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
340 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
342 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
343 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
344 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
347 /* Return a pointer to a copy of the section string name S with all
348 attributes stripped off, and an asterisk prepended (for assemble_name). */
351 stripattributes (const char *s)
353 char *stripped = XNEWVEC (char, strlen (s) + 2);
358 while (*s && *s != ',')
365 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
366 switch to the data section instead, and write out a synthetic start label
367 for collect2 the first time around. */
370 switch_to_eh_frame_section (bool back)
374 #ifdef EH_FRAME_SECTION_NAME
375 if (eh_frame_section == 0)
379 if (EH_TABLES_CAN_BE_READ_ONLY)
385 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
387 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
389 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
392 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
393 && (fde_encoding & 0x70) != DW_EH_PE_aligned
394 && (per_encoding & 0x70) != DW_EH_PE_absptr
395 && (per_encoding & 0x70) != DW_EH_PE_aligned
396 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
397 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
398 ? 0 : SECTION_WRITE);
401 flags = SECTION_WRITE;
402 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
404 #endif /* EH_FRAME_SECTION_NAME */
406 if (eh_frame_section)
407 switch_to_section (eh_frame_section);
410 /* We have no special eh_frame section. Put the information in
411 the data section and emit special labels to guide collect2. */
412 switch_to_section (data_section);
416 label = get_file_function_name ("F");
417 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
418 targetm.asm_out.globalize_label (asm_out_file,
419 IDENTIFIER_POINTER (label));
420 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
425 /* Switch [BACK] to the eh or debug frame table section, depending on
429 switch_to_frame_table_section (int for_eh, bool back)
432 switch_to_eh_frame_section (back);
435 if (!debug_frame_section)
436 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
437 SECTION_DEBUG, NULL);
438 switch_to_section (debug_frame_section);
442 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
444 enum dw_cfi_oprnd_type
445 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
450 case DW_CFA_GNU_window_save:
451 case DW_CFA_remember_state:
452 case DW_CFA_restore_state:
453 return dw_cfi_oprnd_unused;
456 case DW_CFA_advance_loc1:
457 case DW_CFA_advance_loc2:
458 case DW_CFA_advance_loc4:
459 case DW_CFA_MIPS_advance_loc8:
460 return dw_cfi_oprnd_addr;
463 case DW_CFA_offset_extended:
465 case DW_CFA_offset_extended_sf:
466 case DW_CFA_def_cfa_sf:
468 case DW_CFA_restore_extended:
469 case DW_CFA_undefined:
470 case DW_CFA_same_value:
471 case DW_CFA_def_cfa_register:
472 case DW_CFA_register:
473 case DW_CFA_expression:
474 return dw_cfi_oprnd_reg_num;
476 case DW_CFA_def_cfa_offset:
477 case DW_CFA_GNU_args_size:
478 case DW_CFA_def_cfa_offset_sf:
479 return dw_cfi_oprnd_offset;
481 case DW_CFA_def_cfa_expression:
482 return dw_cfi_oprnd_loc;
489 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
491 enum dw_cfi_oprnd_type
492 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
497 case DW_CFA_def_cfa_sf:
499 case DW_CFA_offset_extended_sf:
500 case DW_CFA_offset_extended:
501 return dw_cfi_oprnd_offset;
503 case DW_CFA_register:
504 return dw_cfi_oprnd_reg_num;
506 case DW_CFA_expression:
507 return dw_cfi_oprnd_loc;
510 return dw_cfi_oprnd_unused;
514 /* Output one FDE. */
517 output_fde (dw_fde_ref fde, bool for_eh, bool second,
518 char *section_start_label, int fde_encoding, char *augmentation,
519 bool any_lsda_needed, int lsda_encoding)
522 const char *begin, *end;
523 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
607 fde->dw_fde_current_label = begin;
608 if (fde->dw_fde_second_begin == NULL)
609 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
610 output_cfi (cfi, fde, for_eh);
613 if (fde->dw_fde_switch_cfi_index > 0)
614 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
616 if (ix == fde->dw_fde_switch_cfi_index)
618 output_cfi (cfi, fde, for_eh);
624 int until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
626 if (fde->dw_fde_switch_cfi_index > 0)
628 from = fde->dw_fde_switch_cfi_index;
629 output_cfis (fde->dw_fde_cfi, from, false, fde, for_eh);
631 for (i = from; i < until; i++)
632 output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i),
636 /* If we are to emit a ref/link from function bodies to their frame tables,
637 do it now. This is typically performed to make sure that tables
638 associated with functions are dragged with them and not discarded in
639 garbage collecting links. We need to do this on a per function basis to
640 cope with -ffunction-sections. */
642 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
643 /* Switch to the function section, emit the ref to the tables, and
644 switch *back* into the table section. */
645 switch_to_section (function_section (fde->decl));
646 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
647 switch_to_frame_table_section (for_eh, true);
650 /* Pad the FDE out to an address sized boundary. */
651 ASM_OUTPUT_ALIGN (asm_out_file,
652 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
653 ASM_OUTPUT_LABEL (asm_out_file, l2);
658 /* Return true if frame description entry FDE is needed for EH. */
661 fde_needed_for_eh_p (dw_fde_ref fde)
663 if (flag_asynchronous_unwind_tables)
666 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
669 if (fde->uses_eh_lsda)
672 /* If exceptions are enabled, we have collected nothrow info. */
673 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
679 /* Output the call frame information used to record information
680 that relates to calculating the frame pointer, and records the
681 location of saved registers. */
684 output_call_frame_info (int for_eh)
689 char l1[20], l2[20], section_start_label[20];
690 bool any_lsda_needed = false;
691 char augmentation[6];
692 int augmentation_size;
693 int fde_encoding = DW_EH_PE_absptr;
694 int per_encoding = DW_EH_PE_absptr;
695 int lsda_encoding = DW_EH_PE_absptr;
697 rtx personality = NULL;
700 /* Don't emit a CIE if there won't be any FDEs. */
704 /* Nothing to do if the assembler's doing it all. */
705 if (dwarf2out_do_cfi_asm ())
708 /* If we don't have any functions we'll want to unwind out of, don't emit
709 any EH unwind information. If we make FDEs linkonce, we may have to
710 emit an empty label for an FDE that wouldn't otherwise be emitted. We
711 want to avoid having an FDE kept around when the function it refers to
712 is discarded. Example where this matters: a primary function template
713 in C++ requires EH information, an explicit specialization doesn't. */
716 bool any_eh_needed = false;
718 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, i, fde)
720 if (fde->uses_eh_lsda)
721 any_eh_needed = any_lsda_needed = true;
722 else if (fde_needed_for_eh_p (fde))
723 any_eh_needed = true;
724 else if (TARGET_USES_WEAK_UNWIND_INFO)
725 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, 1, 1);
732 /* We're going to be generating comments, so turn on app. */
736 /* Switch to the proper frame section, first time. */
737 switch_to_frame_table_section (for_eh, false);
739 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
740 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
742 /* Output the CIE. */
743 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
744 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
745 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
746 dw2_asm_output_data (4, 0xffffffff,
747 "Initial length escape value indicating 64-bit DWARF extension");
748 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
749 "Length of Common Information Entry");
750 ASM_OUTPUT_LABEL (asm_out_file, l1);
752 /* Now that the CIE pointer is PC-relative for EH,
753 use 0 to identify the CIE. */
754 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
755 (for_eh ? 0 : DWARF_CIE_ID),
756 "CIE Identifier Tag");
758 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
759 use CIE version 1, unless that would produce incorrect results
760 due to overflowing the return register column. */
761 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
763 if (return_reg >= 256 || dwarf_version > 2)
765 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
768 augmentation_size = 0;
770 personality = current_unit_personality;
776 z Indicates that a uleb128 is present to size the
777 augmentation section.
778 L Indicates the encoding (and thus presence) of
779 an LSDA pointer in the FDE augmentation.
780 R Indicates a non-default pointer encoding for
782 P Indicates the presence of an encoding + language
783 personality routine in the CIE augmentation. */
785 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
786 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
787 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
789 p = augmentation + 1;
793 augmentation_size += 1 + size_of_encoded_value (per_encoding);
794 assemble_external_libcall (personality);
799 augmentation_size += 1;
801 if (fde_encoding != DW_EH_PE_absptr)
804 augmentation_size += 1;
806 if (p > augmentation + 1)
808 augmentation[0] = 'z';
812 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
813 if (personality && per_encoding == DW_EH_PE_aligned)
815 int offset = ( 4 /* Length */
817 + 1 /* CIE version */
818 + strlen (augmentation) + 1 /* Augmentation */
819 + size_of_uleb128 (1) /* Code alignment */
820 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
822 + 1 /* Augmentation size */
823 + 1 /* Personality encoding */ );
824 int pad = -offset & (PTR_SIZE - 1);
826 augmentation_size += pad;
828 /* Augmentations should be small, so there's scarce need to
829 iterate for a solution. Die if we exceed one uleb128 byte. */
830 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
834 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
835 if (dw_cie_version >= 4)
837 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
838 dw2_asm_output_data (1, 0, "CIE Segment Size");
840 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
841 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
842 "CIE Data Alignment Factor");
844 if (dw_cie_version == 1)
845 dw2_asm_output_data (1, return_reg, "CIE RA Column");
847 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
851 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
854 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
855 eh_data_format_name (per_encoding));
856 dw2_asm_output_encoded_addr_rtx (per_encoding,
862 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
863 eh_data_format_name (lsda_encoding));
865 if (fde_encoding != DW_EH_PE_absptr)
866 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
867 eh_data_format_name (fde_encoding));
870 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, i, cfi)
871 output_cfi (cfi, NULL, for_eh);
873 /* Pad the CIE out to an address sized boundary. */
874 ASM_OUTPUT_ALIGN (asm_out_file,
875 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
876 ASM_OUTPUT_LABEL (asm_out_file, l2);
878 /* Loop through all of the FDE's. */
879 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, i, fde)
883 /* Don't emit EH unwind info for leaf functions that don't need it. */
884 if (for_eh && !fde_needed_for_eh_p (fde))
887 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
888 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
889 augmentation, any_lsda_needed, lsda_encoding);
892 if (for_eh && targetm.terminate_dw2_eh_frame_info)
893 dw2_asm_output_data (4, 0, "End of Table");
894 #ifdef MIPS_DEBUGGING_INFO
895 /* Work around Irix 6 assembler bug whereby labels at the end of a section
896 get a value of 0. Putting .align 0 after the label fixes it. */
897 ASM_OUTPUT_ALIGN (asm_out_file, 0);
900 /* Turn off app to make assembly quicker. */
905 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
908 dwarf2out_do_cfi_startproc (bool second)
912 rtx personality = get_personality_function (current_function_decl);
914 fprintf (asm_out_file, "\t.cfi_startproc\n");
918 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
921 /* ??? The GAS support isn't entirely consistent. We have to
922 handle indirect support ourselves, but PC-relative is done
923 in the assembler. Further, the assembler can't handle any
924 of the weirder relocation types. */
925 if (enc & DW_EH_PE_indirect)
926 ref = dw2_force_const_mem (ref, true);
928 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
929 output_addr_const (asm_out_file, ref);
930 fputc ('\n', asm_out_file);
933 if (crtl->uses_eh_lsda)
937 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
938 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
939 current_function_funcdef_no);
940 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
941 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
943 if (enc & DW_EH_PE_indirect)
944 ref = dw2_force_const_mem (ref, true);
946 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
947 output_addr_const (asm_out_file, ref);
948 fputc ('\n', asm_out_file);
952 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
953 this allocation may be done before pass_final. */
956 dwarf2out_alloc_current_fde (void)
960 fde = ggc_alloc_cleared_dw_fde_node ();
961 fde->decl = current_function_decl;
962 fde->funcdef_number = current_function_funcdef_no;
963 fde->fde_index = VEC_length (dw_fde_ref, fde_vec);
964 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
965 fde->uses_eh_lsda = crtl->uses_eh_lsda;
966 fde->nothrow = crtl->nothrow;
967 fde->drap_reg = INVALID_REGNUM;
968 fde->vdrap_reg = INVALID_REGNUM;
970 /* Record the FDE associated with this function. */
972 VEC_safe_push (dw_fde_ref, gc, fde_vec, fde);
977 /* Output a marker (i.e. a label) for the beginning of a function, before
981 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
982 const char *file ATTRIBUTE_UNUSED)
984 char label[MAX_ARTIFICIAL_LABEL_BYTES];
990 current_function_func_begin_label = NULL;
992 do_frame = dwarf2out_do_frame ();
994 /* ??? current_function_func_begin_label is also used by except.c for
995 call-site information. We must emit this label if it might be used. */
998 || targetm_common.except_unwind_info (&global_options) != UI_TARGET))
1001 fnsec = function_section (current_function_decl);
1002 switch_to_section (fnsec);
1003 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1004 current_function_funcdef_no);
1005 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1006 current_function_funcdef_no);
1007 dup_label = xstrdup (label);
1008 current_function_func_begin_label = dup_label;
1010 /* We can elide the fde allocation if we're not emitting debug info. */
1014 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1015 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1016 would include pass_dwarf2_frame. If we've not created the FDE yet,
1020 fde = dwarf2out_alloc_current_fde ();
1022 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1023 fde->dw_fde_begin = dup_label;
1024 fde->dw_fde_current_label = dup_label;
1025 fde->in_std_section = (fnsec == text_section
1026 || (cold_text_section && fnsec == cold_text_section));
1028 /* We only want to output line number information for the genuine dwarf2
1029 prologue case, not the eh frame case. */
1030 #ifdef DWARF2_DEBUGGING_INFO
1032 dwarf2out_source_line (line, file, 0, true);
1035 if (dwarf2out_do_cfi_asm ())
1036 dwarf2out_do_cfi_startproc (false);
1039 rtx personality = get_personality_function (current_function_decl);
1040 if (!current_unit_personality)
1041 current_unit_personality = personality;
1043 /* We cannot keep a current personality per function as without CFI
1044 asm, at the point where we emit the CFI data, there is no current
1045 function anymore. */
1046 if (personality && current_unit_personality != personality)
1047 sorry ("multiple EH personalities are supported only with assemblers "
1048 "supporting .cfi_personality directive");
1052 /* Output a marker (i.e. a label) for the end of the generated code
1053 for a function prologue. This gets called *after* the prologue code has
1057 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
1058 const char *file ATTRIBUTE_UNUSED)
1060 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1062 /* Output a label to mark the endpoint of the code generated for this
1064 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
1065 current_function_funcdef_no);
1066 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
1067 current_function_funcdef_no);
1068 cfun->fde->dw_fde_vms_end_prologue = xstrdup (label);
1071 /* Output a marker (i.e. a label) for the beginning of the generated code
1072 for a function epilogue. This gets called *before* the prologue code has
1076 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1077 const char *file ATTRIBUTE_UNUSED)
1079 dw_fde_ref fde = cfun->fde;
1080 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1082 if (fde->dw_fde_vms_begin_epilogue)
1085 /* Output a label to mark the endpoint of the code generated for this
1087 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
1088 current_function_funcdef_no);
1089 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
1090 current_function_funcdef_no);
1091 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
1094 /* Output a marker (i.e. a label) for the absolute end of the generated code
1095 for a function definition. This gets called *after* the epilogue code has
1099 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1100 const char *file ATTRIBUTE_UNUSED)
1103 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1105 last_var_location_insn = NULL_RTX;
1107 if (dwarf2out_do_cfi_asm ())
1108 fprintf (asm_out_file, "\t.cfi_endproc\n");
1110 /* Output a label to mark the endpoint of the code generated for this
1112 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1113 current_function_funcdef_no);
1114 ASM_OUTPUT_LABEL (asm_out_file, label);
1116 gcc_assert (fde != NULL);
1117 if (fde->dw_fde_second_begin == NULL)
1118 fde->dw_fde_end = xstrdup (label);
1122 dwarf2out_frame_finish (void)
1124 /* Output call frame information. */
1125 if (targetm.debug_unwind_info () == UI_DWARF2)
1126 output_call_frame_info (0);
1128 /* Output another copy for the unwinder. */
1129 if ((flag_unwind_tables || flag_exceptions)
1130 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
1131 output_call_frame_info (1);
1134 /* Note that the current function section is being used for code. */
1137 dwarf2out_note_section_used (void)
1139 section *sec = current_function_section ();
1140 if (sec == text_section)
1141 text_section_used = true;
1142 else if (sec == cold_text_section)
1143 cold_text_section_used = true;
1146 static void var_location_switch_text_section (void);
1147 static void set_cur_line_info_table (section *);
1150 dwarf2out_switch_text_section (void)
1153 dw_fde_ref fde = cfun->fde;
1155 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1157 if (!in_cold_section_p)
1159 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
1160 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
1161 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
1165 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1166 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
1167 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1169 have_multiple_function_sections = true;
1171 /* There is no need to mark used sections when not debugging. */
1172 if (cold_text_section != NULL)
1173 dwarf2out_note_section_used ();
1175 if (dwarf2out_do_cfi_asm ())
1176 fprintf (asm_out_file, "\t.cfi_endproc\n");
1178 /* Now do the real section switch. */
1179 sect = current_function_section ();
1180 switch_to_section (sect);
1182 fde->second_in_std_section
1183 = (sect == text_section
1184 || (cold_text_section && sect == cold_text_section));
1186 fde->dw_fde_switch_cfi_index = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
1188 if (dwarf2out_do_cfi_asm ())
1190 dwarf2out_do_cfi_startproc (true);
1191 /* As this is a different FDE, insert all current CFI instructions
1193 output_cfis (fde->dw_fde_cfi, fde->dw_fde_switch_cfi_index,
1197 var_location_switch_text_section ();
1199 set_cur_line_info_table (sect);
1202 /* And now, the subset of the debugging information support code necessary
1203 for emitting location expressions. */
1205 /* Data about a single source file. */
1206 struct GTY(()) dwarf_file_data {
1207 const char * filename;
1211 typedef struct GTY(()) deferred_locations_struct
1215 } deferred_locations;
1217 DEF_VEC_O(deferred_locations);
1218 DEF_VEC_ALLOC_O(deferred_locations,gc);
1220 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
1222 DEF_VEC_P(dw_die_ref);
1223 DEF_VEC_ALLOC_P(dw_die_ref,heap);
1225 /* Location lists are ranges + location descriptions for that range,
1226 so you can track variables that are in different places over
1227 their entire life. */
1228 typedef struct GTY(()) dw_loc_list_struct {
1229 dw_loc_list_ref dw_loc_next;
1230 const char *begin; /* Label for begin address of range */
1231 const char *end; /* Label for end address of range */
1232 char *ll_symbol; /* Label for beginning of location list.
1233 Only on head of list */
1234 const char *section; /* Section this loclist is relative to */
1235 dw_loc_descr_ref expr;
1237 /* True if all addresses in this and subsequent lists are known to be
1240 /* True if this list has been replaced by dw_loc_next. */
1243 /* True if the range should be emitted even if begin and end
1248 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
1250 /* Convert a DWARF stack opcode into its string name. */
1253 dwarf_stack_op_name (unsigned int op)
1258 return "DW_OP_addr";
1260 return "DW_OP_deref";
1262 return "DW_OP_const1u";
1264 return "DW_OP_const1s";
1266 return "DW_OP_const2u";
1268 return "DW_OP_const2s";
1270 return "DW_OP_const4u";
1272 return "DW_OP_const4s";
1274 return "DW_OP_const8u";
1276 return "DW_OP_const8s";
1278 return "DW_OP_constu";
1280 return "DW_OP_consts";
1284 return "DW_OP_drop";
1286 return "DW_OP_over";
1288 return "DW_OP_pick";
1290 return "DW_OP_swap";
1294 return "DW_OP_xderef";
1302 return "DW_OP_minus";
1314 return "DW_OP_plus";
1315 case DW_OP_plus_uconst:
1316 return "DW_OP_plus_uconst";
1322 return "DW_OP_shra";
1340 return "DW_OP_skip";
1342 return "DW_OP_lit0";
1344 return "DW_OP_lit1";
1346 return "DW_OP_lit2";
1348 return "DW_OP_lit3";
1350 return "DW_OP_lit4";
1352 return "DW_OP_lit5";
1354 return "DW_OP_lit6";
1356 return "DW_OP_lit7";
1358 return "DW_OP_lit8";
1360 return "DW_OP_lit9";
1362 return "DW_OP_lit10";
1364 return "DW_OP_lit11";
1366 return "DW_OP_lit12";
1368 return "DW_OP_lit13";
1370 return "DW_OP_lit14";
1372 return "DW_OP_lit15";
1374 return "DW_OP_lit16";
1376 return "DW_OP_lit17";
1378 return "DW_OP_lit18";
1380 return "DW_OP_lit19";
1382 return "DW_OP_lit20";
1384 return "DW_OP_lit21";
1386 return "DW_OP_lit22";
1388 return "DW_OP_lit23";
1390 return "DW_OP_lit24";
1392 return "DW_OP_lit25";
1394 return "DW_OP_lit26";
1396 return "DW_OP_lit27";
1398 return "DW_OP_lit28";
1400 return "DW_OP_lit29";
1402 return "DW_OP_lit30";
1404 return "DW_OP_lit31";
1406 return "DW_OP_reg0";
1408 return "DW_OP_reg1";
1410 return "DW_OP_reg2";
1412 return "DW_OP_reg3";
1414 return "DW_OP_reg4";
1416 return "DW_OP_reg5";
1418 return "DW_OP_reg6";
1420 return "DW_OP_reg7";
1422 return "DW_OP_reg8";
1424 return "DW_OP_reg9";
1426 return "DW_OP_reg10";
1428 return "DW_OP_reg11";
1430 return "DW_OP_reg12";
1432 return "DW_OP_reg13";
1434 return "DW_OP_reg14";
1436 return "DW_OP_reg15";
1438 return "DW_OP_reg16";
1440 return "DW_OP_reg17";
1442 return "DW_OP_reg18";
1444 return "DW_OP_reg19";
1446 return "DW_OP_reg20";
1448 return "DW_OP_reg21";
1450 return "DW_OP_reg22";
1452 return "DW_OP_reg23";
1454 return "DW_OP_reg24";
1456 return "DW_OP_reg25";
1458 return "DW_OP_reg26";
1460 return "DW_OP_reg27";
1462 return "DW_OP_reg28";
1464 return "DW_OP_reg29";
1466 return "DW_OP_reg30";
1468 return "DW_OP_reg31";
1470 return "DW_OP_breg0";
1472 return "DW_OP_breg1";
1474 return "DW_OP_breg2";
1476 return "DW_OP_breg3";
1478 return "DW_OP_breg4";
1480 return "DW_OP_breg5";
1482 return "DW_OP_breg6";
1484 return "DW_OP_breg7";
1486 return "DW_OP_breg8";
1488 return "DW_OP_breg9";
1490 return "DW_OP_breg10";
1492 return "DW_OP_breg11";
1494 return "DW_OP_breg12";
1496 return "DW_OP_breg13";
1498 return "DW_OP_breg14";
1500 return "DW_OP_breg15";
1502 return "DW_OP_breg16";
1504 return "DW_OP_breg17";
1506 return "DW_OP_breg18";
1508 return "DW_OP_breg19";
1510 return "DW_OP_breg20";
1512 return "DW_OP_breg21";
1514 return "DW_OP_breg22";
1516 return "DW_OP_breg23";
1518 return "DW_OP_breg24";
1520 return "DW_OP_breg25";
1522 return "DW_OP_breg26";
1524 return "DW_OP_breg27";
1526 return "DW_OP_breg28";
1528 return "DW_OP_breg29";
1530 return "DW_OP_breg30";
1532 return "DW_OP_breg31";
1534 return "DW_OP_regx";
1536 return "DW_OP_fbreg";
1538 return "DW_OP_bregx";
1540 return "DW_OP_piece";
1541 case DW_OP_deref_size:
1542 return "DW_OP_deref_size";
1543 case DW_OP_xderef_size:
1544 return "DW_OP_xderef_size";
1548 case DW_OP_push_object_address:
1549 return "DW_OP_push_object_address";
1551 return "DW_OP_call2";
1553 return "DW_OP_call4";
1554 case DW_OP_call_ref:
1555 return "DW_OP_call_ref";
1556 case DW_OP_implicit_value:
1557 return "DW_OP_implicit_value";
1558 case DW_OP_stack_value:
1559 return "DW_OP_stack_value";
1560 case DW_OP_form_tls_address:
1561 return "DW_OP_form_tls_address";
1562 case DW_OP_call_frame_cfa:
1563 return "DW_OP_call_frame_cfa";
1564 case DW_OP_bit_piece:
1565 return "DW_OP_bit_piece";
1567 case DW_OP_GNU_push_tls_address:
1568 return "DW_OP_GNU_push_tls_address";
1569 case DW_OP_GNU_uninit:
1570 return "DW_OP_GNU_uninit";
1571 case DW_OP_GNU_encoded_addr:
1572 return "DW_OP_GNU_encoded_addr";
1573 case DW_OP_GNU_implicit_pointer:
1574 return "DW_OP_GNU_implicit_pointer";
1575 case DW_OP_GNU_entry_value:
1576 return "DW_OP_GNU_entry_value";
1577 case DW_OP_GNU_const_type:
1578 return "DW_OP_GNU_const_type";
1579 case DW_OP_GNU_regval_type:
1580 return "DW_OP_GNU_regval_type";
1581 case DW_OP_GNU_deref_type:
1582 return "DW_OP_GNU_deref_type";
1583 case DW_OP_GNU_convert:
1584 return "DW_OP_GNU_convert";
1585 case DW_OP_GNU_reinterpret:
1586 return "DW_OP_GNU_reinterpret";
1587 case DW_OP_GNU_parameter_ref:
1588 return "DW_OP_GNU_parameter_ref";
1591 return "OP_<unknown>";
1595 /* Return a pointer to a newly allocated location description. Location
1596 descriptions are simple expression terms that can be strung
1597 together to form more complicated location (address) descriptions. */
1599 static inline dw_loc_descr_ref
1600 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
1601 unsigned HOST_WIDE_INT oprnd2)
1603 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
1605 descr->dw_loc_opc = op;
1606 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
1607 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
1608 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
1609 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
1614 /* Return a pointer to a newly allocated location description for
1617 static inline dw_loc_descr_ref
1618 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
1621 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
1624 return new_loc_descr (DW_OP_bregx, reg, offset);
1627 /* Add a location description term to a location description expression. */
1630 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
1632 dw_loc_descr_ref *d;
1634 /* Find the end of the chain. */
1635 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
1641 /* Add a constant OFFSET to a location expression. */
1644 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
1646 dw_loc_descr_ref loc;
1649 gcc_assert (*list_head != NULL);
1654 /* Find the end of the chain. */
1655 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
1659 if (loc->dw_loc_opc == DW_OP_fbreg
1660 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
1661 p = &loc->dw_loc_oprnd1.v.val_int;
1662 else if (loc->dw_loc_opc == DW_OP_bregx)
1663 p = &loc->dw_loc_oprnd2.v.val_int;
1665 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1666 offset. Don't optimize if an signed integer overflow would happen. */
1668 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
1669 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
1672 else if (offset > 0)
1673 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
1677 loc->dw_loc_next = int_loc_descriptor (-offset);
1678 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
1682 /* Add a constant OFFSET to a location list. */
1685 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
1688 for (d = list_head; d != NULL; d = d->dw_loc_next)
1689 loc_descr_plus_const (&d->expr, offset);
1692 #define DWARF_REF_SIZE \
1693 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1695 static unsigned long int get_base_type_offset (dw_die_ref);
1697 /* Return the size of a location descriptor. */
1699 static unsigned long
1700 size_of_loc_descr (dw_loc_descr_ref loc)
1702 unsigned long size = 1;
1704 switch (loc->dw_loc_opc)
1707 size += DWARF2_ADDR_SIZE;
1726 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1729 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1734 case DW_OP_plus_uconst:
1735 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1773 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1776 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1779 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1782 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1783 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1786 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1788 case DW_OP_bit_piece:
1789 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1790 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
1792 case DW_OP_deref_size:
1793 case DW_OP_xderef_size:
1802 case DW_OP_call_ref:
1803 size += DWARF_REF_SIZE;
1805 case DW_OP_implicit_value:
1806 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1807 + loc->dw_loc_oprnd1.v.val_unsigned;
1809 case DW_OP_GNU_implicit_pointer:
1810 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1812 case DW_OP_GNU_entry_value:
1814 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
1815 size += size_of_uleb128 (op_size) + op_size;
1818 case DW_OP_GNU_const_type:
1821 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1822 size += size_of_uleb128 (o) + 1;
1823 switch (loc->dw_loc_oprnd2.val_class)
1825 case dw_val_class_vec:
1826 size += loc->dw_loc_oprnd2.v.val_vec.length
1827 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
1829 case dw_val_class_const:
1830 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1832 case dw_val_class_const_double:
1833 size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1840 case DW_OP_GNU_regval_type:
1843 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1844 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1845 + size_of_uleb128 (o);
1848 case DW_OP_GNU_deref_type:
1851 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1852 size += 1 + size_of_uleb128 (o);
1855 case DW_OP_GNU_convert:
1856 case DW_OP_GNU_reinterpret:
1857 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
1858 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1862 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1863 size += size_of_uleb128 (o);
1866 case DW_OP_GNU_parameter_ref:
1876 /* Return the size of a series of location descriptors. */
1879 size_of_locs (dw_loc_descr_ref loc)
1884 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1885 field, to avoid writing to a PCH file. */
1886 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1888 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
1890 size += size_of_loc_descr (l);
1895 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1897 l->dw_loc_addr = size;
1898 size += size_of_loc_descr (l);
1904 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
1905 static void get_ref_die_offset_label (char *, dw_die_ref);
1906 static unsigned long int get_ref_die_offset (dw_die_ref);
1908 /* Output location description stack opcode's operands (if any).
1909 The for_eh_or_skip parameter controls whether register numbers are
1910 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1911 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1912 info). This should be suppressed for the cases that have not been converted
1913 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1916 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
1918 dw_val_ref val1 = &loc->dw_loc_oprnd1;
1919 dw_val_ref val2 = &loc->dw_loc_oprnd2;
1921 switch (loc->dw_loc_opc)
1923 #ifdef DWARF2_DEBUGGING_INFO
1926 dw2_asm_output_data (2, val1->v.val_int, NULL);
1931 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
1932 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
1934 fputc ('\n', asm_out_file);
1939 dw2_asm_output_data (4, val1->v.val_int, NULL);
1944 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
1945 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
1947 fputc ('\n', asm_out_file);
1952 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
1953 dw2_asm_output_data (8, val1->v.val_int, NULL);
1960 gcc_assert (val1->val_class == dw_val_class_loc);
1961 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
1963 dw2_asm_output_data (2, offset, NULL);
1966 case DW_OP_implicit_value:
1967 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1968 switch (val2->val_class)
1970 case dw_val_class_const:
1971 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
1973 case dw_val_class_vec:
1975 unsigned int elt_size = val2->v.val_vec.elt_size;
1976 unsigned int len = val2->v.val_vec.length;
1980 if (elt_size > sizeof (HOST_WIDE_INT))
1985 for (i = 0, p = val2->v.val_vec.array;
1988 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
1989 "fp or vector constant word %u", i);
1992 case dw_val_class_const_double:
1994 unsigned HOST_WIDE_INT first, second;
1996 if (WORDS_BIG_ENDIAN)
1998 first = val2->v.val_double.high;
1999 second = val2->v.val_double.low;
2003 first = val2->v.val_double.low;
2004 second = val2->v.val_double.high;
2006 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2008 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2012 case dw_val_class_addr:
2013 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
2014 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
2029 case DW_OP_implicit_value:
2030 /* We currently don't make any attempt to make sure these are
2031 aligned properly like we do for the main unwind info, so
2032 don't support emitting things larger than a byte if we're
2033 only doing unwinding. */
2038 dw2_asm_output_data (1, val1->v.val_int, NULL);
2041 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2044 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2047 dw2_asm_output_data (1, val1->v.val_int, NULL);
2049 case DW_OP_plus_uconst:
2050 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2084 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2088 unsigned r = val1->v.val_unsigned;
2089 if (for_eh_or_skip >= 0)
2090 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2091 gcc_assert (size_of_uleb128 (r)
2092 == size_of_uleb128 (val1->v.val_unsigned));
2093 dw2_asm_output_data_uleb128 (r, NULL);
2097 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2101 unsigned r = val1->v.val_unsigned;
2102 if (for_eh_or_skip >= 0)
2103 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2104 gcc_assert (size_of_uleb128 (r)
2105 == size_of_uleb128 (val1->v.val_unsigned));
2106 dw2_asm_output_data_uleb128 (r, NULL);
2107 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2111 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2113 case DW_OP_bit_piece:
2114 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2115 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
2117 case DW_OP_deref_size:
2118 case DW_OP_xderef_size:
2119 dw2_asm_output_data (1, val1->v.val_int, NULL);
2125 if (targetm.asm_out.output_dwarf_dtprel)
2127 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
2130 fputc ('\n', asm_out_file);
2137 #ifdef DWARF2_DEBUGGING_INFO
2138 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2145 case DW_OP_GNU_implicit_pointer:
2147 char label[MAX_ARTIFICIAL_LABEL_BYTES
2148 + HOST_BITS_PER_WIDE_INT / 2 + 2];
2149 gcc_assert (val1->val_class == dw_val_class_die_ref);
2150 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2151 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2152 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2156 case DW_OP_GNU_entry_value:
2157 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2158 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2161 case DW_OP_GNU_const_type:
2163 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2165 dw2_asm_output_data_uleb128 (o, NULL);
2166 switch (val2->val_class)
2168 case dw_val_class_const:
2169 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2170 dw2_asm_output_data (1, l, NULL);
2171 dw2_asm_output_data (l, val2->v.val_int, NULL);
2173 case dw_val_class_vec:
2175 unsigned int elt_size = val2->v.val_vec.elt_size;
2176 unsigned int len = val2->v.val_vec.length;
2181 dw2_asm_output_data (1, l, NULL);
2182 if (elt_size > sizeof (HOST_WIDE_INT))
2187 for (i = 0, p = val2->v.val_vec.array;
2190 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2191 "fp or vector constant word %u", i);
2194 case dw_val_class_const_double:
2196 unsigned HOST_WIDE_INT first, second;
2197 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2199 dw2_asm_output_data (1, 2 * l, NULL);
2200 if (WORDS_BIG_ENDIAN)
2202 first = val2->v.val_double.high;
2203 second = val2->v.val_double.low;
2207 first = val2->v.val_double.low;
2208 second = val2->v.val_double.high;
2210 dw2_asm_output_data (l, first, NULL);
2211 dw2_asm_output_data (l, second, NULL);
2219 case DW_OP_GNU_regval_type:
2221 unsigned r = val1->v.val_unsigned;
2222 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2224 if (for_eh_or_skip >= 0)
2226 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2227 gcc_assert (size_of_uleb128 (r)
2228 == size_of_uleb128 (val1->v.val_unsigned));
2230 dw2_asm_output_data_uleb128 (r, NULL);
2231 dw2_asm_output_data_uleb128 (o, NULL);
2234 case DW_OP_GNU_deref_type:
2236 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2238 dw2_asm_output_data (1, val1->v.val_int, NULL);
2239 dw2_asm_output_data_uleb128 (o, NULL);
2242 case DW_OP_GNU_convert:
2243 case DW_OP_GNU_reinterpret:
2244 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2245 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2248 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2250 dw2_asm_output_data_uleb128 (o, NULL);
2254 case DW_OP_GNU_parameter_ref:
2257 gcc_assert (val1->val_class == dw_val_class_die_ref);
2258 o = get_ref_die_offset (val1->v.val_die_ref.die);
2259 dw2_asm_output_data (4, o, NULL);
2264 /* Other codes have no operands. */
2269 /* Output a sequence of location operations.
2270 The for_eh_or_skip parameter controls whether register numbers are
2271 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2272 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2273 info). This should be suppressed for the cases that have not been converted
2274 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2277 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2279 for (; loc != NULL; loc = loc->dw_loc_next)
2281 enum dwarf_location_atom opc = loc->dw_loc_opc;
2282 /* Output the opcode. */
2283 if (for_eh_or_skip >= 0
2284 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2286 unsigned r = (opc - DW_OP_breg0);
2287 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2288 gcc_assert (r <= 31);
2289 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2291 else if (for_eh_or_skip >= 0
2292 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2294 unsigned r = (opc - DW_OP_reg0);
2295 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2296 gcc_assert (r <= 31);
2297 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2300 dw2_asm_output_data (1, opc,
2301 "%s", dwarf_stack_op_name (opc));
2303 /* Output the operand(s) (if any). */
2304 output_loc_operands (loc, for_eh_or_skip);
2308 /* Output location description stack opcode's operands (if any).
2309 The output is single bytes on a line, suitable for .cfi_escape. */
2312 output_loc_operands_raw (dw_loc_descr_ref loc)
2314 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2315 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2317 switch (loc->dw_loc_opc)
2320 case DW_OP_implicit_value:
2321 /* We cannot output addresses in .cfi_escape, only bytes. */
2327 case DW_OP_deref_size:
2328 case DW_OP_xderef_size:
2329 fputc (',', asm_out_file);
2330 dw2_asm_output_data_raw (1, val1->v.val_int);
2335 fputc (',', asm_out_file);
2336 dw2_asm_output_data_raw (2, val1->v.val_int);
2341 fputc (',', asm_out_file);
2342 dw2_asm_output_data_raw (4, val1->v.val_int);
2347 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2348 fputc (',', asm_out_file);
2349 dw2_asm_output_data_raw (8, val1->v.val_int);
2357 gcc_assert (val1->val_class == dw_val_class_loc);
2358 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2360 fputc (',', asm_out_file);
2361 dw2_asm_output_data_raw (2, offset);
2367 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2368 gcc_assert (size_of_uleb128 (r)
2369 == size_of_uleb128 (val1->v.val_unsigned));
2370 fputc (',', asm_out_file);
2371 dw2_asm_output_data_uleb128_raw (r);
2376 case DW_OP_plus_uconst:
2378 fputc (',', asm_out_file);
2379 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2382 case DW_OP_bit_piece:
2383 fputc (',', asm_out_file);
2384 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2385 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
2422 fputc (',', asm_out_file);
2423 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
2428 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2429 gcc_assert (size_of_uleb128 (r)
2430 == size_of_uleb128 (val1->v.val_unsigned));
2431 fputc (',', asm_out_file);
2432 dw2_asm_output_data_uleb128_raw (r);
2433 fputc (',', asm_out_file);
2434 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
2438 case DW_OP_GNU_implicit_pointer:
2439 case DW_OP_GNU_entry_value:
2440 case DW_OP_GNU_const_type:
2441 case DW_OP_GNU_regval_type:
2442 case DW_OP_GNU_deref_type:
2443 case DW_OP_GNU_convert:
2444 case DW_OP_GNU_reinterpret:
2445 case DW_OP_GNU_parameter_ref:
2450 /* Other codes have no operands. */
2456 output_loc_sequence_raw (dw_loc_descr_ref loc)
2460 enum dwarf_location_atom opc = loc->dw_loc_opc;
2461 /* Output the opcode. */
2462 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2464 unsigned r = (opc - DW_OP_breg0);
2465 r = DWARF2_FRAME_REG_OUT (r, 1);
2466 gcc_assert (r <= 31);
2467 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2469 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2471 unsigned r = (opc - DW_OP_reg0);
2472 r = DWARF2_FRAME_REG_OUT (r, 1);
2473 gcc_assert (r <= 31);
2474 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2476 /* Output the opcode. */
2477 fprintf (asm_out_file, "%#x", opc);
2478 output_loc_operands_raw (loc);
2480 if (!loc->dw_loc_next)
2482 loc = loc->dw_loc_next;
2484 fputc (',', asm_out_file);
2488 /* This function builds a dwarf location descriptor sequence from a
2489 dw_cfa_location, adding the given OFFSET to the result of the
2492 struct dw_loc_descr_struct *
2493 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
2495 struct dw_loc_descr_struct *head, *tmp;
2497 offset += cfa->offset;
2501 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
2502 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2503 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2504 add_loc_descr (&head, tmp);
2507 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
2508 add_loc_descr (&head, tmp);
2512 head = new_reg_loc_descr (cfa->reg, offset);
2517 /* This function builds a dwarf location descriptor sequence for
2518 the address at OFFSET from the CFA when stack is aligned to
2521 struct dw_loc_descr_struct *
2522 build_cfa_aligned_loc (dw_cfa_location *cfa,
2523 HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
2525 struct dw_loc_descr_struct *head;
2526 unsigned int dwarf_fp
2527 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
2529 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2530 if (cfa->reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
2532 head = new_reg_loc_descr (dwarf_fp, 0);
2533 add_loc_descr (&head, int_loc_descriptor (alignment));
2534 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
2535 loc_descr_plus_const (&head, offset);
2538 head = new_reg_loc_descr (dwarf_fp, offset);
2542 /* And now, the support for symbolic debugging information. */
2544 /* .debug_str support. */
2545 static int output_indirect_string (void **, void *);
2547 static void dwarf2out_init (const char *);
2548 static void dwarf2out_finish (const char *);
2549 static void dwarf2out_assembly_start (void);
2550 static void dwarf2out_define (unsigned int, const char *);
2551 static void dwarf2out_undef (unsigned int, const char *);
2552 static void dwarf2out_start_source_file (unsigned, const char *);
2553 static void dwarf2out_end_source_file (unsigned);
2554 static void dwarf2out_function_decl (tree);
2555 static void dwarf2out_begin_block (unsigned, unsigned);
2556 static void dwarf2out_end_block (unsigned, unsigned);
2557 static bool dwarf2out_ignore_block (const_tree);
2558 static void dwarf2out_global_decl (tree);
2559 static void dwarf2out_type_decl (tree, int);
2560 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
2561 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
2563 static void dwarf2out_abstract_function (tree);
2564 static void dwarf2out_var_location (rtx);
2565 static void dwarf2out_begin_function (tree);
2566 static void dwarf2out_set_name (tree, tree);
2568 /* The debug hooks structure. */
2570 const struct gcc_debug_hooks dwarf2_debug_hooks =
2574 dwarf2out_assembly_start,
2577 dwarf2out_start_source_file,
2578 dwarf2out_end_source_file,
2579 dwarf2out_begin_block,
2580 dwarf2out_end_block,
2581 dwarf2out_ignore_block,
2582 dwarf2out_source_line,
2583 dwarf2out_begin_prologue,
2584 #if VMS_DEBUGGING_INFO
2585 dwarf2out_vms_end_prologue,
2586 dwarf2out_vms_begin_epilogue,
2588 debug_nothing_int_charstar,
2589 debug_nothing_int_charstar,
2591 dwarf2out_end_epilogue,
2592 dwarf2out_begin_function,
2593 debug_nothing_int, /* end_function */
2594 dwarf2out_function_decl, /* function_decl */
2595 dwarf2out_global_decl,
2596 dwarf2out_type_decl, /* type_decl */
2597 dwarf2out_imported_module_or_decl,
2598 debug_nothing_tree, /* deferred_inline_function */
2599 /* The DWARF 2 backend tries to reduce debugging bloat by not
2600 emitting the abstract description of inline functions until
2601 something tries to reference them. */
2602 dwarf2out_abstract_function, /* outlining_inline_function */
2603 debug_nothing_rtx, /* label */
2604 debug_nothing_int, /* handle_pch */
2605 dwarf2out_var_location,
2606 dwarf2out_switch_text_section,
2608 1, /* start_end_main_source_file */
2609 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
2612 /* NOTE: In the comments in this file, many references are made to
2613 "Debugging Information Entries". This term is abbreviated as `DIE'
2614 throughout the remainder of this file. */
2616 /* An internal representation of the DWARF output is built, and then
2617 walked to generate the DWARF debugging info. The walk of the internal
2618 representation is done after the entire program has been compiled.
2619 The types below are used to describe the internal representation. */
2621 /* Whether to put type DIEs into their own section .debug_types instead
2622 of making them part of the .debug_info section. Only supported for
2623 Dwarf V4 or higher and the user didn't disable them through
2624 -fno-debug-types-section. It is more efficient to put them in a
2625 separate comdat sections since the linker will then be able to
2626 remove duplicates. But not all tools support .debug_types sections
2629 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2631 /* Various DIE's use offsets relative to the beginning of the
2632 .debug_info section to refer to each other. */
2634 typedef long int dw_offset;
2636 /* Define typedefs here to avoid circular dependencies. */
2638 typedef struct dw_attr_struct *dw_attr_ref;
2639 typedef struct dw_line_info_struct *dw_line_info_ref;
2640 typedef struct pubname_struct *pubname_ref;
2641 typedef struct dw_ranges_struct *dw_ranges_ref;
2642 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
2643 typedef struct comdat_type_struct *comdat_type_node_ref;
2645 /* The entries in the line_info table more-or-less mirror the opcodes
2646 that are used in the real dwarf line table. Arrays of these entries
2647 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2650 enum dw_line_info_opcode {
2651 /* Emit DW_LNE_set_address; the operand is the label index. */
2654 /* Emit a row to the matrix with the given line. This may be done
2655 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2659 /* Emit a DW_LNS_set_file. */
2662 /* Emit a DW_LNS_set_column. */
2665 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2668 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2669 LI_set_prologue_end,
2670 LI_set_epilogue_begin,
2672 /* Emit a DW_LNE_set_discriminator. */
2673 LI_set_discriminator
2676 typedef struct GTY(()) dw_line_info_struct {
2677 enum dw_line_info_opcode opcode;
2679 } dw_line_info_entry;
2681 DEF_VEC_O(dw_line_info_entry);
2682 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
2684 typedef struct GTY(()) dw_line_info_table_struct {
2685 /* The label that marks the end of this section. */
2686 const char *end_label;
2688 /* The values for the last row of the matrix, as collected in the table.
2689 These are used to minimize the changes to the next row. */
2690 unsigned int file_num;
2691 unsigned int line_num;
2692 unsigned int column_num;
2697 VEC(dw_line_info_entry, gc) *entries;
2698 } dw_line_info_table;
2700 typedef dw_line_info_table *dw_line_info_table_p;
2702 DEF_VEC_P(dw_line_info_table_p);
2703 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
2705 /* Each DIE attribute has a field specifying the attribute kind,
2706 a link to the next attribute in the chain, and an attribute value.
2707 Attributes are typically linked below the DIE they modify. */
2709 typedef struct GTY(()) dw_attr_struct {
2710 enum dwarf_attribute dw_attr;
2711 dw_val_node dw_attr_val;
2715 DEF_VEC_O(dw_attr_node);
2716 DEF_VEC_ALLOC_O(dw_attr_node,gc);
2718 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2719 The children of each node form a circular list linked by
2720 die_sib. die_child points to the node *before* the "first" child node. */
2722 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
2723 union die_symbol_or_type_node
2725 char * GTY ((tag ("0"))) die_symbol;
2726 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
2728 GTY ((desc ("use_debug_types"))) die_id;
2729 VEC(dw_attr_node,gc) * die_attr;
2730 dw_die_ref die_parent;
2731 dw_die_ref die_child;
2733 dw_die_ref die_definition; /* ref from a specification to its definition */
2734 dw_offset die_offset;
2735 unsigned long die_abbrev;
2737 /* Die is used and must not be pruned as unused. */
2738 int die_perennial_p;
2739 unsigned int decl_id;
2740 enum dwarf_tag die_tag;
2744 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2745 #define FOR_EACH_CHILD(die, c, expr) do { \
2746 c = die->die_child; \
2750 } while (c != die->die_child); \
2753 /* The pubname structure */
2755 typedef struct GTY(()) pubname_struct {
2761 DEF_VEC_O(pubname_entry);
2762 DEF_VEC_ALLOC_O(pubname_entry, gc);
2764 struct GTY(()) dw_ranges_struct {
2765 /* If this is positive, it's a block number, otherwise it's a
2766 bitwise-negated index into dw_ranges_by_label. */
2770 /* A structure to hold a macinfo entry. */
2772 typedef struct GTY(()) macinfo_struct {
2773 unsigned HOST_WIDE_INT code;
2774 unsigned HOST_WIDE_INT lineno;
2779 DEF_VEC_O(macinfo_entry);
2780 DEF_VEC_ALLOC_O(macinfo_entry, gc);
2782 struct GTY(()) dw_ranges_by_label_struct {
2787 /* The comdat type node structure. */
2788 typedef struct GTY(()) comdat_type_struct
2790 dw_die_ref root_die;
2791 dw_die_ref type_die;
2792 char signature[DWARF_TYPE_SIGNATURE_SIZE];
2793 struct comdat_type_struct *next;
2797 /* The limbo die list structure. */
2798 typedef struct GTY(()) limbo_die_struct {
2801 struct limbo_die_struct *next;
2805 typedef struct skeleton_chain_struct
2809 struct skeleton_chain_struct *parent;
2811 skeleton_chain_node;
2813 /* Define a macro which returns nonzero for a TYPE_DECL which was
2814 implicitly generated for a type.
2816 Note that, unlike the C front-end (which generates a NULL named
2817 TYPE_DECL node for each complete tagged type, each array type,
2818 and each function type node created) the C++ front-end generates
2819 a _named_ TYPE_DECL node for each tagged type node created.
2820 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2821 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2822 front-end, but for each type, tagged or not. */
2824 #define TYPE_DECL_IS_STUB(decl) \
2825 (DECL_NAME (decl) == NULL_TREE \
2826 || (DECL_ARTIFICIAL (decl) \
2827 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2828 /* This is necessary for stub decls that \
2829 appear in nested inline functions. */ \
2830 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2831 && (decl_ultimate_origin (decl) \
2832 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2834 /* Information concerning the compilation unit's programming
2835 language, and compiler version. */
2837 /* Fixed size portion of the DWARF compilation unit header. */
2838 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2839 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2841 /* Fixed size portion of the DWARF comdat type unit header. */
2842 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2843 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2844 + DWARF_OFFSET_SIZE)
2846 /* Fixed size portion of public names info. */
2847 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2849 /* Fixed size portion of the address range info. */
2850 #define DWARF_ARANGES_HEADER_SIZE \
2851 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2852 DWARF2_ADDR_SIZE * 2) \
2853 - DWARF_INITIAL_LENGTH_SIZE)
2855 /* Size of padding portion in the address range info. It must be
2856 aligned to twice the pointer size. */
2857 #define DWARF_ARANGES_PAD_SIZE \
2858 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2859 DWARF2_ADDR_SIZE * 2) \
2860 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2862 /* Use assembler line directives if available. */
2863 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2864 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2865 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2867 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2871 /* Minimum line offset in a special line info. opcode.
2872 This value was chosen to give a reasonable range of values. */
2873 #define DWARF_LINE_BASE -10
2875 /* First special line opcode - leave room for the standard opcodes. */
2876 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2878 /* Range of line offsets in a special line info. opcode. */
2879 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2881 /* Flag that indicates the initial value of the is_stmt_start flag.
2882 In the present implementation, we do not mark any lines as
2883 the beginning of a source statement, because that information
2884 is not made available by the GCC front-end. */
2885 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2887 /* Maximum number of operations per instruction bundle. */
2888 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2889 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2892 /* This location is used by calc_die_sizes() to keep track
2893 the offset of each DIE within the .debug_info section. */
2894 static unsigned long next_die_offset;
2896 /* Record the root of the DIE's built for the current compilation unit. */
2897 static GTY(()) dw_die_ref single_comp_unit_die;
2899 /* A list of type DIEs that have been separated into comdat sections. */
2900 static GTY(()) comdat_type_node *comdat_type_list;
2902 /* A list of DIEs with a NULL parent waiting to be relocated. */
2903 static GTY(()) limbo_die_node *limbo_die_list;
2905 /* A list of DIEs for which we may have to generate
2906 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2907 static GTY(()) limbo_die_node *deferred_asm_name;
2909 /* Filenames referenced by this compilation unit. */
2910 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
2912 /* A hash table of references to DIE's that describe declarations.
2913 The key is a DECL_UID() which is a unique number identifying each decl. */
2914 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
2916 /* A hash table of references to DIE's that describe COMMON blocks.
2917 The key is DECL_UID() ^ die_parent. */
2918 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
2920 typedef struct GTY(()) die_arg_entry_struct {
2925 DEF_VEC_O(die_arg_entry);
2926 DEF_VEC_ALLOC_O(die_arg_entry,gc);
2928 /* Node of the variable location list. */
2929 struct GTY ((chain_next ("%h.next"))) var_loc_node {
2930 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2931 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2932 in mode of the EXPR_LIST node and first EXPR_LIST operand
2933 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2934 location or NULL for padding. For larger bitsizes,
2935 mode is 0 and first operand is a CONCAT with bitsize
2936 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2937 NULL as second operand. */
2939 const char * GTY (()) label;
2940 struct var_loc_node * GTY (()) next;
2943 /* Variable location list. */
2944 struct GTY (()) var_loc_list_def {
2945 struct var_loc_node * GTY (()) first;
2947 /* Pointer to the last but one or last element of the
2948 chained list. If the list is empty, both first and
2949 last are NULL, if the list contains just one node
2950 or the last node certainly is not redundant, it points
2951 to the last node, otherwise points to the last but one.
2952 Do not mark it for GC because it is marked through the chain. */
2953 struct var_loc_node * GTY ((skip ("%h"))) last;
2955 /* Pointer to the last element before section switch,
2956 if NULL, either sections weren't switched or first
2957 is after section switch. */
2958 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
2960 /* DECL_UID of the variable decl. */
2961 unsigned int decl_id;
2963 typedef struct var_loc_list_def var_loc_list;
2965 /* Call argument location list. */
2966 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
2967 rtx GTY (()) call_arg_loc_note;
2968 const char * GTY (()) label;
2969 tree GTY (()) block;
2971 rtx GTY (()) symbol_ref;
2972 struct call_arg_loc_node * GTY (()) next;
2976 /* Table of decl location linked lists. */
2977 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
2979 /* Head and tail of call_arg_loc chain. */
2980 static GTY (()) struct call_arg_loc_node *call_arg_locations;
2981 static struct call_arg_loc_node *call_arg_loc_last;
2983 /* Number of call sites in the current function. */
2984 static int call_site_count = -1;
2985 /* Number of tail call sites in the current function. */
2986 static int tail_call_site_count = -1;
2988 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2990 static VEC (dw_die_ref, heap) *block_map;
2992 /* A cached location list. */
2993 struct GTY (()) cached_dw_loc_list_def {
2994 /* The DECL_UID of the decl that this entry describes. */
2995 unsigned int decl_id;
2997 /* The cached location list. */
2998 dw_loc_list_ref loc_list;
3000 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
3002 /* Table of cached location lists. */
3003 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
3005 /* A pointer to the base of a list of references to DIE's that
3006 are uniquely identified by their tag, presence/absence of
3007 children DIE's, and list of attribute/value pairs. */
3008 static GTY((length ("abbrev_die_table_allocated")))
3009 dw_die_ref *abbrev_die_table;
3011 /* Number of elements currently allocated for abbrev_die_table. */
3012 static GTY(()) unsigned abbrev_die_table_allocated;
3014 /* Number of elements in type_die_table currently in use. */
3015 static GTY(()) unsigned abbrev_die_table_in_use;
3017 /* Size (in elements) of increments by which we may expand the
3018 abbrev_die_table. */
3019 #define ABBREV_DIE_TABLE_INCREMENT 256
3021 /* A global counter for generating labels for line number data. */
3022 static unsigned int line_info_label_num;
3024 /* The current table to which we should emit line number information
3025 for the current function. This will be set up at the beginning of
3026 assembly for the function. */
3027 static dw_line_info_table *cur_line_info_table;
3029 /* The two default tables of line number info. */
3030 static GTY(()) dw_line_info_table *text_section_line_info;
3031 static GTY(()) dw_line_info_table *cold_text_section_line_info;
3033 /* The set of all non-default tables of line number info. */
3034 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
3036 /* A flag to tell pubnames/types export if there is an info section to
3038 static bool info_section_emitted;
3040 /* A pointer to the base of a table that contains a list of publicly
3041 accessible names. */
3042 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
3044 /* A pointer to the base of a table that contains a list of publicly
3045 accessible types. */
3046 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
3048 /* A pointer to the base of a table that contains a list of macro
3049 defines/undefines (and file start/end markers). */
3050 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
3052 /* Array of dies for which we should generate .debug_ranges info. */
3053 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3055 /* Number of elements currently allocated for ranges_table. */
3056 static GTY(()) unsigned ranges_table_allocated;
3058 /* Number of elements in ranges_table currently in use. */
3059 static GTY(()) unsigned ranges_table_in_use;
3061 /* Array of pairs of labels referenced in ranges_table. */
3062 static GTY ((length ("ranges_by_label_allocated")))
3063 dw_ranges_by_label_ref ranges_by_label;
3065 /* Number of elements currently allocated for ranges_by_label. */
3066 static GTY(()) unsigned ranges_by_label_allocated;
3068 /* Number of elements in ranges_by_label currently in use. */
3069 static GTY(()) unsigned ranges_by_label_in_use;
3071 /* Size (in elements) of increments by which we may expand the
3073 #define RANGES_TABLE_INCREMENT 64
3075 /* Whether we have location lists that need outputting */
3076 static GTY(()) bool have_location_lists;
3078 /* Unique label counter. */
3079 static GTY(()) unsigned int loclabel_num;
3081 /* Unique label counter for point-of-call tables. */
3082 static GTY(()) unsigned int poc_label_num;
3084 /* Record whether the function being analyzed contains inlined functions. */
3085 static int current_function_has_inlines;
3087 /* The last file entry emitted by maybe_emit_file(). */
3088 static GTY(()) struct dwarf_file_data * last_emitted_file;
3090 /* Number of internal labels generated by gen_internal_sym(). */
3091 static GTY(()) int label_num;
3093 /* Cached result of previous call to lookup_filename. */
3094 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
3096 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
3098 /* Instances of generic types for which we need to generate debug
3099 info that describe their generic parameters and arguments. That
3100 generation needs to happen once all types are properly laid out so
3101 we do it at the end of compilation. */
3102 static GTY(()) VEC(tree,gc) *generic_type_instances;
3104 /* Offset from the "steady-state frame pointer" to the frame base,
3105 within the current function. */
3106 static HOST_WIDE_INT frame_pointer_fb_offset;
3107 static bool frame_pointer_fb_offset_valid;
3109 static VEC (dw_die_ref, heap) *base_types;
3111 /* Forward declarations for functions defined in this file. */
3113 static int is_pseudo_reg (const_rtx);
3114 static tree type_main_variant (tree);
3115 static int is_tagged_type (const_tree);
3116 static const char *dwarf_tag_name (unsigned);
3117 static const char *dwarf_attr_name (unsigned);
3118 static const char *dwarf_form_name (unsigned);
3119 static tree decl_ultimate_origin (const_tree);
3120 static tree decl_class_context (tree);
3121 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3122 static inline enum dw_val_class AT_class (dw_attr_ref);
3123 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3124 static inline unsigned AT_flag (dw_attr_ref);
3125 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3126 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3127 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3128 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3129 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3130 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3131 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3132 unsigned int, unsigned char *);
3133 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3134 static hashval_t debug_str_do_hash (const void *);
3135 static int debug_str_eq (const void *, const void *);
3136 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3137 static inline const char *AT_string (dw_attr_ref);
3138 static enum dwarf_form AT_string_form (dw_attr_ref);
3139 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3140 static void add_AT_specification (dw_die_ref, dw_die_ref);
3141 static inline dw_die_ref AT_ref (dw_attr_ref);
3142 static inline int AT_ref_external (dw_attr_ref);
3143 static inline void set_AT_ref_external (dw_attr_ref, int);
3144 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3145 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3146 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3147 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3149 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3150 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3151 static inline rtx AT_addr (dw_attr_ref);
3152 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3153 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3154 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3155 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3156 unsigned HOST_WIDE_INT);
3157 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3159 static inline const char *AT_lbl (dw_attr_ref);
3160 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3161 static const char *get_AT_low_pc (dw_die_ref);
3162 static const char *get_AT_hi_pc (dw_die_ref);
3163 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3164 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3165 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3166 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3167 static bool is_cxx (void);
3168 static bool is_fortran (void);
3169 static bool is_ada (void);
3170 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3171 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3172 static void add_child_die (dw_die_ref, dw_die_ref);
3173 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3174 static dw_die_ref lookup_type_die (tree);
3175 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3176 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3177 static void equate_type_number_to_die (tree, dw_die_ref);
3178 static hashval_t decl_die_table_hash (const void *);
3179 static int decl_die_table_eq (const void *, const void *);
3180 static dw_die_ref lookup_decl_die (tree);
3181 static hashval_t common_block_die_table_hash (const void *);
3182 static int common_block_die_table_eq (const void *, const void *);
3183 static hashval_t decl_loc_table_hash (const void *);
3184 static int decl_loc_table_eq (const void *, const void *);
3185 static var_loc_list *lookup_decl_loc (const_tree);
3186 static void equate_decl_number_to_die (tree, dw_die_ref);
3187 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
3188 static void print_spaces (FILE *);
3189 static void print_die (dw_die_ref, FILE *);
3190 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3191 static dw_die_ref pop_compile_unit (dw_die_ref);
3192 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3193 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3194 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3195 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3196 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3197 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3198 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
3199 struct md5_ctx *, int *);
3200 struct checksum_attributes;
3201 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3202 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3203 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3204 static void generate_type_signature (dw_die_ref, comdat_type_node *);
3205 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3206 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3207 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3208 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3209 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3210 static void compute_section_prefix (dw_die_ref);
3211 static int is_type_die (dw_die_ref);
3212 static int is_comdat_die (dw_die_ref);
3213 static int is_symbol_die (dw_die_ref);
3214 static void assign_symbol_names (dw_die_ref);
3215 static void break_out_includes (dw_die_ref);
3216 static int is_declaration_die (dw_die_ref);
3217 static int should_move_die_to_comdat (dw_die_ref);
3218 static dw_die_ref clone_as_declaration (dw_die_ref);
3219 static dw_die_ref clone_die (dw_die_ref);
3220 static dw_die_ref clone_tree (dw_die_ref);
3221 static void copy_declaration_context (dw_die_ref, dw_die_ref);
3222 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3223 static void generate_skeleton_bottom_up (skeleton_chain_node *);
3224 static dw_die_ref generate_skeleton (dw_die_ref);
3225 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3227 static void break_out_comdat_types (dw_die_ref);
3228 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
3229 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
3230 static void copy_decls_for_unworthy_types (dw_die_ref);
3232 static hashval_t htab_cu_hash (const void *);
3233 static int htab_cu_eq (const void *, const void *);
3234 static void htab_cu_del (void *);
3235 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3236 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3237 static void add_sibling_attributes (dw_die_ref);
3238 static void build_abbrev_table (dw_die_ref);
3239 static void output_location_lists (dw_die_ref);
3240 static int constant_size (unsigned HOST_WIDE_INT);
3241 static unsigned long size_of_die (dw_die_ref);
3242 static void calc_die_sizes (dw_die_ref);
3243 static void calc_base_type_die_sizes (void);
3244 static void mark_dies (dw_die_ref);
3245 static void unmark_dies (dw_die_ref);
3246 static void unmark_all_dies (dw_die_ref);
3247 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
3248 static unsigned long size_of_aranges (void);
3249 static enum dwarf_form value_format (dw_attr_ref);
3250 static void output_value_format (dw_attr_ref);
3251 static void output_abbrev_section (void);
3252 static void output_die_symbol (dw_die_ref);
3253 static void output_die (dw_die_ref);
3254 static void output_compilation_unit_header (void);
3255 static void output_comp_unit (dw_die_ref, int);
3256 static void output_comdat_type_unit (comdat_type_node *);
3257 static const char *dwarf2_name (tree, int);
3258 static void add_pubname (tree, dw_die_ref);
3259 static void add_pubname_string (const char *, dw_die_ref);
3260 static void add_pubtype (tree, dw_die_ref);
3261 static void output_pubnames (VEC (pubname_entry,gc) *);
3262 static void output_aranges (unsigned long);
3263 static unsigned int add_ranges_num (int);
3264 static unsigned int add_ranges (const_tree);
3265 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3267 static void output_ranges (void);
3268 static dw_line_info_table *new_line_info_table (void);
3269 static void output_line_info (void);
3270 static void output_file_names (void);
3271 static dw_die_ref base_type_die (tree);
3272 static int is_base_type (tree);
3273 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
3274 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3275 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3276 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3277 static int type_is_enum (const_tree);
3278 static unsigned int dbx_reg_number (const_rtx);
3279 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3280 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3281 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3282 enum var_init_status);
3283 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3284 enum var_init_status);
3285 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
3286 enum var_init_status);
3287 static int is_based_loc (const_rtx);
3288 static int resolve_one_addr (rtx *, void *);
3289 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3290 enum var_init_status);
3291 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
3292 enum var_init_status);
3293 static dw_loc_list_ref loc_list_from_tree (tree, int);
3294 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3295 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3296 static tree field_type (const_tree);
3297 static unsigned int simple_type_align_in_bits (const_tree);
3298 static unsigned int simple_decl_align_in_bits (const_tree);
3299 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3300 static HOST_WIDE_INT field_byte_offset (const_tree);
3301 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3303 static void add_data_member_location_attribute (dw_die_ref, tree);
3304 static bool add_const_value_attribute (dw_die_ref, rtx);
3305 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3306 static void insert_double (double_int, unsigned char *);
3307 static void insert_float (const_rtx, unsigned char *);
3308 static rtx rtl_for_decl_location (tree);
3309 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
3310 enum dwarf_attribute);
3311 static bool tree_add_const_value_attribute (dw_die_ref, tree);
3312 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3313 static void add_name_attribute (dw_die_ref, const char *);
3314 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3315 static void add_comp_dir_attribute (dw_die_ref);
3316 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3317 static void add_subscript_info (dw_die_ref, tree, bool);
3318 static void add_byte_size_attribute (dw_die_ref, tree);
3319 static void add_bit_offset_attribute (dw_die_ref, tree);
3320 static void add_bit_size_attribute (dw_die_ref, tree);
3321 static void add_prototyped_attribute (dw_die_ref, tree);
3322 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
3323 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3324 static void add_src_coords_attributes (dw_die_ref, tree);
3325 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3326 static void push_decl_scope (tree);
3327 static void pop_decl_scope (void);
3328 static dw_die_ref scope_die_for (tree, dw_die_ref);
3329 static inline int local_scope_p (dw_die_ref);
3330 static inline int class_scope_p (dw_die_ref);
3331 static inline int class_or_namespace_scope_p (dw_die_ref);
3332 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3333 static void add_calling_convention_attribute (dw_die_ref, tree);
3334 static const char *type_tag (const_tree);
3335 static tree member_declared_type (const_tree);
3337 static const char *decl_start_label (tree);
3339 static void gen_array_type_die (tree, dw_die_ref);
3340 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
3342 static void gen_entry_point_die (tree, dw_die_ref);
3344 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3345 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
3346 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
3347 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3348 static void gen_formal_types_die (tree, dw_die_ref);
3349 static void gen_subprogram_die (tree, dw_die_ref);
3350 static void gen_variable_die (tree, tree, dw_die_ref);
3351 static void gen_const_die (tree, dw_die_ref);
3352 static void gen_label_die (tree, dw_die_ref);
3353 static void gen_lexical_block_die (tree, dw_die_ref, int);
3354 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3355 static void gen_field_die (tree, dw_die_ref);
3356 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3357 static dw_die_ref gen_compile_unit_die (const char *);
3358 static void gen_inheritance_die (tree, tree, dw_die_ref);
3359 static void gen_member_die (tree, dw_die_ref);
3360 static void gen_struct_or_union_type_die (tree, dw_die_ref,
3361 enum debug_info_usage);
3362 static void gen_subroutine_type_die (tree, dw_die_ref);
3363 static void gen_typedef_die (tree, dw_die_ref);
3364 static void gen_type_die (tree, dw_die_ref);
3365 static void gen_block_die (tree, dw_die_ref, int);
3366 static void decls_for_scope (tree, dw_die_ref, int);
3367 static inline int is_redundant_typedef (const_tree);
3368 static bool is_naming_typedef_decl (const_tree);
3369 static inline dw_die_ref get_context_die (tree);
3370 static void gen_namespace_die (tree, dw_die_ref);
3371 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
3372 static dw_die_ref force_decl_die (tree);
3373 static dw_die_ref force_type_die (tree);
3374 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3375 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
3376 static struct dwarf_file_data * lookup_filename (const char *);
3377 static void retry_incomplete_types (void);
3378 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3379 static void gen_generic_params_dies (tree);
3380 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
3381 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
3382 static void splice_child_die (dw_die_ref, dw_die_ref);
3383 static int file_info_cmp (const void *, const void *);
3384 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3385 const char *, const char *);
3386 static void output_loc_list (dw_loc_list_ref);
3387 static char *gen_internal_sym (const char *);
3389 static void prune_unmark_dies (dw_die_ref);
3390 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
3391 static void prune_unused_types_mark (dw_die_ref, int);
3392 static void prune_unused_types_walk (dw_die_ref);
3393 static void prune_unused_types_walk_attribs (dw_die_ref);
3394 static void prune_unused_types_prune (dw_die_ref);
3395 static void prune_unused_types (void);
3396 static int maybe_emit_file (struct dwarf_file_data *fd);
3397 static inline const char *AT_vms_delta1 (dw_attr_ref);
3398 static inline const char *AT_vms_delta2 (dw_attr_ref);
3399 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
3400 const char *, const char *);
3401 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
3402 static void gen_remaining_tmpl_value_param_die_attribute (void);
3403 static bool generic_type_p (tree);
3404 static void schedule_generic_params_dies_gen (tree t);
3405 static void gen_scheduled_generic_parms_dies (void);
3407 /* Section names used to hold DWARF debugging information. */
3408 #ifndef DEBUG_INFO_SECTION
3409 #define DEBUG_INFO_SECTION ".debug_info"
3411 #ifndef DEBUG_ABBREV_SECTION
3412 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3414 #ifndef DEBUG_ARANGES_SECTION
3415 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3417 #ifndef DEBUG_MACINFO_SECTION
3418 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3420 #ifndef DEBUG_LINE_SECTION
3421 #define DEBUG_LINE_SECTION ".debug_line"
3423 #ifndef DEBUG_LOC_SECTION
3424 #define DEBUG_LOC_SECTION ".debug_loc"
3426 #ifndef DEBUG_PUBNAMES_SECTION
3427 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3429 #ifndef DEBUG_PUBTYPES_SECTION
3430 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3432 #ifndef DEBUG_STR_SECTION
3433 #define DEBUG_STR_SECTION ".debug_str"
3435 #ifndef DEBUG_RANGES_SECTION
3436 #define DEBUG_RANGES_SECTION ".debug_ranges"
3439 /* Standard ELF section names for compiled code and data. */
3440 #ifndef TEXT_SECTION_NAME
3441 #define TEXT_SECTION_NAME ".text"
3444 /* Section flags for .debug_str section. */
3445 #define DEBUG_STR_SECTION_FLAGS \
3446 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3447 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3450 /* Labels we insert at beginning sections we can reference instead of
3451 the section names themselves. */
3453 #ifndef TEXT_SECTION_LABEL
3454 #define TEXT_SECTION_LABEL "Ltext"
3456 #ifndef COLD_TEXT_SECTION_LABEL
3457 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3459 #ifndef DEBUG_LINE_SECTION_LABEL
3460 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3462 #ifndef DEBUG_INFO_SECTION_LABEL
3463 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3465 #ifndef DEBUG_ABBREV_SECTION_LABEL
3466 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3468 #ifndef DEBUG_LOC_SECTION_LABEL
3469 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3471 #ifndef DEBUG_RANGES_SECTION_LABEL
3472 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3474 #ifndef DEBUG_MACINFO_SECTION_LABEL
3475 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3479 /* Definitions of defaults for formats and names of various special
3480 (artificial) labels which may be generated within this file (when the -g
3481 options is used and DWARF2_DEBUGGING_INFO is in effect.
3482 If necessary, these may be overridden from within the tm.h file, but
3483 typically, overriding these defaults is unnecessary. */
3485 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3486 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3487 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3488 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3489 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3490 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3491 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3492 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3493 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3494 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3496 #ifndef TEXT_END_LABEL
3497 #define TEXT_END_LABEL "Letext"
3499 #ifndef COLD_END_LABEL
3500 #define COLD_END_LABEL "Letext_cold"
3502 #ifndef BLOCK_BEGIN_LABEL
3503 #define BLOCK_BEGIN_LABEL "LBB"
3505 #ifndef BLOCK_END_LABEL
3506 #define BLOCK_END_LABEL "LBE"
3508 #ifndef LINE_CODE_LABEL
3509 #define LINE_CODE_LABEL "LM"
3513 /* Return the root of the DIE's built for the current compilation unit. */
3515 comp_unit_die (void)
3517 if (!single_comp_unit_die)
3518 single_comp_unit_die = gen_compile_unit_die (NULL);
3519 return single_comp_unit_die;
3522 /* We allow a language front-end to designate a function that is to be
3523 called to "demangle" any name before it is put into a DIE. */
3525 static const char *(*demangle_name_func) (const char *);
3528 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3530 demangle_name_func = func;
3533 /* Test if rtl node points to a pseudo register. */
3536 is_pseudo_reg (const_rtx rtl)
3538 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3539 || (GET_CODE (rtl) == SUBREG
3540 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3543 /* Return a reference to a type, with its const and volatile qualifiers
3547 type_main_variant (tree type)
3549 type = TYPE_MAIN_VARIANT (type);
3551 /* ??? There really should be only one main variant among any group of
3552 variants of a given type (and all of the MAIN_VARIANT values for all
3553 members of the group should point to that one type) but sometimes the C
3554 front-end messes this up for array types, so we work around that bug
3556 if (TREE_CODE (type) == ARRAY_TYPE)
3557 while (type != TYPE_MAIN_VARIANT (type))
3558 type = TYPE_MAIN_VARIANT (type);
3563 /* Return nonzero if the given type node represents a tagged type. */
3566 is_tagged_type (const_tree type)
3568 enum tree_code code = TREE_CODE (type);
3570 return (code == RECORD_TYPE || code == UNION_TYPE
3571 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3574 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3577 get_ref_die_offset_label (char *label, dw_die_ref ref)
3579 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
3582 /* Return die_offset of a DIE reference to a base type. */
3584 static unsigned long int
3585 get_base_type_offset (dw_die_ref ref)
3587 if (ref->die_offset)
3588 return ref->die_offset;
3589 if (comp_unit_die ()->die_abbrev)
3591 calc_base_type_die_sizes ();
3592 gcc_assert (ref->die_offset);
3594 return ref->die_offset;
3597 /* Return die_offset of a DIE reference other than base type. */
3599 static unsigned long int
3600 get_ref_die_offset (dw_die_ref ref)
3602 gcc_assert (ref->die_offset);
3603 return ref->die_offset;
3606 /* Convert a DIE tag into its string name. */
3609 dwarf_tag_name (unsigned int tag)
3613 case DW_TAG_padding:
3614 return "DW_TAG_padding";
3615 case DW_TAG_array_type:
3616 return "DW_TAG_array_type";
3617 case DW_TAG_class_type:
3618 return "DW_TAG_class_type";
3619 case DW_TAG_entry_point:
3620 return "DW_TAG_entry_point";
3621 case DW_TAG_enumeration_type:
3622 return "DW_TAG_enumeration_type";
3623 case DW_TAG_formal_parameter:
3624 return "DW_TAG_formal_parameter";
3625 case DW_TAG_imported_declaration:
3626 return "DW_TAG_imported_declaration";
3628 return "DW_TAG_label";
3629 case DW_TAG_lexical_block:
3630 return "DW_TAG_lexical_block";
3632 return "DW_TAG_member";
3633 case DW_TAG_pointer_type:
3634 return "DW_TAG_pointer_type";
3635 case DW_TAG_reference_type:
3636 return "DW_TAG_reference_type";
3637 case DW_TAG_compile_unit:
3638 return "DW_TAG_compile_unit";
3639 case DW_TAG_string_type:
3640 return "DW_TAG_string_type";
3641 case DW_TAG_structure_type:
3642 return "DW_TAG_structure_type";
3643 case DW_TAG_subroutine_type:
3644 return "DW_TAG_subroutine_type";
3645 case DW_TAG_typedef:
3646 return "DW_TAG_typedef";
3647 case DW_TAG_union_type:
3648 return "DW_TAG_union_type";
3649 case DW_TAG_unspecified_parameters:
3650 return "DW_TAG_unspecified_parameters";
3651 case DW_TAG_variant:
3652 return "DW_TAG_variant";
3653 case DW_TAG_common_block:
3654 return "DW_TAG_common_block";
3655 case DW_TAG_common_inclusion:
3656 return "DW_TAG_common_inclusion";
3657 case DW_TAG_inheritance:
3658 return "DW_TAG_inheritance";
3659 case DW_TAG_inlined_subroutine:
3660 return "DW_TAG_inlined_subroutine";
3662 return "DW_TAG_module";
3663 case DW_TAG_ptr_to_member_type:
3664 return "DW_TAG_ptr_to_member_type";
3665 case DW_TAG_set_type:
3666 return "DW_TAG_set_type";
3667 case DW_TAG_subrange_type:
3668 return "DW_TAG_subrange_type";
3669 case DW_TAG_with_stmt:
3670 return "DW_TAG_with_stmt";
3671 case DW_TAG_access_declaration:
3672 return "DW_TAG_access_declaration";
3673 case DW_TAG_base_type:
3674 return "DW_TAG_base_type";
3675 case DW_TAG_catch_block:
3676 return "DW_TAG_catch_block";
3677 case DW_TAG_const_type:
3678 return "DW_TAG_const_type";
3679 case DW_TAG_constant:
3680 return "DW_TAG_constant";
3681 case DW_TAG_enumerator:
3682 return "DW_TAG_enumerator";
3683 case DW_TAG_file_type:
3684 return "DW_TAG_file_type";
3686 return "DW_TAG_friend";
3687 case DW_TAG_namelist:
3688 return "DW_TAG_namelist";
3689 case DW_TAG_namelist_item:
3690 return "DW_TAG_namelist_item";
3691 case DW_TAG_packed_type:
3692 return "DW_TAG_packed_type";
3693 case DW_TAG_subprogram:
3694 return "DW_TAG_subprogram";
3695 case DW_TAG_template_type_param:
3696 return "DW_TAG_template_type_param";
3697 case DW_TAG_template_value_param:
3698 return "DW_TAG_template_value_param";
3699 case DW_TAG_thrown_type:
3700 return "DW_TAG_thrown_type";
3701 case DW_TAG_try_block:
3702 return "DW_TAG_try_block";
3703 case DW_TAG_variant_part:
3704 return "DW_TAG_variant_part";
3705 case DW_TAG_variable:
3706 return "DW_TAG_variable";
3707 case DW_TAG_volatile_type:
3708 return "DW_TAG_volatile_type";
3709 case DW_TAG_dwarf_procedure:
3710 return "DW_TAG_dwarf_procedure";
3711 case DW_TAG_restrict_type:
3712 return "DW_TAG_restrict_type";
3713 case DW_TAG_interface_type:
3714 return "DW_TAG_interface_type";
3715 case DW_TAG_namespace:
3716 return "DW_TAG_namespace";
3717 case DW_TAG_imported_module:
3718 return "DW_TAG_imported_module";
3719 case DW_TAG_unspecified_type:
3720 return "DW_TAG_unspecified_type";
3721 case DW_TAG_partial_unit:
3722 return "DW_TAG_partial_unit";
3723 case DW_TAG_imported_unit:
3724 return "DW_TAG_imported_unit";
3725 case DW_TAG_condition:
3726 return "DW_TAG_condition";
3727 case DW_TAG_shared_type:
3728 return "DW_TAG_shared_type";
3729 case DW_TAG_type_unit:
3730 return "DW_TAG_type_unit";
3731 case DW_TAG_rvalue_reference_type:
3732 return "DW_TAG_rvalue_reference_type";
3733 case DW_TAG_template_alias:
3734 return "DW_TAG_template_alias";
3735 case DW_TAG_GNU_template_parameter_pack:
3736 return "DW_TAG_GNU_template_parameter_pack";
3737 case DW_TAG_GNU_formal_parameter_pack:
3738 return "DW_TAG_GNU_formal_parameter_pack";
3739 case DW_TAG_MIPS_loop:
3740 return "DW_TAG_MIPS_loop";
3741 case DW_TAG_format_label:
3742 return "DW_TAG_format_label";
3743 case DW_TAG_function_template:
3744 return "DW_TAG_function_template";
3745 case DW_TAG_class_template:
3746 return "DW_TAG_class_template";
3747 case DW_TAG_GNU_BINCL:
3748 return "DW_TAG_GNU_BINCL";
3749 case DW_TAG_GNU_EINCL:
3750 return "DW_TAG_GNU_EINCL";
3751 case DW_TAG_GNU_template_template_param:
3752 return "DW_TAG_GNU_template_template_param";
3753 case DW_TAG_GNU_call_site:
3754 return "DW_TAG_GNU_call_site";
3755 case DW_TAG_GNU_call_site_parameter:
3756 return "DW_TAG_GNU_call_site_parameter";
3758 return "DW_TAG_<unknown>";
3762 /* Convert a DWARF attribute code into its string name. */
3765 dwarf_attr_name (unsigned int attr)
3770 return "DW_AT_sibling";
3771 case DW_AT_location:
3772 return "DW_AT_location";
3774 return "DW_AT_name";
3775 case DW_AT_ordering:
3776 return "DW_AT_ordering";
3777 case DW_AT_subscr_data:
3778 return "DW_AT_subscr_data";
3779 case DW_AT_byte_size:
3780 return "DW_AT_byte_size";
3781 case DW_AT_bit_offset:
3782 return "DW_AT_bit_offset";
3783 case DW_AT_bit_size:
3784 return "DW_AT_bit_size";
3785 case DW_AT_element_list:
3786 return "DW_AT_element_list";
3787 case DW_AT_stmt_list:
3788 return "DW_AT_stmt_list";
3790 return "DW_AT_low_pc";
3792 return "DW_AT_high_pc";
3793 case DW_AT_language:
3794 return "DW_AT_language";
3796 return "DW_AT_member";
3798 return "DW_AT_discr";
3799 case DW_AT_discr_value:
3800 return "DW_AT_discr_value";
3801 case DW_AT_visibility:
3802 return "DW_AT_visibility";
3804 return "DW_AT_import";
3805 case DW_AT_string_length:
3806 return "DW_AT_string_length";
3807 case DW_AT_common_reference:
3808 return "DW_AT_common_reference";
3809 case DW_AT_comp_dir:
3810 return "DW_AT_comp_dir";
3811 case DW_AT_const_value:
3812 return "DW_AT_const_value";
3813 case DW_AT_containing_type:
3814 return "DW_AT_containing_type";
3815 case DW_AT_default_value:
3816 return "DW_AT_default_value";
3818 return "DW_AT_inline";
3819 case DW_AT_is_optional:
3820 return "DW_AT_is_optional";
3821 case DW_AT_lower_bound:
3822 return "DW_AT_lower_bound";
3823 case DW_AT_producer:
3824 return "DW_AT_producer";
3825 case DW_AT_prototyped:
3826 return "DW_AT_prototyped";
3827 case DW_AT_return_addr:
3828 return "DW_AT_return_addr";
3829 case DW_AT_start_scope:
3830 return "DW_AT_start_scope";
3831 case DW_AT_bit_stride:
3832 return "DW_AT_bit_stride";
3833 case DW_AT_upper_bound:
3834 return "DW_AT_upper_bound";
3835 case DW_AT_abstract_origin:
3836 return "DW_AT_abstract_origin";
3837 case DW_AT_accessibility:
3838 return "DW_AT_accessibility";
3839 case DW_AT_address_class:
3840 return "DW_AT_address_class";
3841 case DW_AT_artificial:
3842 return "DW_AT_artificial";
3843 case DW_AT_base_types:
3844 return "DW_AT_base_types";
3845 case DW_AT_calling_convention:
3846 return "DW_AT_calling_convention";
3848 return "DW_AT_count";
3849 case DW_AT_data_member_location:
3850 return "DW_AT_data_member_location";
3851 case DW_AT_decl_column:
3852 return "DW_AT_decl_column";
3853 case DW_AT_decl_file:
3854 return "DW_AT_decl_file";
3855 case DW_AT_decl_line:
3856 return "DW_AT_decl_line";
3857 case DW_AT_declaration:
3858 return "DW_AT_declaration";
3859 case DW_AT_discr_list:
3860 return "DW_AT_discr_list";
3861 case DW_AT_encoding:
3862 return "DW_AT_encoding";
3863 case DW_AT_external:
3864 return "DW_AT_external";
3865 case DW_AT_explicit:
3866 return "DW_AT_explicit";
3867 case DW_AT_frame_base:
3868 return "DW_AT_frame_base";
3870 return "DW_AT_friend";
3871 case DW_AT_identifier_case:
3872 return "DW_AT_identifier_case";
3873 case DW_AT_macro_info:
3874 return "DW_AT_macro_info";
3875 case DW_AT_namelist_items:
3876 return "DW_AT_namelist_items";
3877 case DW_AT_priority:
3878 return "DW_AT_priority";
3880 return "DW_AT_segment";
3881 case DW_AT_specification:
3882 return "DW_AT_specification";
3883 case DW_AT_static_link:
3884 return "DW_AT_static_link";
3886 return "DW_AT_type";
3887 case DW_AT_use_location:
3888 return "DW_AT_use_location";
3889 case DW_AT_variable_parameter:
3890 return "DW_AT_variable_parameter";
3891 case DW_AT_virtuality:
3892 return "DW_AT_virtuality";
3893 case DW_AT_vtable_elem_location:
3894 return "DW_AT_vtable_elem_location";
3896 case DW_AT_allocated:
3897 return "DW_AT_allocated";
3898 case DW_AT_associated:
3899 return "DW_AT_associated";
3900 case DW_AT_data_location:
3901 return "DW_AT_data_location";
3902 case DW_AT_byte_stride:
3903 return "DW_AT_byte_stride";
3904 case DW_AT_entry_pc:
3905 return "DW_AT_entry_pc";
3906 case DW_AT_use_UTF8:
3907 return "DW_AT_use_UTF8";
3908 case DW_AT_extension:
3909 return "DW_AT_extension";
3911 return "DW_AT_ranges";
3912 case DW_AT_trampoline:
3913 return "DW_AT_trampoline";
3914 case DW_AT_call_column:
3915 return "DW_AT_call_column";
3916 case DW_AT_call_file:
3917 return "DW_AT_call_file";
3918 case DW_AT_call_line:
3919 return "DW_AT_call_line";
3920 case DW_AT_object_pointer:
3921 return "DW_AT_object_pointer";
3923 case DW_AT_signature:
3924 return "DW_AT_signature";
3925 case DW_AT_main_subprogram:
3926 return "DW_AT_main_subprogram";
3927 case DW_AT_data_bit_offset:
3928 return "DW_AT_data_bit_offset";
3929 case DW_AT_const_expr:
3930 return "DW_AT_const_expr";
3931 case DW_AT_enum_class:
3932 return "DW_AT_enum_class";
3933 case DW_AT_linkage_name:
3934 return "DW_AT_linkage_name";
3936 case DW_AT_MIPS_fde:
3937 return "DW_AT_MIPS_fde";
3938 case DW_AT_MIPS_loop_begin:
3939 return "DW_AT_MIPS_loop_begin";
3940 case DW_AT_MIPS_tail_loop_begin:
3941 return "DW_AT_MIPS_tail_loop_begin";
3942 case DW_AT_MIPS_epilog_begin:
3943 return "DW_AT_MIPS_epilog_begin";
3944 #if VMS_DEBUGGING_INFO
3945 case DW_AT_HP_prologue:
3946 return "DW_AT_HP_prologue";
3948 case DW_AT_MIPS_loop_unroll_factor:
3949 return "DW_AT_MIPS_loop_unroll_factor";
3951 case DW_AT_MIPS_software_pipeline_depth:
3952 return "DW_AT_MIPS_software_pipeline_depth";
3953 case DW_AT_MIPS_linkage_name:
3954 return "DW_AT_MIPS_linkage_name";
3955 #if VMS_DEBUGGING_INFO
3956 case DW_AT_HP_epilogue:
3957 return "DW_AT_HP_epilogue";
3959 case DW_AT_MIPS_stride:
3960 return "DW_AT_MIPS_stride";
3962 case DW_AT_MIPS_abstract_name:
3963 return "DW_AT_MIPS_abstract_name";
3964 case DW_AT_MIPS_clone_origin:
3965 return "DW_AT_MIPS_clone_origin";
3966 case DW_AT_MIPS_has_inlines:
3967 return "DW_AT_MIPS_has_inlines";
3969 case DW_AT_sf_names:
3970 return "DW_AT_sf_names";
3971 case DW_AT_src_info:
3972 return "DW_AT_src_info";
3973 case DW_AT_mac_info:
3974 return "DW_AT_mac_info";
3975 case DW_AT_src_coords:
3976 return "DW_AT_src_coords";
3977 case DW_AT_body_begin:
3978 return "DW_AT_body_begin";
3979 case DW_AT_body_end:
3980 return "DW_AT_body_end";
3982 case DW_AT_GNU_vector:
3983 return "DW_AT_GNU_vector";
3984 case DW_AT_GNU_guarded_by:
3985 return "DW_AT_GNU_guarded_by";
3986 case DW_AT_GNU_pt_guarded_by:
3987 return "DW_AT_GNU_pt_guarded_by";
3988 case DW_AT_GNU_guarded:
3989 return "DW_AT_GNU_guarded";
3990 case DW_AT_GNU_pt_guarded:
3991 return "DW_AT_GNU_pt_guarded";
3992 case DW_AT_GNU_locks_excluded:
3993 return "DW_AT_GNU_locks_excluded";
3994 case DW_AT_GNU_exclusive_locks_required:
3995 return "DW_AT_GNU_exclusive_locks_required";
3996 case DW_AT_GNU_shared_locks_required:
3997 return "DW_AT_GNU_shared_locks_required";
3998 case DW_AT_GNU_odr_signature:
3999 return "DW_AT_GNU_odr_signature";
4000 case DW_AT_GNU_template_name:
4001 return "DW_AT_GNU_template_name";
4002 case DW_AT_GNU_call_site_value:
4003 return "DW_AT_GNU_call_site_value";
4004 case DW_AT_GNU_call_site_data_value:
4005 return "DW_AT_GNU_call_site_data_value";
4006 case DW_AT_GNU_call_site_target:
4007 return "DW_AT_GNU_call_site_target";
4008 case DW_AT_GNU_call_site_target_clobbered:
4009 return "DW_AT_GNU_call_site_target_clobbered";
4010 case DW_AT_GNU_tail_call:
4011 return "DW_AT_GNU_tail_call";
4012 case DW_AT_GNU_all_tail_call_sites:
4013 return "DW_AT_GNU_all_tail_call_sites";
4014 case DW_AT_GNU_all_call_sites:
4015 return "DW_AT_GNU_all_call_sites";
4016 case DW_AT_GNU_all_source_call_sites:
4017 return "DW_AT_GNU_all_source_call_sites";
4019 case DW_AT_GNAT_descriptive_type:
4020 return "DW_AT_GNAT_descriptive_type";
4022 case DW_AT_VMS_rtnbeg_pd_address:
4023 return "DW_AT_VMS_rtnbeg_pd_address";
4026 return "DW_AT_<unknown>";
4030 /* Convert a DWARF value form code into its string name. */
4033 dwarf_form_name (unsigned int form)
4038 return "DW_FORM_addr";
4039 case DW_FORM_block2:
4040 return "DW_FORM_block2";
4041 case DW_FORM_block4:
4042 return "DW_FORM_block4";
4044 return "DW_FORM_data2";
4046 return "DW_FORM_data4";
4048 return "DW_FORM_data8";
4049 case DW_FORM_string:
4050 return "DW_FORM_string";
4052 return "DW_FORM_block";
4053 case DW_FORM_block1:
4054 return "DW_FORM_block1";
4056 return "DW_FORM_data1";
4058 return "DW_FORM_flag";
4060 return "DW_FORM_sdata";
4062 return "DW_FORM_strp";
4064 return "DW_FORM_udata";
4065 case DW_FORM_ref_addr:
4066 return "DW_FORM_ref_addr";
4068 return "DW_FORM_ref1";
4070 return "DW_FORM_ref2";
4072 return "DW_FORM_ref4";
4074 return "DW_FORM_ref8";
4075 case DW_FORM_ref_udata:
4076 return "DW_FORM_ref_udata";
4077 case DW_FORM_indirect:
4078 return "DW_FORM_indirect";
4079 case DW_FORM_sec_offset:
4080 return "DW_FORM_sec_offset";
4081 case DW_FORM_exprloc:
4082 return "DW_FORM_exprloc";
4083 case DW_FORM_flag_present:
4084 return "DW_FORM_flag_present";
4085 case DW_FORM_ref_sig8:
4086 return "DW_FORM_ref_sig8";
4088 return "DW_FORM_<unknown>";
4092 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4093 instance of an inlined instance of a decl which is local to an inline
4094 function, so we have to trace all of the way back through the origin chain
4095 to find out what sort of node actually served as the original seed for the
4099 decl_ultimate_origin (const_tree decl)
4101 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4104 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4105 nodes in the function to point to themselves; ignore that if
4106 we're trying to output the abstract instance of this function. */
4107 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4110 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4111 most distant ancestor, this should never happen. */
4112 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4114 return DECL_ABSTRACT_ORIGIN (decl);
4117 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4118 of a virtual function may refer to a base class, so we check the 'this'
4122 decl_class_context (tree decl)
4124 tree context = NULL_TREE;
4126 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4127 context = DECL_CONTEXT (decl);
4129 context = TYPE_MAIN_VARIANT
4130 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4132 if (context && !TYPE_P (context))
4133 context = NULL_TREE;
4138 /* Add an attribute/value pair to a DIE. */
4141 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4143 /* Maybe this should be an assert? */
4147 if (die->die_attr == NULL)
4148 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4149 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4152 static inline enum dw_val_class
4153 AT_class (dw_attr_ref a)
4155 return a->dw_attr_val.val_class;
4158 /* Add a flag value attribute to a DIE. */
4161 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4165 attr.dw_attr = attr_kind;
4166 attr.dw_attr_val.val_class = dw_val_class_flag;
4167 attr.dw_attr_val.v.val_flag = flag;
4168 add_dwarf_attr (die, &attr);
4171 static inline unsigned
4172 AT_flag (dw_attr_ref a)
4174 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4175 return a->dw_attr_val.v.val_flag;
4178 /* Add a signed integer attribute value to a DIE. */
4181 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4185 attr.dw_attr = attr_kind;
4186 attr.dw_attr_val.val_class = dw_val_class_const;
4187 attr.dw_attr_val.v.val_int = int_val;
4188 add_dwarf_attr (die, &attr);
4191 static inline HOST_WIDE_INT
4192 AT_int (dw_attr_ref a)
4194 gcc_assert (a && AT_class (a) == dw_val_class_const);
4195 return a->dw_attr_val.v.val_int;
4198 /* Add an unsigned integer attribute value to a DIE. */
4201 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4202 unsigned HOST_WIDE_INT unsigned_val)
4206 attr.dw_attr = attr_kind;
4207 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4208 attr.dw_attr_val.v.val_unsigned = unsigned_val;
4209 add_dwarf_attr (die, &attr);
4212 static inline unsigned HOST_WIDE_INT
4213 AT_unsigned (dw_attr_ref a)
4215 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4216 return a->dw_attr_val.v.val_unsigned;
4219 /* Add an unsigned double integer attribute value to a DIE. */
4222 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
4223 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
4227 attr.dw_attr = attr_kind;
4228 attr.dw_attr_val.val_class = dw_val_class_const_double;
4229 attr.dw_attr_val.v.val_double.high = high;
4230 attr.dw_attr_val.v.val_double.low = low;
4231 add_dwarf_attr (die, &attr);
4234 /* Add a floating point attribute value to a DIE and return it. */
4237 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4238 unsigned int length, unsigned int elt_size, unsigned char *array)
4242 attr.dw_attr = attr_kind;
4243 attr.dw_attr_val.val_class = dw_val_class_vec;
4244 attr.dw_attr_val.v.val_vec.length = length;
4245 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4246 attr.dw_attr_val.v.val_vec.array = array;
4247 add_dwarf_attr (die, &attr);
4250 /* Add an 8-byte data attribute value to a DIE. */
4253 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
4254 unsigned char data8[8])
4258 attr.dw_attr = attr_kind;
4259 attr.dw_attr_val.val_class = dw_val_class_data8;
4260 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
4261 add_dwarf_attr (die, &attr);
4264 /* Hash and equality functions for debug_str_hash. */
4267 debug_str_do_hash (const void *x)
4269 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4273 debug_str_eq (const void *x1, const void *x2)
4275 return strcmp ((((const struct indirect_string_node *)x1)->str),
4276 (const char *)x2) == 0;
4279 /* Add STR to the indirect string hash table. */
4281 static struct indirect_string_node *
4282 find_AT_string (const char *str)
4284 struct indirect_string_node *node;
4287 if (! debug_str_hash)
4288 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4289 debug_str_eq, NULL);
4291 slot = htab_find_slot_with_hash (debug_str_hash, str,
4292 htab_hash_string (str), INSERT);
4295 node = ggc_alloc_cleared_indirect_string_node ();
4296 node->str = ggc_strdup (str);
4300 node = (struct indirect_string_node *) *slot;
4306 /* Add a string attribute value to a DIE. */
4309 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4312 struct indirect_string_node *node;
4314 node = find_AT_string (str);
4316 attr.dw_attr = attr_kind;
4317 attr.dw_attr_val.val_class = dw_val_class_str;
4318 attr.dw_attr_val.v.val_str = node;
4319 add_dwarf_attr (die, &attr);
4322 static inline const char *
4323 AT_string (dw_attr_ref a)
4325 gcc_assert (a && AT_class (a) == dw_val_class_str);
4326 return a->dw_attr_val.v.val_str->str;
4329 /* Find out whether a string should be output inline in DIE
4330 or out-of-line in .debug_str section. */
4332 static enum dwarf_form
4333 AT_string_form (dw_attr_ref a)
4335 struct indirect_string_node *node;
4339 gcc_assert (a && AT_class (a) == dw_val_class_str);
4341 node = a->dw_attr_val.v.val_str;
4345 len = strlen (node->str) + 1;
4347 /* If the string is shorter or equal to the size of the reference, it is
4348 always better to put it inline. */
4349 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4350 return node->form = DW_FORM_string;
4352 /* If we cannot expect the linker to merge strings in .debug_str
4353 section, only put it into .debug_str if it is worth even in this
4355 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4356 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
4357 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
4358 return node->form = DW_FORM_string;
4360 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4361 ++dw2_string_counter;
4362 node->label = xstrdup (label);
4364 return node->form = DW_FORM_strp;
4367 /* Add a DIE reference attribute value to a DIE. */
4370 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4374 #ifdef ENABLE_CHECKING
4375 gcc_assert (targ_die != NULL);
4377 /* With LTO we can end up trying to reference something we didn't create
4378 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4379 if (targ_die == NULL)
4383 attr.dw_attr = attr_kind;
4384 attr.dw_attr_val.val_class = dw_val_class_die_ref;
4385 attr.dw_attr_val.v.val_die_ref.die = targ_die;
4386 attr.dw_attr_val.v.val_die_ref.external = 0;
4387 add_dwarf_attr (die, &attr);
4390 /* Add an AT_specification attribute to a DIE, and also make the back
4391 pointer from the specification to the definition. */
4394 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4396 add_AT_die_ref (die, DW_AT_specification, targ_die);
4397 gcc_assert (!targ_die->die_definition);
4398 targ_die->die_definition = die;
4401 static inline dw_die_ref
4402 AT_ref (dw_attr_ref a)
4404 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4405 return a->dw_attr_val.v.val_die_ref.die;
4409 AT_ref_external (dw_attr_ref a)
4411 if (a && AT_class (a) == dw_val_class_die_ref)
4412 return a->dw_attr_val.v.val_die_ref.external;
4418 set_AT_ref_external (dw_attr_ref a, int i)
4420 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4421 a->dw_attr_val.v.val_die_ref.external = i;
4424 /* Add an FDE reference attribute value to a DIE. */
4427 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4431 attr.dw_attr = attr_kind;
4432 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
4433 attr.dw_attr_val.v.val_fde_index = targ_fde;
4434 add_dwarf_attr (die, &attr);
4437 /* Add a location description attribute value to a DIE. */
4440 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4444 attr.dw_attr = attr_kind;
4445 attr.dw_attr_val.val_class = dw_val_class_loc;
4446 attr.dw_attr_val.v.val_loc = loc;
4447 add_dwarf_attr (die, &attr);
4450 static inline dw_loc_descr_ref
4451 AT_loc (dw_attr_ref a)
4453 gcc_assert (a && AT_class (a) == dw_val_class_loc);
4454 return a->dw_attr_val.v.val_loc;
4458 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4462 attr.dw_attr = attr_kind;
4463 attr.dw_attr_val.val_class = dw_val_class_loc_list;
4464 attr.dw_attr_val.v.val_loc_list = loc_list;
4465 add_dwarf_attr (die, &attr);
4466 have_location_lists = true;
4469 static inline dw_loc_list_ref
4470 AT_loc_list (dw_attr_ref a)
4472 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4473 return a->dw_attr_val.v.val_loc_list;
4476 static inline dw_loc_list_ref *
4477 AT_loc_list_ptr (dw_attr_ref a)
4479 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4480 return &a->dw_attr_val.v.val_loc_list;
4483 /* Add an address constant attribute value to a DIE. */
4486 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
4490 attr.dw_attr = attr_kind;
4491 attr.dw_attr_val.val_class = dw_val_class_addr;
4492 attr.dw_attr_val.v.val_addr = addr;
4493 add_dwarf_attr (die, &attr);
4496 /* Get the RTX from to an address DIE attribute. */
4499 AT_addr (dw_attr_ref a)
4501 gcc_assert (a && AT_class (a) == dw_val_class_addr);
4502 return a->dw_attr_val.v.val_addr;
4505 /* Add a file attribute value to a DIE. */
4508 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
4509 struct dwarf_file_data *fd)
4513 attr.dw_attr = attr_kind;
4514 attr.dw_attr_val.val_class = dw_val_class_file;
4515 attr.dw_attr_val.v.val_file = fd;
4516 add_dwarf_attr (die, &attr);
4519 /* Get the dwarf_file_data from a file DIE attribute. */
4521 static inline struct dwarf_file_data *
4522 AT_file (dw_attr_ref a)
4524 gcc_assert (a && AT_class (a) == dw_val_class_file);
4525 return a->dw_attr_val.v.val_file;
4528 /* Add a vms delta attribute value to a DIE. */
4531 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
4532 const char *lbl1, const char *lbl2)
4536 attr.dw_attr = attr_kind;
4537 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
4538 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
4539 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
4540 add_dwarf_attr (die, &attr);
4543 /* Add a label identifier attribute value to a DIE. */
4546 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
4550 attr.dw_attr = attr_kind;
4551 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4552 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4553 add_dwarf_attr (die, &attr);
4556 /* Add a section offset attribute value to a DIE, an offset into the
4557 debug_line section. */
4560 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4565 attr.dw_attr = attr_kind;
4566 attr.dw_attr_val.val_class = dw_val_class_lineptr;
4567 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4568 add_dwarf_attr (die, &attr);
4571 /* Add a section offset attribute value to a DIE, an offset into the
4572 debug_macinfo section. */
4575 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4580 attr.dw_attr = attr_kind;
4581 attr.dw_attr_val.val_class = dw_val_class_macptr;
4582 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4583 add_dwarf_attr (die, &attr);
4586 /* Add an offset attribute value to a DIE. */
4589 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
4590 unsigned HOST_WIDE_INT offset)
4594 attr.dw_attr = attr_kind;
4595 attr.dw_attr_val.val_class = dw_val_class_offset;
4596 attr.dw_attr_val.v.val_offset = offset;
4597 add_dwarf_attr (die, &attr);
4600 /* Add an range_list attribute value to a DIE. */
4603 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4604 long unsigned int offset)
4608 attr.dw_attr = attr_kind;
4609 attr.dw_attr_val.val_class = dw_val_class_range_list;
4610 attr.dw_attr_val.v.val_offset = offset;
4611 add_dwarf_attr (die, &attr);
4614 /* Return the start label of a delta attribute. */
4616 static inline const char *
4617 AT_vms_delta1 (dw_attr_ref a)
4619 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4620 return a->dw_attr_val.v.val_vms_delta.lbl1;
4623 /* Return the end label of a delta attribute. */
4625 static inline const char *
4626 AT_vms_delta2 (dw_attr_ref a)
4628 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4629 return a->dw_attr_val.v.val_vms_delta.lbl2;
4632 static inline const char *
4633 AT_lbl (dw_attr_ref a)
4635 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
4636 || AT_class (a) == dw_val_class_lineptr
4637 || AT_class (a) == dw_val_class_macptr));
4638 return a->dw_attr_val.v.val_lbl_id;
4641 /* Get the attribute of type attr_kind. */
4644 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4648 dw_die_ref spec = NULL;
4653 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
4654 if (a->dw_attr == attr_kind)
4656 else if (a->dw_attr == DW_AT_specification
4657 || a->dw_attr == DW_AT_abstract_origin)
4661 return get_AT (spec, attr_kind);
4666 /* Return the "low pc" attribute value, typically associated with a subprogram
4667 DIE. Return null if the "low pc" attribute is either not present, or if it
4668 cannot be represented as an assembler label identifier. */
4670 static inline const char *
4671 get_AT_low_pc (dw_die_ref die)
4673 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4675 return a ? AT_lbl (a) : NULL;
4678 /* Return the "high pc" attribute value, typically associated with a subprogram
4679 DIE. Return null if the "high pc" attribute is either not present, or if it
4680 cannot be represented as an assembler label identifier. */
4682 static inline const char *
4683 get_AT_hi_pc (dw_die_ref die)
4685 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4687 return a ? AT_lbl (a) : NULL;
4690 /* Return the value of the string attribute designated by ATTR_KIND, or
4691 NULL if it is not present. */
4693 static inline const char *
4694 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4696 dw_attr_ref a = get_AT (die, attr_kind);
4698 return a ? AT_string (a) : NULL;
4701 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4702 if it is not present. */
4705 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4707 dw_attr_ref a = get_AT (die, attr_kind);
4709 return a ? AT_flag (a) : 0;
4712 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4713 if it is not present. */
4715 static inline unsigned
4716 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4718 dw_attr_ref a = get_AT (die, attr_kind);
4720 return a ? AT_unsigned (a) : 0;
4723 static inline dw_die_ref
4724 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4726 dw_attr_ref a = get_AT (die, attr_kind);
4728 return a ? AT_ref (a) : NULL;
4731 static inline struct dwarf_file_data *
4732 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
4734 dw_attr_ref a = get_AT (die, attr_kind);
4736 return a ? AT_file (a) : NULL;
4739 /* Return TRUE if the language is C++. */
4744 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4746 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
4749 /* Return TRUE if the language is Fortran. */
4754 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4756 return (lang == DW_LANG_Fortran77
4757 || lang == DW_LANG_Fortran90
4758 || lang == DW_LANG_Fortran95);
4761 /* Return TRUE if the language is Ada. */
4766 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4768 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4771 /* Remove the specified attribute if present. */
4774 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4782 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
4783 if (a->dw_attr == attr_kind)
4785 if (AT_class (a) == dw_val_class_str)
4786 if (a->dw_attr_val.v.val_str->refcount)
4787 a->dw_attr_val.v.val_str->refcount--;
4789 /* VEC_ordered_remove should help reduce the number of abbrevs
4791 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
4796 /* Remove CHILD from its parent. PREV must have the property that
4797 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4800 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
4802 gcc_assert (child->die_parent == prev->die_parent);
4803 gcc_assert (prev->die_sib == child);
4806 gcc_assert (child->die_parent->die_child == child);
4810 prev->die_sib = child->die_sib;
4811 if (child->die_parent->die_child == child)
4812 child->die_parent->die_child = prev;
4815 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4816 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4819 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
4821 dw_die_ref parent = old_child->die_parent;
4823 gcc_assert (parent == prev->die_parent);
4824 gcc_assert (prev->die_sib == old_child);
4826 new_child->die_parent = parent;
4827 if (prev == old_child)
4829 gcc_assert (parent->die_child == old_child);
4830 new_child->die_sib = new_child;
4834 prev->die_sib = new_child;
4835 new_child->die_sib = old_child->die_sib;
4837 if (old_child->die_parent->die_child == old_child)
4838 old_child->die_parent->die_child = new_child;
4841 /* Move all children from OLD_PARENT to NEW_PARENT. */
4844 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
4847 new_parent->die_child = old_parent->die_child;
4848 old_parent->die_child = NULL;
4849 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
4852 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4856 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
4862 dw_die_ref prev = c;
4864 while (c->die_tag == tag)
4866 remove_child_with_prev (c, prev);
4867 /* Might have removed every child. */
4868 if (c == c->die_sib)
4872 } while (c != die->die_child);
4875 /* Add a CHILD_DIE as the last child of DIE. */
4878 add_child_die (dw_die_ref die, dw_die_ref child_die)
4880 /* FIXME this should probably be an assert. */
4881 if (! die || ! child_die)
4883 gcc_assert (die != child_die);
4885 child_die->die_parent = die;
4888 child_die->die_sib = die->die_child->die_sib;
4889 die->die_child->die_sib = child_die;
4892 child_die->die_sib = child_die;
4893 die->die_child = child_die;
4896 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4897 is the specification, to the end of PARENT's list of children.
4898 This is done by removing and re-adding it. */
4901 splice_child_die (dw_die_ref parent, dw_die_ref child)
4905 /* We want the declaration DIE from inside the class, not the
4906 specification DIE at toplevel. */
4907 if (child->die_parent != parent)
4909 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4915 gcc_assert (child->die_parent == parent
4916 || (child->die_parent
4917 == get_AT_ref (parent, DW_AT_specification)));
4919 for (p = child->die_parent->die_child; ; p = p->die_sib)
4920 if (p->die_sib == child)
4922 remove_child_with_prev (child, p);
4926 add_child_die (parent, child);
4929 /* Return a pointer to a newly created DIE node. */
4931 static inline dw_die_ref
4932 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
4934 dw_die_ref die = ggc_alloc_cleared_die_node ();
4936 die->die_tag = tag_value;
4938 if (parent_die != NULL)
4939 add_child_die (parent_die, die);
4942 limbo_die_node *limbo_node;
4944 limbo_node = ggc_alloc_cleared_limbo_die_node ();
4945 limbo_node->die = die;
4946 limbo_node->created_for = t;
4947 limbo_node->next = limbo_die_list;
4948 limbo_die_list = limbo_node;
4954 /* Return the DIE associated with the given type specifier. */
4956 static inline dw_die_ref
4957 lookup_type_die (tree type)
4959 return TYPE_SYMTAB_DIE (type);
4962 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4963 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4964 anonymous type instead the one of the naming typedef. */
4966 static inline dw_die_ref
4967 strip_naming_typedef (tree type, dw_die_ref type_die)
4970 && TREE_CODE (type) == RECORD_TYPE
4972 && type_die->die_tag == DW_TAG_typedef
4973 && is_naming_typedef_decl (TYPE_NAME (type)))
4974 type_die = get_AT_ref (type_die, DW_AT_type);
4978 /* Like lookup_type_die, but if type is an anonymous type named by a
4979 typedef[1], return the DIE of the anonymous type instead the one of
4980 the naming typedef. This is because in gen_typedef_die, we did
4981 equate the anonymous struct named by the typedef with the DIE of
4982 the naming typedef. So by default, lookup_type_die on an anonymous
4983 struct yields the DIE of the naming typedef.
4985 [1]: Read the comment of is_naming_typedef_decl to learn about what
4986 a naming typedef is. */
4988 static inline dw_die_ref
4989 lookup_type_die_strip_naming_typedef (tree type)
4991 dw_die_ref die = lookup_type_die (type);
4992 return strip_naming_typedef (type, die);
4995 /* Equate a DIE to a given type specifier. */
4998 equate_type_number_to_die (tree type, dw_die_ref type_die)
5000 TYPE_SYMTAB_DIE (type) = type_die;
5003 /* Returns a hash value for X (which really is a die_struct). */
5006 decl_die_table_hash (const void *x)
5008 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5011 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5014 decl_die_table_eq (const void *x, const void *y)
5016 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5019 /* Return the DIE associated with a given declaration. */
5021 static inline dw_die_ref
5022 lookup_decl_die (tree decl)
5024 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5027 /* Returns a hash value for X (which really is a var_loc_list). */
5030 decl_loc_table_hash (const void *x)
5032 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5035 /* Return nonzero if decl_id of var_loc_list X is the same as
5039 decl_loc_table_eq (const void *x, const void *y)
5041 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5044 /* Return the var_loc list associated with a given declaration. */
5046 static inline var_loc_list *
5047 lookup_decl_loc (const_tree decl)
5049 if (!decl_loc_table)
5051 return (var_loc_list *)
5052 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5055 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5058 cached_dw_loc_list_table_hash (const void *x)
5060 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
5063 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5067 cached_dw_loc_list_table_eq (const void *x, const void *y)
5069 return (((const cached_dw_loc_list *) x)->decl_id
5070 == DECL_UID ((const_tree) y));
5073 /* Equate a DIE to a particular declaration. */
5076 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5078 unsigned int decl_id = DECL_UID (decl);
5081 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5083 decl_die->decl_id = decl_id;
5086 /* Return how many bits covers PIECE EXPR_LIST. */
5089 decl_piece_bitsize (rtx piece)
5091 int ret = (int) GET_MODE (piece);
5094 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
5095 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
5096 return INTVAL (XEXP (XEXP (piece, 0), 0));
5099 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5102 decl_piece_varloc_ptr (rtx piece)
5104 if ((int) GET_MODE (piece))
5105 return &XEXP (piece, 0);
5107 return &XEXP (XEXP (piece, 0), 1);
5110 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5111 Next is the chain of following piece nodes. */
5114 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
5116 if (bitsize <= (int) MAX_MACHINE_MODE)
5117 return alloc_EXPR_LIST (bitsize, loc_note, next);
5119 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
5124 /* Return rtx that should be stored into loc field for
5125 LOC_NOTE and BITPOS/BITSIZE. */
5128 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
5129 HOST_WIDE_INT bitsize)
5133 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
5135 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
5140 /* This function either modifies location piece list *DEST in
5141 place (if SRC and INNER is NULL), or copies location piece list
5142 *SRC to *DEST while modifying it. Location BITPOS is modified
5143 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5144 not copied and if needed some padding around it is added.
5145 When modifying in place, DEST should point to EXPR_LIST where
5146 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5147 to the start of the whole list and INNER points to the EXPR_LIST
5148 where earlier pieces cover PIECE_BITPOS bits. */
5151 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
5152 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
5153 HOST_WIDE_INT bitsize, rtx loc_note)
5156 bool copy = inner != NULL;
5160 /* First copy all nodes preceeding the current bitpos. */
5161 while (src != inner)
5163 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5164 decl_piece_bitsize (*src), NULL_RTX);
5165 dest = &XEXP (*dest, 1);
5166 src = &XEXP (*src, 1);
5169 /* Add padding if needed. */
5170 if (bitpos != piece_bitpos)
5172 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
5173 copy ? NULL_RTX : *dest);
5174 dest = &XEXP (*dest, 1);
5176 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
5179 /* A piece with correct bitpos and bitsize already exist,
5180 just update the location for it and return. */
5181 *decl_piece_varloc_ptr (*dest) = loc_note;
5184 /* Add the piece that changed. */
5185 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
5186 dest = &XEXP (*dest, 1);
5187 /* Skip over pieces that overlap it. */
5188 diff = bitpos - piece_bitpos + bitsize;
5191 while (diff > 0 && *src)
5194 diff -= decl_piece_bitsize (piece);
5196 src = &XEXP (piece, 1);
5199 *src = XEXP (piece, 1);
5200 free_EXPR_LIST_node (piece);
5203 /* Add padding if needed. */
5204 if (diff < 0 && *src)
5208 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
5209 dest = &XEXP (*dest, 1);
5213 /* Finally copy all nodes following it. */
5216 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5217 decl_piece_bitsize (*src), NULL_RTX);
5218 dest = &XEXP (*dest, 1);
5219 src = &XEXP (*src, 1);
5223 /* Add a variable location node to the linked list for DECL. */
5225 static struct var_loc_node *
5226 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
5228 unsigned int decl_id;
5231 struct var_loc_node *loc = NULL;
5232 HOST_WIDE_INT bitsize = -1, bitpos = -1;
5234 if (DECL_DEBUG_EXPR_IS_FROM (decl))
5236 tree realdecl = DECL_DEBUG_EXPR (decl);
5237 if (realdecl && handled_component_p (realdecl))
5239 HOST_WIDE_INT maxsize;
5242 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
5243 if (!DECL_P (innerdecl)
5244 || DECL_IGNORED_P (innerdecl)
5245 || TREE_STATIC (innerdecl)
5247 || bitpos + bitsize > 256
5248 || bitsize != maxsize)
5254 decl_id = DECL_UID (decl);
5255 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5258 temp = ggc_alloc_cleared_var_loc_list ();
5259 temp->decl_id = decl_id;
5263 temp = (var_loc_list *) *slot;
5265 /* For PARM_DECLs try to keep around the original incoming value,
5266 even if that means we'll emit a zero-range .debug_loc entry. */
5268 && temp->first == temp->last
5269 && TREE_CODE (decl) == PARM_DECL
5270 && GET_CODE (temp->first->loc) == NOTE
5271 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
5272 && DECL_INCOMING_RTL (decl)
5273 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
5274 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
5275 == GET_CODE (DECL_INCOMING_RTL (decl))
5276 && prev_real_insn (temp->first->loc) == NULL_RTX
5278 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
5279 NOTE_VAR_LOCATION_LOC (loc_note))
5280 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
5281 != NOTE_VAR_LOCATION_STATUS (loc_note))))
5283 loc = ggc_alloc_cleared_var_loc_node ();
5284 temp->first->next = loc;
5286 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5288 else if (temp->last)
5290 struct var_loc_node *last = temp->last, *unused = NULL;
5291 rtx *piece_loc = NULL, last_loc_note;
5292 int piece_bitpos = 0;
5296 gcc_assert (last->next == NULL);
5298 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
5300 piece_loc = &last->loc;
5303 int cur_bitsize = decl_piece_bitsize (*piece_loc);
5304 if (piece_bitpos + cur_bitsize > bitpos)
5306 piece_bitpos += cur_bitsize;
5307 piece_loc = &XEXP (*piece_loc, 1);
5311 /* TEMP->LAST here is either pointer to the last but one or
5312 last element in the chained list, LAST is pointer to the
5314 if (label && strcmp (last->label, label) == 0)
5316 /* For SRA optimized variables if there weren't any real
5317 insns since last note, just modify the last node. */
5318 if (piece_loc != NULL)
5320 adjust_piece_list (piece_loc, NULL, NULL,
5321 bitpos, piece_bitpos, bitsize, loc_note);
5324 /* If the last note doesn't cover any instructions, remove it. */
5325 if (temp->last != last)
5327 temp->last->next = NULL;
5330 gcc_assert (strcmp (last->label, label) != 0);
5334 gcc_assert (temp->first == temp->last
5335 || (temp->first->next == temp->last
5336 && TREE_CODE (decl) == PARM_DECL));
5337 memset (temp->last, '\0', sizeof (*temp->last));
5338 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
5342 if (bitsize == -1 && NOTE_P (last->loc))
5343 last_loc_note = last->loc;
5344 else if (piece_loc != NULL
5345 && *piece_loc != NULL_RTX
5346 && piece_bitpos == bitpos
5347 && decl_piece_bitsize (*piece_loc) == bitsize)
5348 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
5350 last_loc_note = NULL_RTX;
5351 /* If the current location is the same as the end of the list,
5352 and either both or neither of the locations is uninitialized,
5353 we have nothing to do. */
5354 if (last_loc_note == NULL_RTX
5355 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
5356 NOTE_VAR_LOCATION_LOC (loc_note)))
5357 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5358 != NOTE_VAR_LOCATION_STATUS (loc_note))
5359 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5360 == VAR_INIT_STATUS_UNINITIALIZED)
5361 || (NOTE_VAR_LOCATION_STATUS (loc_note)
5362 == VAR_INIT_STATUS_UNINITIALIZED))))
5364 /* Add LOC to the end of list and update LAST. If the last
5365 element of the list has been removed above, reuse its
5366 memory for the new node, otherwise allocate a new one. */
5370 memset (loc, '\0', sizeof (*loc));
5373 loc = ggc_alloc_cleared_var_loc_node ();
5374 if (bitsize == -1 || piece_loc == NULL)
5375 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5377 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
5378 bitpos, piece_bitpos, bitsize, loc_note);
5380 /* Ensure TEMP->LAST will point either to the new last but one
5381 element of the chain, or to the last element in it. */
5382 if (last != temp->last)
5390 loc = ggc_alloc_cleared_var_loc_node ();
5393 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5398 /* Keep track of the number of spaces used to indent the
5399 output of the debugging routines that print the structure of
5400 the DIE internal representation. */
5401 static int print_indent;
5403 /* Indent the line the number of spaces given by print_indent. */
5406 print_spaces (FILE *outfile)
5408 fprintf (outfile, "%*s", print_indent, "");
5411 /* Print a type signature in hex. */
5414 print_signature (FILE *outfile, char *sig)
5418 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
5419 fprintf (outfile, "%02x", sig[i] & 0xff);
5422 /* Print the information associated with a given DIE, and its children.
5423 This routine is a debugging aid only. */
5426 print_die (dw_die_ref die, FILE *outfile)
5432 print_spaces (outfile);
5433 fprintf (outfile, "DIE %4ld: %s (%p)\n",
5434 die->die_offset, dwarf_tag_name (die->die_tag),
5436 print_spaces (outfile);
5437 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5438 fprintf (outfile, " offset: %ld", die->die_offset);
5439 fprintf (outfile, " mark: %d\n", die->die_mark);
5441 if (use_debug_types && die->die_id.die_type_node)
5443 print_spaces (outfile);
5444 fprintf (outfile, " signature: ");
5445 print_signature (outfile, die->die_id.die_type_node->signature);
5446 fprintf (outfile, "\n");
5449 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5451 print_spaces (outfile);
5452 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5454 switch (AT_class (a))
5456 case dw_val_class_addr:
5457 fprintf (outfile, "address");
5459 case dw_val_class_offset:
5460 fprintf (outfile, "offset");
5462 case dw_val_class_loc:
5463 fprintf (outfile, "location descriptor");
5465 case dw_val_class_loc_list:
5466 fprintf (outfile, "location list -> label:%s",
5467 AT_loc_list (a)->ll_symbol);
5469 case dw_val_class_range_list:
5470 fprintf (outfile, "range list");
5472 case dw_val_class_const:
5473 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5475 case dw_val_class_unsigned_const:
5476 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5478 case dw_val_class_const_double:
5479 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
5480 HOST_WIDE_INT_PRINT_UNSIGNED")",
5481 a->dw_attr_val.v.val_double.high,
5482 a->dw_attr_val.v.val_double.low);
5484 case dw_val_class_vec:
5485 fprintf (outfile, "floating-point or vector constant");
5487 case dw_val_class_flag:
5488 fprintf (outfile, "%u", AT_flag (a));
5490 case dw_val_class_die_ref:
5491 if (AT_ref (a) != NULL)
5493 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
5495 fprintf (outfile, "die -> signature: ");
5496 print_signature (outfile,
5497 AT_ref (a)->die_id.die_type_node->signature);
5499 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
5500 fprintf (outfile, "die -> label: %s",
5501 AT_ref (a)->die_id.die_symbol);
5503 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5504 fprintf (outfile, " (%p)", (void *) AT_ref (a));
5507 fprintf (outfile, "die -> <null>");
5509 case dw_val_class_vms_delta:
5510 fprintf (outfile, "delta: @slotcount(%s-%s)",
5511 AT_vms_delta2 (a), AT_vms_delta1 (a));
5513 case dw_val_class_lbl_id:
5514 case dw_val_class_lineptr:
5515 case dw_val_class_macptr:
5516 fprintf (outfile, "label: %s", AT_lbl (a));
5518 case dw_val_class_str:
5519 if (AT_string (a) != NULL)
5520 fprintf (outfile, "\"%s\"", AT_string (a));
5522 fprintf (outfile, "<null>");
5524 case dw_val_class_file:
5525 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
5526 AT_file (a)->emitted_number);
5528 case dw_val_class_data8:
5532 for (i = 0; i < 8; i++)
5533 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
5540 fprintf (outfile, "\n");
5543 if (die->die_child != NULL)
5546 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5549 if (print_indent == 0)
5550 fprintf (outfile, "\n");
5553 /* Print the information collected for a given DIE. */
5556 debug_dwarf_die (dw_die_ref die)
5558 print_die (die, stderr);
5561 /* Print all DWARF information collected for the compilation unit.
5562 This routine is a debugging aid only. */
5568 print_die (comp_unit_die (), stderr);
5571 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5572 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5573 DIE that marks the start of the DIEs for this include file. */
5576 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5578 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5579 dw_die_ref new_unit = gen_compile_unit_die (filename);
5581 new_unit->die_sib = old_unit;
5585 /* Close an include-file CU and reopen the enclosing one. */
5588 pop_compile_unit (dw_die_ref old_unit)
5590 dw_die_ref new_unit = old_unit->die_sib;
5592 old_unit->die_sib = NULL;
5596 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5597 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5599 /* Calculate the checksum of a location expression. */
5602 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5606 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
5608 CHECKSUM (loc->dw_loc_oprnd1);
5609 CHECKSUM (loc->dw_loc_oprnd2);
5612 /* Calculate the checksum of an attribute. */
5615 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5617 dw_loc_descr_ref loc;
5620 CHECKSUM (at->dw_attr);
5622 /* We don't care that this was compiled with a different compiler
5623 snapshot; if the output is the same, that's what matters. */
5624 if (at->dw_attr == DW_AT_producer)
5627 switch (AT_class (at))
5629 case dw_val_class_const:
5630 CHECKSUM (at->dw_attr_val.v.val_int);
5632 case dw_val_class_unsigned_const:
5633 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5635 case dw_val_class_const_double:
5636 CHECKSUM (at->dw_attr_val.v.val_double);
5638 case dw_val_class_vec:
5639 CHECKSUM (at->dw_attr_val.v.val_vec);
5641 case dw_val_class_flag:
5642 CHECKSUM (at->dw_attr_val.v.val_flag);
5644 case dw_val_class_str:
5645 CHECKSUM_STRING (AT_string (at));
5648 case dw_val_class_addr:
5650 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5651 CHECKSUM_STRING (XSTR (r, 0));
5654 case dw_val_class_offset:
5655 CHECKSUM (at->dw_attr_val.v.val_offset);
5658 case dw_val_class_loc:
5659 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5660 loc_checksum (loc, ctx);
5663 case dw_val_class_die_ref:
5664 die_checksum (AT_ref (at), ctx, mark);
5667 case dw_val_class_fde_ref:
5668 case dw_val_class_vms_delta:
5669 case dw_val_class_lbl_id:
5670 case dw_val_class_lineptr:
5671 case dw_val_class_macptr:
5674 case dw_val_class_file:
5675 CHECKSUM_STRING (AT_file (at)->filename);
5678 case dw_val_class_data8:
5679 CHECKSUM (at->dw_attr_val.v.val_data8);
5687 /* Calculate the checksum of a DIE. */
5690 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5696 /* To avoid infinite recursion. */
5699 CHECKSUM (die->die_mark);
5702 die->die_mark = ++(*mark);
5704 CHECKSUM (die->die_tag);
5706 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5707 attr_checksum (a, ctx, mark);
5709 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
5713 #undef CHECKSUM_STRING
5715 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5716 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5717 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5718 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5719 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5720 #define CHECKSUM_ATTR(FOO) \
5721 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5723 /* Calculate the checksum of a number in signed LEB128 format. */
5726 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
5733 byte = (value & 0x7f);
5735 more = !((value == 0 && (byte & 0x40) == 0)
5736 || (value == -1 && (byte & 0x40) != 0));
5745 /* Calculate the checksum of a number in unsigned LEB128 format. */
5748 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
5752 unsigned char byte = (value & 0x7f);
5755 /* More bytes to follow. */
5763 /* Checksum the context of the DIE. This adds the names of any
5764 surrounding namespaces or structures to the checksum. */
5767 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
5771 int tag = die->die_tag;
5773 if (tag != DW_TAG_namespace
5774 && tag != DW_TAG_structure_type
5775 && tag != DW_TAG_class_type)
5778 name = get_AT_string (die, DW_AT_name);
5780 spec = get_AT_ref (die, DW_AT_specification);
5784 if (die->die_parent != NULL)
5785 checksum_die_context (die->die_parent, ctx);
5787 CHECKSUM_ULEB128 ('C');
5788 CHECKSUM_ULEB128 (tag);
5790 CHECKSUM_STRING (name);
5793 /* Calculate the checksum of a location expression. */
5796 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5798 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5799 were emitted as a DW_FORM_sdata instead of a location expression. */
5800 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
5802 CHECKSUM_ULEB128 (DW_FORM_sdata);
5803 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
5807 /* Otherwise, just checksum the raw location expression. */
5810 CHECKSUM_ULEB128 (loc->dw_loc_opc);
5811 CHECKSUM (loc->dw_loc_oprnd1);
5812 CHECKSUM (loc->dw_loc_oprnd2);
5813 loc = loc->dw_loc_next;
5817 /* Calculate the checksum of an attribute. */
5820 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
5821 struct md5_ctx *ctx, int *mark)
5823 dw_loc_descr_ref loc;
5826 if (AT_class (at) == dw_val_class_die_ref)
5828 dw_die_ref target_die = AT_ref (at);
5830 /* For pointer and reference types, we checksum only the (qualified)
5831 name of the target type (if there is a name). For friend entries,
5832 we checksum only the (qualified) name of the target type or function.
5833 This allows the checksum to remain the same whether the target type
5834 is complete or not. */
5835 if ((at->dw_attr == DW_AT_type
5836 && (tag == DW_TAG_pointer_type
5837 || tag == DW_TAG_reference_type
5838 || tag == DW_TAG_rvalue_reference_type
5839 || tag == DW_TAG_ptr_to_member_type))
5840 || (at->dw_attr == DW_AT_friend
5841 && tag == DW_TAG_friend))
5843 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
5845 if (name_attr != NULL)
5847 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
5851 CHECKSUM_ULEB128 ('N');
5852 CHECKSUM_ULEB128 (at->dw_attr);
5853 if (decl->die_parent != NULL)
5854 checksum_die_context (decl->die_parent, ctx);
5855 CHECKSUM_ULEB128 ('E');
5856 CHECKSUM_STRING (AT_string (name_attr));
5861 /* For all other references to another DIE, we check to see if the
5862 target DIE has already been visited. If it has, we emit a
5863 backward reference; if not, we descend recursively. */
5864 if (target_die->die_mark > 0)
5866 CHECKSUM_ULEB128 ('R');
5867 CHECKSUM_ULEB128 (at->dw_attr);
5868 CHECKSUM_ULEB128 (target_die->die_mark);
5872 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
5876 target_die->die_mark = ++(*mark);
5877 CHECKSUM_ULEB128 ('T');
5878 CHECKSUM_ULEB128 (at->dw_attr);
5879 if (decl->die_parent != NULL)
5880 checksum_die_context (decl->die_parent, ctx);
5881 die_checksum_ordered (target_die, ctx, mark);
5886 CHECKSUM_ULEB128 ('A');
5887 CHECKSUM_ULEB128 (at->dw_attr);
5889 switch (AT_class (at))
5891 case dw_val_class_const:
5892 CHECKSUM_ULEB128 (DW_FORM_sdata);
5893 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
5896 case dw_val_class_unsigned_const:
5897 CHECKSUM_ULEB128 (DW_FORM_sdata);
5898 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
5901 case dw_val_class_const_double:
5902 CHECKSUM_ULEB128 (DW_FORM_block);
5903 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
5904 CHECKSUM (at->dw_attr_val.v.val_double);
5907 case dw_val_class_vec:
5908 CHECKSUM_ULEB128 (DW_FORM_block);
5909 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
5910 CHECKSUM (at->dw_attr_val.v.val_vec);
5913 case dw_val_class_flag:
5914 CHECKSUM_ULEB128 (DW_FORM_flag);
5915 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
5918 case dw_val_class_str:
5919 CHECKSUM_ULEB128 (DW_FORM_string);
5920 CHECKSUM_STRING (AT_string (at));
5923 case dw_val_class_addr:
5925 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5926 CHECKSUM_ULEB128 (DW_FORM_string);
5927 CHECKSUM_STRING (XSTR (r, 0));
5930 case dw_val_class_offset:
5931 CHECKSUM_ULEB128 (DW_FORM_sdata);
5932 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
5935 case dw_val_class_loc:
5936 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5937 loc_checksum_ordered (loc, ctx);
5940 case dw_val_class_fde_ref:
5941 case dw_val_class_lbl_id:
5942 case dw_val_class_lineptr:
5943 case dw_val_class_macptr:
5946 case dw_val_class_file:
5947 CHECKSUM_ULEB128 (DW_FORM_string);
5948 CHECKSUM_STRING (AT_file (at)->filename);
5951 case dw_val_class_data8:
5952 CHECKSUM (at->dw_attr_val.v.val_data8);
5960 struct checksum_attributes
5962 dw_attr_ref at_name;
5963 dw_attr_ref at_type;
5964 dw_attr_ref at_friend;
5965 dw_attr_ref at_accessibility;
5966 dw_attr_ref at_address_class;
5967 dw_attr_ref at_allocated;
5968 dw_attr_ref at_artificial;
5969 dw_attr_ref at_associated;
5970 dw_attr_ref at_binary_scale;
5971 dw_attr_ref at_bit_offset;
5972 dw_attr_ref at_bit_size;
5973 dw_attr_ref at_bit_stride;
5974 dw_attr_ref at_byte_size;
5975 dw_attr_ref at_byte_stride;
5976 dw_attr_ref at_const_value;
5977 dw_attr_ref at_containing_type;
5978 dw_attr_ref at_count;
5979 dw_attr_ref at_data_location;
5980 dw_attr_ref at_data_member_location;
5981 dw_attr_ref at_decimal_scale;
5982 dw_attr_ref at_decimal_sign;
5983 dw_attr_ref at_default_value;
5984 dw_attr_ref at_digit_count;
5985 dw_attr_ref at_discr;
5986 dw_attr_ref at_discr_list;
5987 dw_attr_ref at_discr_value;
5988 dw_attr_ref at_encoding;
5989 dw_attr_ref at_endianity;
5990 dw_attr_ref at_explicit;
5991 dw_attr_ref at_is_optional;
5992 dw_attr_ref at_location;
5993 dw_attr_ref at_lower_bound;
5994 dw_attr_ref at_mutable;
5995 dw_attr_ref at_ordering;
5996 dw_attr_ref at_picture_string;
5997 dw_attr_ref at_prototyped;
5998 dw_attr_ref at_small;
5999 dw_attr_ref at_segment;
6000 dw_attr_ref at_string_length;
6001 dw_attr_ref at_threads_scaled;
6002 dw_attr_ref at_upper_bound;
6003 dw_attr_ref at_use_location;
6004 dw_attr_ref at_use_UTF8;
6005 dw_attr_ref at_variable_parameter;
6006 dw_attr_ref at_virtuality;
6007 dw_attr_ref at_visibility;
6008 dw_attr_ref at_vtable_elem_location;
6011 /* Collect the attributes that we will want to use for the checksum. */
6014 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
6019 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6030 attrs->at_friend = a;
6032 case DW_AT_accessibility:
6033 attrs->at_accessibility = a;
6035 case DW_AT_address_class:
6036 attrs->at_address_class = a;
6038 case DW_AT_allocated:
6039 attrs->at_allocated = a;
6041 case DW_AT_artificial:
6042 attrs->at_artificial = a;
6044 case DW_AT_associated:
6045 attrs->at_associated = a;
6047 case DW_AT_binary_scale:
6048 attrs->at_binary_scale = a;
6050 case DW_AT_bit_offset:
6051 attrs->at_bit_offset = a;
6053 case DW_AT_bit_size:
6054 attrs->at_bit_size = a;
6056 case DW_AT_bit_stride:
6057 attrs->at_bit_stride = a;
6059 case DW_AT_byte_size:
6060 attrs->at_byte_size = a;
6062 case DW_AT_byte_stride:
6063 attrs->at_byte_stride = a;
6065 case DW_AT_const_value:
6066 attrs->at_const_value = a;
6068 case DW_AT_containing_type:
6069 attrs->at_containing_type = a;
6072 attrs->at_count = a;
6074 case DW_AT_data_location:
6075 attrs->at_data_location = a;
6077 case DW_AT_data_member_location:
6078 attrs->at_data_member_location = a;
6080 case DW_AT_decimal_scale:
6081 attrs->at_decimal_scale = a;
6083 case DW_AT_decimal_sign:
6084 attrs->at_decimal_sign = a;
6086 case DW_AT_default_value:
6087 attrs->at_default_value = a;
6089 case DW_AT_digit_count:
6090 attrs->at_digit_count = a;
6093 attrs->at_discr = a;
6095 case DW_AT_discr_list:
6096 attrs->at_discr_list = a;
6098 case DW_AT_discr_value:
6099 attrs->at_discr_value = a;
6101 case DW_AT_encoding:
6102 attrs->at_encoding = a;
6104 case DW_AT_endianity:
6105 attrs->at_endianity = a;
6107 case DW_AT_explicit:
6108 attrs->at_explicit = a;
6110 case DW_AT_is_optional:
6111 attrs->at_is_optional = a;
6113 case DW_AT_location:
6114 attrs->at_location = a;
6116 case DW_AT_lower_bound:
6117 attrs->at_lower_bound = a;
6120 attrs->at_mutable = a;
6122 case DW_AT_ordering:
6123 attrs->at_ordering = a;
6125 case DW_AT_picture_string:
6126 attrs->at_picture_string = a;
6128 case DW_AT_prototyped:
6129 attrs->at_prototyped = a;
6132 attrs->at_small = a;
6135 attrs->at_segment = a;
6137 case DW_AT_string_length:
6138 attrs->at_string_length = a;
6140 case DW_AT_threads_scaled:
6141 attrs->at_threads_scaled = a;
6143 case DW_AT_upper_bound:
6144 attrs->at_upper_bound = a;
6146 case DW_AT_use_location:
6147 attrs->at_use_location = a;
6149 case DW_AT_use_UTF8:
6150 attrs->at_use_UTF8 = a;
6152 case DW_AT_variable_parameter:
6153 attrs->at_variable_parameter = a;
6155 case DW_AT_virtuality:
6156 attrs->at_virtuality = a;
6158 case DW_AT_visibility:
6159 attrs->at_visibility = a;
6161 case DW_AT_vtable_elem_location:
6162 attrs->at_vtable_elem_location = a;
6170 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6173 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6177 struct checksum_attributes attrs;
6179 CHECKSUM_ULEB128 ('D');
6180 CHECKSUM_ULEB128 (die->die_tag);
6182 memset (&attrs, 0, sizeof (attrs));
6184 decl = get_AT_ref (die, DW_AT_specification);
6186 collect_checksum_attributes (&attrs, decl);
6187 collect_checksum_attributes (&attrs, die);
6189 CHECKSUM_ATTR (attrs.at_name);
6190 CHECKSUM_ATTR (attrs.at_accessibility);
6191 CHECKSUM_ATTR (attrs.at_address_class);
6192 CHECKSUM_ATTR (attrs.at_allocated);
6193 CHECKSUM_ATTR (attrs.at_artificial);
6194 CHECKSUM_ATTR (attrs.at_associated);
6195 CHECKSUM_ATTR (attrs.at_binary_scale);
6196 CHECKSUM_ATTR (attrs.at_bit_offset);
6197 CHECKSUM_ATTR (attrs.at_bit_size);
6198 CHECKSUM_ATTR (attrs.at_bit_stride);
6199 CHECKSUM_ATTR (attrs.at_byte_size);
6200 CHECKSUM_ATTR (attrs.at_byte_stride);
6201 CHECKSUM_ATTR (attrs.at_const_value);
6202 CHECKSUM_ATTR (attrs.at_containing_type);
6203 CHECKSUM_ATTR (attrs.at_count);
6204 CHECKSUM_ATTR (attrs.at_data_location);
6205 CHECKSUM_ATTR (attrs.at_data_member_location);
6206 CHECKSUM_ATTR (attrs.at_decimal_scale);
6207 CHECKSUM_ATTR (attrs.at_decimal_sign);
6208 CHECKSUM_ATTR (attrs.at_default_value);
6209 CHECKSUM_ATTR (attrs.at_digit_count);
6210 CHECKSUM_ATTR (attrs.at_discr);
6211 CHECKSUM_ATTR (attrs.at_discr_list);
6212 CHECKSUM_ATTR (attrs.at_discr_value);
6213 CHECKSUM_ATTR (attrs.at_encoding);
6214 CHECKSUM_ATTR (attrs.at_endianity);
6215 CHECKSUM_ATTR (attrs.at_explicit);
6216 CHECKSUM_ATTR (attrs.at_is_optional);
6217 CHECKSUM_ATTR (attrs.at_location);
6218 CHECKSUM_ATTR (attrs.at_lower_bound);
6219 CHECKSUM_ATTR (attrs.at_mutable);
6220 CHECKSUM_ATTR (attrs.at_ordering);
6221 CHECKSUM_ATTR (attrs.at_picture_string);
6222 CHECKSUM_ATTR (attrs.at_prototyped);
6223 CHECKSUM_ATTR (attrs.at_small);
6224 CHECKSUM_ATTR (attrs.at_segment);
6225 CHECKSUM_ATTR (attrs.at_string_length);
6226 CHECKSUM_ATTR (attrs.at_threads_scaled);
6227 CHECKSUM_ATTR (attrs.at_upper_bound);
6228 CHECKSUM_ATTR (attrs.at_use_location);
6229 CHECKSUM_ATTR (attrs.at_use_UTF8);
6230 CHECKSUM_ATTR (attrs.at_variable_parameter);
6231 CHECKSUM_ATTR (attrs.at_virtuality);
6232 CHECKSUM_ATTR (attrs.at_visibility);
6233 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
6234 CHECKSUM_ATTR (attrs.at_type);
6235 CHECKSUM_ATTR (attrs.at_friend);
6237 /* Checksum the child DIEs, except for nested types and member functions. */
6240 dw_attr_ref name_attr;
6243 name_attr = get_AT (c, DW_AT_name);
6244 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
6245 && name_attr != NULL)
6247 CHECKSUM_ULEB128 ('S');
6248 CHECKSUM_ULEB128 (c->die_tag);
6249 CHECKSUM_STRING (AT_string (name_attr));
6253 /* Mark this DIE so it gets processed when unmarking. */
6254 if (c->die_mark == 0)
6256 die_checksum_ordered (c, ctx, mark);
6258 } while (c != die->die_child);
6260 CHECKSUM_ULEB128 (0);
6264 #undef CHECKSUM_STRING
6265 #undef CHECKSUM_ATTR
6266 #undef CHECKSUM_LEB128
6267 #undef CHECKSUM_ULEB128
6269 /* Generate the type signature for DIE. This is computed by generating an
6270 MD5 checksum over the DIE's tag, its relevant attributes, and its
6271 children. Attributes that are references to other DIEs are processed
6272 by recursion, using the MARK field to prevent infinite recursion.
6273 If the DIE is nested inside a namespace or another type, we also
6274 need to include that context in the signature. The lower 64 bits
6275 of the resulting MD5 checksum comprise the signature. */
6278 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
6282 unsigned char checksum[16];
6286 name = get_AT_string (die, DW_AT_name);
6287 decl = get_AT_ref (die, DW_AT_specification);
6289 /* First, compute a signature for just the type name (and its surrounding
6290 context, if any. This is stored in the type unit DIE for link-time
6291 ODR (one-definition rule) checking. */
6293 if (is_cxx() && name != NULL)
6295 md5_init_ctx (&ctx);
6297 /* Checksum the names of surrounding namespaces and structures. */
6298 if (decl != NULL && decl->die_parent != NULL)
6299 checksum_die_context (decl->die_parent, &ctx);
6301 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
6302 md5_process_bytes (name, strlen (name) + 1, &ctx);
6303 md5_finish_ctx (&ctx, checksum);
6305 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
6308 /* Next, compute the complete type signature. */
6310 md5_init_ctx (&ctx);
6312 die->die_mark = mark;
6314 /* Checksum the names of surrounding namespaces and structures. */
6315 if (decl != NULL && decl->die_parent != NULL)
6316 checksum_die_context (decl->die_parent, &ctx);
6318 /* Checksum the DIE and its children. */
6319 die_checksum_ordered (die, &ctx, &mark);
6320 unmark_all_dies (die);
6321 md5_finish_ctx (&ctx, checksum);
6323 /* Store the signature in the type node and link the type DIE and the
6324 type node together. */
6325 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
6326 DWARF_TYPE_SIGNATURE_SIZE);
6327 die->die_id.die_type_node = type_node;
6328 type_node->type_die = die;
6330 /* If the DIE is a specification, link its declaration to the type node
6333 decl->die_id.die_type_node = type_node;
6336 /* Do the location expressions look same? */
6338 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6340 return loc1->dw_loc_opc == loc2->dw_loc_opc
6341 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6342 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6345 /* Do the values look the same? */
6347 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6349 dw_loc_descr_ref loc1, loc2;
6352 if (v1->val_class != v2->val_class)
6355 switch (v1->val_class)
6357 case dw_val_class_const:
6358 return v1->v.val_int == v2->v.val_int;
6359 case dw_val_class_unsigned_const:
6360 return v1->v.val_unsigned == v2->v.val_unsigned;
6361 case dw_val_class_const_double:
6362 return v1->v.val_double.high == v2->v.val_double.high
6363 && v1->v.val_double.low == v2->v.val_double.low;
6364 case dw_val_class_vec:
6365 if (v1->v.val_vec.length != v2->v.val_vec.length
6366 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6368 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6369 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6372 case dw_val_class_flag:
6373 return v1->v.val_flag == v2->v.val_flag;
6374 case dw_val_class_str:
6375 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6377 case dw_val_class_addr:
6378 r1 = v1->v.val_addr;
6379 r2 = v2->v.val_addr;
6380 if (GET_CODE (r1) != GET_CODE (r2))
6382 return !rtx_equal_p (r1, r2);
6384 case dw_val_class_offset:
6385 return v1->v.val_offset == v2->v.val_offset;
6387 case dw_val_class_loc:
6388 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6390 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6391 if (!same_loc_p (loc1, loc2, mark))
6393 return !loc1 && !loc2;
6395 case dw_val_class_die_ref:
6396 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6398 case dw_val_class_fde_ref:
6399 case dw_val_class_vms_delta:
6400 case dw_val_class_lbl_id:
6401 case dw_val_class_lineptr:
6402 case dw_val_class_macptr:
6405 case dw_val_class_file:
6406 return v1->v.val_file == v2->v.val_file;
6408 case dw_val_class_data8:
6409 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
6416 /* Do the attributes look the same? */
6419 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6421 if (at1->dw_attr != at2->dw_attr)
6424 /* We don't care that this was compiled with a different compiler
6425 snapshot; if the output is the same, that's what matters. */
6426 if (at1->dw_attr == DW_AT_producer)
6429 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6432 /* Do the dies look the same? */
6435 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6441 /* To avoid infinite recursion. */
6443 return die1->die_mark == die2->die_mark;
6444 die1->die_mark = die2->die_mark = ++(*mark);
6446 if (die1->die_tag != die2->die_tag)
6449 if (VEC_length (dw_attr_node, die1->die_attr)
6450 != VEC_length (dw_attr_node, die2->die_attr))
6453 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
6454 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6457 c1 = die1->die_child;
6458 c2 = die2->die_child;
6467 if (!same_die_p (c1, c2, mark))
6471 if (c1 == die1->die_child)
6473 if (c2 == die2->die_child)
6483 /* Do the dies look the same? Wrapper around same_die_p. */
6486 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6489 int ret = same_die_p (die1, die2, &mark);
6491 unmark_all_dies (die1);
6492 unmark_all_dies (die2);
6497 /* The prefix to attach to symbols on DIEs in the current comdat debug
6499 static char *comdat_symbol_id;
6501 /* The index of the current symbol within the current comdat CU. */
6502 static unsigned int comdat_symbol_number;
6504 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6505 children, and set comdat_symbol_id accordingly. */
6508 compute_section_prefix (dw_die_ref unit_die)
6510 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6511 const char *base = die_name ? lbasename (die_name) : "anonymous";
6512 char *name = XALLOCAVEC (char, strlen (base) + 64);
6515 unsigned char checksum[16];
6518 /* Compute the checksum of the DIE, then append part of it as hex digits to
6519 the name filename of the unit. */
6521 md5_init_ctx (&ctx);
6523 die_checksum (unit_die, &ctx, &mark);
6524 unmark_all_dies (unit_die);
6525 md5_finish_ctx (&ctx, checksum);
6527 sprintf (name, "%s.", base);
6528 clean_symbol_name (name);
6530 p = name + strlen (name);
6531 for (i = 0; i < 4; i++)
6533 sprintf (p, "%.2x", checksum[i]);
6537 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
6538 comdat_symbol_number = 0;
6541 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6544 is_type_die (dw_die_ref die)
6546 switch (die->die_tag)
6548 case DW_TAG_array_type:
6549 case DW_TAG_class_type:
6550 case DW_TAG_interface_type:
6551 case DW_TAG_enumeration_type:
6552 case DW_TAG_pointer_type:
6553 case DW_TAG_reference_type:
6554 case DW_TAG_rvalue_reference_type:
6555 case DW_TAG_string_type:
6556 case DW_TAG_structure_type:
6557 case DW_TAG_subroutine_type:
6558 case DW_TAG_union_type:
6559 case DW_TAG_ptr_to_member_type:
6560 case DW_TAG_set_type:
6561 case DW_TAG_subrange_type:
6562 case DW_TAG_base_type:
6563 case DW_TAG_const_type:
6564 case DW_TAG_file_type:
6565 case DW_TAG_packed_type:
6566 case DW_TAG_volatile_type:
6567 case DW_TAG_typedef:
6574 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6575 Basically, we want to choose the bits that are likely to be shared between
6576 compilations (types) and leave out the bits that are specific to individual
6577 compilations (functions). */
6580 is_comdat_die (dw_die_ref c)
6582 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6583 we do for stabs. The advantage is a greater likelihood of sharing between
6584 objects that don't include headers in the same order (and therefore would
6585 put the base types in a different comdat). jason 8/28/00 */
6587 if (c->die_tag == DW_TAG_base_type)
6590 if (c->die_tag == DW_TAG_pointer_type
6591 || c->die_tag == DW_TAG_reference_type
6592 || c->die_tag == DW_TAG_rvalue_reference_type
6593 || c->die_tag == DW_TAG_const_type
6594 || c->die_tag == DW_TAG_volatile_type)
6596 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6598 return t ? is_comdat_die (t) : 0;
6601 return is_type_die (c);
6604 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6605 compilation unit. */
6608 is_symbol_die (dw_die_ref c)
6610 return (is_type_die (c)
6611 || is_declaration_die (c)
6612 || c->die_tag == DW_TAG_namespace
6613 || c->die_tag == DW_TAG_module);
6616 /* Returns true iff C is a compile-unit DIE. */
6619 is_cu_die (dw_die_ref c)
6621 return c && c->die_tag == DW_TAG_compile_unit;
6625 gen_internal_sym (const char *prefix)
6629 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6630 return xstrdup (buf);
6633 /* Assign symbols to all worthy DIEs under DIE. */
6636 assign_symbol_names (dw_die_ref die)
6640 if (is_symbol_die (die))
6642 if (comdat_symbol_id)
6644 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
6646 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6647 comdat_symbol_id, comdat_symbol_number++);
6648 die->die_id.die_symbol = xstrdup (p);
6651 die->die_id.die_symbol = gen_internal_sym ("LDIE");
6654 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6657 struct cu_hash_table_entry
6660 unsigned min_comdat_num, max_comdat_num;
6661 struct cu_hash_table_entry *next;
6664 /* Routines to manipulate hash table of CUs. */
6666 htab_cu_hash (const void *of)
6668 const struct cu_hash_table_entry *const entry =
6669 (const struct cu_hash_table_entry *) of;
6671 return htab_hash_string (entry->cu->die_id.die_symbol);
6675 htab_cu_eq (const void *of1, const void *of2)
6677 const struct cu_hash_table_entry *const entry1 =
6678 (const struct cu_hash_table_entry *) of1;
6679 const struct die_struct *const entry2 = (const struct die_struct *) of2;
6681 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
6685 htab_cu_del (void *what)
6687 struct cu_hash_table_entry *next,
6688 *entry = (struct cu_hash_table_entry *) what;
6698 /* Check whether we have already seen this CU and set up SYM_NUM
6701 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6703 struct cu_hash_table_entry dummy;
6704 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6706 dummy.max_comdat_num = 0;
6708 slot = (struct cu_hash_table_entry **)
6709 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
6713 for (; entry; last = entry, entry = entry->next)
6715 if (same_die_p_wrap (cu, entry->cu))
6721 *sym_num = entry->min_comdat_num;
6725 entry = XCNEW (struct cu_hash_table_entry);
6727 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6728 entry->next = *slot;
6734 /* Record SYM_NUM to record of CU in HTABLE. */
6736 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6738 struct cu_hash_table_entry **slot, *entry;
6740 slot = (struct cu_hash_table_entry **)
6741 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
6745 entry->max_comdat_num = sym_num;
6748 /* Traverse the DIE (which is always comp_unit_die), and set up
6749 additional compilation units for each of the include files we see
6750 bracketed by BINCL/EINCL. */
6753 break_out_includes (dw_die_ref die)
6756 dw_die_ref unit = NULL;
6757 limbo_die_node *node, **pnode;
6758 htab_t cu_hash_table;
6762 dw_die_ref prev = c;
6764 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6765 || (unit && is_comdat_die (c)))
6767 dw_die_ref next = c->die_sib;
6769 /* This DIE is for a secondary CU; remove it from the main one. */
6770 remove_child_with_prev (c, prev);
6772 if (c->die_tag == DW_TAG_GNU_BINCL)
6773 unit = push_new_compile_unit (unit, c);
6774 else if (c->die_tag == DW_TAG_GNU_EINCL)
6775 unit = pop_compile_unit (unit);
6777 add_child_die (unit, c);
6779 if (c == die->die_child)
6782 } while (c != die->die_child);
6785 /* We can only use this in debugging, since the frontend doesn't check
6786 to make sure that we leave every include file we enter. */
6790 assign_symbol_names (die);
6791 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6792 for (node = limbo_die_list, pnode = &limbo_die_list;
6798 compute_section_prefix (node->die);
6799 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6800 &comdat_symbol_number);
6801 assign_symbol_names (node->die);
6803 *pnode = node->next;
6806 pnode = &node->next;
6807 record_comdat_symbol_number (node->die, cu_hash_table,
6808 comdat_symbol_number);
6811 htab_delete (cu_hash_table);
6814 /* Return non-zero if this DIE is a declaration. */
6817 is_declaration_die (dw_die_ref die)
6822 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6823 if (a->dw_attr == DW_AT_declaration)
6829 /* Return non-zero if this DIE is nested inside a subprogram. */
6832 is_nested_in_subprogram (dw_die_ref die)
6834 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
6838 return local_scope_p (decl);
6841 /* Return non-zero if this DIE contains a defining declaration of a
6845 contains_subprogram_definition (dw_die_ref die)
6849 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
6851 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
6855 /* Return non-zero if this is a type DIE that should be moved to a
6856 COMDAT .debug_types section. */
6859 should_move_die_to_comdat (dw_die_ref die)
6861 switch (die->die_tag)
6863 case DW_TAG_class_type:
6864 case DW_TAG_structure_type:
6865 case DW_TAG_enumeration_type:
6866 case DW_TAG_union_type:
6867 /* Don't move declarations, inlined instances, or types nested in a
6869 if (is_declaration_die (die)
6870 || get_AT (die, DW_AT_abstract_origin)
6871 || is_nested_in_subprogram (die))
6873 /* A type definition should never contain a subprogram definition. */
6874 gcc_assert (!contains_subprogram_definition (die));
6876 case DW_TAG_array_type:
6877 case DW_TAG_interface_type:
6878 case DW_TAG_pointer_type:
6879 case DW_TAG_reference_type:
6880 case DW_TAG_rvalue_reference_type:
6881 case DW_TAG_string_type:
6882 case DW_TAG_subroutine_type:
6883 case DW_TAG_ptr_to_member_type:
6884 case DW_TAG_set_type:
6885 case DW_TAG_subrange_type:
6886 case DW_TAG_base_type:
6887 case DW_TAG_const_type:
6888 case DW_TAG_file_type:
6889 case DW_TAG_packed_type:
6890 case DW_TAG_volatile_type:
6891 case DW_TAG_typedef:
6897 /* Make a clone of DIE. */
6900 clone_die (dw_die_ref die)
6906 clone = ggc_alloc_cleared_die_node ();
6907 clone->die_tag = die->die_tag;
6909 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6910 add_dwarf_attr (clone, a);
6915 /* Make a clone of the tree rooted at DIE. */
6918 clone_tree (dw_die_ref die)
6921 dw_die_ref clone = clone_die (die);
6923 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
6928 /* Make a clone of DIE as a declaration. */
6931 clone_as_declaration (dw_die_ref die)
6938 /* If the DIE is already a declaration, just clone it. */
6939 if (is_declaration_die (die))
6940 return clone_die (die);
6942 /* If the DIE is a specification, just clone its declaration DIE. */
6943 decl = get_AT_ref (die, DW_AT_specification);
6945 return clone_die (decl);
6947 clone = ggc_alloc_cleared_die_node ();
6948 clone->die_tag = die->die_tag;
6950 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6952 /* We don't want to copy over all attributes.
6953 For example we don't want DW_AT_byte_size because otherwise we will no
6954 longer have a declaration and GDB will treat it as a definition. */
6958 case DW_AT_artificial:
6959 case DW_AT_containing_type:
6960 case DW_AT_external:
6963 case DW_AT_virtuality:
6964 case DW_AT_linkage_name:
6965 case DW_AT_MIPS_linkage_name:
6966 add_dwarf_attr (clone, a);
6968 case DW_AT_byte_size:
6974 if (die->die_id.die_type_node)
6975 add_AT_die_ref (clone, DW_AT_signature, die);
6977 add_AT_flag (clone, DW_AT_declaration, 1);
6981 /* Copy the declaration context to the new compile unit DIE. This includes
6982 any surrounding namespace or type declarations. If the DIE has an
6983 AT_specification attribute, it also includes attributes and children
6984 attached to the specification. */
6987 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
6990 dw_die_ref new_decl;
6992 decl = get_AT_ref (die, DW_AT_specification);
7001 /* Copy the type node pointer from the new DIE to the original
7002 declaration DIE so we can forward references later. */
7003 decl->die_id.die_type_node = die->die_id.die_type_node;
7005 remove_AT (die, DW_AT_specification);
7007 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
7009 if (a->dw_attr != DW_AT_name
7010 && a->dw_attr != DW_AT_declaration
7011 && a->dw_attr != DW_AT_external)
7012 add_dwarf_attr (die, a);
7015 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
7018 if (decl->die_parent != NULL
7019 && decl->die_parent->die_tag != DW_TAG_compile_unit
7020 && decl->die_parent->die_tag != DW_TAG_type_unit)
7022 new_decl = copy_ancestor_tree (unit, decl, NULL);
7023 if (new_decl != NULL)
7025 remove_AT (new_decl, DW_AT_signature);
7026 add_AT_specification (die, new_decl);
7031 /* Generate the skeleton ancestor tree for the given NODE, then clone
7032 the DIE and add the clone into the tree. */
7035 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
7037 if (node->new_die != NULL)
7040 node->new_die = clone_as_declaration (node->old_die);
7042 if (node->parent != NULL)
7044 generate_skeleton_ancestor_tree (node->parent);
7045 add_child_die (node->parent->new_die, node->new_die);
7049 /* Generate a skeleton tree of DIEs containing any declarations that are
7050 found in the original tree. We traverse the tree looking for declaration
7051 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7054 generate_skeleton_bottom_up (skeleton_chain_node *parent)
7056 skeleton_chain_node node;
7059 dw_die_ref prev = NULL;
7060 dw_die_ref next = NULL;
7062 node.parent = parent;
7064 first = c = parent->old_die->die_child;
7068 if (prev == NULL || prev->die_sib == c)
7071 next = (c == first ? NULL : c->die_sib);
7073 node.new_die = NULL;
7074 if (is_declaration_die (c))
7076 /* Clone the existing DIE, move the original to the skeleton
7077 tree (which is in the main CU), and put the clone, with
7078 all the original's children, where the original came from. */
7079 dw_die_ref clone = clone_die (c);
7080 move_all_children (c, clone);
7082 replace_child (c, clone, prev);
7083 generate_skeleton_ancestor_tree (parent);
7084 add_child_die (parent->new_die, c);
7088 generate_skeleton_bottom_up (&node);
7089 } while (next != NULL);
7092 /* Wrapper function for generate_skeleton_bottom_up. */
7095 generate_skeleton (dw_die_ref die)
7097 skeleton_chain_node node;
7100 node.new_die = NULL;
7103 /* If this type definition is nested inside another type,
7104 always leave at least a declaration in its place. */
7105 if (die->die_parent != NULL && is_type_die (die->die_parent))
7106 node.new_die = clone_as_declaration (die);
7108 generate_skeleton_bottom_up (&node);
7109 return node.new_die;
7112 /* Remove the DIE from its parent, possibly replacing it with a cloned
7113 declaration. The original DIE will be moved to a new compile unit
7114 so that existing references to it follow it to the new location. If
7115 any of the original DIE's descendants is a declaration, we need to
7116 replace the original DIE with a skeleton tree and move the
7117 declarations back into the skeleton tree. */
7120 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
7122 dw_die_ref skeleton;
7124 skeleton = generate_skeleton (child);
7125 if (skeleton == NULL)
7126 remove_child_with_prev (child, prev);
7129 skeleton->die_id.die_type_node = child->die_id.die_type_node;
7130 replace_child (child, skeleton, prev);
7136 /* Traverse the DIE and set up additional .debug_types sections for each
7137 type worthy of being placed in a COMDAT section. */
7140 break_out_comdat_types (dw_die_ref die)
7144 dw_die_ref prev = NULL;
7145 dw_die_ref next = NULL;
7146 dw_die_ref unit = NULL;
7148 first = c = die->die_child;
7152 if (prev == NULL || prev->die_sib == c)
7155 next = (c == first ? NULL : c->die_sib);
7156 if (should_move_die_to_comdat (c))
7158 dw_die_ref replacement;
7159 comdat_type_node_ref type_node;
7161 /* Create a new type unit DIE as the root for the new tree, and
7162 add it to the list of comdat types. */
7163 unit = new_die (DW_TAG_type_unit, NULL, NULL);
7164 add_AT_unsigned (unit, DW_AT_language,
7165 get_AT_unsigned (comp_unit_die (), DW_AT_language));
7166 type_node = ggc_alloc_cleared_comdat_type_node ();
7167 type_node->root_die = unit;
7168 type_node->next = comdat_type_list;
7169 comdat_type_list = type_node;
7171 /* Generate the type signature. */
7172 generate_type_signature (c, type_node);
7174 /* Copy the declaration context, attributes, and children of the
7175 declaration into the new compile unit DIE. */
7176 copy_declaration_context (unit, c);
7178 /* Remove this DIE from the main CU. */
7179 replacement = remove_child_or_replace_with_skeleton (c, prev);
7181 /* Break out nested types into their own type units. */
7182 break_out_comdat_types (c);
7184 /* Add the DIE to the new compunit. */
7185 add_child_die (unit, c);
7187 if (replacement != NULL)
7190 else if (c->die_tag == DW_TAG_namespace
7191 || c->die_tag == DW_TAG_class_type
7192 || c->die_tag == DW_TAG_structure_type
7193 || c->die_tag == DW_TAG_union_type)
7195 /* Look for nested types that can be broken out. */
7196 break_out_comdat_types (c);
7198 } while (next != NULL);
7201 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7203 struct decl_table_entry
7209 /* Routines to manipulate hash table of copied declarations. */
7212 htab_decl_hash (const void *of)
7214 const struct decl_table_entry *const entry =
7215 (const struct decl_table_entry *) of;
7217 return htab_hash_pointer (entry->orig);
7221 htab_decl_eq (const void *of1, const void *of2)
7223 const struct decl_table_entry *const entry1 =
7224 (const struct decl_table_entry *) of1;
7225 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7227 return entry1->orig == entry2;
7231 htab_decl_del (void *what)
7233 struct decl_table_entry *entry = (struct decl_table_entry *) what;
7238 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7239 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7240 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7241 to check if the ancestor has already been copied into UNIT. */
7244 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7246 dw_die_ref parent = die->die_parent;
7247 dw_die_ref new_parent = unit;
7250 struct decl_table_entry *entry = NULL;
7254 /* Check if the entry has already been copied to UNIT. */
7255 slot = htab_find_slot_with_hash (decl_table, die,
7256 htab_hash_pointer (die), INSERT);
7257 if (*slot != HTAB_EMPTY_ENTRY)
7259 entry = (struct decl_table_entry *) *slot;
7263 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7264 entry = XCNEW (struct decl_table_entry);
7272 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
7275 if (parent->die_tag != DW_TAG_compile_unit
7276 && parent->die_tag != DW_TAG_type_unit)
7277 new_parent = copy_ancestor_tree (unit, parent, decl_table);
7280 copy = clone_as_declaration (die);
7281 add_child_die (new_parent, copy);
7283 if (decl_table != NULL)
7285 /* Record the pointer to the copy. */
7292 /* Walk the DIE and its children, looking for references to incomplete
7293 or trivial types that are unmarked (i.e., that are not in the current
7297 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7303 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7305 if (AT_class (a) == dw_val_class_die_ref)
7307 dw_die_ref targ = AT_ref (a);
7308 comdat_type_node_ref type_node = targ->die_id.die_type_node;
7310 struct decl_table_entry *entry;
7312 if (targ->die_mark != 0 || type_node != NULL)
7315 slot = htab_find_slot_with_hash (decl_table, targ,
7316 htab_hash_pointer (targ), INSERT);
7318 if (*slot != HTAB_EMPTY_ENTRY)
7320 /* TARG has already been copied, so we just need to
7321 modify the reference to point to the copy. */
7322 entry = (struct decl_table_entry *) *slot;
7323 a->dw_attr_val.v.val_die_ref.die = entry->copy;
7327 dw_die_ref parent = unit;
7328 dw_die_ref copy = clone_tree (targ);
7330 /* Make sure the cloned tree is marked as part of the
7334 /* Record in DECL_TABLE that TARG has been copied.
7335 Need to do this now, before the recursive call,
7336 because DECL_TABLE may be expanded and SLOT
7337 would no longer be a valid pointer. */
7338 entry = XCNEW (struct decl_table_entry);
7343 /* If TARG has surrounding context, copy its ancestor tree
7344 into the new type unit. */
7345 if (targ->die_parent != NULL
7346 && targ->die_parent->die_tag != DW_TAG_compile_unit
7347 && targ->die_parent->die_tag != DW_TAG_type_unit)
7348 parent = copy_ancestor_tree (unit, targ->die_parent,
7351 add_child_die (parent, copy);
7352 a->dw_attr_val.v.val_die_ref.die = copy;
7354 /* Make sure the newly-copied DIE is walked. If it was
7355 installed in a previously-added context, it won't
7356 get visited otherwise. */
7359 /* Find the highest point of the newly-added tree,
7360 mark each node along the way, and walk from there. */
7361 parent->die_mark = 1;
7362 while (parent->die_parent
7363 && parent->die_parent->die_mark == 0)
7365 parent = parent->die_parent;
7366 parent->die_mark = 1;
7368 copy_decls_walk (unit, parent, decl_table);
7374 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
7377 /* Copy declarations for "unworthy" types into the new comdat section.
7378 Incomplete types, modified types, and certain other types aren't broken
7379 out into comdat sections of their own, so they don't have a signature,
7380 and we need to copy the declaration into the same section so that we
7381 don't have an external reference. */
7384 copy_decls_for_unworthy_types (dw_die_ref unit)
7389 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
7390 copy_decls_walk (unit, unit, decl_table);
7391 htab_delete (decl_table);
7395 /* Traverse the DIE and add a sibling attribute if it may have the
7396 effect of speeding up access to siblings. To save some space,
7397 avoid generating sibling attributes for DIE's without children. */
7400 add_sibling_attributes (dw_die_ref die)
7404 if (! die->die_child)
7407 if (die->die_parent && die != die->die_parent->die_child)
7408 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7410 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7413 /* Output all location lists for the DIE and its children. */
7416 output_location_lists (dw_die_ref die)
7422 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7423 if (AT_class (a) == dw_val_class_loc_list)
7424 output_loc_list (AT_loc_list (a));
7426 FOR_EACH_CHILD (die, c, output_location_lists (c));
7429 /* The format of each DIE (and its attribute value pairs) is encoded in an
7430 abbreviation table. This routine builds the abbreviation table and assigns
7431 a unique abbreviation id for each abbreviation entry. The children of each
7432 die are visited recursively. */
7435 build_abbrev_table (dw_die_ref die)
7437 unsigned long abbrev_id;
7438 unsigned int n_alloc;
7443 /* Scan the DIE references, and mark as external any that refer to
7444 DIEs from other CUs (i.e. those which are not marked). */
7445 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7446 if (AT_class (a) == dw_val_class_die_ref
7447 && AT_ref (a)->die_mark == 0)
7449 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
7450 set_AT_ref_external (a, 1);
7453 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7455 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7456 dw_attr_ref die_a, abbrev_a;
7460 if (abbrev->die_tag != die->die_tag)
7462 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7465 if (VEC_length (dw_attr_node, abbrev->die_attr)
7466 != VEC_length (dw_attr_node, die->die_attr))
7469 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
7471 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7472 if ((abbrev_a->dw_attr != die_a->dw_attr)
7473 || (value_format (abbrev_a) != value_format (die_a)))
7483 if (abbrev_id >= abbrev_die_table_in_use)
7485 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7487 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7488 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7491 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7492 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7493 abbrev_die_table_allocated = n_alloc;
7496 ++abbrev_die_table_in_use;
7497 abbrev_die_table[abbrev_id] = die;
7500 die->die_abbrev = abbrev_id;
7501 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7504 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7507 constant_size (unsigned HOST_WIDE_INT value)
7514 log = floor_log2 (value);
7517 log = 1 << (floor_log2 (log) + 1);
7522 /* Return the size of a DIE as it is represented in the
7523 .debug_info section. */
7525 static unsigned long
7526 size_of_die (dw_die_ref die)
7528 unsigned long size = 0;
7532 size += size_of_uleb128 (die->die_abbrev);
7533 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7535 switch (AT_class (a))
7537 case dw_val_class_addr:
7538 size += DWARF2_ADDR_SIZE;
7540 case dw_val_class_offset:
7541 size += DWARF_OFFSET_SIZE;
7543 case dw_val_class_loc:
7545 unsigned long lsize = size_of_locs (AT_loc (a));
7548 if (dwarf_version >= 4)
7549 size += size_of_uleb128 (lsize);
7551 size += constant_size (lsize);
7555 case dw_val_class_loc_list:
7556 size += DWARF_OFFSET_SIZE;
7558 case dw_val_class_range_list:
7559 size += DWARF_OFFSET_SIZE;
7561 case dw_val_class_const:
7562 size += size_of_sleb128 (AT_int (a));
7564 case dw_val_class_unsigned_const:
7565 size += constant_size (AT_unsigned (a));
7567 case dw_val_class_const_double:
7568 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
7569 if (HOST_BITS_PER_WIDE_INT >= 64)
7572 case dw_val_class_vec:
7573 size += constant_size (a->dw_attr_val.v.val_vec.length
7574 * a->dw_attr_val.v.val_vec.elt_size)
7575 + a->dw_attr_val.v.val_vec.length
7576 * a->dw_attr_val.v.val_vec.elt_size; /* block */
7578 case dw_val_class_flag:
7579 if (dwarf_version >= 4)
7580 /* Currently all add_AT_flag calls pass in 1 as last argument,
7581 so DW_FORM_flag_present can be used. If that ever changes,
7582 we'll need to use DW_FORM_flag and have some optimization
7583 in build_abbrev_table that will change those to
7584 DW_FORM_flag_present if it is set to 1 in all DIEs using
7585 the same abbrev entry. */
7586 gcc_assert (a->dw_attr_val.v.val_flag == 1);
7590 case dw_val_class_die_ref:
7591 if (AT_ref_external (a))
7593 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7594 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7595 is sized by target address length, whereas in DWARF3
7596 it's always sized as an offset. */
7597 if (use_debug_types)
7598 size += DWARF_TYPE_SIGNATURE_SIZE;
7599 else if (dwarf_version == 2)
7600 size += DWARF2_ADDR_SIZE;
7602 size += DWARF_OFFSET_SIZE;
7605 size += DWARF_OFFSET_SIZE;
7607 case dw_val_class_fde_ref:
7608 size += DWARF_OFFSET_SIZE;
7610 case dw_val_class_lbl_id:
7611 size += DWARF2_ADDR_SIZE;
7613 case dw_val_class_lineptr:
7614 case dw_val_class_macptr:
7615 size += DWARF_OFFSET_SIZE;
7617 case dw_val_class_str:
7618 if (AT_string_form (a) == DW_FORM_strp)
7619 size += DWARF_OFFSET_SIZE;
7621 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7623 case dw_val_class_file:
7624 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7626 case dw_val_class_data8:
7629 case dw_val_class_vms_delta:
7630 size += DWARF_OFFSET_SIZE;
7640 /* Size the debugging information associated with a given DIE. Visits the
7641 DIE's children recursively. Updates the global variable next_die_offset, on
7642 each time through. Uses the current value of next_die_offset to update the
7643 die_offset field in each DIE. */
7646 calc_die_sizes (dw_die_ref die)
7650 gcc_assert (die->die_offset == 0
7651 || (unsigned long int) die->die_offset == next_die_offset);
7652 die->die_offset = next_die_offset;
7653 next_die_offset += size_of_die (die);
7655 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7657 if (die->die_child != NULL)
7658 /* Count the null byte used to terminate sibling lists. */
7659 next_die_offset += 1;
7662 /* Size just the base type children at the start of the CU.
7663 This is needed because build_abbrev needs to size locs
7664 and sizing of type based stack ops needs to know die_offset
7665 values for the base types. */
7668 calc_base_type_die_sizes (void)
7670 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7672 dw_die_ref base_type;
7673 #if ENABLE_ASSERT_CHECKING
7674 dw_die_ref prev = comp_unit_die ()->die_child;
7677 die_offset += size_of_die (comp_unit_die ());
7678 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
7680 #if ENABLE_ASSERT_CHECKING
7681 gcc_assert (base_type->die_offset == 0
7682 && prev->die_sib == base_type
7683 && base_type->die_child == NULL
7684 && base_type->die_abbrev);
7687 base_type->die_offset = die_offset;
7688 die_offset += size_of_die (base_type);
7692 /* Set the marks for a die and its children. We do this so
7693 that we know whether or not a reference needs to use FORM_ref_addr; only
7694 DIEs in the same CU will be marked. We used to clear out the offset
7695 and use that as the flag, but ran into ordering problems. */
7698 mark_dies (dw_die_ref die)
7702 gcc_assert (!die->die_mark);
7705 FOR_EACH_CHILD (die, c, mark_dies (c));
7708 /* Clear the marks for a die and its children. */
7711 unmark_dies (dw_die_ref die)
7715 if (! use_debug_types)
7716 gcc_assert (die->die_mark);
7719 FOR_EACH_CHILD (die, c, unmark_dies (c));
7722 /* Clear the marks for a die, its children and referred dies. */
7725 unmark_all_dies (dw_die_ref die)
7735 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7737 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7738 if (AT_class (a) == dw_val_class_die_ref)
7739 unmark_all_dies (AT_ref (a));
7742 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7743 generated for the compilation unit. */
7745 static unsigned long
7746 size_of_pubnames (VEC (pubname_entry, gc) * names)
7752 size = DWARF_PUBNAMES_HEADER_SIZE;
7753 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
7754 if (names != pubtype_table
7755 || p->die->die_offset != 0
7756 || !flag_eliminate_unused_debug_types)
7757 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7759 size += DWARF_OFFSET_SIZE;
7763 /* Return the size of the information in the .debug_aranges section. */
7765 static unsigned long
7766 size_of_aranges (void)
7770 size = DWARF_ARANGES_HEADER_SIZE;
7772 /* Count the address/length pair for this compilation unit. */
7773 if (text_section_used)
7774 size += 2 * DWARF2_ADDR_SIZE;
7775 if (cold_text_section_used)
7776 size += 2 * DWARF2_ADDR_SIZE;
7777 if (have_multiple_function_sections)
7782 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
7784 if (!fde->in_std_section)
7785 size += 2 * DWARF2_ADDR_SIZE;
7786 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
7787 size += 2 * DWARF2_ADDR_SIZE;
7791 /* Count the two zero words used to terminated the address range table. */
7792 size += 2 * DWARF2_ADDR_SIZE;
7796 /* Select the encoding of an attribute value. */
7798 static enum dwarf_form
7799 value_format (dw_attr_ref a)
7801 switch (a->dw_attr_val.val_class)
7803 case dw_val_class_addr:
7804 /* Only very few attributes allow DW_FORM_addr. */
7809 case DW_AT_entry_pc:
7810 case DW_AT_trampoline:
7811 return DW_FORM_addr;
7815 switch (DWARF2_ADDR_SIZE)
7818 return DW_FORM_data1;
7820 return DW_FORM_data2;
7822 return DW_FORM_data4;
7824 return DW_FORM_data8;
7828 case dw_val_class_range_list:
7829 case dw_val_class_loc_list:
7830 if (dwarf_version >= 4)
7831 return DW_FORM_sec_offset;
7833 case dw_val_class_vms_delta:
7834 case dw_val_class_offset:
7835 switch (DWARF_OFFSET_SIZE)
7838 return DW_FORM_data4;
7840 return DW_FORM_data8;
7844 case dw_val_class_loc:
7845 if (dwarf_version >= 4)
7846 return DW_FORM_exprloc;
7847 switch (constant_size (size_of_locs (AT_loc (a))))
7850 return DW_FORM_block1;
7852 return DW_FORM_block2;
7856 case dw_val_class_const:
7857 return DW_FORM_sdata;
7858 case dw_val_class_unsigned_const:
7859 switch (constant_size (AT_unsigned (a)))
7862 return DW_FORM_data1;
7864 return DW_FORM_data2;
7866 return DW_FORM_data4;
7868 return DW_FORM_data8;
7872 case dw_val_class_const_double:
7873 switch (HOST_BITS_PER_WIDE_INT)
7876 return DW_FORM_data2;
7878 return DW_FORM_data4;
7880 return DW_FORM_data8;
7883 return DW_FORM_block1;
7885 case dw_val_class_vec:
7886 switch (constant_size (a->dw_attr_val.v.val_vec.length
7887 * a->dw_attr_val.v.val_vec.elt_size))
7890 return DW_FORM_block1;
7892 return DW_FORM_block2;
7894 return DW_FORM_block4;
7898 case dw_val_class_flag:
7899 if (dwarf_version >= 4)
7901 /* Currently all add_AT_flag calls pass in 1 as last argument,
7902 so DW_FORM_flag_present can be used. If that ever changes,
7903 we'll need to use DW_FORM_flag and have some optimization
7904 in build_abbrev_table that will change those to
7905 DW_FORM_flag_present if it is set to 1 in all DIEs using
7906 the same abbrev entry. */
7907 gcc_assert (a->dw_attr_val.v.val_flag == 1);
7908 return DW_FORM_flag_present;
7910 return DW_FORM_flag;
7911 case dw_val_class_die_ref:
7912 if (AT_ref_external (a))
7913 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
7916 case dw_val_class_fde_ref:
7917 return DW_FORM_data;
7918 case dw_val_class_lbl_id:
7919 return DW_FORM_addr;
7920 case dw_val_class_lineptr:
7921 case dw_val_class_macptr:
7922 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
7923 case dw_val_class_str:
7924 return AT_string_form (a);
7925 case dw_val_class_file:
7926 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7929 return DW_FORM_data1;
7931 return DW_FORM_data2;
7933 return DW_FORM_data4;
7938 case dw_val_class_data8:
7939 return DW_FORM_data8;
7946 /* Output the encoding of an attribute value. */
7949 output_value_format (dw_attr_ref a)
7951 enum dwarf_form form = value_format (a);
7953 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7956 /* Output the .debug_abbrev section which defines the DIE abbreviation
7960 output_abbrev_section (void)
7962 unsigned long abbrev_id;
7964 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7966 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7970 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7971 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7972 dwarf_tag_name (abbrev->die_tag));
7974 if (abbrev->die_child != NULL)
7975 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7977 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7979 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7982 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7983 dwarf_attr_name (a_attr->dw_attr));
7984 output_value_format (a_attr);
7987 dw2_asm_output_data (1, 0, NULL);
7988 dw2_asm_output_data (1, 0, NULL);
7991 /* Terminate the table. */
7992 dw2_asm_output_data (1, 0, NULL);
7995 /* Output a symbol we can use to refer to this DIE from another CU. */
7998 output_die_symbol (dw_die_ref die)
8000 char *sym = die->die_id.die_symbol;
8005 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8006 /* We make these global, not weak; if the target doesn't support
8007 .linkonce, it doesn't support combining the sections, so debugging
8009 targetm.asm_out.globalize_label (asm_out_file, sym);
8011 ASM_OUTPUT_LABEL (asm_out_file, sym);
8014 /* Return a new location list, given the begin and end range, and the
8017 static inline dw_loc_list_ref
8018 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8019 const char *section)
8021 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
8023 retlist->begin = begin;
8025 retlist->expr = expr;
8026 retlist->section = section;
8031 /* Generate a new internal symbol for this location list node, if it
8032 hasn't got one yet. */
8035 gen_llsym (dw_loc_list_ref list)
8037 gcc_assert (!list->ll_symbol);
8038 list->ll_symbol = gen_internal_sym ("LLST");
8041 /* Output the location list given to us. */
8044 output_loc_list (dw_loc_list_ref list_head)
8046 dw_loc_list_ref curr = list_head;
8048 if (list_head->emitted)
8050 list_head->emitted = true;
8052 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8054 /* Walk the location list, and output each range + expression. */
8055 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8058 /* Don't output an entry that starts and ends at the same address. */
8059 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
8061 if (!have_multiple_function_sections)
8063 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8064 "Location list begin address (%s)",
8065 list_head->ll_symbol);
8066 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8067 "Location list end address (%s)",
8068 list_head->ll_symbol);
8072 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8073 "Location list begin address (%s)",
8074 list_head->ll_symbol);
8075 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8076 "Location list end address (%s)",
8077 list_head->ll_symbol);
8079 size = size_of_locs (curr->expr);
8081 /* Output the block length for this list of location operations. */
8082 gcc_assert (size <= 0xffff);
8083 dw2_asm_output_data (2, size, "%s", "Location expression size");
8085 output_loc_sequence (curr->expr, -1);
8088 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8089 "Location list terminator begin (%s)",
8090 list_head->ll_symbol);
8091 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8092 "Location list terminator end (%s)",
8093 list_head->ll_symbol);
8096 /* Output a type signature. */
8099 output_signature (const char *sig, const char *name)
8103 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8104 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
8107 /* Output the DIE and its attributes. Called recursively to generate
8108 the definitions of each child DIE. */
8111 output_die (dw_die_ref die)
8118 /* If someone in another CU might refer to us, set up a symbol for
8119 them to point to. */
8120 if (! use_debug_types && die->die_id.die_symbol)
8121 output_die_symbol (die);
8123 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
8124 (unsigned long)die->die_offset,
8125 dwarf_tag_name (die->die_tag));
8127 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8129 const char *name = dwarf_attr_name (a->dw_attr);
8131 switch (AT_class (a))
8133 case dw_val_class_addr:
8134 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8137 case dw_val_class_offset:
8138 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8142 case dw_val_class_range_list:
8144 char *p = strchr (ranges_section_label, '\0');
8146 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8147 a->dw_attr_val.v.val_offset);
8148 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8149 debug_ranges_section, "%s", name);
8154 case dw_val_class_loc:
8155 size = size_of_locs (AT_loc (a));
8157 /* Output the block length for this list of location operations. */
8158 if (dwarf_version >= 4)
8159 dw2_asm_output_data_uleb128 (size, "%s", name);
8161 dw2_asm_output_data (constant_size (size), size, "%s", name);
8163 output_loc_sequence (AT_loc (a), -1);
8166 case dw_val_class_const:
8167 /* ??? It would be slightly more efficient to use a scheme like is
8168 used for unsigned constants below, but gdb 4.x does not sign
8169 extend. Gdb 5.x does sign extend. */
8170 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8173 case dw_val_class_unsigned_const:
8174 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8175 AT_unsigned (a), "%s", name);
8178 case dw_val_class_const_double:
8180 unsigned HOST_WIDE_INT first, second;
8182 if (HOST_BITS_PER_WIDE_INT >= 64)
8183 dw2_asm_output_data (1,
8184 2 * HOST_BITS_PER_WIDE_INT
8185 / HOST_BITS_PER_CHAR,
8188 if (WORDS_BIG_ENDIAN)
8190 first = a->dw_attr_val.v.val_double.high;
8191 second = a->dw_attr_val.v.val_double.low;
8195 first = a->dw_attr_val.v.val_double.low;
8196 second = a->dw_attr_val.v.val_double.high;
8199 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8201 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8206 case dw_val_class_vec:
8208 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8209 unsigned int len = a->dw_attr_val.v.val_vec.length;
8213 dw2_asm_output_data (constant_size (len * elt_size),
8214 len * elt_size, "%s", name);
8215 if (elt_size > sizeof (HOST_WIDE_INT))
8220 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8223 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8224 "fp or vector constant word %u", i);
8228 case dw_val_class_flag:
8229 if (dwarf_version >= 4)
8231 /* Currently all add_AT_flag calls pass in 1 as last argument,
8232 so DW_FORM_flag_present can be used. If that ever changes,
8233 we'll need to use DW_FORM_flag and have some optimization
8234 in build_abbrev_table that will change those to
8235 DW_FORM_flag_present if it is set to 1 in all DIEs using
8236 the same abbrev entry. */
8237 gcc_assert (AT_flag (a) == 1);
8239 fprintf (asm_out_file, "\t\t\t%s %s\n",
8240 ASM_COMMENT_START, name);
8243 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8246 case dw_val_class_loc_list:
8248 char *sym = AT_loc_list (a)->ll_symbol;
8251 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8256 case dw_val_class_die_ref:
8257 if (AT_ref_external (a))
8259 if (use_debug_types)
8261 comdat_type_node_ref type_node =
8262 AT_ref (a)->die_id.die_type_node;
8264 gcc_assert (type_node);
8265 output_signature (type_node->signature, name);
8269 char *sym = AT_ref (a)->die_id.die_symbol;
8273 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8274 length, whereas in DWARF3 it's always sized as an
8276 if (dwarf_version == 2)
8277 size = DWARF2_ADDR_SIZE;
8279 size = DWARF_OFFSET_SIZE;
8280 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
8286 gcc_assert (AT_ref (a)->die_offset);
8287 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8292 case dw_val_class_fde_ref:
8296 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8297 a->dw_attr_val.v.val_fde_index * 2);
8298 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8303 case dw_val_class_vms_delta:
8304 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
8305 AT_vms_delta2 (a), AT_vms_delta1 (a),
8309 case dw_val_class_lbl_id:
8310 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8313 case dw_val_class_lineptr:
8314 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8315 debug_line_section, "%s", name);
8318 case dw_val_class_macptr:
8319 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8320 debug_macinfo_section, "%s", name);
8323 case dw_val_class_str:
8324 if (AT_string_form (a) == DW_FORM_strp)
8325 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8326 a->dw_attr_val.v.val_str->label,
8328 "%s: \"%s\"", name, AT_string (a));
8330 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8333 case dw_val_class_file:
8335 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8337 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8338 a->dw_attr_val.v.val_file->filename);
8342 case dw_val_class_data8:
8346 for (i = 0; i < 8; i++)
8347 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
8348 i == 0 ? "%s" : NULL, name);
8357 FOR_EACH_CHILD (die, c, output_die (c));
8359 /* Add null byte to terminate sibling list. */
8360 if (die->die_child != NULL)
8361 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8362 (unsigned long) die->die_offset);
8365 /* Output the compilation unit that appears at the beginning of the
8366 .debug_info section, and precedes the DIE descriptions. */
8369 output_compilation_unit_header (void)
8371 int ver = dwarf_version;
8373 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8374 dw2_asm_output_data (4, 0xffffffff,
8375 "Initial length escape value indicating 64-bit DWARF extension");
8376 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8377 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8378 "Length of Compilation Unit Info");
8379 dw2_asm_output_data (2, ver, "DWARF version number");
8380 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8381 debug_abbrev_section,
8382 "Offset Into Abbrev. Section");
8383 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8386 /* Output the compilation unit DIE and its children. */
8389 output_comp_unit (dw_die_ref die, int output_if_empty)
8391 const char *secname;
8394 /* Unless we are outputting main CU, we may throw away empty ones. */
8395 if (!output_if_empty && die->die_child == NULL)
8398 /* Even if there are no children of this DIE, we must output the information
8399 about the compilation unit. Otherwise, on an empty translation unit, we
8400 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8401 will then complain when examining the file. First mark all the DIEs in
8402 this CU so we know which get local refs. */
8405 build_abbrev_table (die);
8407 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8408 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8409 calc_die_sizes (die);
8411 oldsym = die->die_id.die_symbol;
8414 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8416 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8418 die->die_id.die_symbol = NULL;
8419 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8423 switch_to_section (debug_info_section);
8424 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
8425 info_section_emitted = true;
8428 /* Output debugging information. */
8429 output_compilation_unit_header ();
8432 /* Leave the marks on the main CU, so we can check them in
8437 die->die_id.die_symbol = oldsym;
8441 /* Output a comdat type unit DIE and its children. */
8444 output_comdat_type_unit (comdat_type_node *node)
8446 const char *secname;
8449 #if defined (OBJECT_FORMAT_ELF)
8453 /* First mark all the DIEs in this CU so we know which get local refs. */
8454 mark_dies (node->root_die);
8456 build_abbrev_table (node->root_die);
8458 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8459 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
8460 calc_die_sizes (node->root_die);
8462 #if defined (OBJECT_FORMAT_ELF)
8463 secname = ".debug_types";
8464 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
8465 sprintf (tmp, "wt.");
8466 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8467 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
8468 comdat_key = get_identifier (tmp);
8469 targetm.asm_out.named_section (secname,
8470 SECTION_DEBUG | SECTION_LINKONCE,
8473 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
8474 sprintf (tmp, ".gnu.linkonce.wt.");
8475 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8476 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
8478 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8481 /* Output debugging information. */
8482 output_compilation_unit_header ();
8483 output_signature (node->signature, "Type Signature");
8484 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
8485 "Offset to Type DIE");
8486 output_die (node->root_die);
8488 unmark_dies (node->root_die);
8491 /* Return the DWARF2/3 pubname associated with a decl. */
8494 dwarf2_name (tree decl, int scope)
8496 if (DECL_NAMELESS (decl))
8498 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8501 /* Add a new entry to .debug_pubnames if appropriate. */
8504 add_pubname_string (const char *str, dw_die_ref die)
8506 if (targetm.want_debug_pub_sections)
8511 e.name = xstrdup (str);
8512 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8517 add_pubname (tree decl, dw_die_ref die)
8519 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
8521 const char *name = dwarf2_name (decl, 1);
8523 add_pubname_string (name, die);
8527 /* Add a new entry to .debug_pubtypes if appropriate. */
8530 add_pubtype (tree decl, dw_die_ref die)
8534 if (!targetm.want_debug_pub_sections)
8538 if ((TREE_PUBLIC (decl)
8539 || is_cu_die (die->die_parent))
8540 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8545 if (TYPE_NAME (decl))
8547 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8548 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8549 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8550 && DECL_NAME (TYPE_NAME (decl)))
8551 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8553 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8558 e.name = dwarf2_name (decl, 1);
8560 e.name = xstrdup (e.name);
8563 /* If we don't have a name for the type, there's no point in adding
8565 if (e.name && e.name[0] != '\0')
8566 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8570 /* Output the public names table used to speed up access to externally
8571 visible names; or the public types table used to find type definitions. */
8574 output_pubnames (VEC (pubname_entry, gc) * names)
8577 unsigned long pubnames_length = size_of_pubnames (names);
8580 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8581 dw2_asm_output_data (4, 0xffffffff,
8582 "Initial length escape value indicating 64-bit DWARF extension");
8583 if (names == pubname_table)
8584 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8585 "Length of Public Names Info");
8587 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8588 "Length of Public Type Names Info");
8589 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8590 dw2_asm_output_data (2, 2, "DWARF Version");
8591 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8593 "Offset of Compilation Unit Info");
8594 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8595 "Compilation Unit Length");
8597 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
8599 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8600 if (names == pubname_table)
8601 gcc_assert (pub->die->die_mark);
8603 if (names != pubtype_table
8604 || pub->die->die_offset != 0
8605 || !flag_eliminate_unused_debug_types)
8607 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8610 dw2_asm_output_nstring (pub->name, -1, "external name");
8614 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8617 /* Output the information that goes into the .debug_aranges table.
8618 Namely, define the beginning and ending address range of the
8619 text section generated for this compilation unit. */
8622 output_aranges (unsigned long aranges_length)
8626 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8627 dw2_asm_output_data (4, 0xffffffff,
8628 "Initial length escape value indicating 64-bit DWARF extension");
8629 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8630 "Length of Address Ranges Info");
8631 /* Version number for aranges is still 2, even in DWARF3. */
8632 dw2_asm_output_data (2, 2, "DWARF Version");
8633 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8635 "Offset of Compilation Unit Info");
8636 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8637 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8639 /* We need to align to twice the pointer size here. */
8640 if (DWARF_ARANGES_PAD_SIZE)
8642 /* Pad using a 2 byte words so that padding is correct for any
8644 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8645 2 * DWARF2_ADDR_SIZE);
8646 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8647 dw2_asm_output_data (2, 0, NULL);
8650 /* It is necessary not to output these entries if the sections were
8651 not used; if the sections were not used, the length will be 0 and
8652 the address may end up as 0 if the section is discarded by ld
8653 --gc-sections, leaving an invalid (0, 0) entry that can be
8654 confused with the terminator. */
8655 if (text_section_used)
8657 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8658 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8659 text_section_label, "Length");
8661 if (cold_text_section_used)
8663 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8665 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8666 cold_text_section_label, "Length");
8669 if (have_multiple_function_sections)
8674 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
8676 if (!fde->in_std_section)
8678 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
8680 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
8681 fde->dw_fde_begin, "Length");
8683 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
8685 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
8687 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
8688 fde->dw_fde_second_begin, "Length");
8693 /* Output the terminator words. */
8694 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8695 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8698 /* Add a new entry to .debug_ranges. Return the offset at which it
8702 add_ranges_num (int num)
8704 unsigned int in_use = ranges_table_in_use;
8706 if (in_use == ranges_table_allocated)
8708 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8709 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8710 ranges_table_allocated);
8711 memset (ranges_table + ranges_table_in_use, 0,
8712 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8715 ranges_table[in_use].num = num;
8716 ranges_table_in_use = in_use + 1;
8718 return in_use * 2 * DWARF2_ADDR_SIZE;
8721 /* Add a new entry to .debug_ranges corresponding to a block, or a
8722 range terminator if BLOCK is NULL. */
8725 add_ranges (const_tree block)
8727 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8730 /* Add a new entry to .debug_ranges corresponding to a pair of
8734 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
8737 unsigned int in_use = ranges_by_label_in_use;
8738 unsigned int offset;
8740 if (in_use == ranges_by_label_allocated)
8742 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8743 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8745 ranges_by_label_allocated);
8746 memset (ranges_by_label + ranges_by_label_in_use, 0,
8747 RANGES_TABLE_INCREMENT
8748 * sizeof (struct dw_ranges_by_label_struct));
8751 ranges_by_label[in_use].begin = begin;
8752 ranges_by_label[in_use].end = end;
8753 ranges_by_label_in_use = in_use + 1;
8755 offset = add_ranges_num (-(int)in_use - 1);
8758 add_AT_range_list (die, DW_AT_ranges, offset);
8764 output_ranges (void)
8767 static const char *const start_fmt = "Offset %#x";
8768 const char *fmt = start_fmt;
8770 for (i = 0; i < ranges_table_in_use; i++)
8772 int block_num = ranges_table[i].num;
8776 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8777 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8779 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8780 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8782 /* If all code is in the text section, then the compilation
8783 unit base address defaults to DW_AT_low_pc, which is the
8784 base of the text section. */
8785 if (!have_multiple_function_sections)
8787 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8789 fmt, i * 2 * DWARF2_ADDR_SIZE);
8790 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8791 text_section_label, NULL);
8794 /* Otherwise, the compilation unit base address is zero,
8795 which allows us to use absolute addresses, and not worry
8796 about whether the target supports cross-section
8800 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8801 fmt, i * 2 * DWARF2_ADDR_SIZE);
8802 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8808 /* Negative block_num stands for an index into ranges_by_label. */
8809 else if (block_num < 0)
8811 int lab_idx = - block_num - 1;
8813 if (!have_multiple_function_sections)
8817 /* If we ever use add_ranges_by_labels () for a single
8818 function section, all we have to do is to take out
8820 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8821 ranges_by_label[lab_idx].begin,
8823 fmt, i * 2 * DWARF2_ADDR_SIZE);
8824 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8825 ranges_by_label[lab_idx].end,
8826 text_section_label, NULL);
8831 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8832 ranges_by_label[lab_idx].begin,
8833 fmt, i * 2 * DWARF2_ADDR_SIZE);
8834 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8835 ranges_by_label[lab_idx].end,
8841 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8842 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8848 /* Data structure containing information about input files. */
8851 const char *path; /* Complete file name. */
8852 const char *fname; /* File name part. */
8853 int length; /* Length of entire string. */
8854 struct dwarf_file_data * file_idx; /* Index in input file table. */
8855 int dir_idx; /* Index in directory table. */
8858 /* Data structure containing information about directories with source
8862 const char *path; /* Path including directory name. */
8863 int length; /* Path length. */
8864 int prefix; /* Index of directory entry which is a prefix. */
8865 int count; /* Number of files in this directory. */
8866 int dir_idx; /* Index of directory used as base. */
8869 /* Callback function for file_info comparison. We sort by looking at
8870 the directories in the path. */
8873 file_info_cmp (const void *p1, const void *p2)
8875 const struct file_info *const s1 = (const struct file_info *) p1;
8876 const struct file_info *const s2 = (const struct file_info *) p2;
8877 const unsigned char *cp1;
8878 const unsigned char *cp2;
8880 /* Take care of file names without directories. We need to make sure that
8881 we return consistent values to qsort since some will get confused if
8882 we return the same value when identical operands are passed in opposite
8883 orders. So if neither has a directory, return 0 and otherwise return
8884 1 or -1 depending on which one has the directory. */
8885 if ((s1->path == s1->fname || s2->path == s2->fname))
8886 return (s2->path == s2->fname) - (s1->path == s1->fname);
8888 cp1 = (const unsigned char *) s1->path;
8889 cp2 = (const unsigned char *) s2->path;
8895 /* Reached the end of the first path? If so, handle like above. */
8896 if ((cp1 == (const unsigned char *) s1->fname)
8897 || (cp2 == (const unsigned char *) s2->fname))
8898 return ((cp2 == (const unsigned char *) s2->fname)
8899 - (cp1 == (const unsigned char *) s1->fname));
8901 /* Character of current path component the same? */
8902 else if (*cp1 != *cp2)
8907 struct file_name_acquire_data
8909 struct file_info *files;
8914 /* Traversal function for the hash table. */
8917 file_name_acquire (void ** slot, void *data)
8919 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
8920 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
8921 struct file_info *fi;
8924 gcc_assert (fnad->max_files >= d->emitted_number);
8926 if (! d->emitted_number)
8929 gcc_assert (fnad->max_files != fnad->used_files);
8931 fi = fnad->files + fnad->used_files++;
8933 /* Skip all leading "./". */
8935 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
8938 /* Create a new array entry. */
8940 fi->length = strlen (f);
8943 /* Search for the file name part. */
8944 f = strrchr (f, DIR_SEPARATOR);
8945 #if defined (DIR_SEPARATOR_2)
8947 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
8951 if (f == NULL || f < g)
8957 fi->fname = f == NULL ? fi->path : f + 1;
8961 /* Output the directory table and the file name table. We try to minimize
8962 the total amount of memory needed. A heuristic is used to avoid large
8963 slowdowns with many input files. */
8966 output_file_names (void)
8968 struct file_name_acquire_data fnad;
8970 struct file_info *files;
8971 struct dir_info *dirs;
8979 if (!last_emitted_file)
8981 dw2_asm_output_data (1, 0, "End directory table");
8982 dw2_asm_output_data (1, 0, "End file name table");
8986 numfiles = last_emitted_file->emitted_number;
8988 /* Allocate the various arrays we need. */
8989 files = XALLOCAVEC (struct file_info, numfiles);
8990 dirs = XALLOCAVEC (struct dir_info, numfiles);
8993 fnad.used_files = 0;
8994 fnad.max_files = numfiles;
8995 htab_traverse (file_table, file_name_acquire, &fnad);
8996 gcc_assert (fnad.used_files == fnad.max_files);
8998 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9000 /* Find all the different directories used. */
9001 dirs[0].path = files[0].path;
9002 dirs[0].length = files[0].fname - files[0].path;
9003 dirs[0].prefix = -1;
9005 dirs[0].dir_idx = 0;
9006 files[0].dir_idx = 0;
9009 for (i = 1; i < numfiles; i++)
9010 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9011 && memcmp (dirs[ndirs - 1].path, files[i].path,
9012 dirs[ndirs - 1].length) == 0)
9014 /* Same directory as last entry. */
9015 files[i].dir_idx = ndirs - 1;
9016 ++dirs[ndirs - 1].count;
9022 /* This is a new directory. */
9023 dirs[ndirs].path = files[i].path;
9024 dirs[ndirs].length = files[i].fname - files[i].path;
9025 dirs[ndirs].count = 1;
9026 dirs[ndirs].dir_idx = ndirs;
9027 files[i].dir_idx = ndirs;
9029 /* Search for a prefix. */
9030 dirs[ndirs].prefix = -1;
9031 for (j = 0; j < ndirs; j++)
9032 if (dirs[j].length < dirs[ndirs].length
9033 && dirs[j].length > 1
9034 && (dirs[ndirs].prefix == -1
9035 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9036 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9037 dirs[ndirs].prefix = j;
9042 /* Now to the actual work. We have to find a subset of the directories which
9043 allow expressing the file name using references to the directory table
9044 with the least amount of characters. We do not do an exhaustive search
9045 where we would have to check out every combination of every single
9046 possible prefix. Instead we use a heuristic which provides nearly optimal
9047 results in most cases and never is much off. */
9048 saved = XALLOCAVEC (int, ndirs);
9049 savehere = XALLOCAVEC (int, ndirs);
9051 memset (saved, '\0', ndirs * sizeof (saved[0]));
9052 for (i = 0; i < ndirs; i++)
9057 /* We can always save some space for the current directory. But this
9058 does not mean it will be enough to justify adding the directory. */
9059 savehere[i] = dirs[i].length;
9060 total = (savehere[i] - saved[i]) * dirs[i].count;
9062 for (j = i + 1; j < ndirs; j++)
9065 if (saved[j] < dirs[i].length)
9067 /* Determine whether the dirs[i] path is a prefix of the
9072 while (k != -1 && k != (int) i)
9077 /* Yes it is. We can possibly save some memory by
9078 writing the filenames in dirs[j] relative to
9080 savehere[j] = dirs[i].length;
9081 total += (savehere[j] - saved[j]) * dirs[j].count;
9086 /* Check whether we can save enough to justify adding the dirs[i]
9088 if (total > dirs[i].length + 1)
9090 /* It's worthwhile adding. */
9091 for (j = i; j < ndirs; j++)
9092 if (savehere[j] > 0)
9094 /* Remember how much we saved for this directory so far. */
9095 saved[j] = savehere[j];
9097 /* Remember the prefix directory. */
9098 dirs[j].dir_idx = i;
9103 /* Emit the directory name table. */
9104 idx_offset = dirs[0].length > 0 ? 1 : 0;
9105 for (i = 1 - idx_offset; i < ndirs; i++)
9106 dw2_asm_output_nstring (dirs[i].path,
9108 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9109 "Directory Entry: %#x", i + idx_offset);
9111 dw2_asm_output_data (1, 0, "End directory table");
9113 /* We have to emit them in the order of emitted_number since that's
9114 used in the debug info generation. To do this efficiently we
9115 generate a back-mapping of the indices first. */
9116 backmap = XALLOCAVEC (int, numfiles);
9117 for (i = 0; i < numfiles; i++)
9118 backmap[files[i].file_idx->emitted_number - 1] = i;
9120 /* Now write all the file names. */
9121 for (i = 0; i < numfiles; i++)
9123 int file_idx = backmap[i];
9124 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9126 #ifdef VMS_DEBUGGING_INFO
9127 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9129 /* Setting these fields can lead to debugger miscomparisons,
9130 but VMS Debug requires them to be set correctly. */
9135 int maxfilelen = strlen (files[file_idx].path)
9136 + dirs[dir_idx].length
9137 + MAX_VMS_VERSION_LEN + 1;
9138 char *filebuf = XALLOCAVEC (char, maxfilelen);
9140 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9141 snprintf (filebuf, maxfilelen, "%s;%d",
9142 files[file_idx].path + dirs[dir_idx].length, ver);
9144 dw2_asm_output_nstring
9145 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
9147 /* Include directory index. */
9148 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9150 /* Modification time. */
9151 dw2_asm_output_data_uleb128
9152 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9156 /* File length in bytes. */
9157 dw2_asm_output_data_uleb128
9158 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9162 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9163 "File Entry: %#x", (unsigned) i + 1);
9165 /* Include directory index. */
9166 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9168 /* Modification time. */
9169 dw2_asm_output_data_uleb128 (0, NULL);
9171 /* File length in bytes. */
9172 dw2_asm_output_data_uleb128 (0, NULL);
9173 #endif /* VMS_DEBUGGING_INFO */
9176 dw2_asm_output_data (1, 0, "End file name table");
9180 /* Output one line number table into the .debug_line section. */
9183 output_one_line_info_table (dw_line_info_table *table)
9185 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9186 unsigned int current_line = 1;
9187 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
9188 dw_line_info_entry *ent;
9191 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
9193 switch (ent->opcode)
9195 case LI_set_address:
9196 /* ??? Unfortunately, we have little choice here currently, and
9197 must always use the most general form. GCC does not know the
9198 address delta itself, so we can't use DW_LNS_advance_pc. Many
9199 ports do have length attributes which will give an upper bound
9200 on the address range. We could perhaps use length attributes
9201 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9202 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
9204 /* This can handle any delta. This takes
9205 4+DWARF2_ADDR_SIZE bytes. */
9206 dw2_asm_output_data (1, 0, "set address %s", line_label);
9207 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9208 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9209 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9213 if (ent->val == current_line)
9215 /* We still need to start a new row, so output a copy insn. */
9216 dw2_asm_output_data (1, DW_LNS_copy,
9217 "copy line %u", current_line);
9221 int line_offset = ent->val - current_line;
9222 int line_delta = line_offset - DWARF_LINE_BASE;
9224 current_line = ent->val;
9225 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9227 /* This can handle deltas from -10 to 234, using the current
9228 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9229 This takes 1 byte. */
9230 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9231 "line %u", current_line);
9235 /* This can handle any delta. This takes at least 4 bytes,
9236 depending on the value being encoded. */
9237 dw2_asm_output_data (1, DW_LNS_advance_line,
9238 "advance to line %u", current_line);
9239 dw2_asm_output_data_sleb128 (line_offset, NULL);
9240 dw2_asm_output_data (1, DW_LNS_copy, NULL);
9246 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
9247 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9251 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
9252 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9255 case LI_negate_stmt:
9256 current_is_stmt = !current_is_stmt;
9257 dw2_asm_output_data (1, DW_LNS_negate_stmt,
9258 "is_stmt %d", current_is_stmt);
9261 case LI_set_prologue_end:
9262 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
9263 "set prologue end");
9266 case LI_set_epilogue_begin:
9267 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
9268 "set epilogue begin");
9271 case LI_set_discriminator:
9272 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
9273 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
9274 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
9275 dw2_asm_output_data_uleb128 (ent->val, NULL);
9280 /* Emit debug info for the address of the end of the table. */
9281 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
9282 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9283 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9284 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
9286 dw2_asm_output_data (1, 0, "end sequence");
9287 dw2_asm_output_data_uleb128 (1, NULL);
9288 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9291 /* Output the source line number correspondence information. This
9292 information goes into the .debug_line section. */
9295 output_line_info (void)
9297 char l1[20], l2[20], p1[20], p2[20];
9298 int ver = dwarf_version;
9299 bool saw_one = false;
9302 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9303 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9304 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9305 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9307 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9308 dw2_asm_output_data (4, 0xffffffff,
9309 "Initial length escape value indicating 64-bit DWARF extension");
9310 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9311 "Length of Source Line Info");
9312 ASM_OUTPUT_LABEL (asm_out_file, l1);
9314 dw2_asm_output_data (2, ver, "DWARF Version");
9315 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9316 ASM_OUTPUT_LABEL (asm_out_file, p1);
9318 /* Define the architecture-dependent minimum instruction length (in bytes).
9319 In this implementation of DWARF, this field is used for information
9320 purposes only. Since GCC generates assembly language, we have no
9321 a priori knowledge of how many instruction bytes are generated for each
9322 source line, and therefore can use only the DW_LNE_set_address and
9323 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9324 this as '1', which is "correct enough" for all architectures,
9325 and don't let the target override. */
9326 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9329 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
9330 "Maximum Operations Per Instruction");
9331 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9332 "Default is_stmt_start flag");
9333 dw2_asm_output_data (1, DWARF_LINE_BASE,
9334 "Line Base Value (Special Opcodes)");
9335 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9336 "Line Range Value (Special Opcodes)");
9337 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9338 "Special Opcode Base");
9340 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9345 case DW_LNS_advance_pc:
9346 case DW_LNS_advance_line:
9347 case DW_LNS_set_file:
9348 case DW_LNS_set_column:
9349 case DW_LNS_fixed_advance_pc:
9350 case DW_LNS_set_isa:
9358 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
9362 /* Write out the information about the files we use. */
9363 output_file_names ();
9364 ASM_OUTPUT_LABEL (asm_out_file, p2);
9366 if (separate_line_info)
9368 dw_line_info_table *table;
9371 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
9374 output_one_line_info_table (table);
9378 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
9380 output_one_line_info_table (cold_text_section_line_info);
9384 /* ??? Some Darwin linkers crash on a .debug_line section with no
9385 sequences. Further, merely a DW_LNE_end_sequence entry is not
9386 sufficient -- the address column must also be initialized.
9387 Make sure to output at least one set_address/end_sequence pair,
9388 choosing .text since that section is always present. */
9389 if (text_section_line_info->in_use || !saw_one)
9390 output_one_line_info_table (text_section_line_info);
9392 /* Output the marker for the end of the line number info. */
9393 ASM_OUTPUT_LABEL (asm_out_file, l2);
9396 /* Given a pointer to a tree node for some base type, return a pointer to
9397 a DIE that describes the given type.
9399 This routine must only be called for GCC type nodes that correspond to
9400 Dwarf base (fundamental) types. */
9403 base_type_die (tree type)
9405 dw_die_ref base_type_result;
9406 enum dwarf_type encoding;
9408 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9411 /* If this is a subtype that should not be emitted as a subrange type,
9412 use the base type. See subrange_type_for_debug_p. */
9413 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
9414 type = TREE_TYPE (type);
9416 switch (TREE_CODE (type))
9419 if ((dwarf_version >= 4 || !dwarf_strict)
9421 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9422 && DECL_IS_BUILTIN (TYPE_NAME (type))
9423 && DECL_NAME (TYPE_NAME (type)))
9425 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
9426 if (strcmp (name, "char16_t") == 0
9427 || strcmp (name, "char32_t") == 0)
9429 encoding = DW_ATE_UTF;
9433 if (TYPE_STRING_FLAG (type))
9435 if (TYPE_UNSIGNED (type))
9436 encoding = DW_ATE_unsigned_char;
9438 encoding = DW_ATE_signed_char;
9440 else if (TYPE_UNSIGNED (type))
9441 encoding = DW_ATE_unsigned;
9443 encoding = DW_ATE_signed;
9447 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9449 if (dwarf_version >= 3 || !dwarf_strict)
9450 encoding = DW_ATE_decimal_float;
9452 encoding = DW_ATE_lo_user;
9455 encoding = DW_ATE_float;
9458 case FIXED_POINT_TYPE:
9459 if (!(dwarf_version >= 3 || !dwarf_strict))
9460 encoding = DW_ATE_lo_user;
9461 else if (TYPE_UNSIGNED (type))
9462 encoding = DW_ATE_unsigned_fixed;
9464 encoding = DW_ATE_signed_fixed;
9467 /* Dwarf2 doesn't know anything about complex ints, so use
9468 a user defined type for it. */
9470 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9471 encoding = DW_ATE_complex_float;
9473 encoding = DW_ATE_lo_user;
9477 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9478 encoding = DW_ATE_boolean;
9482 /* No other TREE_CODEs are Dwarf fundamental types. */
9486 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
9488 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9489 int_size_in_bytes (type));
9490 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9492 return base_type_result;
9495 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9496 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9499 is_base_type (tree type)
9501 switch (TREE_CODE (type))
9507 case FIXED_POINT_TYPE:
9515 case QUAL_UNION_TYPE:
9520 case REFERENCE_TYPE:
9534 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9535 node, return the size in bits for the type if it is a constant, or else
9536 return the alignment for the type if the type's size is not constant, or
9537 else return BITS_PER_WORD if the type actually turns out to be an
9540 static inline unsigned HOST_WIDE_INT
9541 simple_type_size_in_bits (const_tree type)
9543 if (TREE_CODE (type) == ERROR_MARK)
9544 return BITS_PER_WORD;
9545 else if (TYPE_SIZE (type) == NULL_TREE)
9547 else if (host_integerp (TYPE_SIZE (type), 1))
9548 return tree_low_cst (TYPE_SIZE (type), 1);
9550 return TYPE_ALIGN (type);
9553 /* Similarly, but return a double_int instead of UHWI. */
9555 static inline double_int
9556 double_int_type_size_in_bits (const_tree type)
9558 if (TREE_CODE (type) == ERROR_MARK)
9559 return uhwi_to_double_int (BITS_PER_WORD);
9560 else if (TYPE_SIZE (type) == NULL_TREE)
9561 return double_int_zero;
9562 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
9563 return tree_to_double_int (TYPE_SIZE (type));
9565 return uhwi_to_double_int (TYPE_ALIGN (type));
9568 /* Given a pointer to a tree node for a subrange type, return a pointer
9569 to a DIE that describes the given type. */
9572 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
9574 dw_die_ref subrange_die;
9575 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9577 if (context_die == NULL)
9578 context_die = comp_unit_die ();
9580 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9582 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9584 /* The size of the subrange type and its base type do not match,
9585 so we need to generate a size attribute for the subrange type. */
9586 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9590 add_bound_info (subrange_die, DW_AT_lower_bound, low);
9592 add_bound_info (subrange_die, DW_AT_upper_bound, high);
9594 return subrange_die;
9597 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9598 entry that chains various modifiers in front of the given type. */
9601 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9602 dw_die_ref context_die)
9604 enum tree_code code = TREE_CODE (type);
9605 dw_die_ref mod_type_die;
9606 dw_die_ref sub_die = NULL;
9607 tree item_type = NULL;
9608 tree qualified_type;
9609 tree name, low, high;
9611 if (code == ERROR_MARK)
9614 /* See if we already have the appropriately qualified variant of
9617 = get_qualified_type (type,
9618 ((is_const_type ? TYPE_QUAL_CONST : 0)
9619 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9621 if (qualified_type == sizetype
9622 && TYPE_NAME (qualified_type)
9623 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
9625 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
9627 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
9628 && TYPE_PRECISION (t)
9629 == TYPE_PRECISION (qualified_type)
9630 && TYPE_UNSIGNED (t)
9631 == TYPE_UNSIGNED (qualified_type));
9635 /* If we do, then we can just use its DIE, if it exists. */
9638 mod_type_die = lookup_type_die (qualified_type);
9640 return mod_type_die;
9643 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9645 /* Handle C typedef types. */
9646 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
9647 && !DECL_ARTIFICIAL (name))
9649 tree dtype = TREE_TYPE (name);
9651 if (qualified_type == dtype)
9653 /* For a named type, use the typedef. */
9654 gen_type_die (qualified_type, context_die);
9655 return lookup_type_die (qualified_type);
9657 else if (is_const_type < TYPE_READONLY (dtype)
9658 || is_volatile_type < TYPE_VOLATILE (dtype)
9659 || (is_const_type <= TYPE_READONLY (dtype)
9660 && is_volatile_type <= TYPE_VOLATILE (dtype)
9661 && DECL_ORIGINAL_TYPE (name) != type))
9662 /* cv-unqualified version of named type. Just use the unnamed
9663 type to which it refers. */
9664 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9665 is_const_type, is_volatile_type,
9667 /* Else cv-qualified version of named type; fall through. */
9671 /* If both is_const_type and is_volatile_type, prefer the path
9672 which leads to a qualified type. */
9673 && (!is_volatile_type
9674 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
9675 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
9677 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
9678 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9680 else if (is_volatile_type)
9682 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
9683 sub_die = modified_type_die (type, is_const_type, 0, context_die);
9685 else if (code == POINTER_TYPE)
9687 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
9688 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9689 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9690 item_type = TREE_TYPE (type);
9691 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
9692 add_AT_unsigned (mod_type_die, DW_AT_address_class,
9693 TYPE_ADDR_SPACE (item_type));
9695 else if (code == REFERENCE_TYPE)
9697 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
9698 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
9701 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
9702 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9703 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9704 item_type = TREE_TYPE (type);
9705 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
9706 add_AT_unsigned (mod_type_die, DW_AT_address_class,
9707 TYPE_ADDR_SPACE (item_type));
9709 else if (code == INTEGER_TYPE
9710 && TREE_TYPE (type) != NULL_TREE
9711 && subrange_type_for_debug_p (type, &low, &high))
9713 mod_type_die = subrange_type_die (type, low, high, context_die);
9714 item_type = TREE_TYPE (type);
9716 else if (is_base_type (type))
9717 mod_type_die = base_type_die (type);
9720 gen_type_die (type, context_die);
9722 /* We have to get the type_main_variant here (and pass that to the
9723 `lookup_type_die' routine) because the ..._TYPE node we have
9724 might simply be a *copy* of some original type node (where the
9725 copy was created to help us keep track of typedef names) and
9726 that copy might have a different TYPE_UID from the original
9728 if (TREE_CODE (type) != VECTOR_TYPE)
9729 return lookup_type_die (type_main_variant (type));
9731 /* Vectors have the debugging information in the type,
9732 not the main variant. */
9733 return lookup_type_die (type);
9736 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9737 don't output a DW_TAG_typedef, since there isn't one in the
9738 user's program; just attach a DW_AT_name to the type.
9739 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
9740 if the base type already has the same name. */
9742 && ((TREE_CODE (name) != TYPE_DECL
9743 && (qualified_type == TYPE_MAIN_VARIANT (type)
9744 || (!is_const_type && !is_volatile_type)))
9745 || (TREE_CODE (name) == TYPE_DECL
9746 && TREE_TYPE (name) == qualified_type
9747 && DECL_NAME (name))))
9749 if (TREE_CODE (name) == TYPE_DECL)
9750 /* Could just call add_name_and_src_coords_attributes here,
9751 but since this is a builtin type it doesn't have any
9752 useful source coordinates anyway. */
9753 name = DECL_NAME (name);
9754 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9755 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
9756 if (TYPE_ARTIFICIAL (type))
9757 add_AT_flag (mod_type_die, DW_AT_artificial, 1);
9759 /* This probably indicates a bug. */
9760 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
9761 add_name_attribute (mod_type_die, "__unknown__");
9764 equate_type_number_to_die (qualified_type, mod_type_die);
9767 /* We must do this after the equate_type_number_to_die call, in case
9768 this is a recursive type. This ensures that the modified_type_die
9769 recursion will terminate even if the type is recursive. Recursive
9770 types are possible in Ada. */
9771 sub_die = modified_type_die (item_type,
9772 TYPE_READONLY (item_type),
9773 TYPE_VOLATILE (item_type),
9776 if (sub_die != NULL)
9777 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9779 return mod_type_die;
9782 /* Generate DIEs for the generic parameters of T.
9783 T must be either a generic type or a generic function.
9784 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
9787 gen_generic_params_dies (tree t)
9791 dw_die_ref die = NULL;
9793 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
9797 die = lookup_type_die (t);
9798 else if (DECL_P (t))
9799 die = lookup_decl_die (t);
9803 parms = lang_hooks.get_innermost_generic_parms (t);
9805 /* T has no generic parameter. It means T is neither a generic type
9806 or function. End of story. */
9809 parms_num = TREE_VEC_LENGTH (parms);
9810 args = lang_hooks.get_innermost_generic_args (t);
9811 for (i = 0; i < parms_num; i++)
9813 tree parm, arg, arg_pack_elems;
9815 parm = TREE_VEC_ELT (parms, i);
9816 arg = TREE_VEC_ELT (args, i);
9817 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
9818 gcc_assert (parm && TREE_VALUE (parm) && arg);
9820 if (parm && TREE_VALUE (parm) && arg)
9822 /* If PARM represents a template parameter pack,
9823 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
9824 by DW_TAG_template_*_parameter DIEs for the argument
9825 pack elements of ARG. Note that ARG would then be
9826 an argument pack. */
9828 template_parameter_pack_die (TREE_VALUE (parm),
9832 generic_parameter_die (TREE_VALUE (parm), arg,
9833 true /* Emit DW_AT_name */, die);
9838 /* Create and return a DIE for PARM which should be
9839 the representation of a generic type parameter.
9840 For instance, in the C++ front end, PARM would be a template parameter.
9841 ARG is the argument to PARM.
9842 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
9844 PARENT_DIE is the parent DIE which the new created DIE should be added to,
9848 generic_parameter_die (tree parm, tree arg,
9850 dw_die_ref parent_die)
9852 dw_die_ref tmpl_die = NULL;
9853 const char *name = NULL;
9855 if (!parm || !DECL_NAME (parm) || !arg)
9858 /* We support non-type generic parameters and arguments,
9859 type generic parameters and arguments, as well as
9860 generic generic parameters (a.k.a. template template parameters in C++)
9862 if (TREE_CODE (parm) == PARM_DECL)
9863 /* PARM is a nontype generic parameter */
9864 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
9865 else if (TREE_CODE (parm) == TYPE_DECL)
9866 /* PARM is a type generic parameter. */
9867 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
9868 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
9869 /* PARM is a generic generic parameter.
9870 Its DIE is a GNU extension. It shall have a
9871 DW_AT_name attribute to represent the name of the template template
9872 parameter, and a DW_AT_GNU_template_name attribute to represent the
9873 name of the template template argument. */
9874 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
9883 /* If PARM is a generic parameter pack, it means we are
9884 emitting debug info for a template argument pack element.
9885 In other terms, ARG is a template argument pack element.
9886 In that case, we don't emit any DW_AT_name attribute for
9890 name = IDENTIFIER_POINTER (DECL_NAME (parm));
9892 add_AT_string (tmpl_die, DW_AT_name, name);
9895 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
9897 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
9898 TMPL_DIE should have a child DW_AT_type attribute that is set
9899 to the type of the argument to PARM, which is ARG.
9900 If PARM is a type generic parameter, TMPL_DIE should have a
9901 child DW_AT_type that is set to ARG. */
9902 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
9903 add_type_attribute (tmpl_die, tmpl_type, 0,
9904 TREE_THIS_VOLATILE (tmpl_type),
9909 /* So TMPL_DIE is a DIE representing a
9910 a generic generic template parameter, a.k.a template template
9911 parameter in C++ and arg is a template. */
9913 /* The DW_AT_GNU_template_name attribute of the DIE must be set
9914 to the name of the argument. */
9915 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
9917 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
9920 if (TREE_CODE (parm) == PARM_DECL)
9921 /* So PARM is a non-type generic parameter.
9922 DWARF3 5.6.8 says we must set a DW_AT_const_value child
9923 attribute of TMPL_DIE which value represents the value
9925 We must be careful here:
9926 The value of ARG might reference some function decls.
9927 We might currently be emitting debug info for a generic
9928 type and types are emitted before function decls, we don't
9929 know if the function decls referenced by ARG will actually be
9930 emitted after cgraph computations.
9931 So must defer the generation of the DW_AT_const_value to
9932 after cgraph is ready. */
9933 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
9939 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
9940 PARM_PACK must be a template parameter pack. The returned DIE
9941 will be child DIE of PARENT_DIE. */
9944 template_parameter_pack_die (tree parm_pack,
9945 tree parm_pack_args,
9946 dw_die_ref parent_die)
9951 gcc_assert (parent_die && parm_pack);
9953 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
9954 add_name_and_src_coords_attributes (die, parm_pack);
9955 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
9956 generic_parameter_die (parm_pack,
9957 TREE_VEC_ELT (parm_pack_args, j),
9958 false /* Don't emit DW_AT_name */,
9963 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9964 an enumerated type. */
9967 type_is_enum (const_tree type)
9969 return TREE_CODE (type) == ENUMERAL_TYPE;
9972 /* Return the DBX register number described by a given RTL node. */
9975 dbx_reg_number (const_rtx rtl)
9977 unsigned regno = REGNO (rtl);
9979 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
9981 #ifdef LEAF_REG_REMAP
9982 if (current_function_uses_only_leaf_regs)
9984 int leaf_reg = LEAF_REG_REMAP (regno);
9986 regno = (unsigned) leaf_reg;
9990 return DBX_REGISTER_NUMBER (regno);
9993 /* Optionally add a DW_OP_piece term to a location description expression.
9994 DW_OP_piece is only added if the location description expression already
9995 doesn't end with DW_OP_piece. */
9998 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10000 dw_loc_descr_ref loc;
10002 if (*list_head != NULL)
10004 /* Find the end of the chain. */
10005 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10008 if (loc->dw_loc_opc != DW_OP_piece)
10009 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10013 /* Return a location descriptor that designates a machine register or
10014 zero if there is none. */
10016 static dw_loc_descr_ref
10017 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10021 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10024 /* We only use "frame base" when we're sure we're talking about the
10025 post-prologue local stack frame. We do this by *not* running
10026 register elimination until this point, and recognizing the special
10027 argument pointer and soft frame pointer rtx's.
10028 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10029 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
10030 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
10032 dw_loc_descr_ref result = NULL;
10034 if (dwarf_version >= 4 || !dwarf_strict)
10036 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
10039 add_loc_descr (&result,
10040 new_loc_descr (DW_OP_stack_value, 0, 0));
10045 regs = targetm.dwarf_register_span (rtl);
10047 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10048 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10050 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10053 /* Return a location descriptor that designates a machine register for
10054 a given hard register number. */
10056 static dw_loc_descr_ref
10057 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10059 dw_loc_descr_ref reg_loc_descr;
10063 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10065 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10067 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10068 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10070 return reg_loc_descr;
10073 /* Given an RTL of a register, return a location descriptor that
10074 designates a value that spans more than one register. */
10076 static dw_loc_descr_ref
10077 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10078 enum var_init_status initialized)
10080 int nregs, size, i;
10082 dw_loc_descr_ref loc_result = NULL;
10085 #ifdef LEAF_REG_REMAP
10086 if (current_function_uses_only_leaf_regs)
10088 int leaf_reg = LEAF_REG_REMAP (reg);
10089 if (leaf_reg != -1)
10090 reg = (unsigned) leaf_reg;
10093 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10094 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10096 /* Simple, contiguous registers. */
10097 if (regs == NULL_RTX)
10099 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10104 dw_loc_descr_ref t;
10106 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10107 VAR_INIT_STATUS_INITIALIZED);
10108 add_loc_descr (&loc_result, t);
10109 add_loc_descr_op_piece (&loc_result, size);
10115 /* Now onto stupid register sets in non contiguous locations. */
10117 gcc_assert (GET_CODE (regs) == PARALLEL);
10119 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10122 for (i = 0; i < XVECLEN (regs, 0); ++i)
10124 dw_loc_descr_ref t;
10126 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10127 VAR_INIT_STATUS_INITIALIZED);
10128 add_loc_descr (&loc_result, t);
10129 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10130 add_loc_descr_op_piece (&loc_result, size);
10133 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10134 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10138 /* Return a location descriptor that designates a constant. */
10140 static dw_loc_descr_ref
10141 int_loc_descriptor (HOST_WIDE_INT i)
10143 enum dwarf_location_atom op;
10145 /* Pick the smallest representation of a constant, rather than just
10146 defaulting to the LEB encoding. */
10150 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10151 else if (i <= 0xff)
10152 op = DW_OP_const1u;
10153 else if (i <= 0xffff)
10154 op = DW_OP_const2u;
10155 else if (HOST_BITS_PER_WIDE_INT == 32
10156 || i <= 0xffffffff)
10157 op = DW_OP_const4u;
10164 op = DW_OP_const1s;
10165 else if (i >= -0x8000)
10166 op = DW_OP_const2s;
10167 else if (HOST_BITS_PER_WIDE_INT == 32
10168 || i >= -0x80000000)
10169 op = DW_OP_const4s;
10174 return new_loc_descr (op, i, 0);
10177 /* Return size_of_locs (int_loc_descriptor (i)) without
10178 actually allocating it. */
10180 static unsigned long
10181 size_of_int_loc_descriptor (HOST_WIDE_INT i)
10187 else if (i <= 0xff)
10189 else if (i <= 0xffff)
10191 else if (HOST_BITS_PER_WIDE_INT == 32
10192 || i <= 0xffffffff)
10195 return 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
10201 else if (i >= -0x8000)
10203 else if (HOST_BITS_PER_WIDE_INT == 32
10204 || i >= -0x80000000)
10207 return 1 + size_of_sleb128 (i);
10211 /* Return loc description representing "address" of integer value.
10212 This can appear only as toplevel expression. */
10214 static dw_loc_descr_ref
10215 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
10218 dw_loc_descr_ref loc_result = NULL;
10220 if (!(dwarf_version >= 4 || !dwarf_strict))
10223 litsize = size_of_int_loc_descriptor (i);
10224 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10225 is more compact. For DW_OP_stack_value we need:
10226 litsize + 1 (DW_OP_stack_value)
10227 and for DW_OP_implicit_value:
10228 1 (DW_OP_implicit_value) + 1 (length) + size. */
10229 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
10231 loc_result = int_loc_descriptor (i);
10232 add_loc_descr (&loc_result,
10233 new_loc_descr (DW_OP_stack_value, 0, 0));
10237 loc_result = new_loc_descr (DW_OP_implicit_value,
10239 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
10240 loc_result->dw_loc_oprnd2.v.val_int = i;
10244 /* Return a location descriptor that designates a base+offset location. */
10246 static dw_loc_descr_ref
10247 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10248 enum var_init_status initialized)
10250 unsigned int regno;
10251 dw_loc_descr_ref result;
10252 dw_fde_ref fde = cfun->fde;
10254 /* We only use "frame base" when we're sure we're talking about the
10255 post-prologue local stack frame. We do this by *not* running
10256 register elimination until this point, and recognizing the special
10257 argument pointer and soft frame pointer rtx's. */
10258 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10260 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10264 if (GET_CODE (elim) == PLUS)
10266 offset += INTVAL (XEXP (elim, 1));
10267 elim = XEXP (elim, 0);
10269 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10270 && (elim == hard_frame_pointer_rtx
10271 || elim == stack_pointer_rtx))
10272 || elim == (frame_pointer_needed
10273 ? hard_frame_pointer_rtx
10274 : stack_pointer_rtx));
10276 /* If drap register is used to align stack, use frame
10277 pointer + offset to access stack variables. If stack
10278 is aligned without drap, use stack pointer + offset to
10279 access stack variables. */
10280 if (crtl->stack_realign_tried
10281 && reg == frame_pointer_rtx)
10284 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10285 ? HARD_FRAME_POINTER_REGNUM
10287 return new_reg_loc_descr (base_reg, offset);
10290 gcc_assert (frame_pointer_fb_offset_valid);
10291 offset += frame_pointer_fb_offset;
10292 return new_loc_descr (DW_OP_fbreg, offset, 0);
10297 && (fde->drap_reg == REGNO (reg)
10298 || fde->vdrap_reg == REGNO (reg)))
10300 /* Use cfa+offset to represent the location of arguments passed
10301 on the stack when drap is used to align stack.
10302 Only do this when not optimizing, for optimized code var-tracking
10303 is supposed to track where the arguments live and the register
10304 used as vdrap or drap in some spot might be used for something
10305 else in other part of the routine. */
10306 return new_loc_descr (DW_OP_fbreg, offset, 0);
10309 regno = dbx_reg_number (reg);
10311 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10314 result = new_loc_descr (DW_OP_bregx, regno, offset);
10316 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10317 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10322 /* Return true if this RTL expression describes a base+offset calculation. */
10325 is_based_loc (const_rtx rtl)
10327 return (GET_CODE (rtl) == PLUS
10328 && ((REG_P (XEXP (rtl, 0))
10329 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10330 && CONST_INT_P (XEXP (rtl, 1)))));
10333 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10336 static dw_loc_descr_ref
10337 tls_mem_loc_descriptor (rtx mem)
10340 dw_loc_descr_ref loc_result;
10342 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
10345 base = get_base_address (MEM_EXPR (mem));
10347 || TREE_CODE (base) != VAR_DECL
10348 || !DECL_THREAD_LOCAL_P (base))
10351 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
10352 if (loc_result == NULL)
10355 if (INTVAL (MEM_OFFSET (mem)))
10356 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
10361 /* Output debug info about reason why we failed to expand expression as dwarf
10365 expansion_failed (tree expr, rtx rtl, char const *reason)
10367 if (dump_file && (dump_flags & TDF_DETAILS))
10369 fprintf (dump_file, "Failed to expand as dwarf: ");
10371 print_generic_expr (dump_file, expr, dump_flags);
10374 fprintf (dump_file, "\n");
10375 print_rtl (dump_file, rtl);
10377 fprintf (dump_file, "\nReason: %s\n", reason);
10381 /* Helper function for const_ok_for_output, called either directly
10382 or via for_each_rtx. */
10385 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
10389 if (GET_CODE (rtl) == UNSPEC)
10391 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10392 we can't express it in the debug info. */
10393 #ifdef ENABLE_CHECKING
10394 /* Don't complain about TLS UNSPECs, those are just too hard to
10396 if (XVECLEN (rtl, 0) != 1
10397 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
10398 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
10399 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
10400 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
10401 inform (current_function_decl
10402 ? DECL_SOURCE_LOCATION (current_function_decl)
10403 : UNKNOWN_LOCATION,
10404 #if NUM_UNSPEC_VALUES > 0
10405 "non-delegitimized UNSPEC %s (%d) found in variable location",
10406 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
10407 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
10410 "non-delegitimized UNSPEC %d found in variable location",
10414 expansion_failed (NULL_TREE, rtl,
10415 "UNSPEC hasn't been delegitimized.\n");
10419 if (GET_CODE (rtl) != SYMBOL_REF)
10422 if (CONSTANT_POOL_ADDRESS_P (rtl))
10425 get_pool_constant_mark (rtl, &marked);
10426 /* If all references to this pool constant were optimized away,
10427 it was not output and thus we can't represent it. */
10430 expansion_failed (NULL_TREE, rtl,
10431 "Constant was removed from constant pool.\n");
10436 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
10439 /* Avoid references to external symbols in debug info, on several targets
10440 the linker might even refuse to link when linking a shared library,
10441 and in many other cases the relocations for .debug_info/.debug_loc are
10442 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
10443 to be defined within the same shared library or executable are fine. */
10444 if (SYMBOL_REF_EXTERNAL_P (rtl))
10446 tree decl = SYMBOL_REF_DECL (rtl);
10448 if (decl == NULL || !targetm.binds_local_p (decl))
10450 expansion_failed (NULL_TREE, rtl,
10451 "Symbol not defined in current TU.\n");
10459 /* Return true if constant RTL can be emitted in DW_OP_addr or
10460 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
10461 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
10464 const_ok_for_output (rtx rtl)
10466 if (GET_CODE (rtl) == SYMBOL_REF)
10467 return const_ok_for_output_1 (&rtl, NULL) == 0;
10469 if (GET_CODE (rtl) == CONST)
10470 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
10475 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
10476 if possible, NULL otherwise. */
10479 base_type_for_mode (enum machine_mode mode, bool unsignedp)
10481 dw_die_ref type_die;
10482 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
10486 switch (TREE_CODE (type))
10494 type_die = lookup_type_die (type);
10496 type_die = modified_type_die (type, false, false, comp_unit_die ());
10497 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
10502 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
10503 type matching MODE, or, if MODE is narrower than or as wide as
10504 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
10507 static dw_loc_descr_ref
10508 convert_descriptor_to_mode (enum machine_mode mode, dw_loc_descr_ref op)
10510 enum machine_mode outer_mode = mode;
10511 dw_die_ref type_die;
10512 dw_loc_descr_ref cvt;
10514 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
10516 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
10519 type_die = base_type_for_mode (outer_mode, 1);
10520 if (type_die == NULL)
10522 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10523 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10524 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10525 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10526 add_loc_descr (&op, cvt);
10530 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
10532 static dw_loc_descr_ref
10533 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
10534 dw_loc_descr_ref op1)
10536 dw_loc_descr_ref ret = op0;
10537 add_loc_descr (&ret, op1);
10538 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10539 if (STORE_FLAG_VALUE != 1)
10541 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
10542 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
10547 /* Return location descriptor for signed comparison OP RTL. */
10549 static dw_loc_descr_ref
10550 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
10551 enum machine_mode mem_mode)
10553 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
10554 dw_loc_descr_ref op0, op1;
10557 if (op_mode == VOIDmode)
10558 op_mode = GET_MODE (XEXP (rtl, 1));
10559 if (op_mode == VOIDmode)
10563 && (GET_MODE_CLASS (op_mode) != MODE_INT
10564 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
10567 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
10568 VAR_INIT_STATUS_INITIALIZED);
10569 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
10570 VAR_INIT_STATUS_INITIALIZED);
10572 if (op0 == NULL || op1 == NULL)
10575 if (GET_MODE_CLASS (op_mode) != MODE_INT
10576 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
10577 return compare_loc_descriptor (op, op0, op1);
10579 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
10581 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
10582 dw_loc_descr_ref cvt;
10584 if (type_die == NULL)
10586 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10587 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10588 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10589 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10590 add_loc_descr (&op0, cvt);
10591 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10592 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10593 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10594 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10595 add_loc_descr (&op1, cvt);
10596 return compare_loc_descriptor (op, op0, op1);
10599 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
10600 /* For eq/ne, if the operands are known to be zero-extended,
10601 there is no need to do the fancy shifting up. */
10602 if (op == DW_OP_eq || op == DW_OP_ne)
10604 dw_loc_descr_ref last0, last1;
10605 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
10607 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
10609 /* deref_size zero extends, and for constants we can check
10610 whether they are zero extended or not. */
10611 if (((last0->dw_loc_opc == DW_OP_deref_size
10612 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
10613 || (CONST_INT_P (XEXP (rtl, 0))
10614 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
10615 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
10616 && ((last1->dw_loc_opc == DW_OP_deref_size
10617 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
10618 || (CONST_INT_P (XEXP (rtl, 1))
10619 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
10620 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
10621 return compare_loc_descriptor (op, op0, op1);
10623 /* EQ/NE comparison against constant in narrower type than
10624 DWARF2_ADDR_SIZE can be performed either as
10625 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
10628 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
10629 DW_OP_{eq,ne}. Pick whatever is shorter. */
10630 if (CONST_INT_P (XEXP (rtl, 1))
10631 && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
10632 && (size_of_int_loc_descriptor (shift) + 1
10633 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift)
10634 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
10635 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
10636 & GET_MODE_MASK (op_mode))))
10638 add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
10639 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10640 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
10641 & GET_MODE_MASK (op_mode));
10642 return compare_loc_descriptor (op, op0, op1);
10645 add_loc_descr (&op0, int_loc_descriptor (shift));
10646 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
10647 if (CONST_INT_P (XEXP (rtl, 1)))
10648 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
10651 add_loc_descr (&op1, int_loc_descriptor (shift));
10652 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
10654 return compare_loc_descriptor (op, op0, op1);
10657 /* Return location descriptor for unsigned comparison OP RTL. */
10659 static dw_loc_descr_ref
10660 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
10661 enum machine_mode mem_mode)
10663 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
10664 dw_loc_descr_ref op0, op1;
10666 if (op_mode == VOIDmode)
10667 op_mode = GET_MODE (XEXP (rtl, 1));
10668 if (op_mode == VOIDmode)
10670 if (GET_MODE_CLASS (op_mode) != MODE_INT)
10673 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
10676 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
10677 VAR_INIT_STATUS_INITIALIZED);
10678 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
10679 VAR_INIT_STATUS_INITIALIZED);
10681 if (op0 == NULL || op1 == NULL)
10684 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
10686 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
10687 dw_loc_descr_ref last0, last1;
10688 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
10690 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
10692 if (CONST_INT_P (XEXP (rtl, 0)))
10693 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
10694 /* deref_size zero extends, so no need to mask it again. */
10695 else if (last0->dw_loc_opc != DW_OP_deref_size
10696 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
10698 add_loc_descr (&op0, int_loc_descriptor (mask));
10699 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10701 if (CONST_INT_P (XEXP (rtl, 1)))
10702 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
10703 /* deref_size zero extends, so no need to mask it again. */
10704 else if (last1->dw_loc_opc != DW_OP_deref_size
10705 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
10707 add_loc_descr (&op1, int_loc_descriptor (mask));
10708 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
10711 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
10713 HOST_WIDE_INT bias = 1;
10714 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
10715 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
10716 if (CONST_INT_P (XEXP (rtl, 1)))
10717 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
10718 + INTVAL (XEXP (rtl, 1)));
10720 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
10723 return compare_loc_descriptor (op, op0, op1);
10726 /* Return location descriptor for {U,S}{MIN,MAX}. */
10728 static dw_loc_descr_ref
10729 minmax_loc_descriptor (rtx rtl, enum machine_mode mode,
10730 enum machine_mode mem_mode)
10732 enum dwarf_location_atom op;
10733 dw_loc_descr_ref op0, op1, ret;
10734 dw_loc_descr_ref bra_node, drop_node;
10737 && (GET_MODE_CLASS (mode) != MODE_INT
10738 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
10741 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
10742 VAR_INIT_STATUS_INITIALIZED);
10743 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
10744 VAR_INIT_STATUS_INITIALIZED);
10746 if (op0 == NULL || op1 == NULL)
10749 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
10750 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
10751 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
10752 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
10754 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
10756 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
10757 add_loc_descr (&op0, int_loc_descriptor (mask));
10758 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10759 add_loc_descr (&op1, int_loc_descriptor (mask));
10760 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
10762 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
10764 HOST_WIDE_INT bias = 1;
10765 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
10766 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
10767 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
10770 else if (GET_MODE_CLASS (mode) == MODE_INT
10771 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
10773 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
10774 add_loc_descr (&op0, int_loc_descriptor (shift));
10775 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
10776 add_loc_descr (&op1, int_loc_descriptor (shift));
10777 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
10779 else if (GET_MODE_CLASS (mode) == MODE_INT
10780 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
10782 dw_die_ref type_die = base_type_for_mode (mode, 0);
10783 dw_loc_descr_ref cvt;
10784 if (type_die == NULL)
10786 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10787 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10788 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10789 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10790 add_loc_descr (&op0, cvt);
10791 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10792 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10793 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10794 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10795 add_loc_descr (&op1, cvt);
10798 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
10803 add_loc_descr (&ret, op1);
10804 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10805 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
10806 add_loc_descr (&ret, bra_node);
10807 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
10808 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
10809 add_loc_descr (&ret, drop_node);
10810 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10811 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
10812 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
10813 && GET_MODE_CLASS (mode) == MODE_INT
10814 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
10815 ret = convert_descriptor_to_mode (mode, ret);
10819 /* Helper function for mem_loc_descriptor. Perform OP binary op,
10820 but after converting arguments to type_die, afterwards
10821 convert back to unsigned. */
10823 static dw_loc_descr_ref
10824 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
10825 enum machine_mode mode, enum machine_mode mem_mode)
10827 dw_loc_descr_ref cvt, op0, op1;
10829 if (type_die == NULL)
10831 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
10832 VAR_INIT_STATUS_INITIALIZED);
10833 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
10834 VAR_INIT_STATUS_INITIALIZED);
10835 if (op0 == NULL || op1 == 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 (&op0, cvt);
10842 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10843 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10844 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10845 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10846 add_loc_descr (&op1, cvt);
10847 add_loc_descr (&op0, op1);
10848 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
10849 return convert_descriptor_to_mode (mode, op0);
10852 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
10853 const0 is DW_OP_lit0 or corresponding typed constant,
10854 const1 is DW_OP_lit1 or corresponding typed constant
10855 and constMSB is constant with just the MSB bit set
10857 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10858 L1: const0 DW_OP_swap
10859 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
10860 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10865 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10866 L1: const0 DW_OP_swap
10867 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
10868 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10873 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
10874 L1: const1 DW_OP_swap
10875 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
10876 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10880 static dw_loc_descr_ref
10881 clz_loc_descriptor (rtx rtl, enum machine_mode mode,
10882 enum machine_mode mem_mode)
10884 dw_loc_descr_ref op0, ret, tmp;
10885 HOST_WIDE_INT valv;
10886 dw_loc_descr_ref l1jump, l1label;
10887 dw_loc_descr_ref l2jump, l2label;
10888 dw_loc_descr_ref l3jump, l3label;
10889 dw_loc_descr_ref l4jump, l4label;
10892 if (GET_MODE_CLASS (mode) != MODE_INT
10893 || GET_MODE (XEXP (rtl, 0)) != mode
10894 || (GET_CODE (rtl) == CLZ
10895 && GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT))
10898 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
10899 VAR_INIT_STATUS_INITIALIZED);
10903 if (GET_CODE (rtl) == CLZ)
10905 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
10906 valv = GET_MODE_BITSIZE (mode);
10908 else if (GET_CODE (rtl) == FFS)
10910 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
10911 valv = GET_MODE_BITSIZE (mode);
10912 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
10913 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
10914 add_loc_descr (&ret, l1jump);
10915 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
10916 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
10917 VAR_INIT_STATUS_INITIALIZED);
10920 add_loc_descr (&ret, tmp);
10921 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
10922 add_loc_descr (&ret, l4jump);
10923 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
10924 ? const1_rtx : const0_rtx,
10926 VAR_INIT_STATUS_INITIALIZED);
10927 if (l1label == NULL)
10929 add_loc_descr (&ret, l1label);
10930 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
10931 l2label = new_loc_descr (DW_OP_dup, 0, 0);
10932 add_loc_descr (&ret, l2label);
10933 if (GET_CODE (rtl) != CLZ)
10935 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
10936 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
10937 << (GET_MODE_BITSIZE (mode) - 1));
10939 msb = immed_double_const (0, (unsigned HOST_WIDE_INT) 1
10940 << (GET_MODE_BITSIZE (mode)
10941 - HOST_BITS_PER_WIDE_INT - 1), mode);
10942 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
10943 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
10944 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
10945 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
10947 tmp = mem_loc_descriptor (msb, mode, mem_mode,
10948 VAR_INIT_STATUS_INITIALIZED);
10951 add_loc_descr (&ret, tmp);
10952 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
10953 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
10954 add_loc_descr (&ret, l3jump);
10955 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
10956 VAR_INIT_STATUS_INITIALIZED);
10959 add_loc_descr (&ret, tmp);
10960 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
10961 ? DW_OP_shl : DW_OP_shr, 0, 0));
10962 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
10963 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
10964 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
10965 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
10966 add_loc_descr (&ret, l2jump);
10967 l3label = new_loc_descr (DW_OP_drop, 0, 0);
10968 add_loc_descr (&ret, l3label);
10969 l4label = new_loc_descr (DW_OP_nop, 0, 0);
10970 add_loc_descr (&ret, l4label);
10971 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
10972 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
10973 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
10974 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
10975 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
10976 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
10977 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
10978 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
10982 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
10983 const1 is DW_OP_lit1 or corresponding typed constant):
10985 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
10986 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
10990 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
10991 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
10994 static dw_loc_descr_ref
10995 popcount_loc_descriptor (rtx rtl, enum machine_mode mode,
10996 enum machine_mode mem_mode)
10998 dw_loc_descr_ref op0, ret, tmp;
10999 dw_loc_descr_ref l1jump, l1label;
11000 dw_loc_descr_ref l2jump, l2label;
11002 if (GET_MODE_CLASS (mode) != MODE_INT
11003 || GET_MODE (XEXP (rtl, 0)) != mode)
11006 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11007 VAR_INIT_STATUS_INITIALIZED);
11011 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11012 VAR_INIT_STATUS_INITIALIZED);
11015 add_loc_descr (&ret, tmp);
11016 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11017 l1label = new_loc_descr (DW_OP_dup, 0, 0);
11018 add_loc_descr (&ret, l1label);
11019 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11020 add_loc_descr (&ret, l2jump);
11021 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11022 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11023 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11024 VAR_INIT_STATUS_INITIALIZED);
11027 add_loc_descr (&ret, tmp);
11028 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11029 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
11030 ? DW_OP_plus : DW_OP_xor, 0, 0));
11031 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11032 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11033 VAR_INIT_STATUS_INITIALIZED);
11034 add_loc_descr (&ret, tmp);
11035 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11036 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11037 add_loc_descr (&ret, l1jump);
11038 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11039 add_loc_descr (&ret, l2label);
11040 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11041 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11042 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11043 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11047 /* BSWAP (constS is initial shift count, either 56 or 24):
11049 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11050 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11051 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11052 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11053 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11055 static dw_loc_descr_ref
11056 bswap_loc_descriptor (rtx rtl, enum machine_mode mode,
11057 enum machine_mode mem_mode)
11059 dw_loc_descr_ref op0, ret, tmp;
11060 dw_loc_descr_ref l1jump, l1label;
11061 dw_loc_descr_ref l2jump, l2label;
11063 if (GET_MODE_CLASS (mode) != MODE_INT
11064 || BITS_PER_UNIT != 8
11065 || (GET_MODE_BITSIZE (mode) != 32
11066 && GET_MODE_BITSIZE (mode) != 64))
11069 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11070 VAR_INIT_STATUS_INITIALIZED);
11075 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11077 VAR_INIT_STATUS_INITIALIZED);
11080 add_loc_descr (&ret, tmp);
11081 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11082 VAR_INIT_STATUS_INITIALIZED);
11085 add_loc_descr (&ret, tmp);
11086 l1label = new_loc_descr (DW_OP_pick, 2, 0);
11087 add_loc_descr (&ret, l1label);
11088 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11090 VAR_INIT_STATUS_INITIALIZED);
11091 add_loc_descr (&ret, tmp);
11092 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
11093 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11094 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11095 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
11096 VAR_INIT_STATUS_INITIALIZED);
11099 add_loc_descr (&ret, tmp);
11100 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11101 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
11102 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11103 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11104 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11105 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11106 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11107 VAR_INIT_STATUS_INITIALIZED);
11108 add_loc_descr (&ret, tmp);
11109 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
11110 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11111 add_loc_descr (&ret, l2jump);
11112 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
11113 VAR_INIT_STATUS_INITIALIZED);
11114 add_loc_descr (&ret, tmp);
11115 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11116 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11117 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11118 add_loc_descr (&ret, l1jump);
11119 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11120 add_loc_descr (&ret, l2label);
11121 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11122 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11123 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11124 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11125 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11126 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11130 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11131 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11132 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11133 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11135 ROTATERT is similar:
11136 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11137 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11138 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11140 static dw_loc_descr_ref
11141 rotate_loc_descriptor (rtx rtl, enum machine_mode mode,
11142 enum machine_mode mem_mode)
11144 rtx rtlop1 = XEXP (rtl, 1);
11145 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
11148 if (GET_MODE_CLASS (mode) != MODE_INT)
11151 if (GET_MODE (rtlop1) != VOIDmode
11152 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
11153 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11154 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11155 VAR_INIT_STATUS_INITIALIZED);
11156 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11157 VAR_INIT_STATUS_INITIALIZED);
11158 if (op0 == NULL || op1 == NULL)
11160 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11161 for (i = 0; i < 2; i++)
11163 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
11164 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
11166 VAR_INIT_STATUS_INITIALIZED);
11167 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
11168 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11170 : HOST_BITS_PER_WIDE_INT == 64
11171 ? DW_OP_const8u : DW_OP_constu,
11172 GET_MODE_MASK (mode), 0);
11175 if (mask[i] == NULL)
11177 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
11180 add_loc_descr (&ret, op1);
11181 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11182 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11183 if (GET_CODE (rtl) == ROTATERT)
11185 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11186 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11187 GET_MODE_BITSIZE (mode), 0));
11189 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11190 if (mask[0] != NULL)
11191 add_loc_descr (&ret, mask[0]);
11192 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11193 if (mask[1] != NULL)
11195 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11196 add_loc_descr (&ret, mask[1]);
11197 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11199 if (GET_CODE (rtl) == ROTATE)
11201 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11202 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11203 GET_MODE_BITSIZE (mode), 0));
11205 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11206 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11210 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11211 for DEBUG_PARAMETER_REF RTL. */
11213 static dw_loc_descr_ref
11214 parameter_ref_descriptor (rtx rtl)
11216 dw_loc_descr_ref ret;
11221 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
11222 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
11223 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
11226 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11227 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
11228 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
11232 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
11233 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
11238 /* Helper function to get mode of MEM's address. */
11241 get_address_mode (rtx mem)
11243 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
11244 if (mode != VOIDmode)
11246 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
11249 /* The following routine converts the RTL for a variable or parameter
11250 (resident in memory) into an equivalent Dwarf representation of a
11251 mechanism for getting the address of that same variable onto the top of a
11252 hypothetical "address evaluation" stack.
11254 When creating memory location descriptors, we are effectively transforming
11255 the RTL for a memory-resident object into its Dwarf postfix expression
11256 equivalent. This routine recursively descends an RTL tree, turning
11257 it into Dwarf postfix code as it goes.
11259 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11261 MEM_MODE is the mode of the memory reference, needed to handle some
11262 autoincrement addressing modes.
11264 Return 0 if we can't represent the location. */
11267 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11268 enum machine_mode mem_mode,
11269 enum var_init_status initialized)
11271 dw_loc_descr_ref mem_loc_result = NULL;
11272 enum dwarf_location_atom op;
11273 dw_loc_descr_ref op0, op1;
11275 if (mode == VOIDmode)
11276 mode = GET_MODE (rtl);
11278 /* Note that for a dynamically sized array, the location we will generate a
11279 description of here will be the lowest numbered location which is
11280 actually within the array. That's *not* necessarily the same as the
11281 zeroth element of the array. */
11283 rtl = targetm.delegitimize_address (rtl);
11285 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
11288 switch (GET_CODE (rtl))
11293 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
11296 /* The case of a subreg may arise when we have a local (register)
11297 variable or a formal (register) parameter which doesn't quite fill
11298 up an entire register. For now, just assume that it is
11299 legitimate to make the Dwarf info refer to the whole register which
11300 contains the given subreg. */
11301 if (!subreg_lowpart_p (rtl))
11303 if (GET_MODE_CLASS (mode) == MODE_INT
11304 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
11305 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11306 #ifdef POINTERS_EXTEND_UNSIGNED
11307 || (mode == Pmode && mem_mode != VOIDmode)
11310 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
11312 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11313 GET_MODE (SUBREG_REG (rtl)),
11314 mem_mode, initialized);
11319 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11321 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
11322 && (GET_MODE_CLASS (mode) != MODE_INT
11323 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
11327 dw_die_ref type_die;
11328 dw_loc_descr_ref cvt;
11330 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11331 GET_MODE (SUBREG_REG (rtl)),
11332 mem_mode, initialized);
11333 if (mem_loc_result == NULL)
11335 type_die = base_type_for_mode (mode,
11336 GET_MODE_CLASS (mode) == MODE_INT);
11337 if (type_die == NULL)
11339 mem_loc_result = NULL;
11342 if (GET_MODE_SIZE (mode)
11343 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11344 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11346 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
11347 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11348 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11349 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11350 add_loc_descr (&mem_loc_result, cvt);
11355 if (GET_MODE_CLASS (mode) != MODE_INT
11356 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11357 #ifdef POINTERS_EXTEND_UNSIGNED
11358 && (mode != Pmode || mem_mode == VOIDmode)
11362 dw_die_ref type_die;
11366 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
11368 type_die = base_type_for_mode (mode,
11369 GET_MODE_CLASS (mode) == MODE_INT);
11370 if (type_die == NULL)
11372 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
11373 dbx_reg_number (rtl), 0);
11374 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
11375 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
11376 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
11379 /* Whenever a register number forms a part of the description of the
11380 method for calculating the (dynamic) address of a memory resident
11381 object, DWARF rules require the register number be referred to as
11382 a "base register". This distinction is not based in any way upon
11383 what category of register the hardware believes the given register
11384 belongs to. This is strictly DWARF terminology we're dealing with
11385 here. Note that in cases where the location of a memory-resident
11386 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11387 OP_CONST (0)) the actual DWARF location descriptor that we generate
11388 may just be OP_BASEREG (basereg). This may look deceptively like
11389 the object in question was allocated to a register (rather than in
11390 memory) so DWARF consumers need to be aware of the subtle
11391 distinction between OP_REG and OP_BASEREG. */
11392 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
11393 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
11394 else if (stack_realign_drap
11396 && crtl->args.internal_arg_pointer == rtl
11397 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
11399 /* If RTL is internal_arg_pointer, which has been optimized
11400 out, use DRAP instead. */
11401 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
11402 VAR_INIT_STATUS_INITIALIZED);
11408 if (GET_MODE_CLASS (mode) != MODE_INT)
11410 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
11411 mem_mode, VAR_INIT_STATUS_INITIALIZED);
11414 else if (GET_CODE (rtl) == ZERO_EXTEND
11415 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11416 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
11417 < HOST_BITS_PER_WIDE_INT
11418 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11419 to expand zero extend as two shifts instead of
11421 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
11423 enum machine_mode imode = GET_MODE (XEXP (rtl, 0));
11424 mem_loc_result = op0;
11425 add_loc_descr (&mem_loc_result,
11426 int_loc_descriptor (GET_MODE_MASK (imode)));
11427 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
11429 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11431 int shift = DWARF2_ADDR_SIZE
11432 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11433 shift *= BITS_PER_UNIT;
11434 if (GET_CODE (rtl) == SIGN_EXTEND)
11438 mem_loc_result = op0;
11439 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11440 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11441 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11442 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11444 else if (!dwarf_strict)
11446 dw_die_ref type_die1, type_die2;
11447 dw_loc_descr_ref cvt;
11449 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
11450 GET_CODE (rtl) == ZERO_EXTEND);
11451 if (type_die1 == NULL)
11453 type_die2 = base_type_for_mode (mode, 1);
11454 if (type_die2 == NULL)
11456 mem_loc_result = op0;
11457 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11458 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11459 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
11460 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11461 add_loc_descr (&mem_loc_result, cvt);
11462 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11463 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11464 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
11465 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11466 add_loc_descr (&mem_loc_result, cvt);
11471 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
11472 get_address_mode (rtl), mode,
11473 VAR_INIT_STATUS_INITIALIZED);
11474 if (mem_loc_result == NULL)
11475 mem_loc_result = tls_mem_loc_descriptor (rtl);
11476 if (mem_loc_result != 0)
11478 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11479 || GET_MODE_CLASS (mode) != MODE_INT)
11481 dw_die_ref type_die;
11482 dw_loc_descr_ref deref;
11487 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
11488 if (type_die == NULL)
11490 deref = new_loc_descr (DW_OP_GNU_deref_type,
11491 GET_MODE_SIZE (mode), 0);
11492 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
11493 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
11494 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
11495 add_loc_descr (&mem_loc_result, deref);
11497 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
11498 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
11500 add_loc_descr (&mem_loc_result,
11501 new_loc_descr (DW_OP_deref_size,
11502 GET_MODE_SIZE (mode), 0));
11506 rtx new_rtl = avoid_constant_pool_reference (rtl);
11507 if (new_rtl != rtl)
11508 return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized);
11513 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
11516 /* Some ports can transform a symbol ref into a label ref, because
11517 the symbol ref is too far away and has to be dumped into a constant
11521 if (GET_MODE_CLASS (mode) != MODE_INT
11522 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11523 #ifdef POINTERS_EXTEND_UNSIGNED
11524 && (mode != Pmode || mem_mode == VOIDmode)
11528 if (GET_CODE (rtl) == SYMBOL_REF
11529 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11531 dw_loc_descr_ref temp;
11533 /* If this is not defined, we have no way to emit the data. */
11534 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
11537 /* We used to emit DW_OP_addr here, but that's wrong, since
11538 DW_OP_addr should be relocated by the debug info consumer,
11539 while DW_OP_GNU_push_tls_address operand should not. */
11540 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
11541 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
11542 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
11543 temp->dw_loc_oprnd1.v.val_addr = rtl;
11544 temp->dtprel = true;
11546 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
11547 add_loc_descr (&mem_loc_result, temp);
11552 if (!const_ok_for_output (rtl))
11556 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
11557 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
11558 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
11559 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11565 case DEBUG_IMPLICIT_PTR:
11566 expansion_failed (NULL_TREE, rtl,
11567 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11573 if (REG_P (ENTRY_VALUE_EXP (rtl)))
11575 if (GET_MODE_CLASS (mode) != MODE_INT
11576 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11577 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
11578 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11581 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
11582 VAR_INIT_STATUS_INITIALIZED);
11584 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
11585 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
11587 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
11588 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11589 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
11593 gcc_unreachable ();
11596 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
11597 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
11598 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
11601 case DEBUG_PARAMETER_REF:
11602 mem_loc_result = parameter_ref_descriptor (rtl);
11606 /* Extract the PLUS expression nested inside and fall into
11607 PLUS code below. */
11608 rtl = XEXP (rtl, 1);
11613 /* Turn these into a PLUS expression and fall into the PLUS code
11615 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
11616 GEN_INT (GET_CODE (rtl) == PRE_INC
11617 ? GET_MODE_UNIT_SIZE (mem_mode)
11618 : -GET_MODE_UNIT_SIZE (mem_mode)));
11620 /* ... fall through ... */
11624 if (is_based_loc (rtl)
11625 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11626 && GET_MODE_CLASS (mode) == MODE_INT)
11627 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
11628 INTVAL (XEXP (rtl, 1)),
11629 VAR_INIT_STATUS_INITIALIZED);
11632 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11633 VAR_INIT_STATUS_INITIALIZED);
11634 if (mem_loc_result == 0)
11637 if (CONST_INT_P (XEXP (rtl, 1))
11638 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11639 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
11642 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11643 VAR_INIT_STATUS_INITIALIZED);
11646 add_loc_descr (&mem_loc_result, op1);
11647 add_loc_descr (&mem_loc_result,
11648 new_loc_descr (DW_OP_plus, 0, 0));
11653 /* If a pseudo-reg is optimized away, it is possible for it to
11654 be replaced with a MEM containing a multiply or shift. */
11665 && GET_MODE_CLASS (mode) == MODE_INT
11666 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11668 mem_loc_result = typed_binop (DW_OP_div, rtl,
11669 base_type_for_mode (mode, 0),
11693 if (GET_MODE_CLASS (mode) != MODE_INT)
11695 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11696 VAR_INIT_STATUS_INITIALIZED);
11698 rtx rtlop1 = XEXP (rtl, 1);
11699 if (GET_MODE (rtlop1) != VOIDmode
11700 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
11701 < GET_MODE_BITSIZE (mode))
11702 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11703 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11704 VAR_INIT_STATUS_INITIALIZED);
11707 if (op0 == 0 || op1 == 0)
11710 mem_loc_result = op0;
11711 add_loc_descr (&mem_loc_result, op1);
11712 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11728 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11729 VAR_INIT_STATUS_INITIALIZED);
11730 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11731 VAR_INIT_STATUS_INITIALIZED);
11733 if (op0 == 0 || op1 == 0)
11736 mem_loc_result = op0;
11737 add_loc_descr (&mem_loc_result, op1);
11738 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11742 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
11744 mem_loc_result = typed_binop (DW_OP_mod, rtl,
11745 base_type_for_mode (mode, 0),
11750 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11751 VAR_INIT_STATUS_INITIALIZED);
11752 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11753 VAR_INIT_STATUS_INITIALIZED);
11755 if (op0 == 0 || op1 == 0)
11758 mem_loc_result = op0;
11759 add_loc_descr (&mem_loc_result, op1);
11760 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
11761 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
11762 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
11763 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
11764 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
11768 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
11770 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
11775 mem_loc_result = typed_binop (DW_OP_div, rtl,
11776 base_type_for_mode (mode, 1),
11794 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11795 VAR_INIT_STATUS_INITIALIZED);
11800 mem_loc_result = op0;
11801 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11805 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11806 #ifdef POINTERS_EXTEND_UNSIGNED
11808 && mem_mode != VOIDmode
11809 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
11813 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
11817 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
11818 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
11820 dw_die_ref type_die = base_type_for_mode (mode, 1);
11821 if (type_die == NULL)
11823 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
11825 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11826 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11827 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
11828 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
11829 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
11832 mem_loc_result->dw_loc_oprnd2.val_class
11833 = dw_val_class_const_double;
11834 mem_loc_result->dw_loc_oprnd2.v.val_double
11835 = shwi_to_double_int (INTVAL (rtl));
11843 dw_die_ref type_die;
11845 /* Note that a CONST_DOUBLE rtx could represent either an integer
11846 or a floating-point constant. A CONST_DOUBLE is used whenever
11847 the constant requires more than one word in order to be
11848 adequately represented. We output CONST_DOUBLEs as blocks. */
11849 if (mode == VOIDmode
11850 || (GET_MODE (rtl) == VOIDmode
11851 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
11853 type_die = base_type_for_mode (mode,
11854 GET_MODE_CLASS (mode) == MODE_INT);
11855 if (type_die == NULL)
11857 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
11858 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11859 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11860 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
11861 if (SCALAR_FLOAT_MODE_P (mode))
11863 unsigned int length = GET_MODE_SIZE (mode);
11864 unsigned char *array
11865 = (unsigned char*) ggc_alloc_atomic (length);
11867 insert_float (rtl, array);
11868 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
11869 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
11870 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
11871 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
11875 mem_loc_result->dw_loc_oprnd2.val_class
11876 = dw_val_class_const_double;
11877 mem_loc_result->dw_loc_oprnd2.v.val_double
11878 = rtx_to_double_int (rtl);
11884 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
11888 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
11892 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
11896 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
11900 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
11904 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
11908 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
11912 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
11916 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
11920 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
11925 if (GET_MODE_CLASS (mode) != MODE_INT)
11930 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
11935 if (CONST_INT_P (XEXP (rtl, 1))
11936 && CONST_INT_P (XEXP (rtl, 2))
11937 && ((unsigned) INTVAL (XEXP (rtl, 1))
11938 + (unsigned) INTVAL (XEXP (rtl, 2))
11939 <= GET_MODE_BITSIZE (mode))
11940 && GET_MODE_CLASS (mode) == MODE_INT
11941 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11942 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
11945 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
11946 mem_mode, VAR_INIT_STATUS_INITIALIZED);
11949 if (GET_CODE (rtl) == SIGN_EXTRACT)
11953 mem_loc_result = op0;
11954 size = INTVAL (XEXP (rtl, 1));
11955 shift = INTVAL (XEXP (rtl, 2));
11956 if (BITS_BIG_ENDIAN)
11957 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
11959 if (shift + size != (int) DWARF2_ADDR_SIZE)
11961 add_loc_descr (&mem_loc_result,
11962 int_loc_descriptor (DWARF2_ADDR_SIZE
11964 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11966 if (size != (int) DWARF2_ADDR_SIZE)
11968 add_loc_descr (&mem_loc_result,
11969 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
11970 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11977 dw_loc_descr_ref op2, bra_node, drop_node;
11978 op0 = mem_loc_descriptor (XEXP (rtl, 0),
11979 GET_MODE (XEXP (rtl, 0)) == VOIDmode
11980 ? word_mode : GET_MODE (XEXP (rtl, 0)),
11981 mem_mode, VAR_INIT_STATUS_INITIALIZED);
11982 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11983 VAR_INIT_STATUS_INITIALIZED);
11984 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
11985 VAR_INIT_STATUS_INITIALIZED);
11986 if (op0 == NULL || op1 == NULL || op2 == NULL)
11989 mem_loc_result = op1;
11990 add_loc_descr (&mem_loc_result, op2);
11991 add_loc_descr (&mem_loc_result, op0);
11992 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11993 add_loc_descr (&mem_loc_result, bra_node);
11994 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
11995 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
11996 add_loc_descr (&mem_loc_result, drop_node);
11997 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11998 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
12003 case FLOAT_TRUNCATE:
12005 case UNSIGNED_FLOAT:
12010 dw_die_ref type_die;
12011 dw_loc_descr_ref cvt;
12013 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12014 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12017 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
12018 && (GET_CODE (rtl) == FLOAT
12019 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
12020 <= DWARF2_ADDR_SIZE))
12022 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12023 GET_CODE (rtl) == UNSIGNED_FLOAT);
12024 if (type_die == NULL)
12026 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12027 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12028 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12029 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12030 add_loc_descr (&op0, cvt);
12032 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
12033 if (type_die == NULL)
12035 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12036 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12037 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12038 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12039 add_loc_descr (&op0, cvt);
12040 if (GET_MODE_CLASS (mode) == MODE_INT
12041 && (GET_CODE (rtl) == FIX
12042 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
12044 op0 = convert_descriptor_to_mode (mode, op0);
12048 mem_loc_result = op0;
12055 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
12060 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
12064 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
12069 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
12074 /* In theory, we could implement the above. */
12075 /* DWARF cannot represent the unsigned compare operations
12100 case FRACT_CONVERT:
12101 case UNSIGNED_FRACT_CONVERT:
12103 case UNSIGNED_SAT_FRACT:
12109 case VEC_DUPLICATE:
12113 case STRICT_LOW_PART:
12117 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12118 can't express it in the debug info. This can happen e.g. with some
12123 resolve_one_addr (&rtl, NULL);
12127 #ifdef ENABLE_CHECKING
12128 print_rtl (stderr, rtl);
12129 gcc_unreachable ();
12135 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12136 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12138 return mem_loc_result;
12141 /* Return a descriptor that describes the concatenation of two locations.
12142 This is typically a complex variable. */
12144 static dw_loc_descr_ref
12145 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
12147 dw_loc_descr_ref cc_loc_result = NULL;
12148 dw_loc_descr_ref x0_ref
12149 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12150 dw_loc_descr_ref x1_ref
12151 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12153 if (x0_ref == 0 || x1_ref == 0)
12156 cc_loc_result = x0_ref;
12157 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
12159 add_loc_descr (&cc_loc_result, x1_ref);
12160 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
12162 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
12163 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12165 return cc_loc_result;
12168 /* Return a descriptor that describes the concatenation of N
12171 static dw_loc_descr_ref
12172 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
12175 dw_loc_descr_ref cc_loc_result = NULL;
12176 unsigned int n = XVECLEN (concatn, 0);
12178 for (i = 0; i < n; ++i)
12180 dw_loc_descr_ref ref;
12181 rtx x = XVECEXP (concatn, 0, i);
12183 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12187 add_loc_descr (&cc_loc_result, ref);
12188 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
12191 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12192 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12194 return cc_loc_result;
12197 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12198 for DEBUG_IMPLICIT_PTR RTL. */
12200 static dw_loc_descr_ref
12201 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
12203 dw_loc_descr_ref ret;
12208 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
12209 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
12210 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
12211 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
12212 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
12213 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
12216 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12217 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
12218 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
12222 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
12223 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
12228 /* Output a proper Dwarf location descriptor for a variable or parameter
12229 which is either allocated in a register or in a memory location. For a
12230 register, we just generate an OP_REG and the register number. For a
12231 memory location we provide a Dwarf postfix expression describing how to
12232 generate the (dynamic) address of the object onto the address stack.
12234 MODE is mode of the decl if this loc_descriptor is going to be used in
12235 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12236 allowed, VOIDmode otherwise.
12238 If we don't know how to describe it, return 0. */
12240 static dw_loc_descr_ref
12241 loc_descriptor (rtx rtl, enum machine_mode mode,
12242 enum var_init_status initialized)
12244 dw_loc_descr_ref loc_result = NULL;
12246 switch (GET_CODE (rtl))
12249 /* The case of a subreg may arise when we have a local (register)
12250 variable or a formal (register) parameter which doesn't quite fill
12251 up an entire register. For now, just assume that it is
12252 legitimate to make the Dwarf info refer to the whole register which
12253 contains the given subreg. */
12254 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
12255 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
12261 loc_result = reg_loc_descriptor (rtl, initialized);
12265 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
12266 GET_MODE (rtl), initialized);
12267 if (loc_result == NULL)
12268 loc_result = tls_mem_loc_descriptor (rtl);
12269 if (loc_result == NULL)
12271 rtx new_rtl = avoid_constant_pool_reference (rtl);
12272 if (new_rtl != rtl)
12273 loc_result = loc_descriptor (new_rtl, mode, initialized);
12278 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
12283 loc_result = concatn_loc_descriptor (rtl, initialized);
12288 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
12290 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
12291 if (GET_CODE (loc) == EXPR_LIST)
12292 loc = XEXP (loc, 0);
12293 loc_result = loc_descriptor (loc, mode, initialized);
12297 rtl = XEXP (rtl, 1);
12302 rtvec par_elems = XVEC (rtl, 0);
12303 int num_elem = GET_NUM_ELEM (par_elems);
12304 enum machine_mode mode;
12307 /* Create the first one, so we have something to add to. */
12308 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
12309 VOIDmode, initialized);
12310 if (loc_result == NULL)
12312 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
12313 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12314 for (i = 1; i < num_elem; i++)
12316 dw_loc_descr_ref temp;
12318 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
12319 VOIDmode, initialized);
12322 add_loc_descr (&loc_result, temp);
12323 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
12324 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12330 if (mode != VOIDmode && mode != BLKmode)
12331 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
12336 if (mode == VOIDmode)
12337 mode = GET_MODE (rtl);
12339 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12341 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12343 /* Note that a CONST_DOUBLE rtx could represent either an integer
12344 or a floating-point constant. A CONST_DOUBLE is used whenever
12345 the constant requires more than one word in order to be
12346 adequately represented. We output CONST_DOUBLEs as blocks. */
12347 loc_result = new_loc_descr (DW_OP_implicit_value,
12348 GET_MODE_SIZE (mode), 0);
12349 if (SCALAR_FLOAT_MODE_P (mode))
12351 unsigned int length = GET_MODE_SIZE (mode);
12352 unsigned char *array
12353 = (unsigned char*) ggc_alloc_atomic (length);
12355 insert_float (rtl, array);
12356 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12357 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12358 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12359 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12363 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
12364 loc_result->dw_loc_oprnd2.v.val_double
12365 = rtx_to_double_int (rtl);
12371 if (mode == VOIDmode)
12372 mode = GET_MODE (rtl);
12374 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12376 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
12377 unsigned int length = CONST_VECTOR_NUNITS (rtl);
12378 unsigned char *array = (unsigned char *)
12379 ggc_alloc_atomic (length * elt_size);
12383 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12384 switch (GET_MODE_CLASS (mode))
12386 case MODE_VECTOR_INT:
12387 for (i = 0, p = array; i < length; i++, p += elt_size)
12389 rtx elt = CONST_VECTOR_ELT (rtl, i);
12390 double_int val = rtx_to_double_int (elt);
12392 if (elt_size <= sizeof (HOST_WIDE_INT))
12393 insert_int (double_int_to_shwi (val), elt_size, p);
12396 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
12397 insert_double (val, p);
12402 case MODE_VECTOR_FLOAT:
12403 for (i = 0, p = array; i < length; i++, p += elt_size)
12405 rtx elt = CONST_VECTOR_ELT (rtl, i);
12406 insert_float (elt, p);
12411 gcc_unreachable ();
12414 loc_result = new_loc_descr (DW_OP_implicit_value,
12415 length * elt_size, 0);
12416 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12417 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
12418 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
12419 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12424 if (mode == VOIDmode
12425 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
12426 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
12427 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
12429 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
12434 if (!const_ok_for_output (rtl))
12437 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
12438 && (dwarf_version >= 4 || !dwarf_strict))
12440 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
12441 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
12442 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
12443 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
12444 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12448 case DEBUG_IMPLICIT_PTR:
12449 loc_result = implicit_ptr_descriptor (rtl, 0);
12453 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
12454 && CONST_INT_P (XEXP (rtl, 1)))
12457 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
12463 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
12464 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
12465 && dwarf_version >= 4)
12466 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
12468 /* Value expression. */
12469 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
12471 add_loc_descr (&loc_result,
12472 new_loc_descr (DW_OP_stack_value, 0, 0));
12480 /* We need to figure out what section we should use as the base for the
12481 address ranges where a given location is valid.
12482 1. If this particular DECL has a section associated with it, use that.
12483 2. If this function has a section associated with it, use that.
12484 3. Otherwise, use the text section.
12485 XXX: If you split a variable across multiple sections, we won't notice. */
12487 static const char *
12488 secname_for_decl (const_tree decl)
12490 const char *secname;
12492 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
12494 tree sectree = DECL_SECTION_NAME (decl);
12495 secname = TREE_STRING_POINTER (sectree);
12497 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
12499 tree sectree = DECL_SECTION_NAME (current_function_decl);
12500 secname = TREE_STRING_POINTER (sectree);
12502 else if (cfun && in_cold_section_p)
12503 secname = crtl->subsections.cold_section_label;
12505 secname = text_section_label;
12510 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12513 decl_by_reference_p (tree decl)
12515 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
12516 || TREE_CODE (decl) == VAR_DECL)
12517 && DECL_BY_REFERENCE (decl));
12520 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12523 static dw_loc_descr_ref
12524 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
12525 enum var_init_status initialized)
12527 int have_address = 0;
12528 dw_loc_descr_ref descr;
12529 enum machine_mode mode;
12531 if (want_address != 2)
12533 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12535 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
12537 varloc = PAT_VAR_LOCATION_LOC (varloc);
12538 if (GET_CODE (varloc) == EXPR_LIST)
12539 varloc = XEXP (varloc, 0);
12540 mode = GET_MODE (varloc);
12541 if (MEM_P (varloc))
12543 rtx addr = XEXP (varloc, 0);
12544 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
12545 mode, initialized);
12550 rtx x = avoid_constant_pool_reference (varloc);
12552 descr = mem_loc_descriptor (x, mode, VOIDmode,
12557 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
12564 if (GET_CODE (varloc) == VAR_LOCATION)
12565 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
12567 mode = DECL_MODE (loc);
12568 descr = loc_descriptor (varloc, mode, initialized);
12575 if (want_address == 2 && !have_address
12576 && (dwarf_version >= 4 || !dwarf_strict))
12578 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
12580 expansion_failed (loc, NULL_RTX,
12581 "DWARF address size mismatch");
12584 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
12587 /* Show if we can't fill the request for an address. */
12588 if (want_address && !have_address)
12590 expansion_failed (loc, NULL_RTX,
12591 "Want address and only have value");
12595 /* If we've got an address and don't want one, dereference. */
12596 if (!want_address && have_address)
12598 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
12599 enum dwarf_location_atom op;
12601 if (size > DWARF2_ADDR_SIZE || size == -1)
12603 expansion_failed (loc, NULL_RTX,
12604 "DWARF address size mismatch");
12607 else if (size == DWARF2_ADDR_SIZE)
12610 op = DW_OP_deref_size;
12612 add_loc_descr (&descr, new_loc_descr (op, size, 0));
12618 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
12619 if it is not possible. */
12621 static dw_loc_descr_ref
12622 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
12624 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
12625 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
12626 else if (dwarf_version >= 3 || !dwarf_strict)
12627 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
12632 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12633 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
12635 static dw_loc_descr_ref
12636 dw_sra_loc_expr (tree decl, rtx loc)
12639 unsigned int padsize = 0;
12640 dw_loc_descr_ref descr, *descr_tail;
12641 unsigned HOST_WIDE_INT decl_size;
12643 enum var_init_status initialized;
12645 if (DECL_SIZE (decl) == NULL
12646 || !host_integerp (DECL_SIZE (decl), 1))
12649 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
12651 descr_tail = &descr;
12653 for (p = loc; p; p = XEXP (p, 1))
12655 unsigned int bitsize = decl_piece_bitsize (p);
12656 rtx loc_note = *decl_piece_varloc_ptr (p);
12657 dw_loc_descr_ref cur_descr;
12658 dw_loc_descr_ref *tail, last = NULL;
12659 unsigned int opsize = 0;
12661 if (loc_note == NULL_RTX
12662 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
12664 padsize += bitsize;
12667 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
12668 varloc = NOTE_VAR_LOCATION (loc_note);
12669 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
12670 if (cur_descr == NULL)
12672 padsize += bitsize;
12676 /* Check that cur_descr either doesn't use
12677 DW_OP_*piece operations, or their sum is equal
12678 to bitsize. Otherwise we can't embed it. */
12679 for (tail = &cur_descr; *tail != NULL;
12680 tail = &(*tail)->dw_loc_next)
12681 if ((*tail)->dw_loc_opc == DW_OP_piece)
12683 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
12687 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
12689 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
12693 if (last != NULL && opsize != bitsize)
12695 padsize += bitsize;
12699 /* If there is a hole, add DW_OP_*piece after empty DWARF
12700 expression, which means that those bits are optimized out. */
12703 if (padsize > decl_size)
12705 decl_size -= padsize;
12706 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
12707 if (*descr_tail == NULL)
12709 descr_tail = &(*descr_tail)->dw_loc_next;
12712 *descr_tail = cur_descr;
12714 if (bitsize > decl_size)
12716 decl_size -= bitsize;
12719 HOST_WIDE_INT offset = 0;
12720 if (GET_CODE (varloc) == VAR_LOCATION
12721 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
12723 varloc = PAT_VAR_LOCATION_LOC (varloc);
12724 if (GET_CODE (varloc) == EXPR_LIST)
12725 varloc = XEXP (varloc, 0);
12729 if (GET_CODE (varloc) == CONST
12730 || GET_CODE (varloc) == SIGN_EXTEND
12731 || GET_CODE (varloc) == ZERO_EXTEND)
12732 varloc = XEXP (varloc, 0);
12733 else if (GET_CODE (varloc) == SUBREG)
12734 varloc = SUBREG_REG (varloc);
12739 /* DW_OP_bit_size offset should be zero for register
12740 or implicit location descriptions and empty location
12741 descriptions, but for memory addresses needs big endian
12743 if (MEM_P (varloc))
12745 unsigned HOST_WIDE_INT memsize
12746 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
12747 if (memsize != bitsize)
12749 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
12750 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
12752 if (memsize < bitsize)
12754 if (BITS_BIG_ENDIAN)
12755 offset = memsize - bitsize;
12759 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
12760 if (*descr_tail == NULL)
12762 descr_tail = &(*descr_tail)->dw_loc_next;
12766 /* If there were any non-empty expressions, add padding till the end of
12768 if (descr != NULL && decl_size != 0)
12770 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
12771 if (*descr_tail == NULL)
12777 /* Return the dwarf representation of the location list LOC_LIST of
12778 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
12781 static dw_loc_list_ref
12782 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
12784 const char *endname, *secname;
12786 enum var_init_status initialized;
12787 struct var_loc_node *node;
12788 dw_loc_descr_ref descr;
12789 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12790 dw_loc_list_ref list = NULL;
12791 dw_loc_list_ref *listp = &list;
12793 /* Now that we know what section we are using for a base,
12794 actually construct the list of locations.
12795 The first location information is what is passed to the
12796 function that creates the location list, and the remaining
12797 locations just get added on to that list.
12798 Note that we only know the start address for a location
12799 (IE location changes), so to build the range, we use
12800 the range [current location start, next location start].
12801 This means we have to special case the last node, and generate
12802 a range of [last location start, end of function label]. */
12804 secname = secname_for_decl (decl);
12806 for (node = loc_list->first; node; node = node->next)
12807 if (GET_CODE (node->loc) == EXPR_LIST
12808 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
12810 if (GET_CODE (node->loc) == EXPR_LIST)
12812 /* This requires DW_OP_{,bit_}piece, which is not usable
12813 inside DWARF expressions. */
12814 if (want_address != 2)
12816 descr = dw_sra_loc_expr (decl, node->loc);
12822 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
12823 varloc = NOTE_VAR_LOCATION (node->loc);
12824 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
12828 bool range_across_switch = false;
12829 /* If section switch happens in between node->label
12830 and node->next->label (or end of function) and
12831 we can't emit it as a single entry list,
12832 emit two ranges, first one ending at the end
12833 of first partition and second one starting at the
12834 beginning of second partition. */
12835 if (node == loc_list->last_before_switch
12836 && (node != loc_list->first || loc_list->first->next)
12837 && current_function_decl)
12839 endname = cfun->fde->dw_fde_end;
12840 range_across_switch = true;
12842 /* The variable has a location between NODE->LABEL and
12843 NODE->NEXT->LABEL. */
12844 else if (node->next)
12845 endname = node->next->label;
12846 /* If the variable has a location at the last label
12847 it keeps its location until the end of function. */
12848 else if (!current_function_decl)
12849 endname = text_end_label;
12852 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12853 current_function_funcdef_no);
12854 endname = ggc_strdup (label_id);
12857 *listp = new_loc_list (descr, node->label, endname, secname);
12858 if (TREE_CODE (decl) == PARM_DECL
12859 && node == loc_list->first
12860 && GET_CODE (node->loc) == NOTE
12861 && strcmp (node->label, endname) == 0)
12862 (*listp)->force = true;
12863 listp = &(*listp)->dw_loc_next;
12865 if (range_across_switch)
12867 if (GET_CODE (node->loc) == EXPR_LIST)
12868 descr = dw_sra_loc_expr (decl, node->loc);
12871 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
12872 varloc = NOTE_VAR_LOCATION (node->loc);
12873 descr = dw_loc_list_1 (decl, varloc, want_address,
12876 gcc_assert (descr);
12877 /* The variable has a location between NODE->LABEL and
12878 NODE->NEXT->LABEL. */
12880 endname = node->next->label;
12882 endname = cfun->fde->dw_fde_second_end;
12883 *listp = new_loc_list (descr,
12884 cfun->fde->dw_fde_second_begin,
12886 listp = &(*listp)->dw_loc_next;
12891 /* Try to avoid the overhead of a location list emitting a location
12892 expression instead, but only if we didn't have more than one
12893 location entry in the first place. If some entries were not
12894 representable, we don't want to pretend a single entry that was
12895 applies to the entire scope in which the variable is
12897 if (list && loc_list->first->next)
12903 /* Return if the loc_list has only single element and thus can be represented
12904 as location description. */
12907 single_element_loc_list_p (dw_loc_list_ref list)
12909 gcc_assert (!list->dw_loc_next || list->ll_symbol);
12910 return !list->ll_symbol;
12913 /* To each location in list LIST add loc descr REF. */
12916 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
12918 dw_loc_descr_ref copy;
12919 add_loc_descr (&list->expr, ref);
12920 list = list->dw_loc_next;
12923 copy = ggc_alloc_dw_loc_descr_node ();
12924 memcpy (copy, ref, sizeof (dw_loc_descr_node));
12925 add_loc_descr (&list->expr, copy);
12926 while (copy->dw_loc_next)
12928 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
12929 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
12930 copy->dw_loc_next = new_copy;
12933 list = list->dw_loc_next;
12937 /* Given two lists RET and LIST
12938 produce location list that is result of adding expression in LIST
12939 to expression in RET on each possition in program.
12940 Might be destructive on both RET and LIST.
12942 TODO: We handle only simple cases of RET or LIST having at most one
12943 element. General case would inolve sorting the lists in program order
12944 and merging them that will need some additional work.
12945 Adding that will improve quality of debug info especially for SRA-ed
12949 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
12958 if (!list->dw_loc_next)
12960 add_loc_descr_to_each (*ret, list->expr);
12963 if (!(*ret)->dw_loc_next)
12965 add_loc_descr_to_each (list, (*ret)->expr);
12969 expansion_failed (NULL_TREE, NULL_RTX,
12970 "Don't know how to merge two non-trivial"
12971 " location lists.\n");
12976 /* LOC is constant expression. Try a luck, look it up in constant
12977 pool and return its loc_descr of its address. */
12979 static dw_loc_descr_ref
12980 cst_pool_loc_descr (tree loc)
12982 /* Get an RTL for this, if something has been emitted. */
12983 rtx rtl = lookup_constant_def (loc);
12985 if (!rtl || !MEM_P (rtl))
12990 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
12992 /* TODO: We might get more coverage if we was actually delaying expansion
12993 of all expressions till end of compilation when constant pools are fully
12995 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
12997 expansion_failed (loc, NULL_RTX,
12998 "CST value in contant pool but not marked.");
13001 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
13002 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
13005 /* Return dw_loc_list representing address of addr_expr LOC
13006 by looking for innder INDIRECT_REF expression and turing it
13007 into simple arithmetics. */
13009 static dw_loc_list_ref
13010 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
13013 HOST_WIDE_INT bitsize, bitpos, bytepos;
13014 enum machine_mode mode;
13016 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13017 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13019 obj = get_inner_reference (TREE_OPERAND (loc, 0),
13020 &bitsize, &bitpos, &offset, &mode,
13021 &unsignedp, &volatilep, false);
13023 if (bitpos % BITS_PER_UNIT)
13025 expansion_failed (loc, NULL_RTX, "bitfield access");
13028 if (!INDIRECT_REF_P (obj))
13030 expansion_failed (obj,
13031 NULL_RTX, "no indirect ref in inner refrence");
13034 if (!offset && !bitpos)
13035 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
13037 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
13038 && (dwarf_version >= 4 || !dwarf_strict))
13040 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
13045 /* Variable offset. */
13046 list_ret1 = loc_list_from_tree (offset, 0);
13047 if (list_ret1 == 0)
13049 add_loc_list (&list_ret, list_ret1);
13052 add_loc_descr_to_each (list_ret,
13053 new_loc_descr (DW_OP_plus, 0, 0));
13055 bytepos = bitpos / BITS_PER_UNIT;
13057 add_loc_descr_to_each (list_ret,
13058 new_loc_descr (DW_OP_plus_uconst,
13060 else if (bytepos < 0)
13061 loc_list_plus_const (list_ret, bytepos);
13062 add_loc_descr_to_each (list_ret,
13063 new_loc_descr (DW_OP_stack_value, 0, 0));
13069 /* Generate Dwarf location list representing LOC.
13070 If WANT_ADDRESS is false, expression computing LOC will be computed
13071 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13072 if WANT_ADDRESS is 2, expression computing address useable in location
13073 will be returned (i.e. DW_OP_reg can be used
13074 to refer to register values). */
13076 static dw_loc_list_ref
13077 loc_list_from_tree (tree loc, int want_address)
13079 dw_loc_descr_ref ret = NULL, ret1 = NULL;
13080 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13081 int have_address = 0;
13082 enum dwarf_location_atom op;
13084 /* ??? Most of the time we do not take proper care for sign/zero
13085 extending the values properly. Hopefully this won't be a real
13088 switch (TREE_CODE (loc))
13091 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
13094 case PLACEHOLDER_EXPR:
13095 /* This case involves extracting fields from an object to determine the
13096 position of other fields. We don't try to encode this here. The
13097 only user of this is Ada, which encodes the needed information using
13098 the names of types. */
13099 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
13103 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
13104 /* There are no opcodes for these operations. */
13107 case PREINCREMENT_EXPR:
13108 case PREDECREMENT_EXPR:
13109 case POSTINCREMENT_EXPR:
13110 case POSTDECREMENT_EXPR:
13111 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
13112 /* There are no opcodes for these operations. */
13116 /* If we already want an address, see if there is INDIRECT_REF inside
13117 e.g. for &this->field. */
13120 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
13121 (loc, want_address == 2);
13124 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
13125 && (ret = cst_pool_loc_descr (loc)))
13128 /* Otherwise, process the argument and look for the address. */
13129 if (!list_ret && !ret)
13130 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
13134 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
13140 if (DECL_THREAD_LOCAL_P (loc))
13143 enum dwarf_location_atom first_op;
13144 enum dwarf_location_atom second_op;
13145 bool dtprel = false;
13147 if (targetm.have_tls)
13149 /* If this is not defined, we have no way to emit the
13151 if (!targetm.asm_out.output_dwarf_dtprel)
13154 /* The way DW_OP_GNU_push_tls_address is specified, we
13155 can only look up addresses of objects in the current
13156 module. We used DW_OP_addr as first op, but that's
13157 wrong, because DW_OP_addr is relocated by the debug
13158 info consumer, while DW_OP_GNU_push_tls_address
13159 operand shouldn't be. */
13160 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
13162 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
13164 second_op = DW_OP_GNU_push_tls_address;
13168 if (!targetm.emutls.debug_form_tls_address
13169 || !(dwarf_version >= 3 || !dwarf_strict))
13171 /* We stuffed the control variable into the DECL_VALUE_EXPR
13172 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13173 no longer appear in gimple code. We used the control
13174 variable in specific so that we could pick it up here. */
13175 loc = DECL_VALUE_EXPR (loc);
13176 first_op = DW_OP_addr;
13177 second_op = DW_OP_form_tls_address;
13180 rtl = rtl_for_decl_location (loc);
13181 if (rtl == NULL_RTX)
13186 rtl = XEXP (rtl, 0);
13187 if (! CONSTANT_P (rtl))
13190 ret = new_loc_descr (first_op, 0, 0);
13191 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13192 ret->dw_loc_oprnd1.v.val_addr = rtl;
13193 ret->dtprel = dtprel;
13195 ret1 = new_loc_descr (second_op, 0, 0);
13196 add_loc_descr (&ret, ret1);
13205 if (DECL_HAS_VALUE_EXPR_P (loc))
13206 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
13210 case FUNCTION_DECL:
13213 var_loc_list *loc_list = lookup_decl_loc (loc);
13215 if (loc_list && loc_list->first)
13217 list_ret = dw_loc_list (loc_list, loc, want_address);
13218 have_address = want_address != 0;
13221 rtl = rtl_for_decl_location (loc);
13222 if (rtl == NULL_RTX)
13224 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
13227 else if (CONST_INT_P (rtl))
13229 HOST_WIDE_INT val = INTVAL (rtl);
13230 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13231 val &= GET_MODE_MASK (DECL_MODE (loc));
13232 ret = int_loc_descriptor (val);
13234 else if (GET_CODE (rtl) == CONST_STRING)
13236 expansion_failed (loc, NULL_RTX, "CONST_STRING");
13239 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
13241 ret = new_loc_descr (DW_OP_addr, 0, 0);
13242 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13243 ret->dw_loc_oprnd1.v.val_addr = rtl;
13247 enum machine_mode mode, mem_mode;
13249 /* Certain constructs can only be represented at top-level. */
13250 if (want_address == 2)
13252 ret = loc_descriptor (rtl, VOIDmode,
13253 VAR_INIT_STATUS_INITIALIZED);
13258 mode = GET_MODE (rtl);
13259 mem_mode = VOIDmode;
13263 mode = get_address_mode (rtl);
13264 rtl = XEXP (rtl, 0);
13267 ret = mem_loc_descriptor (rtl, mode, mem_mode,
13268 VAR_INIT_STATUS_INITIALIZED);
13271 expansion_failed (loc, rtl,
13272 "failed to produce loc descriptor for rtl");
13279 if (!integer_zerop (TREE_OPERAND (loc, 1)))
13283 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13287 case COMPOUND_EXPR:
13288 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
13291 case VIEW_CONVERT_EXPR:
13294 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
13296 case COMPONENT_REF:
13297 case BIT_FIELD_REF:
13299 case ARRAY_RANGE_REF:
13300 case REALPART_EXPR:
13301 case IMAGPART_EXPR:
13304 HOST_WIDE_INT bitsize, bitpos, bytepos;
13305 enum machine_mode mode;
13307 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13309 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
13310 &unsignedp, &volatilep, false);
13312 gcc_assert (obj != loc);
13314 list_ret = loc_list_from_tree (obj,
13316 && !bitpos && !offset ? 2 : 1);
13317 /* TODO: We can extract value of the small expression via shifting even
13318 for nonzero bitpos. */
13321 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
13323 expansion_failed (loc, NULL_RTX,
13324 "bitfield access");
13328 if (offset != NULL_TREE)
13330 /* Variable offset. */
13331 list_ret1 = loc_list_from_tree (offset, 0);
13332 if (list_ret1 == 0)
13334 add_loc_list (&list_ret, list_ret1);
13337 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
13340 bytepos = bitpos / BITS_PER_UNIT;
13342 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
13343 else if (bytepos < 0)
13344 loc_list_plus_const (list_ret, bytepos);
13351 if ((want_address || !host_integerp (loc, 0))
13352 && (ret = cst_pool_loc_descr (loc)))
13354 else if (want_address == 2
13355 && host_integerp (loc, 0)
13356 && (ret = address_of_int_loc_descriptor
13357 (int_size_in_bytes (TREE_TYPE (loc)),
13358 tree_low_cst (loc, 0))))
13360 else if (host_integerp (loc, 0))
13361 ret = int_loc_descriptor (tree_low_cst (loc, 0));
13364 expansion_failed (loc, NULL_RTX,
13365 "Integer operand is not host integer");
13374 if ((ret = cst_pool_loc_descr (loc)))
13377 /* We can construct small constants here using int_loc_descriptor. */
13378 expansion_failed (loc, NULL_RTX,
13379 "constructor or constant not in constant pool");
13382 case TRUTH_AND_EXPR:
13383 case TRUTH_ANDIF_EXPR:
13388 case TRUTH_XOR_EXPR:
13393 case TRUTH_OR_EXPR:
13394 case TRUTH_ORIF_EXPR:
13399 case FLOOR_DIV_EXPR:
13400 case CEIL_DIV_EXPR:
13401 case ROUND_DIV_EXPR:
13402 case TRUNC_DIV_EXPR:
13403 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13412 case FLOOR_MOD_EXPR:
13413 case CEIL_MOD_EXPR:
13414 case ROUND_MOD_EXPR:
13415 case TRUNC_MOD_EXPR:
13416 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13421 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13422 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
13423 if (list_ret == 0 || list_ret1 == 0)
13426 add_loc_list (&list_ret, list_ret1);
13429 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
13430 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
13431 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
13432 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
13433 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
13445 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
13448 case POINTER_PLUS_EXPR:
13450 if (host_integerp (TREE_OPERAND (loc, 1), 0))
13452 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13456 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
13464 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13471 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13478 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13485 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13500 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13501 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
13502 if (list_ret == 0 || list_ret1 == 0)
13505 add_loc_list (&list_ret, list_ret1);
13508 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
13511 case TRUTH_NOT_EXPR:
13525 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13529 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
13535 const enum tree_code code =
13536 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
13538 loc = build3 (COND_EXPR, TREE_TYPE (loc),
13539 build2 (code, integer_type_node,
13540 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
13541 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
13544 /* ... fall through ... */
13548 dw_loc_descr_ref lhs
13549 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
13550 dw_loc_list_ref rhs
13551 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
13552 dw_loc_descr_ref bra_node, jump_node, tmp;
13554 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13555 if (list_ret == 0 || lhs == 0 || rhs == 0)
13558 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
13559 add_loc_descr_to_each (list_ret, bra_node);
13561 add_loc_list (&list_ret, rhs);
13562 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
13563 add_loc_descr_to_each (list_ret, jump_node);
13565 add_loc_descr_to_each (list_ret, lhs);
13566 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13567 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
13569 /* ??? Need a node to point the skip at. Use a nop. */
13570 tmp = new_loc_descr (DW_OP_nop, 0, 0);
13571 add_loc_descr_to_each (list_ret, tmp);
13572 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13573 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
13577 case FIX_TRUNC_EXPR:
13581 /* Leave front-end specific codes as simply unknown. This comes
13582 up, for instance, with the C STMT_EXPR. */
13583 if ((unsigned int) TREE_CODE (loc)
13584 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
13586 expansion_failed (loc, NULL_RTX,
13587 "language specific tree node");
13591 #ifdef ENABLE_CHECKING
13592 /* Otherwise this is a generic code; we should just lists all of
13593 these explicitly. We forgot one. */
13594 gcc_unreachable ();
13596 /* In a release build, we want to degrade gracefully: better to
13597 generate incomplete debugging information than to crash. */
13602 if (!ret && !list_ret)
13605 if (want_address == 2 && !have_address
13606 && (dwarf_version >= 4 || !dwarf_strict))
13608 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
13610 expansion_failed (loc, NULL_RTX,
13611 "DWARF address size mismatch");
13615 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
13617 add_loc_descr_to_each (list_ret,
13618 new_loc_descr (DW_OP_stack_value, 0, 0));
13621 /* Show if we can't fill the request for an address. */
13622 if (want_address && !have_address)
13624 expansion_failed (loc, NULL_RTX,
13625 "Want address and only have value");
13629 gcc_assert (!ret || !list_ret);
13631 /* If we've got an address and don't want one, dereference. */
13632 if (!want_address && have_address)
13634 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
13636 if (size > DWARF2_ADDR_SIZE || size == -1)
13638 expansion_failed (loc, NULL_RTX,
13639 "DWARF address size mismatch");
13642 else if (size == DWARF2_ADDR_SIZE)
13645 op = DW_OP_deref_size;
13648 add_loc_descr (&ret, new_loc_descr (op, size, 0));
13650 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
13653 list_ret = new_loc_list (ret, NULL, NULL, NULL);
13658 /* Same as above but return only single location expression. */
13659 static dw_loc_descr_ref
13660 loc_descriptor_from_tree (tree loc, int want_address)
13662 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
13665 if (ret->dw_loc_next)
13667 expansion_failed (loc, NULL_RTX,
13668 "Location list where only loc descriptor needed");
13674 /* Given a value, round it up to the lowest multiple of `boundary'
13675 which is not less than the value itself. */
13677 static inline HOST_WIDE_INT
13678 ceiling (HOST_WIDE_INT value, unsigned int boundary)
13680 return (((value + boundary - 1) / boundary) * boundary);
13683 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
13684 pointer to the declared type for the relevant field variable, or return
13685 `integer_type_node' if the given node turns out to be an
13686 ERROR_MARK node. */
13689 field_type (const_tree decl)
13693 if (TREE_CODE (decl) == ERROR_MARK)
13694 return integer_type_node;
13696 type = DECL_BIT_FIELD_TYPE (decl);
13697 if (type == NULL_TREE)
13698 type = TREE_TYPE (decl);
13703 /* Given a pointer to a tree node, return the alignment in bits for
13704 it, or else return BITS_PER_WORD if the node actually turns out to
13705 be an ERROR_MARK node. */
13707 static inline unsigned
13708 simple_type_align_in_bits (const_tree type)
13710 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
13713 static inline unsigned
13714 simple_decl_align_in_bits (const_tree decl)
13716 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
13719 /* Return the result of rounding T up to ALIGN. */
13721 static inline double_int
13722 round_up_to_align (double_int t, unsigned int align)
13724 double_int alignd = uhwi_to_double_int (align);
13725 t = double_int_add (t, alignd);
13726 t = double_int_add (t, double_int_minus_one);
13727 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
13728 t = double_int_mul (t, alignd);
13732 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
13733 lowest addressed byte of the "containing object" for the given FIELD_DECL,
13734 or return 0 if we are unable to determine what that offset is, either
13735 because the argument turns out to be a pointer to an ERROR_MARK node, or
13736 because the offset is actually variable. (We can't handle the latter case
13739 static HOST_WIDE_INT
13740 field_byte_offset (const_tree decl)
13742 double_int object_offset_in_bits;
13743 double_int object_offset_in_bytes;
13744 double_int bitpos_int;
13746 if (TREE_CODE (decl) == ERROR_MARK)
13749 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
13751 /* We cannot yet cope with fields whose positions are variable, so
13752 for now, when we see such things, we simply return 0. Someday, we may
13753 be able to handle such cases, but it will be damn difficult. */
13754 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
13757 bitpos_int = tree_to_double_int (bit_position (decl));
13759 #ifdef PCC_BITFIELD_TYPE_MATTERS
13760 if (PCC_BITFIELD_TYPE_MATTERS)
13763 tree field_size_tree;
13764 double_int deepest_bitpos;
13765 double_int field_size_in_bits;
13766 unsigned int type_align_in_bits;
13767 unsigned int decl_align_in_bits;
13768 double_int type_size_in_bits;
13770 type = field_type (decl);
13771 type_size_in_bits = double_int_type_size_in_bits (type);
13772 type_align_in_bits = simple_type_align_in_bits (type);
13774 field_size_tree = DECL_SIZE (decl);
13776 /* The size could be unspecified if there was an error, or for
13777 a flexible array member. */
13778 if (!field_size_tree)
13779 field_size_tree = bitsize_zero_node;
13781 /* If the size of the field is not constant, use the type size. */
13782 if (TREE_CODE (field_size_tree) == INTEGER_CST)
13783 field_size_in_bits = tree_to_double_int (field_size_tree);
13785 field_size_in_bits = type_size_in_bits;
13787 decl_align_in_bits = simple_decl_align_in_bits (decl);
13789 /* The GCC front-end doesn't make any attempt to keep track of the
13790 starting bit offset (relative to the start of the containing
13791 structure type) of the hypothetical "containing object" for a
13792 bit-field. Thus, when computing the byte offset value for the
13793 start of the "containing object" of a bit-field, we must deduce
13794 this information on our own. This can be rather tricky to do in
13795 some cases. For example, handling the following structure type
13796 definition when compiling for an i386/i486 target (which only
13797 aligns long long's to 32-bit boundaries) can be very tricky:
13799 struct S { int field1; long long field2:31; };
13801 Fortunately, there is a simple rule-of-thumb which can be used
13802 in such cases. When compiling for an i386/i486, GCC will
13803 allocate 8 bytes for the structure shown above. It decides to
13804 do this based upon one simple rule for bit-field allocation.
13805 GCC allocates each "containing object" for each bit-field at
13806 the first (i.e. lowest addressed) legitimate alignment boundary
13807 (based upon the required minimum alignment for the declared
13808 type of the field) which it can possibly use, subject to the
13809 condition that there is still enough available space remaining
13810 in the containing object (when allocated at the selected point)
13811 to fully accommodate all of the bits of the bit-field itself.
13813 This simple rule makes it obvious why GCC allocates 8 bytes for
13814 each object of the structure type shown above. When looking
13815 for a place to allocate the "containing object" for `field2',
13816 the compiler simply tries to allocate a 64-bit "containing
13817 object" at each successive 32-bit boundary (starting at zero)
13818 until it finds a place to allocate that 64- bit field such that
13819 at least 31 contiguous (and previously unallocated) bits remain
13820 within that selected 64 bit field. (As it turns out, for the
13821 example above, the compiler finds it is OK to allocate the
13822 "containing object" 64-bit field at bit-offset zero within the
13825 Here we attempt to work backwards from the limited set of facts
13826 we're given, and we try to deduce from those facts, where GCC
13827 must have believed that the containing object started (within
13828 the structure type). The value we deduce is then used (by the
13829 callers of this routine) to generate DW_AT_location and
13830 DW_AT_bit_offset attributes for fields (both bit-fields and, in
13831 the case of DW_AT_location, regular fields as well). */
13833 /* Figure out the bit-distance from the start of the structure to
13834 the "deepest" bit of the bit-field. */
13835 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
13837 /* This is the tricky part. Use some fancy footwork to deduce
13838 where the lowest addressed bit of the containing object must
13840 object_offset_in_bits
13841 = double_int_sub (deepest_bitpos, type_size_in_bits);
13843 /* Round up to type_align by default. This works best for
13845 object_offset_in_bits
13846 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
13848 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
13850 object_offset_in_bits
13851 = double_int_sub (deepest_bitpos, type_size_in_bits);
13853 /* Round up to decl_align instead. */
13854 object_offset_in_bits
13855 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
13859 #endif /* PCC_BITFIELD_TYPE_MATTERS */
13860 object_offset_in_bits = bitpos_int;
13862 object_offset_in_bytes
13863 = double_int_div (object_offset_in_bits,
13864 uhwi_to_double_int (BITS_PER_UNIT), true,
13866 return double_int_to_shwi (object_offset_in_bytes);
13869 /* The following routines define various Dwarf attributes and any data
13870 associated with them. */
13872 /* Add a location description attribute value to a DIE.
13874 This emits location attributes suitable for whole variables and
13875 whole parameters. Note that the location attributes for struct fields are
13876 generated by the routine `data_member_location_attribute' below. */
13879 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
13880 dw_loc_list_ref descr)
13884 if (single_element_loc_list_p (descr))
13885 add_AT_loc (die, attr_kind, descr->expr);
13887 add_AT_loc_list (die, attr_kind, descr);
13890 /* Add DW_AT_accessibility attribute to DIE if needed. */
13893 add_accessibility_attribute (dw_die_ref die, tree decl)
13895 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
13896 children, otherwise the default is DW_ACCESS_public. In DWARF2
13897 the default has always been DW_ACCESS_public. */
13898 if (TREE_PROTECTED (decl))
13899 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
13900 else if (TREE_PRIVATE (decl))
13902 if (dwarf_version == 2
13903 || die->die_parent == NULL
13904 || die->die_parent->die_tag != DW_TAG_class_type)
13905 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
13907 else if (dwarf_version > 2
13909 && die->die_parent->die_tag == DW_TAG_class_type)
13910 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
13913 /* Attach the specialized form of location attribute used for data members of
13914 struct and union types. In the special case of a FIELD_DECL node which
13915 represents a bit-field, the "offset" part of this special location
13916 descriptor must indicate the distance in bytes from the lowest-addressed
13917 byte of the containing struct or union type to the lowest-addressed byte of
13918 the "containing object" for the bit-field. (See the `field_byte_offset'
13921 For any given bit-field, the "containing object" is a hypothetical object
13922 (of some integral or enum type) within which the given bit-field lives. The
13923 type of this hypothetical "containing object" is always the same as the
13924 declared type of the individual bit-field itself (for GCC anyway... the
13925 DWARF spec doesn't actually mandate this). Note that it is the size (in
13926 bytes) of the hypothetical "containing object" which will be given in the
13927 DW_AT_byte_size attribute for this bit-field. (See the
13928 `byte_size_attribute' function below.) It is also used when calculating the
13929 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
13930 function below.) */
13933 add_data_member_location_attribute (dw_die_ref die, tree decl)
13935 HOST_WIDE_INT offset;
13936 dw_loc_descr_ref loc_descr = 0;
13938 if (TREE_CODE (decl) == TREE_BINFO)
13940 /* We're working on the TAG_inheritance for a base class. */
13941 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
13943 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
13944 aren't at a fixed offset from all (sub)objects of the same
13945 type. We need to extract the appropriate offset from our
13946 vtable. The following dwarf expression means
13948 BaseAddr = ObAddr + *((*ObAddr) - Offset)
13950 This is specific to the V3 ABI, of course. */
13952 dw_loc_descr_ref tmp;
13954 /* Make a copy of the object address. */
13955 tmp = new_loc_descr (DW_OP_dup, 0, 0);
13956 add_loc_descr (&loc_descr, tmp);
13958 /* Extract the vtable address. */
13959 tmp = new_loc_descr (DW_OP_deref, 0, 0);
13960 add_loc_descr (&loc_descr, tmp);
13962 /* Calculate the address of the offset. */
13963 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
13964 gcc_assert (offset < 0);
13966 tmp = int_loc_descriptor (-offset);
13967 add_loc_descr (&loc_descr, tmp);
13968 tmp = new_loc_descr (DW_OP_minus, 0, 0);
13969 add_loc_descr (&loc_descr, tmp);
13971 /* Extract the offset. */
13972 tmp = new_loc_descr (DW_OP_deref, 0, 0);
13973 add_loc_descr (&loc_descr, tmp);
13975 /* Add it to the object address. */
13976 tmp = new_loc_descr (DW_OP_plus, 0, 0);
13977 add_loc_descr (&loc_descr, tmp);
13980 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
13983 offset = field_byte_offset (decl);
13987 if (dwarf_version > 2)
13989 /* Don't need to output a location expression, just the constant. */
13991 add_AT_int (die, DW_AT_data_member_location, offset);
13993 add_AT_unsigned (die, DW_AT_data_member_location, offset);
13998 enum dwarf_location_atom op;
14000 /* The DWARF2 standard says that we should assume that the structure
14001 address is already on the stack, so we can specify a structure
14002 field address by using DW_OP_plus_uconst. */
14004 #ifdef MIPS_DEBUGGING_INFO
14005 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
14006 operator correctly. It works only if we leave the offset on the
14010 op = DW_OP_plus_uconst;
14013 loc_descr = new_loc_descr (op, offset, 0);
14017 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
14020 /* Writes integer values to dw_vec_const array. */
14023 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
14027 *dest++ = val & 0xff;
14033 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14035 static HOST_WIDE_INT
14036 extract_int (const unsigned char *src, unsigned int size)
14038 HOST_WIDE_INT val = 0;
14044 val |= *--src & 0xff;
14050 /* Writes double_int values to dw_vec_const array. */
14053 insert_double (double_int val, unsigned char *dest)
14055 unsigned char *p0 = dest;
14056 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
14058 if (WORDS_BIG_ENDIAN)
14064 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
14065 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
14068 /* Writes floating point values to dw_vec_const array. */
14071 insert_float (const_rtx rtl, unsigned char *array)
14073 REAL_VALUE_TYPE rv;
14077 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
14078 real_to_target (val, &rv, GET_MODE (rtl));
14080 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14081 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
14083 insert_int (val[i], 4, array);
14088 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14089 does not have a "location" either in memory or in a register. These
14090 things can arise in GNU C when a constant is passed as an actual parameter
14091 to an inlined function. They can also arise in C++ where declared
14092 constants do not necessarily get memory "homes". */
14095 add_const_value_attribute (dw_die_ref die, rtx rtl)
14097 switch (GET_CODE (rtl))
14101 HOST_WIDE_INT val = INTVAL (rtl);
14104 add_AT_int (die, DW_AT_const_value, val);
14106 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
14111 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14112 floating-point constant. A CONST_DOUBLE is used whenever the
14113 constant requires more than one word in order to be adequately
14116 enum machine_mode mode = GET_MODE (rtl);
14118 if (SCALAR_FLOAT_MODE_P (mode))
14120 unsigned int length = GET_MODE_SIZE (mode);
14121 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
14123 insert_float (rtl, array);
14124 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
14127 add_AT_double (die, DW_AT_const_value,
14128 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
14134 enum machine_mode mode = GET_MODE (rtl);
14135 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
14136 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14137 unsigned char *array = (unsigned char *) ggc_alloc_atomic
14138 (length * elt_size);
14142 switch (GET_MODE_CLASS (mode))
14144 case MODE_VECTOR_INT:
14145 for (i = 0, p = array; i < length; i++, p += elt_size)
14147 rtx elt = CONST_VECTOR_ELT (rtl, i);
14148 double_int val = rtx_to_double_int (elt);
14150 if (elt_size <= sizeof (HOST_WIDE_INT))
14151 insert_int (double_int_to_shwi (val), elt_size, p);
14154 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14155 insert_double (val, p);
14160 case MODE_VECTOR_FLOAT:
14161 for (i = 0, p = array; i < length; i++, p += elt_size)
14163 rtx elt = CONST_VECTOR_ELT (rtl, i);
14164 insert_float (elt, p);
14169 gcc_unreachable ();
14172 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
14177 if (dwarf_version >= 4 || !dwarf_strict)
14179 dw_loc_descr_ref loc_result;
14180 resolve_one_addr (&rtl, NULL);
14182 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14183 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14184 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14185 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14186 add_AT_loc (die, DW_AT_location, loc_result);
14187 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14193 if (CONSTANT_P (XEXP (rtl, 0)))
14194 return add_const_value_attribute (die, XEXP (rtl, 0));
14197 if (!const_ok_for_output (rtl))
14200 if (dwarf_version >= 4 || !dwarf_strict)
14205 /* In cases where an inlined instance of an inline function is passed
14206 the address of an `auto' variable (which is local to the caller) we
14207 can get a situation where the DECL_RTL of the artificial local
14208 variable (for the inlining) which acts as a stand-in for the
14209 corresponding formal parameter (of the inline function) will look
14210 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14211 exactly a compile-time constant expression, but it isn't the address
14212 of the (artificial) local variable either. Rather, it represents the
14213 *value* which the artificial local variable always has during its
14214 lifetime. We currently have no way to represent such quasi-constant
14215 values in Dwarf, so for now we just punt and generate nothing. */
14223 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
14224 && MEM_READONLY_P (rtl)
14225 && GET_MODE (rtl) == BLKmode)
14227 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
14233 /* No other kinds of rtx should be possible here. */
14234 gcc_unreachable ();
14239 /* Determine whether the evaluation of EXPR references any variables
14240 or functions which aren't otherwise used (and therefore may not be
14243 reference_to_unused (tree * tp, int * walk_subtrees,
14244 void * data ATTRIBUTE_UNUSED)
14246 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
14247 *walk_subtrees = 0;
14249 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
14250 && ! TREE_ASM_WRITTEN (*tp))
14252 /* ??? The C++ FE emits debug information for using decls, so
14253 putting gcc_unreachable here falls over. See PR31899. For now
14254 be conservative. */
14255 else if (!cgraph_global_info_ready
14256 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
14258 else if (TREE_CODE (*tp) == VAR_DECL)
14260 struct varpool_node *node = varpool_get_node (*tp);
14261 if (!node || !node->needed)
14264 else if (TREE_CODE (*tp) == FUNCTION_DECL
14265 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
14267 /* The call graph machinery must have finished analyzing,
14268 optimizing and gimplifying the CU by now.
14269 So if *TP has no call graph node associated
14270 to it, it means *TP will not be emitted. */
14271 if (!cgraph_get_node (*tp))
14274 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
14280 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14281 for use in a later add_const_value_attribute call. */
14284 rtl_for_decl_init (tree init, tree type)
14286 rtx rtl = NULL_RTX;
14290 /* If a variable is initialized with a string constant without embedded
14291 zeros, build CONST_STRING. */
14292 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
14294 tree enttype = TREE_TYPE (type);
14295 tree domain = TYPE_DOMAIN (type);
14296 enum machine_mode mode = TYPE_MODE (enttype);
14298 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
14300 && integer_zerop (TYPE_MIN_VALUE (domain))
14301 && compare_tree_int (TYPE_MAX_VALUE (domain),
14302 TREE_STRING_LENGTH (init) - 1) == 0
14303 && ((size_t) TREE_STRING_LENGTH (init)
14304 == strlen (TREE_STRING_POINTER (init)) + 1))
14306 rtl = gen_rtx_CONST_STRING (VOIDmode,
14307 ggc_strdup (TREE_STRING_POINTER (init)));
14308 rtl = gen_rtx_MEM (BLKmode, rtl);
14309 MEM_READONLY_P (rtl) = 1;
14312 /* Other aggregates, and complex values, could be represented using
14314 else if (AGGREGATE_TYPE_P (type)
14315 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
14316 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
14317 || TREE_CODE (type) == COMPLEX_TYPE)
14319 /* Vectors only work if their mode is supported by the target.
14320 FIXME: generic vectors ought to work too. */
14321 else if (TREE_CODE (type) == VECTOR_TYPE
14322 && !VECTOR_MODE_P (TYPE_MODE (type)))
14324 /* If the initializer is something that we know will expand into an
14325 immediate RTL constant, expand it now. We must be careful not to
14326 reference variables which won't be output. */
14327 else if (initializer_constant_valid_p (init, type)
14328 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
14330 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14332 if (TREE_CODE (type) == VECTOR_TYPE)
14333 switch (TREE_CODE (init))
14338 if (TREE_CONSTANT (init))
14340 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
14341 bool constant_p = true;
14343 unsigned HOST_WIDE_INT ix;
14345 /* Even when ctor is constant, it might contain non-*_CST
14346 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14347 belong into VECTOR_CST nodes. */
14348 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
14349 if (!CONSTANT_CLASS_P (value))
14351 constant_p = false;
14357 init = build_vector_from_ctor (type, elts);
14367 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
14369 /* If expand_expr returns a MEM, it wasn't immediate. */
14370 gcc_assert (!rtl || !MEM_P (rtl));
14376 /* Generate RTL for the variable DECL to represent its location. */
14379 rtl_for_decl_location (tree decl)
14383 /* Here we have to decide where we are going to say the parameter "lives"
14384 (as far as the debugger is concerned). We only have a couple of
14385 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14387 DECL_RTL normally indicates where the parameter lives during most of the
14388 activation of the function. If optimization is enabled however, this
14389 could be either NULL or else a pseudo-reg. Both of those cases indicate
14390 that the parameter doesn't really live anywhere (as far as the code
14391 generation parts of GCC are concerned) during most of the function's
14392 activation. That will happen (for example) if the parameter is never
14393 referenced within the function.
14395 We could just generate a location descriptor here for all non-NULL
14396 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14397 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14398 where DECL_RTL is NULL or is a pseudo-reg.
14400 Note however that we can only get away with using DECL_INCOMING_RTL as
14401 a backup substitute for DECL_RTL in certain limited cases. In cases
14402 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14403 we can be sure that the parameter was passed using the same type as it is
14404 declared to have within the function, and that its DECL_INCOMING_RTL
14405 points us to a place where a value of that type is passed.
14407 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14408 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14409 because in these cases DECL_INCOMING_RTL points us to a value of some
14410 type which is *different* from the type of the parameter itself. Thus,
14411 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14412 such cases, the debugger would end up (for example) trying to fetch a
14413 `float' from a place which actually contains the first part of a
14414 `double'. That would lead to really incorrect and confusing
14415 output at debug-time.
14417 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14418 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14419 are a couple of exceptions however. On little-endian machines we can
14420 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14421 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14422 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14423 when (on a little-endian machine) a non-prototyped function has a
14424 parameter declared to be of type `short' or `char'. In such cases,
14425 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14426 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14427 passed `int' value. If the debugger then uses that address to fetch
14428 a `short' or a `char' (on a little-endian machine) the result will be
14429 the correct data, so we allow for such exceptional cases below.
14431 Note that our goal here is to describe the place where the given formal
14432 parameter lives during most of the function's activation (i.e. between the
14433 end of the prologue and the start of the epilogue). We'll do that as best
14434 as we can. Note however that if the given formal parameter is modified
14435 sometime during the execution of the function, then a stack backtrace (at
14436 debug-time) will show the function as having been called with the *new*
14437 value rather than the value which was originally passed in. This happens
14438 rarely enough that it is not a major problem, but it *is* a problem, and
14439 I'd like to fix it.
14441 A future version of dwarf2out.c may generate two additional attributes for
14442 any given DW_TAG_formal_parameter DIE which will describe the "passed
14443 type" and the "passed location" for the given formal parameter in addition
14444 to the attributes we now generate to indicate the "declared type" and the
14445 "active location" for each parameter. This additional set of attributes
14446 could be used by debuggers for stack backtraces. Separately, note that
14447 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
14448 This happens (for example) for inlined-instances of inline function formal
14449 parameters which are never referenced. This really shouldn't be
14450 happening. All PARM_DECL nodes should get valid non-NULL
14451 DECL_INCOMING_RTL values. FIXME. */
14453 /* Use DECL_RTL as the "location" unless we find something better. */
14454 rtl = DECL_RTL_IF_SET (decl);
14456 /* When generating abstract instances, ignore everything except
14457 constants, symbols living in memory, and symbols living in
14458 fixed registers. */
14459 if (! reload_completed)
14462 && (CONSTANT_P (rtl)
14464 && CONSTANT_P (XEXP (rtl, 0)))
14466 && TREE_CODE (decl) == VAR_DECL
14467 && TREE_STATIC (decl))))
14469 rtl = targetm.delegitimize_address (rtl);
14474 else if (TREE_CODE (decl) == PARM_DECL)
14476 if (rtl == NULL_RTX
14477 || is_pseudo_reg (rtl)
14479 && is_pseudo_reg (XEXP (rtl, 0))
14480 && DECL_INCOMING_RTL (decl)
14481 && MEM_P (DECL_INCOMING_RTL (decl))
14482 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
14484 tree declared_type = TREE_TYPE (decl);
14485 tree passed_type = DECL_ARG_TYPE (decl);
14486 enum machine_mode dmode = TYPE_MODE (declared_type);
14487 enum machine_mode pmode = TYPE_MODE (passed_type);
14489 /* This decl represents a formal parameter which was optimized out.
14490 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
14491 all cases where (rtl == NULL_RTX) just below. */
14492 if (dmode == pmode)
14493 rtl = DECL_INCOMING_RTL (decl);
14494 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
14495 && SCALAR_INT_MODE_P (dmode)
14496 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
14497 && DECL_INCOMING_RTL (decl))
14499 rtx inc = DECL_INCOMING_RTL (decl);
14502 else if (MEM_P (inc))
14504 if (BYTES_BIG_ENDIAN)
14505 rtl = adjust_address_nv (inc, dmode,
14506 GET_MODE_SIZE (pmode)
14507 - GET_MODE_SIZE (dmode));
14514 /* If the parm was passed in registers, but lives on the stack, then
14515 make a big endian correction if the mode of the type of the
14516 parameter is not the same as the mode of the rtl. */
14517 /* ??? This is the same series of checks that are made in dbxout.c before
14518 we reach the big endian correction code there. It isn't clear if all
14519 of these checks are necessary here, but keeping them all is the safe
14521 else if (MEM_P (rtl)
14522 && XEXP (rtl, 0) != const0_rtx
14523 && ! CONSTANT_P (XEXP (rtl, 0))
14524 /* Not passed in memory. */
14525 && !MEM_P (DECL_INCOMING_RTL (decl))
14526 /* Not passed by invisible reference. */
14527 && (!REG_P (XEXP (rtl, 0))
14528 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
14529 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
14530 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
14531 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
14534 /* Big endian correction check. */
14535 && BYTES_BIG_ENDIAN
14536 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
14537 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
14540 int offset = (UNITS_PER_WORD
14541 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
14543 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
14544 plus_constant (XEXP (rtl, 0), offset));
14547 else if (TREE_CODE (decl) == VAR_DECL
14550 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
14551 && BYTES_BIG_ENDIAN)
14553 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
14554 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
14556 /* If a variable is declared "register" yet is smaller than
14557 a register, then if we store the variable to memory, it
14558 looks like we're storing a register-sized value, when in
14559 fact we are not. We need to adjust the offset of the
14560 storage location to reflect the actual value's bytes,
14561 else gdb will not be able to display it. */
14563 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
14564 plus_constant (XEXP (rtl, 0), rsize-dsize));
14567 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
14568 and will have been substituted directly into all expressions that use it.
14569 C does not have such a concept, but C++ and other languages do. */
14570 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
14571 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
14574 rtl = targetm.delegitimize_address (rtl);
14576 /* If we don't look past the constant pool, we risk emitting a
14577 reference to a constant pool entry that isn't referenced from
14578 code, and thus is not emitted. */
14580 rtl = avoid_constant_pool_reference (rtl);
14582 /* Try harder to get a rtl. If this symbol ends up not being emitted
14583 in the current CU, resolve_addr will remove the expression referencing
14585 if (rtl == NULL_RTX
14586 && TREE_CODE (decl) == VAR_DECL
14587 && !DECL_EXTERNAL (decl)
14588 && TREE_STATIC (decl)
14589 && DECL_NAME (decl)
14590 && !DECL_HARD_REGISTER (decl)
14591 && DECL_MODE (decl) != VOIDmode)
14593 rtl = make_decl_rtl_for_debug (decl);
14595 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
14596 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
14603 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
14604 returned. If so, the decl for the COMMON block is returned, and the
14605 value is the offset into the common block for the symbol. */
14608 fortran_common (tree decl, HOST_WIDE_INT *value)
14610 tree val_expr, cvar;
14611 enum machine_mode mode;
14612 HOST_WIDE_INT bitsize, bitpos;
14614 int volatilep = 0, unsignedp = 0;
14616 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
14617 it does not have a value (the offset into the common area), or if it
14618 is thread local (as opposed to global) then it isn't common, and shouldn't
14619 be handled as such. */
14620 if (TREE_CODE (decl) != VAR_DECL
14621 || !TREE_STATIC (decl)
14622 || !DECL_HAS_VALUE_EXPR_P (decl)
14626 val_expr = DECL_VALUE_EXPR (decl);
14627 if (TREE_CODE (val_expr) != COMPONENT_REF)
14630 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
14631 &mode, &unsignedp, &volatilep, true);
14633 if (cvar == NULL_TREE
14634 || TREE_CODE (cvar) != VAR_DECL
14635 || DECL_ARTIFICIAL (cvar)
14636 || !TREE_PUBLIC (cvar))
14640 if (offset != NULL)
14642 if (!host_integerp (offset, 0))
14644 *value = tree_low_cst (offset, 0);
14647 *value += bitpos / BITS_PER_UNIT;
14652 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
14653 data attribute for a variable or a parameter. We generate the
14654 DW_AT_const_value attribute only in those cases where the given variable
14655 or parameter does not have a true "location" either in memory or in a
14656 register. This can happen (for example) when a constant is passed as an
14657 actual argument in a call to an inline function. (It's possible that
14658 these things can crop up in other ways also.) Note that one type of
14659 constant value which can be passed into an inlined function is a constant
14660 pointer. This can happen for example if an actual argument in an inlined
14661 function call evaluates to a compile-time constant address.
14663 CACHE_P is true if it is worth caching the location list for DECL,
14664 so that future calls can reuse it rather than regenerate it from scratch.
14665 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
14666 since we will need to refer to them each time the function is inlined. */
14669 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
14670 enum dwarf_attribute attr)
14673 dw_loc_list_ref list;
14674 var_loc_list *loc_list;
14675 cached_dw_loc_list *cache;
14678 if (TREE_CODE (decl) == ERROR_MARK)
14681 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
14682 || TREE_CODE (decl) == RESULT_DECL);
14684 /* Try to get some constant RTL for this decl, and use that as the value of
14687 rtl = rtl_for_decl_location (decl);
14688 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
14689 && add_const_value_attribute (die, rtl))
14692 /* See if we have single element location list that is equivalent to
14693 a constant value. That way we are better to use add_const_value_attribute
14694 rather than expanding constant value equivalent. */
14695 loc_list = lookup_decl_loc (decl);
14698 && loc_list->first->next == NULL
14699 && NOTE_P (loc_list->first->loc)
14700 && NOTE_VAR_LOCATION (loc_list->first->loc)
14701 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
14703 struct var_loc_node *node;
14705 node = loc_list->first;
14706 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
14707 if (GET_CODE (rtl) == EXPR_LIST)
14708 rtl = XEXP (rtl, 0);
14709 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
14710 && add_const_value_attribute (die, rtl))
14713 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
14714 list several times. See if we've already cached the contents. */
14716 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
14720 cache = (cached_dw_loc_list *)
14721 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
14723 list = cache->loc_list;
14727 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
14728 /* It is usually worth caching this result if the decl is from
14729 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
14730 if (cache_p && list && list->dw_loc_next)
14732 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
14733 DECL_UID (decl), INSERT);
14734 cache = ggc_alloc_cleared_cached_dw_loc_list ();
14735 cache->decl_id = DECL_UID (decl);
14736 cache->loc_list = list;
14742 add_AT_location_description (die, attr, list);
14745 /* None of that worked, so it must not really have a location;
14746 try adding a constant value attribute from the DECL_INITIAL. */
14747 return tree_add_const_value_attribute_for_decl (die, decl);
14750 /* Add VARIABLE and DIE into deferred locations list. */
14753 defer_location (tree variable, dw_die_ref die)
14755 deferred_locations entry;
14756 entry.variable = variable;
14758 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
14761 /* Helper function for tree_add_const_value_attribute. Natively encode
14762 initializer INIT into an array. Return true if successful. */
14765 native_encode_initializer (tree init, unsigned char *array, int size)
14769 if (init == NULL_TREE)
14773 switch (TREE_CODE (init))
14776 type = TREE_TYPE (init);
14777 if (TREE_CODE (type) == ARRAY_TYPE)
14779 tree enttype = TREE_TYPE (type);
14780 enum machine_mode mode = TYPE_MODE (enttype);
14782 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
14784 if (int_size_in_bytes (type) != size)
14786 if (size > TREE_STRING_LENGTH (init))
14788 memcpy (array, TREE_STRING_POINTER (init),
14789 TREE_STRING_LENGTH (init));
14790 memset (array + TREE_STRING_LENGTH (init),
14791 '\0', size - TREE_STRING_LENGTH (init));
14794 memcpy (array, TREE_STRING_POINTER (init), size);
14799 type = TREE_TYPE (init);
14800 if (int_size_in_bytes (type) != size)
14802 if (TREE_CODE (type) == ARRAY_TYPE)
14804 HOST_WIDE_INT min_index;
14805 unsigned HOST_WIDE_INT cnt;
14806 int curpos = 0, fieldsize;
14807 constructor_elt *ce;
14809 if (TYPE_DOMAIN (type) == NULL_TREE
14810 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
14813 fieldsize = int_size_in_bytes (TREE_TYPE (type));
14814 if (fieldsize <= 0)
14817 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
14818 memset (array, '\0', size);
14819 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
14821 tree val = ce->value;
14822 tree index = ce->index;
14824 if (index && TREE_CODE (index) == RANGE_EXPR)
14825 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
14828 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
14833 if (!native_encode_initializer (val, array + pos, fieldsize))
14836 curpos = pos + fieldsize;
14837 if (index && TREE_CODE (index) == RANGE_EXPR)
14839 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
14840 - tree_low_cst (TREE_OPERAND (index, 0), 0);
14841 while (count-- > 0)
14844 memcpy (array + curpos, array + pos, fieldsize);
14845 curpos += fieldsize;
14848 gcc_assert (curpos <= size);
14852 else if (TREE_CODE (type) == RECORD_TYPE
14853 || TREE_CODE (type) == UNION_TYPE)
14855 tree field = NULL_TREE;
14856 unsigned HOST_WIDE_INT cnt;
14857 constructor_elt *ce;
14859 if (int_size_in_bytes (type) != size)
14862 if (TREE_CODE (type) == RECORD_TYPE)
14863 field = TYPE_FIELDS (type);
14865 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
14867 tree val = ce->value;
14868 int pos, fieldsize;
14870 if (ce->index != 0)
14876 if (field == NULL_TREE || DECL_BIT_FIELD (field))
14879 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
14880 && TYPE_DOMAIN (TREE_TYPE (field))
14881 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
14883 else if (DECL_SIZE_UNIT (field) == NULL_TREE
14884 || !host_integerp (DECL_SIZE_UNIT (field), 0))
14886 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
14887 pos = int_byte_position (field);
14888 gcc_assert (pos + fieldsize <= size);
14890 && !native_encode_initializer (val, array + pos, fieldsize))
14896 case VIEW_CONVERT_EXPR:
14897 case NON_LVALUE_EXPR:
14898 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
14900 return native_encode_expr (init, array, size) == size;
14904 /* Attach a DW_AT_const_value attribute to DIE. The value of the
14905 attribute is the const value T. */
14908 tree_add_const_value_attribute (dw_die_ref die, tree t)
14911 tree type = TREE_TYPE (t);
14914 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
14918 gcc_assert (!DECL_P (init));
14920 rtl = rtl_for_decl_init (init, type);
14922 return add_const_value_attribute (die, rtl);
14923 /* If the host and target are sane, try harder. */
14924 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
14925 && initializer_constant_valid_p (init, type))
14927 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
14928 if (size > 0 && (int) size == size)
14930 unsigned char *array = (unsigned char *)
14931 ggc_alloc_cleared_atomic (size);
14933 if (native_encode_initializer (init, array, size))
14935 add_AT_vec (die, DW_AT_const_value, size, 1, array);
14943 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
14944 attribute is the const value of T, where T is an integral constant
14945 variable with static storage duration
14946 (so it can't be a PARM_DECL or a RESULT_DECL). */
14949 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
14953 || (TREE_CODE (decl) != VAR_DECL
14954 && TREE_CODE (decl) != CONST_DECL)
14955 || (TREE_CODE (decl) == VAR_DECL
14956 && !TREE_STATIC (decl)))
14959 if (TREE_READONLY (decl)
14960 && ! TREE_THIS_VOLATILE (decl)
14961 && DECL_INITIAL (decl))
14966 /* Don't add DW_AT_const_value if abstract origin already has one. */
14967 if (get_AT (var_die, DW_AT_const_value))
14970 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
14973 /* Convert the CFI instructions for the current function into a
14974 location list. This is used for DW_AT_frame_base when we targeting
14975 a dwarf2 consumer that does not support the dwarf3
14976 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
14979 static dw_loc_list_ref
14980 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
14984 dw_loc_list_ref list, *list_tail;
14986 dw_cfa_location last_cfa, next_cfa;
14987 const char *start_label, *last_label, *section;
14988 dw_cfa_location remember;
14991 gcc_assert (fde != NULL);
14993 section = secname_for_decl (current_function_decl);
14997 memset (&next_cfa, 0, sizeof (next_cfa));
14998 next_cfa.reg = INVALID_REGNUM;
14999 remember = next_cfa;
15001 start_label = fde->dw_fde_begin;
15003 /* ??? Bald assumption that the CIE opcode list does not contain
15004 advance opcodes. */
15005 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
15006 lookup_cfa_1 (cfi, &next_cfa, &remember);
15008 last_cfa = next_cfa;
15009 last_label = start_label;
15011 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
15013 /* If the first partition contained no CFI adjustments, the
15014 CIE opcodes apply to the whole first partition. */
15015 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15016 fde->dw_fde_begin, fde->dw_fde_end, section);
15017 list_tail =&(*list_tail)->dw_loc_next;
15018 start_label = last_label = fde->dw_fde_second_begin;
15021 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
15023 switch (cfi->dw_cfi_opc)
15025 case DW_CFA_set_loc:
15026 case DW_CFA_advance_loc1:
15027 case DW_CFA_advance_loc2:
15028 case DW_CFA_advance_loc4:
15029 if (!cfa_equal_p (&last_cfa, &next_cfa))
15031 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15032 start_label, last_label, section);
15034 list_tail = &(*list_tail)->dw_loc_next;
15035 last_cfa = next_cfa;
15036 start_label = last_label;
15038 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
15041 case DW_CFA_advance_loc:
15042 /* The encoding is complex enough that we should never emit this. */
15043 gcc_unreachable ();
15046 lookup_cfa_1 (cfi, &next_cfa, &remember);
15049 if (ix + 1 == fde->dw_fde_switch_cfi_index)
15051 if (!cfa_equal_p (&last_cfa, &next_cfa))
15053 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15054 start_label, last_label, section);
15056 list_tail = &(*list_tail)->dw_loc_next;
15057 last_cfa = next_cfa;
15058 start_label = last_label;
15060 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15061 start_label, fde->dw_fde_end, section);
15062 list_tail = &(*list_tail)->dw_loc_next;
15063 start_label = last_label = fde->dw_fde_second_begin;
15067 if (!cfa_equal_p (&last_cfa, &next_cfa))
15069 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15070 start_label, last_label, section);
15071 list_tail = &(*list_tail)->dw_loc_next;
15072 start_label = last_label;
15075 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
15077 fde->dw_fde_second_begin
15078 ? fde->dw_fde_second_end : fde->dw_fde_end,
15081 if (list && list->dw_loc_next)
15087 /* Compute a displacement from the "steady-state frame pointer" to the
15088 frame base (often the same as the CFA), and store it in
15089 frame_pointer_fb_offset. OFFSET is added to the displacement
15090 before the latter is negated. */
15093 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
15097 #ifdef FRAME_POINTER_CFA_OFFSET
15098 reg = frame_pointer_rtx;
15099 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
15101 reg = arg_pointer_rtx;
15102 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
15105 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
15106 if (GET_CODE (elim) == PLUS)
15108 offset += INTVAL (XEXP (elim, 1));
15109 elim = XEXP (elim, 0);
15112 frame_pointer_fb_offset = -offset;
15114 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15115 in which to eliminate. This is because it's stack pointer isn't
15116 directly accessible as a register within the ISA. To work around
15117 this, assume that while we cannot provide a proper value for
15118 frame_pointer_fb_offset, we won't need one either. */
15119 frame_pointer_fb_offset_valid
15120 = ((SUPPORTS_STACK_ALIGNMENT
15121 && (elim == hard_frame_pointer_rtx
15122 || elim == stack_pointer_rtx))
15123 || elim == (frame_pointer_needed
15124 ? hard_frame_pointer_rtx
15125 : stack_pointer_rtx));
15128 /* Generate a DW_AT_name attribute given some string value to be included as
15129 the value of the attribute. */
15132 add_name_attribute (dw_die_ref die, const char *name_string)
15134 if (name_string != NULL && *name_string != 0)
15136 if (demangle_name_func)
15137 name_string = (*demangle_name_func) (name_string);
15139 add_AT_string (die, DW_AT_name, name_string);
15143 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15144 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15145 of TYPE accordingly.
15147 ??? This is a temporary measure until after we're able to generate
15148 regular DWARF for the complex Ada type system. */
15151 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
15152 dw_die_ref context_die)
15155 dw_die_ref dtype_die;
15157 if (!lang_hooks.types.descriptive_type)
15160 dtype = lang_hooks.types.descriptive_type (type);
15164 dtype_die = lookup_type_die (dtype);
15167 gen_type_die (dtype, context_die);
15168 dtype_die = lookup_type_die (dtype);
15169 gcc_assert (dtype_die);
15172 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
15175 /* Generate a DW_AT_comp_dir attribute for DIE. */
15178 add_comp_dir_attribute (dw_die_ref die)
15180 const char *wd = get_src_pwd ();
15186 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
15190 wdlen = strlen (wd);
15191 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
15193 wd1 [wdlen] = DIR_SEPARATOR;
15194 wd1 [wdlen + 1] = 0;
15198 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
15201 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15205 lower_bound_default (void)
15207 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
15212 case DW_LANG_C_plus_plus:
15214 case DW_LANG_ObjC_plus_plus:
15217 case DW_LANG_Fortran77:
15218 case DW_LANG_Fortran90:
15219 case DW_LANG_Fortran95:
15223 case DW_LANG_Python:
15224 return dwarf_version >= 4 ? 0 : -1;
15225 case DW_LANG_Ada95:
15226 case DW_LANG_Ada83:
15227 case DW_LANG_Cobol74:
15228 case DW_LANG_Cobol85:
15229 case DW_LANG_Pascal83:
15230 case DW_LANG_Modula2:
15232 return dwarf_version >= 4 ? 1 : -1;
15238 /* Given a tree node describing an array bound (either lower or upper) output
15239 a representation for that bound. */
15242 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
15244 switch (TREE_CODE (bound))
15249 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15252 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
15255 /* Use the default if possible. */
15256 if (bound_attr == DW_AT_lower_bound
15257 && host_integerp (bound, 0)
15258 && (dflt = lower_bound_default ()) != -1
15259 && tree_low_cst (bound, 0) == dflt)
15262 /* Otherwise represent the bound as an unsigned value with the
15263 precision of its type. The precision and signedness of the
15264 type will be necessary to re-interpret it unambiguously. */
15265 else if (prec < HOST_BITS_PER_WIDE_INT)
15267 unsigned HOST_WIDE_INT mask
15268 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
15269 add_AT_unsigned (subrange_die, bound_attr,
15270 TREE_INT_CST_LOW (bound) & mask);
15272 else if (prec == HOST_BITS_PER_WIDE_INT
15273 || TREE_INT_CST_HIGH (bound) == 0)
15274 add_AT_unsigned (subrange_die, bound_attr,
15275 TREE_INT_CST_LOW (bound));
15277 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
15278 TREE_INT_CST_LOW (bound));
15283 case VIEW_CONVERT_EXPR:
15284 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
15294 dw_die_ref decl_die = lookup_decl_die (bound);
15296 /* ??? Can this happen, or should the variable have been bound
15297 first? Probably it can, since I imagine that we try to create
15298 the types of parameters in the order in which they exist in
15299 the list, and won't have created a forward reference to a
15300 later parameter. */
15301 if (decl_die != NULL)
15303 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15311 /* Otherwise try to create a stack operation procedure to
15312 evaluate the value of the array bound. */
15314 dw_die_ref ctx, decl_die;
15315 dw_loc_list_ref list;
15317 list = loc_list_from_tree (bound, 2);
15318 if (list == NULL || single_element_loc_list_p (list))
15320 /* If DW_AT_*bound is not a reference nor constant, it is
15321 a DWARF expression rather than location description.
15322 For that loc_list_from_tree (bound, 0) is needed.
15323 If that fails to give a single element list,
15324 fall back to outputting this as a reference anyway. */
15325 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
15326 if (list2 && single_element_loc_list_p (list2))
15328 add_AT_loc (subrange_die, bound_attr, list2->expr);
15335 if (current_function_decl == 0)
15336 ctx = comp_unit_die ();
15338 ctx = lookup_decl_die (current_function_decl);
15340 decl_die = new_die (DW_TAG_variable, ctx, bound);
15341 add_AT_flag (decl_die, DW_AT_artificial, 1);
15342 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
15343 add_AT_location_description (decl_die, DW_AT_location, list);
15344 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15350 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15351 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15352 Note that the block of subscript information for an array type also
15353 includes information about the element type of the given array type. */
15356 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
15358 unsigned dimension_number;
15360 dw_die_ref subrange_die;
15362 for (dimension_number = 0;
15363 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
15364 type = TREE_TYPE (type), dimension_number++)
15366 tree domain = TYPE_DOMAIN (type);
15368 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
15371 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15372 and (in GNU C only) variable bounds. Handle all three forms
15374 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
15377 /* We have an array type with specified bounds. */
15378 lower = TYPE_MIN_VALUE (domain);
15379 upper = TYPE_MAX_VALUE (domain);
15381 /* Define the index type. */
15382 if (TREE_TYPE (domain))
15384 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15385 TREE_TYPE field. We can't emit debug info for this
15386 because it is an unnamed integral type. */
15387 if (TREE_CODE (domain) == INTEGER_TYPE
15388 && TYPE_NAME (domain) == NULL_TREE
15389 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
15390 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
15393 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
15397 /* ??? If upper is NULL, the array has unspecified length,
15398 but it does have a lower bound. This happens with Fortran
15400 Since the debugger is definitely going to need to know N
15401 to produce useful results, go ahead and output the lower
15402 bound solo, and hope the debugger can cope. */
15404 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
15406 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
15409 /* Otherwise we have an array type with an unspecified length. The
15410 DWARF-2 spec does not say how to handle this; let's just leave out the
15416 add_byte_size_attribute (dw_die_ref die, tree tree_node)
15420 switch (TREE_CODE (tree_node))
15425 case ENUMERAL_TYPE:
15428 case QUAL_UNION_TYPE:
15429 size = int_size_in_bytes (tree_node);
15432 /* For a data member of a struct or union, the DW_AT_byte_size is
15433 generally given as the number of bytes normally allocated for an
15434 object of the *declared* type of the member itself. This is true
15435 even for bit-fields. */
15436 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
15439 gcc_unreachable ();
15442 /* Note that `size' might be -1 when we get to this point. If it is, that
15443 indicates that the byte size of the entity in question is variable. We
15444 have no good way of expressing this fact in Dwarf at the present time,
15445 so just let the -1 pass on through. */
15446 add_AT_unsigned (die, DW_AT_byte_size, size);
15449 /* For a FIELD_DECL node which represents a bit-field, output an attribute
15450 which specifies the distance in bits from the highest order bit of the
15451 "containing object" for the bit-field to the highest order bit of the
15454 For any given bit-field, the "containing object" is a hypothetical object
15455 (of some integral or enum type) within which the given bit-field lives. The
15456 type of this hypothetical "containing object" is always the same as the
15457 declared type of the individual bit-field itself. The determination of the
15458 exact location of the "containing object" for a bit-field is rather
15459 complicated. It's handled by the `field_byte_offset' function (above).
15461 Note that it is the size (in bytes) of the hypothetical "containing object"
15462 which will be given in the DW_AT_byte_size attribute for this bit-field.
15463 (See `byte_size_attribute' above). */
15466 add_bit_offset_attribute (dw_die_ref die, tree decl)
15468 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
15469 tree type = DECL_BIT_FIELD_TYPE (decl);
15470 HOST_WIDE_INT bitpos_int;
15471 HOST_WIDE_INT highest_order_object_bit_offset;
15472 HOST_WIDE_INT highest_order_field_bit_offset;
15473 HOST_WIDE_INT bit_offset;
15475 /* Must be a field and a bit field. */
15476 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
15478 /* We can't yet handle bit-fields whose offsets are variable, so if we
15479 encounter such things, just return without generating any attribute
15480 whatsoever. Likewise for variable or too large size. */
15481 if (! host_integerp (bit_position (decl), 0)
15482 || ! host_integerp (DECL_SIZE (decl), 1))
15485 bitpos_int = int_bit_position (decl);
15487 /* Note that the bit offset is always the distance (in bits) from the
15488 highest-order bit of the "containing object" to the highest-order bit of
15489 the bit-field itself. Since the "high-order end" of any object or field
15490 is different on big-endian and little-endian machines, the computation
15491 below must take account of these differences. */
15492 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
15493 highest_order_field_bit_offset = bitpos_int;
15495 if (! BYTES_BIG_ENDIAN)
15497 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
15498 highest_order_object_bit_offset += simple_type_size_in_bits (type);
15502 = (! BYTES_BIG_ENDIAN
15503 ? highest_order_object_bit_offset - highest_order_field_bit_offset
15504 : highest_order_field_bit_offset - highest_order_object_bit_offset);
15506 if (bit_offset < 0)
15507 add_AT_int (die, DW_AT_bit_offset, bit_offset);
15509 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
15512 /* For a FIELD_DECL node which represents a bit field, output an attribute
15513 which specifies the length in bits of the given field. */
15516 add_bit_size_attribute (dw_die_ref die, tree decl)
15518 /* Must be a field and a bit field. */
15519 gcc_assert (TREE_CODE (decl) == FIELD_DECL
15520 && DECL_BIT_FIELD_TYPE (decl));
15522 if (host_integerp (DECL_SIZE (decl), 1))
15523 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
15526 /* If the compiled language is ANSI C, then add a 'prototyped'
15527 attribute, if arg types are given for the parameters of a function. */
15530 add_prototyped_attribute (dw_die_ref die, tree func_type)
15532 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
15533 && prototype_p (func_type))
15534 add_AT_flag (die, DW_AT_prototyped, 1);
15537 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
15538 by looking in either the type declaration or object declaration
15541 static inline dw_die_ref
15542 add_abstract_origin_attribute (dw_die_ref die, tree origin)
15544 dw_die_ref origin_die = NULL;
15546 if (TREE_CODE (origin) != FUNCTION_DECL)
15548 /* We may have gotten separated from the block for the inlined
15549 function, if we're in an exception handler or some such; make
15550 sure that the abstract function has been written out.
15552 Doing this for nested functions is wrong, however; functions are
15553 distinct units, and our context might not even be inline. */
15557 fn = TYPE_STUB_DECL (fn);
15559 fn = decl_function_context (fn);
15561 dwarf2out_abstract_function (fn);
15564 if (DECL_P (origin))
15565 origin_die = lookup_decl_die (origin);
15566 else if (TYPE_P (origin))
15567 origin_die = lookup_type_die (origin);
15569 /* XXX: Functions that are never lowered don't always have correct block
15570 trees (in the case of java, they simply have no block tree, in some other
15571 languages). For these functions, there is nothing we can really do to
15572 output correct debug info for inlined functions in all cases. Rather
15573 than die, we'll just produce deficient debug info now, in that we will
15574 have variables without a proper abstract origin. In the future, when all
15575 functions are lowered, we should re-add a gcc_assert (origin_die)
15579 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
15583 /* We do not currently support the pure_virtual attribute. */
15586 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
15588 if (DECL_VINDEX (func_decl))
15590 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
15592 if (host_integerp (DECL_VINDEX (func_decl), 0))
15593 add_AT_loc (die, DW_AT_vtable_elem_location,
15594 new_loc_descr (DW_OP_constu,
15595 tree_low_cst (DECL_VINDEX (func_decl), 0),
15598 /* GNU extension: Record what type this method came from originally. */
15599 if (debug_info_level > DINFO_LEVEL_TERSE
15600 && DECL_CONTEXT (func_decl))
15601 add_AT_die_ref (die, DW_AT_containing_type,
15602 lookup_type_die (DECL_CONTEXT (func_decl)));
15606 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
15607 given decl. This used to be a vendor extension until after DWARF 4
15608 standardized it. */
15611 add_linkage_attr (dw_die_ref die, tree decl)
15613 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15615 /* Mimic what assemble_name_raw does with a leading '*'. */
15616 if (name[0] == '*')
15619 if (dwarf_version >= 4)
15620 add_AT_string (die, DW_AT_linkage_name, name);
15622 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
15625 /* Add source coordinate attributes for the given decl. */
15628 add_src_coords_attributes (dw_die_ref die, tree decl)
15630 expanded_location s;
15632 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
15634 s = expand_location (DECL_SOURCE_LOCATION (decl));
15635 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
15636 add_AT_unsigned (die, DW_AT_decl_line, s.line);
15639 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
15642 add_linkage_name (dw_die_ref die, tree decl)
15644 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
15645 && TREE_PUBLIC (decl)
15646 && !DECL_ABSTRACT (decl)
15647 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
15648 && die->die_tag != DW_TAG_member)
15650 /* Defer until we have an assembler name set. */
15651 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
15653 limbo_die_node *asm_name;
15655 asm_name = ggc_alloc_cleared_limbo_die_node ();
15656 asm_name->die = die;
15657 asm_name->created_for = decl;
15658 asm_name->next = deferred_asm_name;
15659 deferred_asm_name = asm_name;
15661 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
15662 add_linkage_attr (die, decl);
15666 /* Add a DW_AT_name attribute and source coordinate attribute for the
15667 given decl, but only if it actually has a name. */
15670 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
15674 decl_name = DECL_NAME (decl);
15675 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
15677 const char *name = dwarf2_name (decl, 0);
15679 add_name_attribute (die, name);
15680 if (! DECL_ARTIFICIAL (decl))
15681 add_src_coords_attributes (die, decl);
15683 add_linkage_name (die, decl);
15686 #ifdef VMS_DEBUGGING_INFO
15687 /* Get the function's name, as described by its RTL. This may be different
15688 from the DECL_NAME name used in the source file. */
15689 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
15691 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
15692 XEXP (DECL_RTL (decl), 0));
15693 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
15695 #endif /* VMS_DEBUGGING_INFO */
15698 #ifdef VMS_DEBUGGING_INFO
15699 /* Output the debug main pointer die for VMS */
15702 dwarf2out_vms_debug_main_pointer (void)
15704 char label[MAX_ARTIFICIAL_LABEL_BYTES];
15707 /* Allocate the VMS debug main subprogram die. */
15708 die = ggc_alloc_cleared_die_node ();
15709 die->die_tag = DW_TAG_subprogram;
15710 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
15711 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
15712 current_function_funcdef_no);
15713 add_AT_lbl_id (die, DW_AT_entry_pc, label);
15715 /* Make it the first child of comp_unit_die (). */
15716 die->die_parent = comp_unit_die ();
15717 if (comp_unit_die ()->die_child)
15719 die->die_sib = comp_unit_die ()->die_child->die_sib;
15720 comp_unit_die ()->die_child->die_sib = die;
15724 die->die_sib = die;
15725 comp_unit_die ()->die_child = die;
15728 #endif /* VMS_DEBUGGING_INFO */
15730 /* Push a new declaration scope. */
15733 push_decl_scope (tree scope)
15735 VEC_safe_push (tree, gc, decl_scope_table, scope);
15738 /* Pop a declaration scope. */
15741 pop_decl_scope (void)
15743 VEC_pop (tree, decl_scope_table);
15746 /* Return the DIE for the scope that immediately contains this type.
15747 Non-named types get global scope. Named types nested in other
15748 types get their containing scope if it's open, or global scope
15749 otherwise. All other types (i.e. function-local named types) get
15750 the current active scope. */
15753 scope_die_for (tree t, dw_die_ref context_die)
15755 dw_die_ref scope_die = NULL;
15756 tree containing_scope;
15759 /* Non-types always go in the current scope. */
15760 gcc_assert (TYPE_P (t));
15762 containing_scope = TYPE_CONTEXT (t);
15764 /* Use the containing namespace if it was passed in (for a declaration). */
15765 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
15767 if (context_die == lookup_decl_die (containing_scope))
15770 containing_scope = NULL_TREE;
15773 /* Ignore function type "scopes" from the C frontend. They mean that
15774 a tagged type is local to a parmlist of a function declarator, but
15775 that isn't useful to DWARF. */
15776 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
15777 containing_scope = NULL_TREE;
15779 if (SCOPE_FILE_SCOPE_P (containing_scope))
15780 scope_die = comp_unit_die ();
15781 else if (TYPE_P (containing_scope))
15783 /* For types, we can just look up the appropriate DIE. But
15784 first we check to see if we're in the middle of emitting it
15785 so we know where the new DIE should go. */
15786 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
15787 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
15792 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
15793 || TREE_ASM_WRITTEN (containing_scope));
15794 /*We are not in the middle of emitting the type
15795 CONTAINING_SCOPE. Let's see if it's emitted already. */
15796 scope_die = lookup_type_die (containing_scope);
15798 /* If none of the current dies are suitable, we get file scope. */
15799 if (scope_die == NULL)
15800 scope_die = comp_unit_die ();
15803 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
15806 scope_die = context_die;
15811 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
15814 local_scope_p (dw_die_ref context_die)
15816 for (; context_die; context_die = context_die->die_parent)
15817 if (context_die->die_tag == DW_TAG_inlined_subroutine
15818 || context_die->die_tag == DW_TAG_subprogram)
15824 /* Returns nonzero if CONTEXT_DIE is a class. */
15827 class_scope_p (dw_die_ref context_die)
15829 return (context_die
15830 && (context_die->die_tag == DW_TAG_structure_type
15831 || context_die->die_tag == DW_TAG_class_type
15832 || context_die->die_tag == DW_TAG_interface_type
15833 || context_die->die_tag == DW_TAG_union_type));
15836 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
15837 whether or not to treat a DIE in this context as a declaration. */
15840 class_or_namespace_scope_p (dw_die_ref context_die)
15842 return (class_scope_p (context_die)
15843 || (context_die && context_die->die_tag == DW_TAG_namespace));
15846 /* Many forms of DIEs require a "type description" attribute. This
15847 routine locates the proper "type descriptor" die for the type given
15848 by 'type', and adds a DW_AT_type attribute below the given die. */
15851 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
15852 int decl_volatile, dw_die_ref context_die)
15854 enum tree_code code = TREE_CODE (type);
15855 dw_die_ref type_die = NULL;
15857 /* ??? If this type is an unnamed subrange type of an integral, floating-point
15858 or fixed-point type, use the inner type. This is because we have no
15859 support for unnamed types in base_type_die. This can happen if this is
15860 an Ada subrange type. Correct solution is emit a subrange type die. */
15861 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
15862 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
15863 type = TREE_TYPE (type), code = TREE_CODE (type);
15865 if (code == ERROR_MARK
15866 /* Handle a special case. For functions whose return type is void, we
15867 generate *no* type attribute. (Note that no object may have type
15868 `void', so this only applies to function return types). */
15869 || code == VOID_TYPE)
15872 type_die = modified_type_die (type,
15873 decl_const || TYPE_READONLY (type),
15874 decl_volatile || TYPE_VOLATILE (type),
15877 if (type_die != NULL)
15878 add_AT_die_ref (object_die, DW_AT_type, type_die);
15881 /* Given an object die, add the calling convention attribute for the
15882 function call type. */
15884 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
15886 enum dwarf_calling_convention value = DW_CC_normal;
15888 value = ((enum dwarf_calling_convention)
15889 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
15892 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
15894 /* DWARF 2 doesn't provide a way to identify a program's source-level
15895 entry point. DW_AT_calling_convention attributes are only meant
15896 to describe functions' calling conventions. However, lacking a
15897 better way to signal the Fortran main program, we used this for
15898 a long time, following existing custom. Now, DWARF 4 has
15899 DW_AT_main_subprogram, which we add below, but some tools still
15900 rely on the old way, which we thus keep. */
15901 value = DW_CC_program;
15903 if (dwarf_version >= 4 || !dwarf_strict)
15904 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
15907 /* Only add the attribute if the backend requests it, and
15908 is not DW_CC_normal. */
15909 if (value && (value != DW_CC_normal))
15910 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
15913 /* Given a tree pointer to a struct, class, union, or enum type node, return
15914 a pointer to the (string) tag name for the given type, or zero if the type
15915 was declared without a tag. */
15917 static const char *
15918 type_tag (const_tree type)
15920 const char *name = 0;
15922 if (TYPE_NAME (type) != 0)
15926 /* Find the IDENTIFIER_NODE for the type name. */
15927 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
15928 && !TYPE_NAMELESS (type))
15929 t = TYPE_NAME (type);
15931 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
15932 a TYPE_DECL node, regardless of whether or not a `typedef' was
15934 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
15935 && ! DECL_IGNORED_P (TYPE_NAME (type)))
15937 /* We want to be extra verbose. Don't call dwarf_name if
15938 DECL_NAME isn't set. The default hook for decl_printable_name
15939 doesn't like that, and in this context it's correct to return
15940 0, instead of "<anonymous>" or the like. */
15941 if (DECL_NAME (TYPE_NAME (type))
15942 && !DECL_NAMELESS (TYPE_NAME (type)))
15943 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
15946 /* Now get the name as a string, or invent one. */
15947 if (!name && t != 0)
15948 name = IDENTIFIER_POINTER (t);
15951 return (name == 0 || *name == '\0') ? 0 : name;
15954 /* Return the type associated with a data member, make a special check
15955 for bit field types. */
15958 member_declared_type (const_tree member)
15960 return (DECL_BIT_FIELD_TYPE (member)
15961 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
15964 /* Get the decl's label, as described by its RTL. This may be different
15965 from the DECL_NAME name used in the source file. */
15968 static const char *
15969 decl_start_label (tree decl)
15972 const char *fnname;
15974 x = DECL_RTL (decl);
15975 gcc_assert (MEM_P (x));
15978 gcc_assert (GET_CODE (x) == SYMBOL_REF);
15980 fnname = XSTR (x, 0);
15985 /* These routines generate the internal representation of the DIE's for
15986 the compilation unit. Debugging information is collected by walking
15987 the declaration trees passed in from dwarf2out_decl(). */
15990 gen_array_type_die (tree type, dw_die_ref context_die)
15992 dw_die_ref scope_die = scope_die_for (type, context_die);
15993 dw_die_ref array_die;
15995 /* GNU compilers represent multidimensional array types as sequences of one
15996 dimensional array types whose element types are themselves array types.
15997 We sometimes squish that down to a single array_type DIE with multiple
15998 subscripts in the Dwarf debugging info. The draft Dwarf specification
15999 say that we are allowed to do this kind of compression in C, because
16000 there is no difference between an array of arrays and a multidimensional
16001 array. We don't do this for Ada to remain as close as possible to the
16002 actual representation, which is especially important against the language
16003 flexibilty wrt arrays of variable size. */
16005 bool collapse_nested_arrays = !is_ada ();
16008 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16009 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16010 if (TYPE_STRING_FLAG (type)
16011 && TREE_CODE (type) == ARRAY_TYPE
16013 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
16015 HOST_WIDE_INT size;
16017 array_die = new_die (DW_TAG_string_type, scope_die, type);
16018 add_name_attribute (array_die, type_tag (type));
16019 equate_type_number_to_die (type, array_die);
16020 size = int_size_in_bytes (type);
16022 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16023 else if (TYPE_DOMAIN (type) != NULL_TREE
16024 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
16025 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
16027 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
16028 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
16030 size = int_size_in_bytes (TREE_TYPE (szdecl));
16031 if (loc && size > 0)
16033 add_AT_location_description (array_die, DW_AT_string_length, loc);
16034 if (size != DWARF2_ADDR_SIZE)
16035 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16041 /* ??? The SGI dwarf reader fails for array of array of enum types
16042 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
16043 array type comes before the outer array type. We thus call gen_type_die
16044 before we new_die and must prevent nested array types collapsing for this
16047 #ifdef MIPS_DEBUGGING_INFO
16048 gen_type_die (TREE_TYPE (type), context_die);
16049 collapse_nested_arrays = false;
16052 array_die = new_die (DW_TAG_array_type, scope_die, type);
16053 add_name_attribute (array_die, type_tag (type));
16054 add_gnat_descriptive_type_attribute (array_die, type, context_die);
16055 if (TYPE_ARTIFICIAL (type))
16056 add_AT_flag (array_die, DW_AT_artificial, 1);
16057 equate_type_number_to_die (type, array_die);
16059 if (TREE_CODE (type) == VECTOR_TYPE)
16060 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
16062 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16064 && TREE_CODE (type) == ARRAY_TYPE
16065 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
16066 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
16067 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16070 /* We default the array ordering. SDB will probably do
16071 the right things even if DW_AT_ordering is not present. It's not even
16072 an issue until we start to get into multidimensional arrays anyway. If
16073 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16074 then we'll have to put the DW_AT_ordering attribute back in. (But if
16075 and when we find out that we need to put these in, we will only do so
16076 for multidimensional arrays. */
16077 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
16080 #ifdef MIPS_DEBUGGING_INFO
16081 /* The SGI compilers handle arrays of unknown bound by setting
16082 AT_declaration and not emitting any subrange DIEs. */
16083 if (TREE_CODE (type) == ARRAY_TYPE
16084 && ! TYPE_DOMAIN (type))
16085 add_AT_flag (array_die, DW_AT_declaration, 1);
16088 if (TREE_CODE (type) == VECTOR_TYPE)
16090 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16091 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
16092 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
16093 add_bound_info (subrange_die, DW_AT_upper_bound,
16094 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
16097 add_subscript_info (array_die, type, collapse_nested_arrays);
16099 /* Add representation of the type of the elements of this array type and
16100 emit the corresponding DIE if we haven't done it already. */
16101 element_type = TREE_TYPE (type);
16102 if (collapse_nested_arrays)
16103 while (TREE_CODE (element_type) == ARRAY_TYPE)
16105 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
16107 element_type = TREE_TYPE (element_type);
16110 #ifndef MIPS_DEBUGGING_INFO
16111 gen_type_die (element_type, context_die);
16114 add_type_attribute (array_die, element_type, 0, 0, context_die);
16116 if (get_AT (array_die, DW_AT_name))
16117 add_pubtype (type, array_die);
16120 static dw_loc_descr_ref
16121 descr_info_loc (tree val, tree base_decl)
16123 HOST_WIDE_INT size;
16124 dw_loc_descr_ref loc, loc2;
16125 enum dwarf_location_atom op;
16127 if (val == base_decl)
16128 return new_loc_descr (DW_OP_push_object_address, 0, 0);
16130 switch (TREE_CODE (val))
16133 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16135 return loc_descriptor_from_tree (val, 0);
16137 if (host_integerp (val, 0))
16138 return int_loc_descriptor (tree_low_cst (val, 0));
16141 size = int_size_in_bytes (TREE_TYPE (val));
16144 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16147 if (size == DWARF2_ADDR_SIZE)
16148 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
16150 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
16152 case POINTER_PLUS_EXPR:
16154 if (host_integerp (TREE_OPERAND (val, 1), 1)
16155 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
16158 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16161 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
16167 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16170 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
16173 add_loc_descr (&loc, loc2);
16174 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
16196 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
16197 tree val, tree base_decl)
16199 dw_loc_descr_ref loc;
16201 if (host_integerp (val, 0))
16203 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
16207 loc = descr_info_loc (val, base_decl);
16211 add_AT_loc (die, attr, loc);
16214 /* This routine generates DIE for array with hidden descriptor, details
16215 are filled into *info by a langhook. */
16218 gen_descr_array_type_die (tree type, struct array_descr_info *info,
16219 dw_die_ref context_die)
16221 dw_die_ref scope_die = scope_die_for (type, context_die);
16222 dw_die_ref array_die;
16225 array_die = new_die (DW_TAG_array_type, scope_die, type);
16226 add_name_attribute (array_die, type_tag (type));
16227 equate_type_number_to_die (type, array_die);
16229 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16231 && info->ndimensions >= 2)
16232 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16234 if (info->data_location)
16235 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
16237 if (info->associated)
16238 add_descr_info_field (array_die, DW_AT_associated, info->associated,
16240 if (info->allocated)
16241 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
16244 for (dim = 0; dim < info->ndimensions; dim++)
16246 dw_die_ref subrange_die
16247 = new_die (DW_TAG_subrange_type, array_die, NULL);
16249 if (info->dimen[dim].lower_bound)
16251 /* If it is the default value, omit it. */
16254 if (host_integerp (info->dimen[dim].lower_bound, 0)
16255 && (dflt = lower_bound_default ()) != -1
16256 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
16259 add_descr_info_field (subrange_die, DW_AT_lower_bound,
16260 info->dimen[dim].lower_bound,
16263 if (info->dimen[dim].upper_bound)
16264 add_descr_info_field (subrange_die, DW_AT_upper_bound,
16265 info->dimen[dim].upper_bound,
16267 if (info->dimen[dim].stride)
16268 add_descr_info_field (subrange_die, DW_AT_byte_stride,
16269 info->dimen[dim].stride,
16273 gen_type_die (info->element_type, context_die);
16274 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
16276 if (get_AT (array_die, DW_AT_name))
16277 add_pubtype (type, array_die);
16282 gen_entry_point_die (tree decl, dw_die_ref context_die)
16284 tree origin = decl_ultimate_origin (decl);
16285 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
16287 if (origin != NULL)
16288 add_abstract_origin_attribute (decl_die, origin);
16291 add_name_and_src_coords_attributes (decl_die, decl);
16292 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
16293 0, 0, context_die);
16296 if (DECL_ABSTRACT (decl))
16297 equate_decl_number_to_die (decl, decl_die);
16299 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
16303 /* Walk through the list of incomplete types again, trying once more to
16304 emit full debugging info for them. */
16307 retry_incomplete_types (void)
16311 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
16312 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
16313 DINFO_USAGE_DIR_USE))
16314 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
16317 /* Determine what tag to use for a record type. */
16319 static enum dwarf_tag
16320 record_type_tag (tree type)
16322 if (! lang_hooks.types.classify_record)
16323 return DW_TAG_structure_type;
16325 switch (lang_hooks.types.classify_record (type))
16327 case RECORD_IS_STRUCT:
16328 return DW_TAG_structure_type;
16330 case RECORD_IS_CLASS:
16331 return DW_TAG_class_type;
16333 case RECORD_IS_INTERFACE:
16334 if (dwarf_version >= 3 || !dwarf_strict)
16335 return DW_TAG_interface_type;
16336 return DW_TAG_structure_type;
16339 gcc_unreachable ();
16343 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16344 include all of the information about the enumeration values also. Each
16345 enumerated type name/value is listed as a child of the enumerated type
16349 gen_enumeration_type_die (tree type, dw_die_ref context_die)
16351 dw_die_ref type_die = lookup_type_die (type);
16353 if (type_die == NULL)
16355 type_die = new_die (DW_TAG_enumeration_type,
16356 scope_die_for (type, context_die), type);
16357 equate_type_number_to_die (type, type_die);
16358 add_name_attribute (type_die, type_tag (type));
16359 add_gnat_descriptive_type_attribute (type_die, type, context_die);
16360 if (TYPE_ARTIFICIAL (type))
16361 add_AT_flag (type_die, DW_AT_artificial, 1);
16362 if (dwarf_version >= 4 || !dwarf_strict)
16364 if (ENUM_IS_SCOPED (type))
16365 add_AT_flag (type_die, DW_AT_enum_class, 1);
16366 if (ENUM_IS_OPAQUE (type))
16367 add_AT_flag (type_die, DW_AT_declaration, 1);
16370 else if (! TYPE_SIZE (type))
16373 remove_AT (type_die, DW_AT_declaration);
16375 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16376 given enum type is incomplete, do not generate the DW_AT_byte_size
16377 attribute or the DW_AT_element_list attribute. */
16378 if (TYPE_SIZE (type))
16382 TREE_ASM_WRITTEN (type) = 1;
16383 add_byte_size_attribute (type_die, type);
16384 if (TYPE_STUB_DECL (type) != NULL_TREE)
16386 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
16387 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
16390 /* If the first reference to this type was as the return type of an
16391 inline function, then it may not have a parent. Fix this now. */
16392 if (type_die->die_parent == NULL)
16393 add_child_die (scope_die_for (type, context_die), type_die);
16395 for (link = TYPE_VALUES (type);
16396 link != NULL; link = TREE_CHAIN (link))
16398 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
16399 tree value = TREE_VALUE (link);
16401 add_name_attribute (enum_die,
16402 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
16404 if (TREE_CODE (value) == CONST_DECL)
16405 value = DECL_INITIAL (value);
16407 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
16408 /* DWARF2 does not provide a way of indicating whether or
16409 not enumeration constants are signed or unsigned. GDB
16410 always assumes the values are signed, so we output all
16411 values as if they were signed. That means that
16412 enumeration constants with very large unsigned values
16413 will appear to have negative values in the debugger. */
16414 add_AT_int (enum_die, DW_AT_const_value,
16415 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
16419 add_AT_flag (type_die, DW_AT_declaration, 1);
16421 if (get_AT (type_die, DW_AT_name))
16422 add_pubtype (type, type_die);
16427 /* Generate a DIE to represent either a real live formal parameter decl or to
16428 represent just the type of some formal parameter position in some function
16431 Note that this routine is a bit unusual because its argument may be a
16432 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
16433 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
16434 node. If it's the former then this function is being called to output a
16435 DIE to represent a formal parameter object (or some inlining thereof). If
16436 it's the latter, then this function is only being called to output a
16437 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
16438 argument type of some subprogram type.
16439 If EMIT_NAME_P is true, name and source coordinate attributes
16443 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
16444 dw_die_ref context_die)
16446 tree node_or_origin = node ? node : origin;
16447 tree ultimate_origin;
16448 dw_die_ref parm_die
16449 = new_die (DW_TAG_formal_parameter, context_die, node);
16451 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
16453 case tcc_declaration:
16454 ultimate_origin = decl_ultimate_origin (node_or_origin);
16455 if (node || ultimate_origin)
16456 origin = ultimate_origin;
16457 if (origin != NULL)
16458 add_abstract_origin_attribute (parm_die, origin);
16459 else if (emit_name_p)
16460 add_name_and_src_coords_attributes (parm_die, node);
16462 || (! DECL_ABSTRACT (node_or_origin)
16463 && variably_modified_type_p (TREE_TYPE (node_or_origin),
16464 decl_function_context
16465 (node_or_origin))))
16467 tree type = TREE_TYPE (node_or_origin);
16468 if (decl_by_reference_p (node_or_origin))
16469 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
16472 add_type_attribute (parm_die, type,
16473 TREE_READONLY (node_or_origin),
16474 TREE_THIS_VOLATILE (node_or_origin),
16477 if (origin == NULL && DECL_ARTIFICIAL (node))
16478 add_AT_flag (parm_die, DW_AT_artificial, 1);
16480 if (node && node != origin)
16481 equate_decl_number_to_die (node, parm_die);
16482 if (! DECL_ABSTRACT (node_or_origin))
16483 add_location_or_const_value_attribute (parm_die, node_or_origin,
16484 node == NULL, DW_AT_location);
16489 /* We were called with some kind of a ..._TYPE node. */
16490 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
16494 gcc_unreachable ();
16500 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
16501 children DW_TAG_formal_parameter DIEs representing the arguments of the
16504 PARM_PACK must be a function parameter pack.
16505 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
16506 must point to the subsequent arguments of the function PACK_ARG belongs to.
16507 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
16508 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
16509 following the last one for which a DIE was generated. */
16512 gen_formal_parameter_pack_die (tree parm_pack,
16514 dw_die_ref subr_die,
16518 dw_die_ref parm_pack_die;
16520 gcc_assert (parm_pack
16521 && lang_hooks.function_parameter_pack_p (parm_pack)
16524 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
16525 add_src_coords_attributes (parm_pack_die, parm_pack);
16527 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
16529 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
16532 gen_formal_parameter_die (arg, NULL,
16533 false /* Don't emit name attribute. */,
16538 return parm_pack_die;
16541 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
16542 at the end of an (ANSI prototyped) formal parameters list. */
16545 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
16547 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
16550 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
16551 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
16552 parameters as specified in some function type specification (except for
16553 those which appear as part of a function *definition*). */
16556 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
16559 tree formal_type = NULL;
16560 tree first_parm_type;
16563 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
16565 arg = DECL_ARGUMENTS (function_or_method_type);
16566 function_or_method_type = TREE_TYPE (function_or_method_type);
16571 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
16573 /* Make our first pass over the list of formal parameter types and output a
16574 DW_TAG_formal_parameter DIE for each one. */
16575 for (link = first_parm_type; link; )
16577 dw_die_ref parm_die;
16579 formal_type = TREE_VALUE (link);
16580 if (formal_type == void_type_node)
16583 /* Output a (nameless) DIE to represent the formal parameter itself. */
16584 parm_die = gen_formal_parameter_die (formal_type, NULL,
16585 true /* Emit name attribute. */,
16587 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
16588 && link == first_parm_type)
16590 add_AT_flag (parm_die, DW_AT_artificial, 1);
16591 if (dwarf_version >= 3 || !dwarf_strict)
16592 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
16594 else if (arg && DECL_ARTIFICIAL (arg))
16595 add_AT_flag (parm_die, DW_AT_artificial, 1);
16597 link = TREE_CHAIN (link);
16599 arg = DECL_CHAIN (arg);
16602 /* If this function type has an ellipsis, add a
16603 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
16604 if (formal_type != void_type_node)
16605 gen_unspecified_parameters_die (function_or_method_type, context_die);
16607 /* Make our second (and final) pass over the list of formal parameter types
16608 and output DIEs to represent those types (as necessary). */
16609 for (link = TYPE_ARG_TYPES (function_or_method_type);
16610 link && TREE_VALUE (link);
16611 link = TREE_CHAIN (link))
16612 gen_type_die (TREE_VALUE (link), context_die);
16615 /* We want to generate the DIE for TYPE so that we can generate the
16616 die for MEMBER, which has been defined; we will need to refer back
16617 to the member declaration nested within TYPE. If we're trying to
16618 generate minimal debug info for TYPE, processing TYPE won't do the
16619 trick; we need to attach the member declaration by hand. */
16622 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
16624 gen_type_die (type, context_die);
16626 /* If we're trying to avoid duplicate debug info, we may not have
16627 emitted the member decl for this function. Emit it now. */
16628 if (TYPE_STUB_DECL (type)
16629 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
16630 && ! lookup_decl_die (member))
16632 dw_die_ref type_die;
16633 gcc_assert (!decl_ultimate_origin (member));
16635 push_decl_scope (type);
16636 type_die = lookup_type_die_strip_naming_typedef (type);
16637 if (TREE_CODE (member) == FUNCTION_DECL)
16638 gen_subprogram_die (member, type_die);
16639 else if (TREE_CODE (member) == FIELD_DECL)
16641 /* Ignore the nameless fields that are used to skip bits but handle
16642 C++ anonymous unions and structs. */
16643 if (DECL_NAME (member) != NULL_TREE
16644 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
16645 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
16647 gen_type_die (member_declared_type (member), type_die);
16648 gen_field_die (member, type_die);
16652 gen_variable_die (member, NULL_TREE, type_die);
16658 /* Generate the DWARF2 info for the "abstract" instance of a function which we
16659 may later generate inlined and/or out-of-line instances of. */
16662 dwarf2out_abstract_function (tree decl)
16664 dw_die_ref old_die;
16668 htab_t old_decl_loc_table;
16669 htab_t old_cached_dw_loc_list_table;
16670 int old_call_site_count, old_tail_call_site_count;
16671 struct call_arg_loc_node *old_call_arg_locations;
16673 /* Make sure we have the actual abstract inline, not a clone. */
16674 decl = DECL_ORIGIN (decl);
16676 old_die = lookup_decl_die (decl);
16677 if (old_die && get_AT (old_die, DW_AT_inline))
16678 /* We've already generated the abstract instance. */
16681 /* We can be called while recursively when seeing block defining inlined subroutine
16682 DIE. Be sure to not clobber the outer location table nor use it or we would
16683 get locations in abstract instantces. */
16684 old_decl_loc_table = decl_loc_table;
16685 decl_loc_table = NULL;
16686 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
16687 cached_dw_loc_list_table = NULL;
16688 old_call_arg_locations = call_arg_locations;
16689 call_arg_locations = NULL;
16690 old_call_site_count = call_site_count;
16691 call_site_count = -1;
16692 old_tail_call_site_count = tail_call_site_count;
16693 tail_call_site_count = -1;
16695 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
16696 we don't get confused by DECL_ABSTRACT. */
16697 if (debug_info_level > DINFO_LEVEL_TERSE)
16699 context = decl_class_context (decl);
16701 gen_type_die_for_member
16702 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
16705 /* Pretend we've just finished compiling this function. */
16706 save_fn = current_function_decl;
16707 current_function_decl = decl;
16708 push_cfun (DECL_STRUCT_FUNCTION (decl));
16710 was_abstract = DECL_ABSTRACT (decl);
16711 set_decl_abstract_flags (decl, 1);
16712 dwarf2out_decl (decl);
16713 if (! was_abstract)
16714 set_decl_abstract_flags (decl, 0);
16716 current_function_decl = save_fn;
16717 decl_loc_table = old_decl_loc_table;
16718 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
16719 call_arg_locations = old_call_arg_locations;
16720 call_site_count = old_call_site_count;
16721 tail_call_site_count = old_tail_call_site_count;
16725 /* Helper function of premark_used_types() which gets called through
16728 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16729 marked as unused by prune_unused_types. */
16732 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
16737 type = (tree) *slot;
16738 die = lookup_type_die (type);
16740 die->die_perennial_p = 1;
16744 /* Helper function of premark_types_used_by_global_vars which gets called
16745 through htab_traverse.
16747 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16748 marked as unused by prune_unused_types. The DIE of the type is marked
16749 only if the global variable using the type will actually be emitted. */
16752 premark_types_used_by_global_vars_helper (void **slot,
16753 void *data ATTRIBUTE_UNUSED)
16755 struct types_used_by_vars_entry *entry;
16758 entry = (struct types_used_by_vars_entry *) *slot;
16759 gcc_assert (entry->type != NULL
16760 && entry->var_decl != NULL);
16761 die = lookup_type_die (entry->type);
16764 /* Ask cgraph if the global variable really is to be emitted.
16765 If yes, then we'll keep the DIE of ENTRY->TYPE. */
16766 struct varpool_node *node = varpool_get_node (entry->var_decl);
16767 if (node && node->needed)
16769 die->die_perennial_p = 1;
16770 /* Keep the parent DIEs as well. */
16771 while ((die = die->die_parent) && die->die_perennial_p == 0)
16772 die->die_perennial_p = 1;
16778 /* Mark all members of used_types_hash as perennial. */
16781 premark_used_types (void)
16783 if (cfun && cfun->used_types_hash)
16784 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
16787 /* Mark all members of types_used_by_vars_entry as perennial. */
16790 premark_types_used_by_global_vars (void)
16792 if (types_used_by_vars_hash)
16793 htab_traverse (types_used_by_vars_hash,
16794 premark_types_used_by_global_vars_helper, NULL);
16797 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
16798 for CA_LOC call arg loc node. */
16801 gen_call_site_die (tree decl, dw_die_ref subr_die,
16802 struct call_arg_loc_node *ca_loc)
16804 dw_die_ref stmt_die = NULL, die;
16805 tree block = ca_loc->block;
16808 && block != DECL_INITIAL (decl)
16809 && TREE_CODE (block) == BLOCK)
16811 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
16812 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
16815 block = BLOCK_SUPERCONTEXT (block);
16817 if (stmt_die == NULL)
16818 stmt_die = subr_die;
16819 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
16820 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
16821 if (ca_loc->tail_call_p)
16822 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
16823 if (ca_loc->symbol_ref)
16825 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
16827 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
16829 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
16834 /* Generate a DIE to represent a declared function (either file-scope or
16838 gen_subprogram_die (tree decl, dw_die_ref context_die)
16840 tree origin = decl_ultimate_origin (decl);
16841 dw_die_ref subr_die;
16843 dw_die_ref old_die = lookup_decl_die (decl);
16844 int declaration = (current_function_decl != decl
16845 || class_or_namespace_scope_p (context_die));
16847 premark_used_types ();
16849 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
16850 started to generate the abstract instance of an inline, decided to output
16851 its containing class, and proceeded to emit the declaration of the inline
16852 from the member list for the class. If so, DECLARATION takes priority;
16853 we'll get back to the abstract instance when done with the class. */
16855 /* The class-scope declaration DIE must be the primary DIE. */
16856 if (origin && declaration && class_or_namespace_scope_p (context_die))
16859 gcc_assert (!old_die);
16862 /* Now that the C++ front end lazily declares artificial member fns, we
16863 might need to retrofit the declaration into its class. */
16864 if (!declaration && !origin && !old_die
16865 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
16866 && !class_or_namespace_scope_p (context_die)
16867 && debug_info_level > DINFO_LEVEL_TERSE)
16868 old_die = force_decl_die (decl);
16870 if (origin != NULL)
16872 gcc_assert (!declaration || local_scope_p (context_die));
16874 /* Fixup die_parent for the abstract instance of a nested
16875 inline function. */
16876 if (old_die && old_die->die_parent == NULL)
16877 add_child_die (context_die, old_die);
16879 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
16880 add_abstract_origin_attribute (subr_die, origin);
16881 /* This is where the actual code for a cloned function is.
16882 Let's emit linkage name attribute for it. This helps
16883 debuggers to e.g, set breakpoints into
16884 constructors/destructors when the user asks "break
16886 add_linkage_name (subr_die, decl);
16890 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
16891 struct dwarf_file_data * file_index = lookup_filename (s.file);
16893 if (!get_AT_flag (old_die, DW_AT_declaration)
16894 /* We can have a normal definition following an inline one in the
16895 case of redefinition of GNU C extern inlines.
16896 It seems reasonable to use AT_specification in this case. */
16897 && !get_AT (old_die, DW_AT_inline))
16899 /* Detect and ignore this case, where we are trying to output
16900 something we have already output. */
16904 /* If the definition comes from the same place as the declaration,
16905 maybe use the old DIE. We always want the DIE for this function
16906 that has the *_pc attributes to be under comp_unit_die so the
16907 debugger can find it. We also need to do this for abstract
16908 instances of inlines, since the spec requires the out-of-line copy
16909 to have the same parent. For local class methods, this doesn't
16910 apply; we just use the old DIE. */
16911 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
16912 && (DECL_ARTIFICIAL (decl)
16913 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
16914 && (get_AT_unsigned (old_die, DW_AT_decl_line)
16915 == (unsigned) s.line))))
16917 subr_die = old_die;
16919 /* Clear out the declaration attribute and the formal parameters.
16920 Do not remove all children, because it is possible that this
16921 declaration die was forced using force_decl_die(). In such
16922 cases die that forced declaration die (e.g. TAG_imported_module)
16923 is one of the children that we do not want to remove. */
16924 remove_AT (subr_die, DW_AT_declaration);
16925 remove_AT (subr_die, DW_AT_object_pointer);
16926 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
16930 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
16931 add_AT_specification (subr_die, old_die);
16932 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
16933 add_AT_file (subr_die, DW_AT_decl_file, file_index);
16934 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
16935 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
16940 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
16942 if (TREE_PUBLIC (decl))
16943 add_AT_flag (subr_die, DW_AT_external, 1);
16945 add_name_and_src_coords_attributes (subr_die, decl);
16946 if (debug_info_level > DINFO_LEVEL_TERSE)
16948 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
16949 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
16950 0, 0, context_die);
16953 add_pure_or_virtual_attribute (subr_die, decl);
16954 if (DECL_ARTIFICIAL (decl))
16955 add_AT_flag (subr_die, DW_AT_artificial, 1);
16957 add_accessibility_attribute (subr_die, decl);
16962 if (!old_die || !get_AT (old_die, DW_AT_inline))
16964 add_AT_flag (subr_die, DW_AT_declaration, 1);
16966 /* If this is an explicit function declaration then generate
16967 a DW_AT_explicit attribute. */
16968 if (lang_hooks.decls.function_decl_explicit_p (decl)
16969 && (dwarf_version >= 3 || !dwarf_strict))
16970 add_AT_flag (subr_die, DW_AT_explicit, 1);
16972 /* The first time we see a member function, it is in the context of
16973 the class to which it belongs. We make sure of this by emitting
16974 the class first. The next time is the definition, which is
16975 handled above. The two may come from the same source text.
16977 Note that force_decl_die() forces function declaration die. It is
16978 later reused to represent definition. */
16979 equate_decl_number_to_die (decl, subr_die);
16982 else if (DECL_ABSTRACT (decl))
16984 if (DECL_DECLARED_INLINE_P (decl))
16986 if (cgraph_function_possibly_inlined_p (decl))
16987 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
16989 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
16993 if (cgraph_function_possibly_inlined_p (decl))
16994 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
16996 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
16999 if (DECL_DECLARED_INLINE_P (decl)
17000 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
17001 add_AT_flag (subr_die, DW_AT_artificial, 1);
17003 equate_decl_number_to_die (decl, subr_die);
17005 else if (!DECL_EXTERNAL (decl))
17007 HOST_WIDE_INT cfa_fb_offset;
17009 if (!old_die || !get_AT (old_die, DW_AT_inline))
17010 equate_decl_number_to_die (decl, subr_die);
17012 if (!flag_reorder_blocks_and_partition)
17014 dw_fde_ref fde = cfun->fde;
17015 if (fde->dw_fde_begin)
17017 /* We have already generated the labels. */
17018 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17019 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17023 /* Create start/end labels and add the range. */
17024 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
17025 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
17026 current_function_funcdef_no);
17027 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
17028 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
17029 current_function_funcdef_no);
17030 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
17033 #if VMS_DEBUGGING_INFO
17034 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17035 Section 2.3 Prologue and Epilogue Attributes:
17036 When a breakpoint is set on entry to a function, it is generally
17037 desirable for execution to be suspended, not on the very first
17038 instruction of the function, but rather at a point after the
17039 function's frame has been set up, after any language defined local
17040 declaration processing has been completed, and before execution of
17041 the first statement of the function begins. Debuggers generally
17042 cannot properly determine where this point is. Similarly for a
17043 breakpoint set on exit from a function. The prologue and epilogue
17044 attributes allow a compiler to communicate the location(s) to use. */
17047 if (fde->dw_fde_vms_end_prologue)
17048 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
17049 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
17051 if (fde->dw_fde_vms_begin_epilogue)
17052 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
17053 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
17057 add_pubname (decl, subr_die);
17061 /* Generate pubnames entries for the split function code ranges. */
17062 dw_fde_ref fde = cfun->fde;
17064 if (fde->dw_fde_second_begin)
17066 if (dwarf_version >= 3 || !dwarf_strict)
17068 /* We should use ranges for non-contiguous code section
17069 addresses. Use the actual code range for the initial
17070 section, since the HOT/COLD labels might precede an
17071 alignment offset. */
17072 bool range_list_added = false;
17073 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
17074 fde->dw_fde_end, &range_list_added);
17075 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
17076 fde->dw_fde_second_end,
17077 &range_list_added);
17078 add_pubname (decl, subr_die);
17079 if (range_list_added)
17084 /* There is no real support in DW2 for this .. so we make
17085 a work-around. First, emit the pub name for the segment
17086 containing the function label. Then make and emit a
17087 simplified subprogram DIE for the second segment with the
17088 name pre-fixed by __hot/cold_sect_of_. We use the same
17089 linkage name for the second die so that gdb will find both
17090 sections when given "b foo". */
17091 const char *name = NULL;
17092 tree decl_name = DECL_NAME (decl);
17093 dw_die_ref seg_die;
17095 /* Do the 'primary' section. */
17096 add_AT_lbl_id (subr_die, DW_AT_low_pc,
17097 fde->dw_fde_begin);
17098 add_AT_lbl_id (subr_die, DW_AT_high_pc,
17101 add_pubname (decl, subr_die);
17103 /* Build a minimal DIE for the secondary section. */
17104 seg_die = new_die (DW_TAG_subprogram,
17105 subr_die->die_parent, decl);
17107 if (TREE_PUBLIC (decl))
17108 add_AT_flag (seg_die, DW_AT_external, 1);
17110 if (decl_name != NULL
17111 && IDENTIFIER_POINTER (decl_name) != NULL)
17113 name = dwarf2_name (decl, 1);
17114 if (! DECL_ARTIFICIAL (decl))
17115 add_src_coords_attributes (seg_die, decl);
17117 add_linkage_name (seg_die, decl);
17119 gcc_assert (name != NULL);
17120 add_pure_or_virtual_attribute (seg_die, decl);
17121 if (DECL_ARTIFICIAL (decl))
17122 add_AT_flag (seg_die, DW_AT_artificial, 1);
17124 name = concat ("__second_sect_of_", name, NULL);
17125 add_AT_lbl_id (seg_die, DW_AT_low_pc,
17126 fde->dw_fde_second_begin);
17127 add_AT_lbl_id (seg_die, DW_AT_high_pc,
17128 fde->dw_fde_second_end);
17129 add_name_attribute (seg_die, name);
17130 add_pubname_string (name, seg_die);
17135 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17136 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17137 add_pubname (decl, subr_die);
17141 #ifdef MIPS_DEBUGGING_INFO
17142 /* Add a reference to the FDE for this routine. */
17143 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, cfun->fde->fde_index);
17146 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
17148 /* We define the "frame base" as the function's CFA. This is more
17149 convenient for several reasons: (1) It's stable across the prologue
17150 and epilogue, which makes it better than just a frame pointer,
17151 (2) With dwarf3, there exists a one-byte encoding that allows us
17152 to reference the .debug_frame data by proxy, but failing that,
17153 (3) We can at least reuse the code inspection and interpretation
17154 code that determines the CFA position at various points in the
17156 if (dwarf_version >= 3)
17158 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
17159 add_AT_loc (subr_die, DW_AT_frame_base, op);
17163 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
17164 if (list->dw_loc_next)
17165 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
17167 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
17170 /* Compute a displacement from the "steady-state frame pointer" to
17171 the CFA. The former is what all stack slots and argument slots
17172 will reference in the rtl; the later is what we've told the
17173 debugger about. We'll need to adjust all frame_base references
17174 by this displacement. */
17175 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
17177 if (cfun->static_chain_decl)
17178 add_AT_location_description (subr_die, DW_AT_static_link,
17179 loc_list_from_tree (cfun->static_chain_decl, 2));
17182 /* Generate child dies for template paramaters. */
17183 if (debug_info_level > DINFO_LEVEL_TERSE)
17184 gen_generic_params_dies (decl);
17186 /* Now output descriptions of the arguments for this function. This gets
17187 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17188 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17189 `...' at the end of the formal parameter list. In order to find out if
17190 there was a trailing ellipsis or not, we must instead look at the type
17191 associated with the FUNCTION_DECL. This will be a node of type
17192 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17193 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17194 an ellipsis at the end. */
17196 /* In the case where we are describing a mere function declaration, all we
17197 need to do here (and all we *can* do here) is to describe the *types* of
17198 its formal parameters. */
17199 if (debug_info_level <= DINFO_LEVEL_TERSE)
17201 else if (declaration)
17202 gen_formal_types_die (decl, subr_die);
17205 /* Generate DIEs to represent all known formal parameters. */
17206 tree parm = DECL_ARGUMENTS (decl);
17207 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
17208 tree generic_decl_parm = generic_decl
17209 ? DECL_ARGUMENTS (generic_decl)
17212 /* Now we want to walk the list of parameters of the function and
17213 emit their relevant DIEs.
17215 We consider the case of DECL being an instance of a generic function
17216 as well as it being a normal function.
17218 If DECL is an instance of a generic function we walk the
17219 parameters of the generic function declaration _and_ the parameters of
17220 DECL itself. This is useful because we want to emit specific DIEs for
17221 function parameter packs and those are declared as part of the
17222 generic function declaration. In that particular case,
17223 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17224 That DIE has children DIEs representing the set of arguments
17225 of the pack. Note that the set of pack arguments can be empty.
17226 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17229 Otherwise, we just consider the parameters of DECL. */
17230 while (generic_decl_parm || parm)
17232 if (generic_decl_parm
17233 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
17234 gen_formal_parameter_pack_die (generic_decl_parm,
17239 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
17241 if (parm == DECL_ARGUMENTS (decl)
17242 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
17244 && (dwarf_version >= 3 || !dwarf_strict))
17245 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
17247 parm = DECL_CHAIN (parm);
17250 if (generic_decl_parm)
17251 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
17254 /* Decide whether we need an unspecified_parameters DIE at the end.
17255 There are 2 more cases to do this for: 1) the ansi ... declaration -
17256 this is detectable when the end of the arg list is not a
17257 void_type_node 2) an unprototyped function declaration (not a
17258 definition). This just means that we have no info about the
17259 parameters at all. */
17260 if (prototype_p (TREE_TYPE (decl)))
17262 /* This is the prototyped case, check for.... */
17263 if (stdarg_p (TREE_TYPE (decl)))
17264 gen_unspecified_parameters_die (decl, subr_die);
17266 else if (DECL_INITIAL (decl) == NULL_TREE)
17267 gen_unspecified_parameters_die (decl, subr_die);
17270 /* Output Dwarf info for all of the stuff within the body of the function
17271 (if it has one - it may be just a declaration). */
17272 outer_scope = DECL_INITIAL (decl);
17274 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17275 a function. This BLOCK actually represents the outermost binding contour
17276 for the function, i.e. the contour in which the function's formal
17277 parameters and labels get declared. Curiously, it appears that the front
17278 end doesn't actually put the PARM_DECL nodes for the current function onto
17279 the BLOCK_VARS list for this outer scope, but are strung off of the
17280 DECL_ARGUMENTS list for the function instead.
17282 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17283 the LABEL_DECL nodes for the function however, and we output DWARF info
17284 for those in decls_for_scope. Just within the `outer_scope' there will be
17285 a BLOCK node representing the function's outermost pair of curly braces,
17286 and any blocks used for the base and member initializers of a C++
17287 constructor function. */
17288 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
17290 int call_site_note_count = 0;
17291 int tail_call_site_note_count = 0;
17293 /* Emit a DW_TAG_variable DIE for a named return value. */
17294 if (DECL_NAME (DECL_RESULT (decl)))
17295 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
17297 current_function_has_inlines = 0;
17298 decls_for_scope (outer_scope, subr_die, 0);
17300 if (call_arg_locations && !dwarf_strict)
17302 struct call_arg_loc_node *ca_loc;
17303 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
17305 dw_die_ref die = NULL;
17306 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
17309 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
17310 arg; arg = next_arg)
17312 dw_loc_descr_ref reg, val;
17313 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
17314 dw_die_ref cdie, tdie = NULL;
17316 next_arg = XEXP (arg, 1);
17317 if (REG_P (XEXP (XEXP (arg, 0), 0))
17319 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
17320 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
17321 && REGNO (XEXP (XEXP (arg, 0), 0))
17322 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
17323 next_arg = XEXP (next_arg, 1);
17324 if (mode == VOIDmode)
17326 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
17327 if (mode == VOIDmode)
17328 mode = GET_MODE (XEXP (arg, 0));
17330 if (mode == VOIDmode || mode == BLKmode)
17332 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
17334 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17335 tloc = XEXP (XEXP (arg, 0), 1);
17338 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
17339 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
17341 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17342 tlocc = XEXP (XEXP (arg, 0), 1);
17346 if (REG_P (XEXP (XEXP (arg, 0), 0)))
17347 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
17348 VAR_INIT_STATUS_INITIALIZED);
17349 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
17351 rtx mem = XEXP (XEXP (arg, 0), 0);
17352 reg = mem_loc_descriptor (XEXP (mem, 0),
17353 get_address_mode (mem),
17355 VAR_INIT_STATUS_INITIALIZED);
17357 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
17358 == DEBUG_PARAMETER_REF)
17361 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
17362 tdie = lookup_decl_die (tdecl);
17369 && GET_CODE (XEXP (XEXP (arg, 0), 0))
17370 != DEBUG_PARAMETER_REF)
17372 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
17374 VAR_INIT_STATUS_INITIALIZED);
17378 die = gen_call_site_die (decl, subr_die, ca_loc);
17379 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
17382 add_AT_loc (cdie, DW_AT_location, reg);
17383 else if (tdie != NULL)
17384 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
17385 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
17386 if (next_arg != XEXP (arg, 1))
17388 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
17389 if (mode == VOIDmode)
17390 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
17391 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
17394 VAR_INIT_STATUS_INITIALIZED);
17396 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
17400 && (ca_loc->symbol_ref || tloc))
17401 die = gen_call_site_die (decl, subr_die, ca_loc);
17402 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
17404 dw_loc_descr_ref tval = NULL;
17406 if (tloc != NULL_RTX)
17407 tval = mem_loc_descriptor (tloc,
17408 GET_MODE (tloc) == VOIDmode
17409 ? Pmode : GET_MODE (tloc),
17411 VAR_INIT_STATUS_INITIALIZED);
17413 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
17414 else if (tlocc != NULL_RTX)
17416 tval = mem_loc_descriptor (tlocc,
17417 GET_MODE (tlocc) == VOIDmode
17418 ? Pmode : GET_MODE (tlocc),
17420 VAR_INIT_STATUS_INITIALIZED);
17422 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
17428 call_site_note_count++;
17429 if (ca_loc->tail_call_p)
17430 tail_call_site_note_count++;
17434 call_arg_locations = NULL;
17435 call_arg_loc_last = NULL;
17436 if (tail_call_site_count >= 0
17437 && tail_call_site_count == tail_call_site_note_count
17440 if (call_site_count >= 0
17441 && call_site_count == call_site_note_count)
17442 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
17444 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
17446 call_site_count = -1;
17447 tail_call_site_count = -1;
17449 /* Add the calling convention attribute if requested. */
17450 add_calling_convention_attribute (subr_die, decl);
17454 /* Returns a hash value for X (which really is a die_struct). */
17457 common_block_die_table_hash (const void *x)
17459 const_dw_die_ref d = (const_dw_die_ref) x;
17460 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
17463 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17464 as decl_id and die_parent of die_struct Y. */
17467 common_block_die_table_eq (const void *x, const void *y)
17469 const_dw_die_ref d = (const_dw_die_ref) x;
17470 const_dw_die_ref e = (const_dw_die_ref) y;
17471 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
17474 /* Generate a DIE to represent a declared data object.
17475 Either DECL or ORIGIN must be non-null. */
17478 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
17482 tree decl_or_origin = decl ? decl : origin;
17483 tree ultimate_origin;
17484 dw_die_ref var_die;
17485 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
17486 dw_die_ref origin_die;
17487 bool declaration = (DECL_EXTERNAL (decl_or_origin)
17488 || class_or_namespace_scope_p (context_die));
17489 bool specialization_p = false;
17491 ultimate_origin = decl_ultimate_origin (decl_or_origin);
17492 if (decl || ultimate_origin)
17493 origin = ultimate_origin;
17494 com_decl = fortran_common (decl_or_origin, &off);
17496 /* Symbol in common gets emitted as a child of the common block, in the form
17497 of a data member. */
17500 dw_die_ref com_die;
17501 dw_loc_list_ref loc;
17502 die_node com_die_arg;
17504 var_die = lookup_decl_die (decl_or_origin);
17507 if (get_AT (var_die, DW_AT_location) == NULL)
17509 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
17514 /* Optimize the common case. */
17515 if (single_element_loc_list_p (loc)
17516 && loc->expr->dw_loc_opc == DW_OP_addr
17517 && loc->expr->dw_loc_next == NULL
17518 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
17520 loc->expr->dw_loc_oprnd1.v.val_addr
17521 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
17523 loc_list_plus_const (loc, off);
17525 add_AT_location_description (var_die, DW_AT_location, loc);
17526 remove_AT (var_die, DW_AT_declaration);
17532 if (common_block_die_table == NULL)
17533 common_block_die_table
17534 = htab_create_ggc (10, common_block_die_table_hash,
17535 common_block_die_table_eq, NULL);
17537 com_die_arg.decl_id = DECL_UID (com_decl);
17538 com_die_arg.die_parent = context_die;
17539 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
17540 loc = loc_list_from_tree (com_decl, 2);
17541 if (com_die == NULL)
17544 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
17547 com_die = new_die (DW_TAG_common_block, context_die, decl);
17548 add_name_and_src_coords_attributes (com_die, com_decl);
17551 add_AT_location_description (com_die, DW_AT_location, loc);
17552 /* Avoid sharing the same loc descriptor between
17553 DW_TAG_common_block and DW_TAG_variable. */
17554 loc = loc_list_from_tree (com_decl, 2);
17556 else if (DECL_EXTERNAL (decl))
17557 add_AT_flag (com_die, DW_AT_declaration, 1);
17558 add_pubname_string (cnam, com_die); /* ??? needed? */
17559 com_die->decl_id = DECL_UID (com_decl);
17560 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
17561 *slot = (void *) com_die;
17563 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
17565 add_AT_location_description (com_die, DW_AT_location, loc);
17566 loc = loc_list_from_tree (com_decl, 2);
17567 remove_AT (com_die, DW_AT_declaration);
17569 var_die = new_die (DW_TAG_variable, com_die, decl);
17570 add_name_and_src_coords_attributes (var_die, decl);
17571 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
17572 TREE_THIS_VOLATILE (decl), context_die);
17573 add_AT_flag (var_die, DW_AT_external, 1);
17578 /* Optimize the common case. */
17579 if (single_element_loc_list_p (loc)
17580 && loc->expr->dw_loc_opc == DW_OP_addr
17581 && loc->expr->dw_loc_next == NULL
17582 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
17583 loc->expr->dw_loc_oprnd1.v.val_addr
17584 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
17586 loc_list_plus_const (loc, off);
17588 add_AT_location_description (var_die, DW_AT_location, loc);
17590 else if (DECL_EXTERNAL (decl))
17591 add_AT_flag (var_die, DW_AT_declaration, 1);
17592 equate_decl_number_to_die (decl, var_die);
17596 /* If the compiler emitted a definition for the DECL declaration
17597 and if we already emitted a DIE for it, don't emit a second
17598 DIE for it again. Allow re-declarations of DECLs that are
17599 inside functions, though. */
17600 if (old_die && declaration && !local_scope_p (context_die))
17603 /* For static data members, the declaration in the class is supposed
17604 to have DW_TAG_member tag; the specification should still be
17605 DW_TAG_variable referencing the DW_TAG_member DIE. */
17606 if (declaration && class_scope_p (context_die))
17607 var_die = new_die (DW_TAG_member, context_die, decl);
17609 var_die = new_die (DW_TAG_variable, context_die, decl);
17612 if (origin != NULL)
17613 origin_die = add_abstract_origin_attribute (var_die, origin);
17615 /* Loop unrolling can create multiple blocks that refer to the same
17616 static variable, so we must test for the DW_AT_declaration flag.
17618 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17619 copy decls and set the DECL_ABSTRACT flag on them instead of
17622 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17624 ??? The declare_in_namespace support causes us to get two DIEs for one
17625 variable, both of which are declarations. We want to avoid considering
17626 one to be a specification, so we must test that this DIE is not a
17628 else if (old_die && TREE_STATIC (decl) && ! declaration
17629 && get_AT_flag (old_die, DW_AT_declaration) == 1)
17631 /* This is a definition of a C++ class level static. */
17632 add_AT_specification (var_die, old_die);
17633 specialization_p = true;
17634 if (DECL_NAME (decl))
17636 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17637 struct dwarf_file_data * file_index = lookup_filename (s.file);
17639 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
17640 add_AT_file (var_die, DW_AT_decl_file, file_index);
17642 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
17643 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
17645 if (old_die->die_tag == DW_TAG_member)
17646 add_linkage_name (var_die, decl);
17650 add_name_and_src_coords_attributes (var_die, decl);
17652 if ((origin == NULL && !specialization_p)
17654 && !DECL_ABSTRACT (decl_or_origin)
17655 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
17656 decl_function_context
17657 (decl_or_origin))))
17659 tree type = TREE_TYPE (decl_or_origin);
17661 if (decl_by_reference_p (decl_or_origin))
17662 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
17664 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
17665 TREE_THIS_VOLATILE (decl_or_origin), context_die);
17668 if (origin == NULL && !specialization_p)
17670 if (TREE_PUBLIC (decl))
17671 add_AT_flag (var_die, DW_AT_external, 1);
17673 if (DECL_ARTIFICIAL (decl))
17674 add_AT_flag (var_die, DW_AT_artificial, 1);
17676 add_accessibility_attribute (var_die, decl);
17680 add_AT_flag (var_die, DW_AT_declaration, 1);
17682 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
17683 equate_decl_number_to_die (decl, var_die);
17686 && (! DECL_ABSTRACT (decl_or_origin)
17687 /* Local static vars are shared between all clones/inlines,
17688 so emit DW_AT_location on the abstract DIE if DECL_RTL is
17690 || (TREE_CODE (decl_or_origin) == VAR_DECL
17691 && TREE_STATIC (decl_or_origin)
17692 && DECL_RTL_SET_P (decl_or_origin)))
17693 /* When abstract origin already has DW_AT_location attribute, no need
17694 to add it again. */
17695 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
17697 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
17698 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
17699 defer_location (decl_or_origin, var_die);
17701 add_location_or_const_value_attribute (var_die, decl_or_origin,
17702 decl == NULL, DW_AT_location);
17703 add_pubname (decl_or_origin, var_die);
17706 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
17709 /* Generate a DIE to represent a named constant. */
17712 gen_const_die (tree decl, dw_die_ref context_die)
17714 dw_die_ref const_die;
17715 tree type = TREE_TYPE (decl);
17717 const_die = new_die (DW_TAG_constant, context_die, decl);
17718 add_name_and_src_coords_attributes (const_die, decl);
17719 add_type_attribute (const_die, type, 1, 0, context_die);
17720 if (TREE_PUBLIC (decl))
17721 add_AT_flag (const_die, DW_AT_external, 1);
17722 if (DECL_ARTIFICIAL (decl))
17723 add_AT_flag (const_die, DW_AT_artificial, 1);
17724 tree_add_const_value_attribute_for_decl (const_die, decl);
17727 /* Generate a DIE to represent a label identifier. */
17730 gen_label_die (tree decl, dw_die_ref context_die)
17732 tree origin = decl_ultimate_origin (decl);
17733 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
17735 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17737 if (origin != NULL)
17738 add_abstract_origin_attribute (lbl_die, origin);
17740 add_name_and_src_coords_attributes (lbl_die, decl);
17742 if (DECL_ABSTRACT (decl))
17743 equate_decl_number_to_die (decl, lbl_die);
17746 insn = DECL_RTL_IF_SET (decl);
17748 /* Deleted labels are programmer specified labels which have been
17749 eliminated because of various optimizations. We still emit them
17750 here so that it is possible to put breakpoints on them. */
17754 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
17756 /* When optimization is enabled (via -O) some parts of the compiler
17757 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
17758 represent source-level labels which were explicitly declared by
17759 the user. This really shouldn't be happening though, so catch
17760 it if it ever does happen. */
17761 gcc_assert (!INSN_DELETED_P (insn));
17763 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
17764 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
17769 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
17770 attributes to the DIE for a block STMT, to describe where the inlined
17771 function was called from. This is similar to add_src_coords_attributes. */
17774 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
17776 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
17778 if (dwarf_version >= 3 || !dwarf_strict)
17780 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
17781 add_AT_unsigned (die, DW_AT_call_line, s.line);
17786 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
17787 Add low_pc and high_pc attributes to the DIE for a block STMT. */
17790 add_high_low_attributes (tree stmt, dw_die_ref die)
17792 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17794 if (BLOCK_FRAGMENT_CHAIN (stmt)
17795 && (dwarf_version >= 3 || !dwarf_strict))
17799 if (inlined_function_outer_scope_p (stmt))
17801 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
17802 BLOCK_NUMBER (stmt));
17803 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17806 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
17808 chain = BLOCK_FRAGMENT_CHAIN (stmt);
17811 add_ranges (chain);
17812 chain = BLOCK_FRAGMENT_CHAIN (chain);
17819 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
17820 BLOCK_NUMBER (stmt));
17821 add_AT_lbl_id (die, DW_AT_low_pc, label);
17822 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
17823 BLOCK_NUMBER (stmt));
17824 add_AT_lbl_id (die, DW_AT_high_pc, label);
17828 /* Generate a DIE for a lexical block. */
17831 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
17833 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
17835 if (call_arg_locations)
17837 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
17838 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
17839 BLOCK_NUMBER (stmt) + 1);
17840 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
17843 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
17844 add_high_low_attributes (stmt, stmt_die);
17846 decls_for_scope (stmt, stmt_die, depth);
17849 /* Generate a DIE for an inlined subprogram. */
17852 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
17856 /* The instance of function that is effectively being inlined shall not
17858 gcc_assert (! BLOCK_ABSTRACT (stmt));
17860 decl = block_ultimate_origin (stmt);
17862 /* Emit info for the abstract instance first, if we haven't yet. We
17863 must emit this even if the block is abstract, otherwise when we
17864 emit the block below (or elsewhere), we may end up trying to emit
17865 a die whose origin die hasn't been emitted, and crashing. */
17866 dwarf2out_abstract_function (decl);
17868 if (! BLOCK_ABSTRACT (stmt))
17870 dw_die_ref subr_die
17871 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
17873 if (call_arg_locations)
17875 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
17876 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
17877 BLOCK_NUMBER (stmt) + 1);
17878 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
17880 add_abstract_origin_attribute (subr_die, decl);
17881 if (TREE_ASM_WRITTEN (stmt))
17882 add_high_low_attributes (stmt, subr_die);
17883 add_call_src_coords_attributes (stmt, subr_die);
17885 decls_for_scope (stmt, subr_die, depth);
17886 current_function_has_inlines = 1;
17890 /* Generate a DIE for a field in a record, or structure. */
17893 gen_field_die (tree decl, dw_die_ref context_die)
17895 dw_die_ref decl_die;
17897 if (TREE_TYPE (decl) == error_mark_node)
17900 decl_die = new_die (DW_TAG_member, context_die, decl);
17901 add_name_and_src_coords_attributes (decl_die, decl);
17902 add_type_attribute (decl_die, member_declared_type (decl),
17903 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
17906 if (DECL_BIT_FIELD_TYPE (decl))
17908 add_byte_size_attribute (decl_die, decl);
17909 add_bit_size_attribute (decl_die, decl);
17910 add_bit_offset_attribute (decl_die, decl);
17913 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
17914 add_data_member_location_attribute (decl_die, decl);
17916 if (DECL_ARTIFICIAL (decl))
17917 add_AT_flag (decl_die, DW_AT_artificial, 1);
17919 add_accessibility_attribute (decl_die, decl);
17921 /* Equate decl number to die, so that we can look up this decl later on. */
17922 equate_decl_number_to_die (decl, decl_die);
17926 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
17927 Use modified_type_die instead.
17928 We keep this code here just in case these types of DIEs may be needed to
17929 represent certain things in other languages (e.g. Pascal) someday. */
17932 gen_pointer_type_die (tree type, dw_die_ref context_die)
17935 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
17937 equate_type_number_to_die (type, ptr_die);
17938 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
17939 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
17942 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
17943 Use modified_type_die instead.
17944 We keep this code here just in case these types of DIEs may be needed to
17945 represent certain things in other languages (e.g. Pascal) someday. */
17948 gen_reference_type_die (tree type, dw_die_ref context_die)
17950 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
17952 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
17953 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
17955 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
17957 equate_type_number_to_die (type, ref_die);
17958 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
17959 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
17963 /* Generate a DIE for a pointer to a member type. */
17966 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
17969 = new_die (DW_TAG_ptr_to_member_type,
17970 scope_die_for (type, context_die), type);
17972 equate_type_number_to_die (type, ptr_die);
17973 add_AT_die_ref (ptr_die, DW_AT_containing_type,
17974 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
17975 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
17978 /* Generate the DIE for the compilation unit. */
17981 gen_compile_unit_die (const char *filename)
17984 char producer[250];
17985 const char *language_string = lang_hooks.name;
17988 die = new_die (DW_TAG_compile_unit, NULL, NULL);
17992 add_name_attribute (die, filename);
17993 /* Don't add cwd for <built-in>. */
17994 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
17995 add_comp_dir_attribute (die);
17998 sprintf (producer, "%s %s", language_string, version_string);
18000 #ifdef MIPS_DEBUGGING_INFO
18001 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
18002 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
18003 not appear in the producer string, the debugger reaches the conclusion
18004 that the object file is stripped and has no debugging information.
18005 To get the MIPS/SGI debugger to believe that there is debugging
18006 information in the object file, we add a -g to the producer string. */
18007 if (debug_info_level > DINFO_LEVEL_TERSE)
18008 strcat (producer, " -g");
18011 add_AT_string (die, DW_AT_producer, producer);
18013 /* If our producer is LTO try to figure out a common language to use
18014 from the global list of translation units. */
18015 if (strcmp (language_string, "GNU GIMPLE") == 0)
18019 const char *common_lang = NULL;
18021 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
18023 if (!TRANSLATION_UNIT_LANGUAGE (t))
18026 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
18027 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
18029 else if (strncmp (common_lang, "GNU C", 5) == 0
18030 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
18031 /* Mixing C and C++ is ok, use C++ in that case. */
18032 common_lang = "GNU C++";
18035 /* Fall back to C. */
18036 common_lang = NULL;
18042 language_string = common_lang;
18045 language = DW_LANG_C89;
18046 if (strcmp (language_string, "GNU C++") == 0)
18047 language = DW_LANG_C_plus_plus;
18048 else if (strcmp (language_string, "GNU F77") == 0)
18049 language = DW_LANG_Fortran77;
18050 else if (strcmp (language_string, "GNU Pascal") == 0)
18051 language = DW_LANG_Pascal83;
18052 else if (dwarf_version >= 3 || !dwarf_strict)
18054 if (strcmp (language_string, "GNU Ada") == 0)
18055 language = DW_LANG_Ada95;
18056 else if (strcmp (language_string, "GNU Fortran") == 0)
18057 language = DW_LANG_Fortran95;
18058 else if (strcmp (language_string, "GNU Java") == 0)
18059 language = DW_LANG_Java;
18060 else if (strcmp (language_string, "GNU Objective-C") == 0)
18061 language = DW_LANG_ObjC;
18062 else if (strcmp (language_string, "GNU Objective-C++") == 0)
18063 language = DW_LANG_ObjC_plus_plus;
18066 add_AT_unsigned (die, DW_AT_language, language);
18070 case DW_LANG_Fortran77:
18071 case DW_LANG_Fortran90:
18072 case DW_LANG_Fortran95:
18073 /* Fortran has case insensitive identifiers and the front-end
18074 lowercases everything. */
18075 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
18078 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18084 /* Generate the DIE for a base class. */
18087 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
18089 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
18091 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
18092 add_data_member_location_attribute (die, binfo);
18094 if (BINFO_VIRTUAL_P (binfo))
18095 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18097 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18098 children, otherwise the default is DW_ACCESS_public. In DWARF2
18099 the default has always been DW_ACCESS_private. */
18100 if (access == access_public_node)
18102 if (dwarf_version == 2
18103 || context_die->die_tag == DW_TAG_class_type)
18104 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
18106 else if (access == access_protected_node)
18107 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
18108 else if (dwarf_version > 2
18109 && context_die->die_tag != DW_TAG_class_type)
18110 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
18113 /* Generate a DIE for a class member. */
18116 gen_member_die (tree type, dw_die_ref context_die)
18119 tree binfo = TYPE_BINFO (type);
18122 /* If this is not an incomplete type, output descriptions of each of its
18123 members. Note that as we output the DIEs necessary to represent the
18124 members of this record or union type, we will also be trying to output
18125 DIEs to represent the *types* of those members. However the `type'
18126 function (above) will specifically avoid generating type DIEs for member
18127 types *within* the list of member DIEs for this (containing) type except
18128 for those types (of members) which are explicitly marked as also being
18129 members of this (containing) type themselves. The g++ front- end can
18130 force any given type to be treated as a member of some other (containing)
18131 type by setting the TYPE_CONTEXT of the given (member) type to point to
18132 the TREE node representing the appropriate (containing) type. */
18134 /* First output info about the base classes. */
18137 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
18141 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
18142 gen_inheritance_die (base,
18143 (accesses ? VEC_index (tree, accesses, i)
18144 : access_public_node), context_die);
18147 /* Now output info about the data members and type members. */
18148 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
18150 /* If we thought we were generating minimal debug info for TYPE
18151 and then changed our minds, some of the member declarations
18152 may have already been defined. Don't define them again, but
18153 do put them in the right order. */
18155 child = lookup_decl_die (member);
18157 splice_child_die (context_die, child);
18159 gen_decl_die (member, NULL, context_die);
18162 /* Now output info about the function members (if any). */
18163 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
18165 /* Don't include clones in the member list. */
18166 if (DECL_ABSTRACT_ORIGIN (member))
18169 child = lookup_decl_die (member);
18171 splice_child_die (context_die, child);
18173 gen_decl_die (member, NULL, context_die);
18177 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18178 is set, we pretend that the type was never defined, so we only get the
18179 member DIEs needed by later specification DIEs. */
18182 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
18183 enum debug_info_usage usage)
18185 dw_die_ref type_die = lookup_type_die (type);
18186 dw_die_ref scope_die = 0;
18188 int complete = (TYPE_SIZE (type)
18189 && (! TYPE_STUB_DECL (type)
18190 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
18191 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
18192 complete = complete && should_emit_struct_debug (type, usage);
18194 if (type_die && ! complete)
18197 if (TYPE_CONTEXT (type) != NULL_TREE
18198 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18199 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
18202 scope_die = scope_die_for (type, context_die);
18204 if (! type_die || (nested && is_cu_die (scope_die)))
18205 /* First occurrence of type or toplevel definition of nested class. */
18207 dw_die_ref old_die = type_die;
18209 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
18210 ? record_type_tag (type) : DW_TAG_union_type,
18212 equate_type_number_to_die (type, type_die);
18214 add_AT_specification (type_die, old_die);
18217 add_name_attribute (type_die, type_tag (type));
18218 add_gnat_descriptive_type_attribute (type_die, type, context_die);
18219 if (TYPE_ARTIFICIAL (type))
18220 add_AT_flag (type_die, DW_AT_artificial, 1);
18224 remove_AT (type_die, DW_AT_declaration);
18226 /* Generate child dies for template paramaters. */
18227 if (debug_info_level > DINFO_LEVEL_TERSE
18228 && COMPLETE_TYPE_P (type))
18229 schedule_generic_params_dies_gen (type);
18231 /* If this type has been completed, then give it a byte_size attribute and
18232 then give a list of members. */
18233 if (complete && !ns_decl)
18235 /* Prevent infinite recursion in cases where the type of some member of
18236 this type is expressed in terms of this type itself. */
18237 TREE_ASM_WRITTEN (type) = 1;
18238 add_byte_size_attribute (type_die, type);
18239 if (TYPE_STUB_DECL (type) != NULL_TREE)
18241 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18242 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18245 /* If the first reference to this type was as the return type of an
18246 inline function, then it may not have a parent. Fix this now. */
18247 if (type_die->die_parent == NULL)
18248 add_child_die (scope_die, type_die);
18250 push_decl_scope (type);
18251 gen_member_die (type, type_die);
18254 /* GNU extension: Record what type our vtable lives in. */
18255 if (TYPE_VFIELD (type))
18257 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
18259 gen_type_die (vtype, context_die);
18260 add_AT_die_ref (type_die, DW_AT_containing_type,
18261 lookup_type_die (vtype));
18266 add_AT_flag (type_die, DW_AT_declaration, 1);
18268 /* We don't need to do this for function-local types. */
18269 if (TYPE_STUB_DECL (type)
18270 && ! decl_function_context (TYPE_STUB_DECL (type)))
18271 VEC_safe_push (tree, gc, incomplete_types, type);
18274 if (get_AT (type_die, DW_AT_name))
18275 add_pubtype (type, type_die);
18278 /* Generate a DIE for a subroutine _type_. */
18281 gen_subroutine_type_die (tree type, dw_die_ref context_die)
18283 tree return_type = TREE_TYPE (type);
18284 dw_die_ref subr_die
18285 = new_die (DW_TAG_subroutine_type,
18286 scope_die_for (type, context_die), type);
18288 equate_type_number_to_die (type, subr_die);
18289 add_prototyped_attribute (subr_die, type);
18290 add_type_attribute (subr_die, return_type, 0, 0, context_die);
18291 gen_formal_types_die (type, subr_die);
18293 if (get_AT (subr_die, DW_AT_name))
18294 add_pubtype (type, subr_die);
18297 /* Generate a DIE for a type definition. */
18300 gen_typedef_die (tree decl, dw_die_ref context_die)
18302 dw_die_ref type_die;
18305 if (TREE_ASM_WRITTEN (decl))
18308 TREE_ASM_WRITTEN (decl) = 1;
18309 type_die = new_die (DW_TAG_typedef, context_die, decl);
18310 origin = decl_ultimate_origin (decl);
18311 if (origin != NULL)
18312 add_abstract_origin_attribute (type_die, origin);
18317 add_name_and_src_coords_attributes (type_die, decl);
18318 if (DECL_ORIGINAL_TYPE (decl))
18320 type = DECL_ORIGINAL_TYPE (decl);
18322 gcc_assert (type != TREE_TYPE (decl));
18323 equate_type_number_to_die (TREE_TYPE (decl), type_die);
18327 type = TREE_TYPE (decl);
18329 if (is_naming_typedef_decl (TYPE_NAME (type)))
18331 /* Here, we are in the case of decl being a typedef naming
18332 an anonymous type, e.g:
18333 typedef struct {...} foo;
18334 In that case TREE_TYPE (decl) is not a typedef variant
18335 type and TYPE_NAME of the anonymous type is set to the
18336 TYPE_DECL of the typedef. This construct is emitted by
18339 TYPE is the anonymous struct named by the typedef
18340 DECL. As we need the DW_AT_type attribute of the
18341 DW_TAG_typedef to point to the DIE of TYPE, let's
18342 generate that DIE right away. add_type_attribute
18343 called below will then pick (via lookup_type_die) that
18344 anonymous struct DIE. */
18345 if (!TREE_ASM_WRITTEN (type))
18346 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
18348 /* This is a GNU Extension. We are adding a
18349 DW_AT_linkage_name attribute to the DIE of the
18350 anonymous struct TYPE. The value of that attribute
18351 is the name of the typedef decl naming the anonymous
18352 struct. This greatly eases the work of consumers of
18353 this debug info. */
18354 add_linkage_attr (lookup_type_die (type), decl);
18358 add_type_attribute (type_die, type, TREE_READONLY (decl),
18359 TREE_THIS_VOLATILE (decl), context_die);
18361 if (is_naming_typedef_decl (decl))
18362 /* We want that all subsequent calls to lookup_type_die with
18363 TYPE in argument yield the DW_TAG_typedef we have just
18365 equate_type_number_to_die (type, type_die);
18367 add_accessibility_attribute (type_die, decl);
18370 if (DECL_ABSTRACT (decl))
18371 equate_decl_number_to_die (decl, type_die);
18373 if (get_AT (type_die, DW_AT_name))
18374 add_pubtype (decl, type_die);
18377 /* Generate a DIE for a struct, class, enum or union type. */
18380 gen_tagged_type_die (tree type,
18381 dw_die_ref context_die,
18382 enum debug_info_usage usage)
18386 if (type == NULL_TREE
18387 || !is_tagged_type (type))
18390 /* If this is a nested type whose containing class hasn't been written
18391 out yet, writing it out will cover this one, too. This does not apply
18392 to instantiations of member class templates; they need to be added to
18393 the containing class as they are generated. FIXME: This hurts the
18394 idea of combining type decls from multiple TUs, since we can't predict
18395 what set of template instantiations we'll get. */
18396 if (TYPE_CONTEXT (type)
18397 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18398 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
18400 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
18402 if (TREE_ASM_WRITTEN (type))
18405 /* If that failed, attach ourselves to the stub. */
18406 push_decl_scope (TYPE_CONTEXT (type));
18407 context_die = lookup_type_die (TYPE_CONTEXT (type));
18410 else if (TYPE_CONTEXT (type) != NULL_TREE
18411 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
18413 /* If this type is local to a function that hasn't been written
18414 out yet, use a NULL context for now; it will be fixed up in
18415 decls_for_scope. */
18416 context_die = lookup_decl_die (TYPE_CONTEXT (type));
18417 /* A declaration DIE doesn't count; nested types need to go in the
18419 if (context_die && is_declaration_die (context_die))
18420 context_die = NULL;
18425 context_die = declare_in_namespace (type, context_die);
18429 if (TREE_CODE (type) == ENUMERAL_TYPE)
18431 /* This might have been written out by the call to
18432 declare_in_namespace. */
18433 if (!TREE_ASM_WRITTEN (type))
18434 gen_enumeration_type_die (type, context_die);
18437 gen_struct_or_union_type_die (type, context_die, usage);
18442 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18443 it up if it is ever completed. gen_*_type_die will set it for us
18444 when appropriate. */
18447 /* Generate a type description DIE. */
18450 gen_type_die_with_usage (tree type, dw_die_ref context_die,
18451 enum debug_info_usage usage)
18453 struct array_descr_info info;
18455 if (type == NULL_TREE || type == error_mark_node)
18458 if (TYPE_NAME (type) != NULL_TREE
18459 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18460 && is_redundant_typedef (TYPE_NAME (type))
18461 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
18462 /* The DECL of this type is a typedef we don't want to emit debug
18463 info for but we want debug info for its underlying typedef.
18464 This can happen for e.g, the injected-class-name of a C++
18466 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
18468 /* If TYPE is a typedef type variant, let's generate debug info
18469 for the parent typedef which TYPE is a type of. */
18470 if (typedef_variant_p (type))
18472 if (TREE_ASM_WRITTEN (type))
18475 /* Prevent broken recursion; we can't hand off to the same type. */
18476 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
18478 /* Use the DIE of the containing namespace as the parent DIE of
18479 the type description DIE we want to generate. */
18480 if (DECL_CONTEXT (TYPE_NAME (type))
18481 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
18482 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
18484 TREE_ASM_WRITTEN (type) = 1;
18486 gen_decl_die (TYPE_NAME (type), NULL, context_die);
18490 /* If type is an anonymous tagged type named by a typedef, let's
18491 generate debug info for the typedef. */
18492 if (is_naming_typedef_decl (TYPE_NAME (type)))
18494 /* Use the DIE of the containing namespace as the parent DIE of
18495 the type description DIE we want to generate. */
18496 if (DECL_CONTEXT (TYPE_NAME (type))
18497 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
18498 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
18500 gen_decl_die (TYPE_NAME (type), NULL, context_die);
18504 /* If this is an array type with hidden descriptor, handle it first. */
18505 if (!TREE_ASM_WRITTEN (type)
18506 && lang_hooks.types.get_array_descr_info
18507 && lang_hooks.types.get_array_descr_info (type, &info)
18508 && (dwarf_version >= 3 || !dwarf_strict))
18510 gen_descr_array_type_die (type, &info, context_die);
18511 TREE_ASM_WRITTEN (type) = 1;
18515 /* We are going to output a DIE to represent the unqualified version
18516 of this type (i.e. without any const or volatile qualifiers) so
18517 get the main variant (i.e. the unqualified version) of this type
18518 now. (Vectors are special because the debugging info is in the
18519 cloned type itself). */
18520 if (TREE_CODE (type) != VECTOR_TYPE)
18521 type = type_main_variant (type);
18523 if (TREE_ASM_WRITTEN (type))
18526 switch (TREE_CODE (type))
18532 case REFERENCE_TYPE:
18533 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
18534 ensures that the gen_type_die recursion will terminate even if the
18535 type is recursive. Recursive types are possible in Ada. */
18536 /* ??? We could perhaps do this for all types before the switch
18538 TREE_ASM_WRITTEN (type) = 1;
18540 /* For these types, all that is required is that we output a DIE (or a
18541 set of DIEs) to represent the "basis" type. */
18542 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18543 DINFO_USAGE_IND_USE);
18547 /* This code is used for C++ pointer-to-data-member types.
18548 Output a description of the relevant class type. */
18549 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
18550 DINFO_USAGE_IND_USE);
18552 /* Output a description of the type of the object pointed to. */
18553 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18554 DINFO_USAGE_IND_USE);
18556 /* Now output a DIE to represent this pointer-to-data-member type
18558 gen_ptr_to_mbr_type_die (type, context_die);
18561 case FUNCTION_TYPE:
18562 /* Force out return type (in case it wasn't forced out already). */
18563 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18564 DINFO_USAGE_DIR_USE);
18565 gen_subroutine_type_die (type, context_die);
18569 /* Force out return type (in case it wasn't forced out already). */
18570 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18571 DINFO_USAGE_DIR_USE);
18572 gen_subroutine_type_die (type, context_die);
18576 gen_array_type_die (type, context_die);
18580 gen_array_type_die (type, context_die);
18583 case ENUMERAL_TYPE:
18586 case QUAL_UNION_TYPE:
18587 gen_tagged_type_die (type, context_die, usage);
18593 case FIXED_POINT_TYPE:
18596 /* No DIEs needed for fundamental types. */
18601 /* Just use DW_TAG_unspecified_type. */
18603 dw_die_ref type_die = lookup_type_die (type);
18604 if (type_die == NULL)
18606 tree name = TYPE_NAME (type);
18607 if (TREE_CODE (name) == TYPE_DECL)
18608 name = DECL_NAME (name);
18609 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
18610 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
18611 equate_type_number_to_die (type, type_die);
18617 gcc_unreachable ();
18620 TREE_ASM_WRITTEN (type) = 1;
18624 gen_type_die (tree type, dw_die_ref context_die)
18626 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
18629 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
18630 things which are local to the given block. */
18633 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
18635 int must_output_die = 0;
18638 /* Ignore blocks that are NULL. */
18639 if (stmt == NULL_TREE)
18642 inlined_func = inlined_function_outer_scope_p (stmt);
18644 /* If the block is one fragment of a non-contiguous block, do not
18645 process the variables, since they will have been done by the
18646 origin block. Do process subblocks. */
18647 if (BLOCK_FRAGMENT_ORIGIN (stmt))
18651 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
18652 gen_block_die (sub, context_die, depth + 1);
18657 /* Determine if we need to output any Dwarf DIEs at all to represent this
18660 /* The outer scopes for inlinings *must* always be represented. We
18661 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
18662 must_output_die = 1;
18665 /* Determine if this block directly contains any "significant"
18666 local declarations which we will need to output DIEs for. */
18667 if (debug_info_level > DINFO_LEVEL_TERSE)
18668 /* We are not in terse mode so *any* local declaration counts
18669 as being a "significant" one. */
18670 must_output_die = ((BLOCK_VARS (stmt) != NULL
18671 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
18672 && (TREE_USED (stmt)
18673 || TREE_ASM_WRITTEN (stmt)
18674 || BLOCK_ABSTRACT (stmt)));
18675 else if ((TREE_USED (stmt)
18676 || TREE_ASM_WRITTEN (stmt)
18677 || BLOCK_ABSTRACT (stmt))
18678 && !dwarf2out_ignore_block (stmt))
18679 must_output_die = 1;
18682 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
18683 DIE for any block which contains no significant local declarations at
18684 all. Rather, in such cases we just call `decls_for_scope' so that any
18685 needed Dwarf info for any sub-blocks will get properly generated. Note
18686 that in terse mode, our definition of what constitutes a "significant"
18687 local declaration gets restricted to include only inlined function
18688 instances and local (nested) function definitions. */
18689 if (must_output_die)
18693 /* If STMT block is abstract, that means we have been called
18694 indirectly from dwarf2out_abstract_function.
18695 That function rightfully marks the descendent blocks (of
18696 the abstract function it is dealing with) as being abstract,
18697 precisely to prevent us from emitting any
18698 DW_TAG_inlined_subroutine DIE as a descendent
18699 of an abstract function instance. So in that case, we should
18700 not call gen_inlined_subroutine_die.
18702 Later though, when cgraph asks dwarf2out to emit info
18703 for the concrete instance of the function decl into which
18704 the concrete instance of STMT got inlined, the later will lead
18705 to the generation of a DW_TAG_inlined_subroutine DIE. */
18706 if (! BLOCK_ABSTRACT (stmt))
18707 gen_inlined_subroutine_die (stmt, context_die, depth);
18710 gen_lexical_block_die (stmt, context_die, depth);
18713 decls_for_scope (stmt, context_die, depth);
18716 /* Process variable DECL (or variable with origin ORIGIN) within
18717 block STMT and add it to CONTEXT_DIE. */
18719 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
18722 tree decl_or_origin = decl ? decl : origin;
18724 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
18725 die = lookup_decl_die (decl_or_origin);
18726 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
18727 && TYPE_DECL_IS_STUB (decl_or_origin))
18728 die = lookup_type_die (TREE_TYPE (decl_or_origin));
18732 if (die != NULL && die->die_parent == NULL)
18733 add_child_die (context_die, die);
18734 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
18735 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
18736 stmt, context_die);
18738 gen_decl_die (decl, origin, context_die);
18741 /* Generate all of the decls declared within a given scope and (recursively)
18742 all of its sub-blocks. */
18745 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
18751 /* Ignore NULL blocks. */
18752 if (stmt == NULL_TREE)
18755 /* Output the DIEs to represent all of the data objects and typedefs
18756 declared directly within this block but not within any nested
18757 sub-blocks. Also, nested function and tag DIEs have been
18758 generated with a parent of NULL; fix that up now. */
18759 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
18760 process_scope_var (stmt, decl, NULL_TREE, context_die);
18761 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
18762 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
18765 /* If we're at -g1, we're not interested in subblocks. */
18766 if (debug_info_level <= DINFO_LEVEL_TERSE)
18769 /* Output the DIEs to represent all sub-blocks (and the items declared
18770 therein) of this block. */
18771 for (subblocks = BLOCK_SUBBLOCKS (stmt);
18773 subblocks = BLOCK_CHAIN (subblocks))
18774 gen_block_die (subblocks, context_die, depth + 1);
18777 /* Is this a typedef we can avoid emitting? */
18780 is_redundant_typedef (const_tree decl)
18782 if (TYPE_DECL_IS_STUB (decl))
18785 if (DECL_ARTIFICIAL (decl)
18786 && DECL_CONTEXT (decl)
18787 && is_tagged_type (DECL_CONTEXT (decl))
18788 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
18789 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
18790 /* Also ignore the artificial member typedef for the class name. */
18796 /* Return TRUE if TYPE is a typedef that names a type for linkage
18797 purposes. This kind of typedefs is produced by the C++ FE for
18800 typedef struct {...} foo;
18802 In that case, there is no typedef variant type produced for foo.
18803 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
18807 is_naming_typedef_decl (const_tree decl)
18809 if (decl == NULL_TREE
18810 || TREE_CODE (decl) != TYPE_DECL
18811 || !is_tagged_type (TREE_TYPE (decl))
18812 || DECL_IS_BUILTIN (decl)
18813 || is_redundant_typedef (decl)
18814 /* It looks like Ada produces TYPE_DECLs that are very similar
18815 to C++ naming typedefs but that have different
18816 semantics. Let's be specific to c++ for now. */
18820 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
18821 && TYPE_NAME (TREE_TYPE (decl)) == decl
18822 && (TYPE_STUB_DECL (TREE_TYPE (decl))
18823 != TYPE_NAME (TREE_TYPE (decl))));
18826 /* Returns the DIE for a context. */
18828 static inline dw_die_ref
18829 get_context_die (tree context)
18833 /* Find die that represents this context. */
18834 if (TYPE_P (context))
18836 context = TYPE_MAIN_VARIANT (context);
18837 return strip_naming_typedef (context, force_type_die (context));
18840 return force_decl_die (context);
18842 return comp_unit_die ();
18845 /* Returns the DIE for decl. A DIE will always be returned. */
18848 force_decl_die (tree decl)
18850 dw_die_ref decl_die;
18851 unsigned saved_external_flag;
18852 tree save_fn = NULL_TREE;
18853 decl_die = lookup_decl_die (decl);
18856 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
18858 decl_die = lookup_decl_die (decl);
18862 switch (TREE_CODE (decl))
18864 case FUNCTION_DECL:
18865 /* Clear current_function_decl, so that gen_subprogram_die thinks
18866 that this is a declaration. At this point, we just want to force
18867 declaration die. */
18868 save_fn = current_function_decl;
18869 current_function_decl = NULL_TREE;
18870 gen_subprogram_die (decl, context_die);
18871 current_function_decl = save_fn;
18875 /* Set external flag to force declaration die. Restore it after
18876 gen_decl_die() call. */
18877 saved_external_flag = DECL_EXTERNAL (decl);
18878 DECL_EXTERNAL (decl) = 1;
18879 gen_decl_die (decl, NULL, context_die);
18880 DECL_EXTERNAL (decl) = saved_external_flag;
18883 case NAMESPACE_DECL:
18884 if (dwarf_version >= 3 || !dwarf_strict)
18885 dwarf2out_decl (decl);
18887 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
18888 decl_die = comp_unit_die ();
18891 case TRANSLATION_UNIT_DECL:
18892 decl_die = comp_unit_die ();
18896 gcc_unreachable ();
18899 /* We should be able to find the DIE now. */
18901 decl_die = lookup_decl_die (decl);
18902 gcc_assert (decl_die);
18908 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
18909 always returned. */
18912 force_type_die (tree type)
18914 dw_die_ref type_die;
18916 type_die = lookup_type_die (type);
18919 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
18921 type_die = modified_type_die (type, TYPE_READONLY (type),
18922 TYPE_VOLATILE (type), context_die);
18923 gcc_assert (type_die);
18928 /* Force out any required namespaces to be able to output DECL,
18929 and return the new context_die for it, if it's changed. */
18932 setup_namespace_context (tree thing, dw_die_ref context_die)
18934 tree context = (DECL_P (thing)
18935 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
18936 if (context && TREE_CODE (context) == NAMESPACE_DECL)
18937 /* Force out the namespace. */
18938 context_die = force_decl_die (context);
18940 return context_die;
18943 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
18944 type) within its namespace, if appropriate.
18946 For compatibility with older debuggers, namespace DIEs only contain
18947 declarations; all definitions are emitted at CU scope. */
18950 declare_in_namespace (tree thing, dw_die_ref context_die)
18952 dw_die_ref ns_context;
18954 if (debug_info_level <= DINFO_LEVEL_TERSE)
18955 return context_die;
18957 /* If this decl is from an inlined function, then don't try to emit it in its
18958 namespace, as we will get confused. It would have already been emitted
18959 when the abstract instance of the inline function was emitted anyways. */
18960 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
18961 return context_die;
18963 ns_context = setup_namespace_context (thing, context_die);
18965 if (ns_context != context_die)
18969 if (DECL_P (thing))
18970 gen_decl_die (thing, NULL, ns_context);
18972 gen_type_die (thing, ns_context);
18974 return context_die;
18977 /* Generate a DIE for a namespace or namespace alias. */
18980 gen_namespace_die (tree decl, dw_die_ref context_die)
18982 dw_die_ref namespace_die;
18984 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
18985 they are an alias of. */
18986 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
18988 /* Output a real namespace or module. */
18989 context_die = setup_namespace_context (decl, comp_unit_die ());
18990 namespace_die = new_die (is_fortran ()
18991 ? DW_TAG_module : DW_TAG_namespace,
18992 context_die, decl);
18993 /* For Fortran modules defined in different CU don't add src coords. */
18994 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
18996 const char *name = dwarf2_name (decl, 0);
18998 add_name_attribute (namespace_die, name);
19001 add_name_and_src_coords_attributes (namespace_die, decl);
19002 if (DECL_EXTERNAL (decl))
19003 add_AT_flag (namespace_die, DW_AT_declaration, 1);
19004 equate_decl_number_to_die (decl, namespace_die);
19008 /* Output a namespace alias. */
19010 /* Force out the namespace we are an alias of, if necessary. */
19011 dw_die_ref origin_die
19012 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
19014 if (DECL_FILE_SCOPE_P (decl)
19015 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
19016 context_die = setup_namespace_context (decl, comp_unit_die ());
19017 /* Now create the namespace alias DIE. */
19018 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
19019 add_name_and_src_coords_attributes (namespace_die, decl);
19020 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
19021 equate_decl_number_to_die (decl, namespace_die);
19025 /* Generate Dwarf debug information for a decl described by DECL.
19026 The return value is currently only meaningful for PARM_DECLs,
19027 for all other decls it returns NULL. */
19030 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
19032 tree decl_or_origin = decl ? decl : origin;
19033 tree class_origin = NULL, ultimate_origin;
19035 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
19038 switch (TREE_CODE (decl_or_origin))
19044 if (!is_fortran () && !is_ada ())
19046 /* The individual enumerators of an enum type get output when we output
19047 the Dwarf representation of the relevant enum type itself. */
19051 /* Emit its type. */
19052 gen_type_die (TREE_TYPE (decl), context_die);
19054 /* And its containing namespace. */
19055 context_die = declare_in_namespace (decl, context_die);
19057 gen_const_die (decl, context_die);
19060 case FUNCTION_DECL:
19061 /* Don't output any DIEs to represent mere function declarations,
19062 unless they are class members or explicit block externs. */
19063 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
19064 && DECL_FILE_SCOPE_P (decl_or_origin)
19065 && (current_function_decl == NULL_TREE
19066 || DECL_ARTIFICIAL (decl_or_origin)))
19071 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19072 on local redeclarations of global functions. That seems broken. */
19073 if (current_function_decl != decl)
19074 /* This is only a declaration. */;
19077 /* If we're emitting a clone, emit info for the abstract instance. */
19078 if (origin || DECL_ORIGIN (decl) != decl)
19079 dwarf2out_abstract_function (origin
19080 ? DECL_ORIGIN (origin)
19081 : DECL_ABSTRACT_ORIGIN (decl));
19083 /* If we're emitting an out-of-line copy of an inline function,
19084 emit info for the abstract instance and set up to refer to it. */
19085 else if (cgraph_function_possibly_inlined_p (decl)
19086 && ! DECL_ABSTRACT (decl)
19087 && ! class_or_namespace_scope_p (context_die)
19088 /* dwarf2out_abstract_function won't emit a die if this is just
19089 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19090 that case, because that works only if we have a die. */
19091 && DECL_INITIAL (decl) != NULL_TREE)
19093 dwarf2out_abstract_function (decl);
19094 set_decl_origin_self (decl);
19097 /* Otherwise we're emitting the primary DIE for this decl. */
19098 else if (debug_info_level > DINFO_LEVEL_TERSE)
19100 /* Before we describe the FUNCTION_DECL itself, make sure that we
19101 have its containing type. */
19103 origin = decl_class_context (decl);
19104 if (origin != NULL_TREE)
19105 gen_type_die (origin, context_die);
19107 /* And its return type. */
19108 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
19110 /* And its virtual context. */
19111 if (DECL_VINDEX (decl) != NULL_TREE)
19112 gen_type_die (DECL_CONTEXT (decl), context_die);
19114 /* Make sure we have a member DIE for decl. */
19115 if (origin != NULL_TREE)
19116 gen_type_die_for_member (origin, decl, context_die);
19118 /* And its containing namespace. */
19119 context_die = declare_in_namespace (decl, context_die);
19122 /* Now output a DIE to represent the function itself. */
19124 gen_subprogram_die (decl, context_die);
19128 /* If we are in terse mode, don't generate any DIEs to represent any
19129 actual typedefs. */
19130 if (debug_info_level <= DINFO_LEVEL_TERSE)
19133 /* In the special case of a TYPE_DECL node representing the declaration
19134 of some type tag, if the given TYPE_DECL is marked as having been
19135 instantiated from some other (original) TYPE_DECL node (e.g. one which
19136 was generated within the original definition of an inline function) we
19137 used to generate a special (abbreviated) DW_TAG_structure_type,
19138 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19139 should be actually referencing those DIEs, as variable DIEs with that
19140 type would be emitted already in the abstract origin, so it was always
19141 removed during unused type prunning. Don't add anything in this
19143 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
19146 if (is_redundant_typedef (decl))
19147 gen_type_die (TREE_TYPE (decl), context_die);
19149 /* Output a DIE to represent the typedef itself. */
19150 gen_typedef_die (decl, context_die);
19154 if (debug_info_level >= DINFO_LEVEL_NORMAL)
19155 gen_label_die (decl, context_die);
19160 /* If we are in terse mode, don't generate any DIEs to represent any
19161 variable declarations or definitions. */
19162 if (debug_info_level <= DINFO_LEVEL_TERSE)
19165 /* Output any DIEs that are needed to specify the type of this data
19167 if (decl_by_reference_p (decl_or_origin))
19168 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19170 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19172 /* And its containing type. */
19173 class_origin = decl_class_context (decl_or_origin);
19174 if (class_origin != NULL_TREE)
19175 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
19177 /* And its containing namespace. */
19178 context_die = declare_in_namespace (decl_or_origin, context_die);
19180 /* Now output the DIE to represent the data object itself. This gets
19181 complicated because of the possibility that the VAR_DECL really
19182 represents an inlined instance of a formal parameter for an inline
19184 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19185 if (ultimate_origin != NULL_TREE
19186 && TREE_CODE (ultimate_origin) == PARM_DECL)
19187 gen_formal_parameter_die (decl, origin,
19188 true /* Emit name attribute. */,
19191 gen_variable_die (decl, origin, context_die);
19195 /* Ignore the nameless fields that are used to skip bits but handle C++
19196 anonymous unions and structs. */
19197 if (DECL_NAME (decl) != NULL_TREE
19198 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
19199 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
19201 gen_type_die (member_declared_type (decl), context_die);
19202 gen_field_die (decl, context_die);
19207 if (DECL_BY_REFERENCE (decl_or_origin))
19208 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19210 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19211 return gen_formal_parameter_die (decl, origin,
19212 true /* Emit name attribute. */,
19215 case NAMESPACE_DECL:
19216 case IMPORTED_DECL:
19217 if (dwarf_version >= 3 || !dwarf_strict)
19218 gen_namespace_die (decl, context_die);
19222 /* Probably some frontend-internal decl. Assume we don't care. */
19223 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
19230 /* Output debug information for global decl DECL. Called from toplev.c after
19231 compilation proper has finished. */
19234 dwarf2out_global_decl (tree decl)
19236 /* Output DWARF2 information for file-scope tentative data object
19237 declarations, file-scope (extern) function declarations (which
19238 had no corresponding body) and file-scope tagged type declarations
19239 and definitions which have not yet been forced out. */
19240 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
19241 dwarf2out_decl (decl);
19244 /* Output debug information for type decl DECL. Called from toplev.c
19245 and from language front ends (to record built-in types). */
19247 dwarf2out_type_decl (tree decl, int local)
19250 dwarf2out_decl (decl);
19253 /* Output debug information for imported module or decl DECL.
19254 NAME is non-NULL name in the lexical block if the decl has been renamed.
19255 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19256 that DECL belongs to.
19257 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19259 dwarf2out_imported_module_or_decl_1 (tree decl,
19261 tree lexical_block,
19262 dw_die_ref lexical_block_die)
19264 expanded_location xloc;
19265 dw_die_ref imported_die = NULL;
19266 dw_die_ref at_import_die;
19268 if (TREE_CODE (decl) == IMPORTED_DECL)
19270 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
19271 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
19275 xloc = expand_location (input_location);
19277 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
19279 at_import_die = force_type_die (TREE_TYPE (decl));
19280 /* For namespace N { typedef void T; } using N::T; base_type_die
19281 returns NULL, but DW_TAG_imported_declaration requires
19282 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19283 if (!at_import_die)
19285 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
19286 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
19287 at_import_die = lookup_type_die (TREE_TYPE (decl));
19288 gcc_assert (at_import_die);
19293 at_import_die = lookup_decl_die (decl);
19294 if (!at_import_die)
19296 /* If we're trying to avoid duplicate debug info, we may not have
19297 emitted the member decl for this field. Emit it now. */
19298 if (TREE_CODE (decl) == FIELD_DECL)
19300 tree type = DECL_CONTEXT (decl);
19302 if (TYPE_CONTEXT (type)
19303 && TYPE_P (TYPE_CONTEXT (type))
19304 && !should_emit_struct_debug (TYPE_CONTEXT (type),
19305 DINFO_USAGE_DIR_USE))
19307 gen_type_die_for_member (type, decl,
19308 get_context_die (TYPE_CONTEXT (type)));
19310 at_import_die = force_decl_die (decl);
19314 if (TREE_CODE (decl) == NAMESPACE_DECL)
19316 if (dwarf_version >= 3 || !dwarf_strict)
19317 imported_die = new_die (DW_TAG_imported_module,
19324 imported_die = new_die (DW_TAG_imported_declaration,
19328 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
19329 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
19331 add_AT_string (imported_die, DW_AT_name,
19332 IDENTIFIER_POINTER (name));
19333 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
19336 /* Output debug information for imported module or decl DECL.
19337 NAME is non-NULL name in context if the decl has been renamed.
19338 CHILD is true if decl is one of the renamed decls as part of
19339 importing whole module. */
19342 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
19345 /* dw_die_ref at_import_die; */
19346 dw_die_ref scope_die;
19348 if (debug_info_level <= DINFO_LEVEL_TERSE)
19353 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19354 We need decl DIE for reference and scope die. First, get DIE for the decl
19357 /* Get the scope die for decl context. Use comp_unit_die for global module
19358 or decl. If die is not found for non globals, force new die. */
19360 && TYPE_P (context)
19361 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
19364 if (!(dwarf_version >= 3 || !dwarf_strict))
19367 scope_die = get_context_die (context);
19371 gcc_assert (scope_die->die_child);
19372 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
19373 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
19374 scope_die = scope_die->die_child;
19377 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19378 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
19382 /* Write the debugging output for DECL. */
19385 dwarf2out_decl (tree decl)
19387 dw_die_ref context_die = comp_unit_die ();
19389 switch (TREE_CODE (decl))
19394 case FUNCTION_DECL:
19395 /* What we would really like to do here is to filter out all mere
19396 file-scope declarations of file-scope functions which are never
19397 referenced later within this translation unit (and keep all of ones
19398 that *are* referenced later on) but we aren't clairvoyant, so we have
19399 no idea which functions will be referenced in the future (i.e. later
19400 on within the current translation unit). So here we just ignore all
19401 file-scope function declarations which are not also definitions. If
19402 and when the debugger needs to know something about these functions,
19403 it will have to hunt around and find the DWARF information associated
19404 with the definition of the function.
19406 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19407 nodes represent definitions and which ones represent mere
19408 declarations. We have to check DECL_INITIAL instead. That's because
19409 the C front-end supports some weird semantics for "extern inline"
19410 function definitions. These can get inlined within the current
19411 translation unit (and thus, we need to generate Dwarf info for their
19412 abstract instances so that the Dwarf info for the concrete inlined
19413 instances can have something to refer to) but the compiler never
19414 generates any out-of-lines instances of such things (despite the fact
19415 that they *are* definitions).
19417 The important point is that the C front-end marks these "extern
19418 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19419 them anyway. Note that the C++ front-end also plays some similar games
19420 for inline function definitions appearing within include files which
19421 also contain `#pragma interface' pragmas. */
19422 if (DECL_INITIAL (decl) == NULL_TREE)
19425 /* If we're a nested function, initially use a parent of NULL; if we're
19426 a plain function, this will be fixed up in decls_for_scope. If
19427 we're a method, it will be ignored, since we already have a DIE. */
19428 if (decl_function_context (decl)
19429 /* But if we're in terse mode, we don't care about scope. */
19430 && debug_info_level > DINFO_LEVEL_TERSE)
19431 context_die = NULL;
19435 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19436 declaration and if the declaration was never even referenced from
19437 within this entire compilation unit. We suppress these DIEs in
19438 order to save space in the .debug section (by eliminating entries
19439 which are probably useless). Note that we must not suppress
19440 block-local extern declarations (whether used or not) because that
19441 would screw-up the debugger's name lookup mechanism and cause it to
19442 miss things which really ought to be in scope at a given point. */
19443 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
19446 /* For local statics lookup proper context die. */
19447 if (TREE_STATIC (decl) && decl_function_context (decl))
19448 context_die = lookup_decl_die (DECL_CONTEXT (decl));
19450 /* If we are in terse mode, don't generate any DIEs to represent any
19451 variable declarations or definitions. */
19452 if (debug_info_level <= DINFO_LEVEL_TERSE)
19457 if (debug_info_level <= DINFO_LEVEL_TERSE)
19459 if (!is_fortran () && !is_ada ())
19461 if (TREE_STATIC (decl) && decl_function_context (decl))
19462 context_die = lookup_decl_die (DECL_CONTEXT (decl));
19465 case NAMESPACE_DECL:
19466 case IMPORTED_DECL:
19467 if (debug_info_level <= DINFO_LEVEL_TERSE)
19469 if (lookup_decl_die (decl) != NULL)
19474 /* Don't emit stubs for types unless they are needed by other DIEs. */
19475 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
19478 /* Don't bother trying to generate any DIEs to represent any of the
19479 normal built-in types for the language we are compiling. */
19480 if (DECL_IS_BUILTIN (decl))
19483 /* If we are in terse mode, don't generate any DIEs for types. */
19484 if (debug_info_level <= DINFO_LEVEL_TERSE)
19487 /* If we're a function-scope tag, initially use a parent of NULL;
19488 this will be fixed up in decls_for_scope. */
19489 if (decl_function_context (decl))
19490 context_die = NULL;
19498 gen_decl_die (decl, NULL, context_die);
19501 /* Write the debugging output for DECL. */
19504 dwarf2out_function_decl (tree decl)
19506 dwarf2out_decl (decl);
19507 call_arg_locations = NULL;
19508 call_arg_loc_last = NULL;
19509 call_site_count = -1;
19510 tail_call_site_count = -1;
19511 VEC_free (dw_die_ref, heap, block_map);
19512 htab_empty (decl_loc_table);
19513 htab_empty (cached_dw_loc_list_table);
19516 /* Output a marker (i.e. a label) for the beginning of the generated code for
19517 a lexical block. */
19520 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
19521 unsigned int blocknum)
19523 switch_to_section (current_function_section ());
19524 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
19527 /* Output a marker (i.e. a label) for the end of the generated code for a
19531 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
19533 switch_to_section (current_function_section ());
19534 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
19537 /* Returns nonzero if it is appropriate not to emit any debugging
19538 information for BLOCK, because it doesn't contain any instructions.
19540 Don't allow this for blocks with nested functions or local classes
19541 as we would end up with orphans, and in the presence of scheduling
19542 we may end up calling them anyway. */
19545 dwarf2out_ignore_block (const_tree block)
19550 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
19551 if (TREE_CODE (decl) == FUNCTION_DECL
19552 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
19554 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
19556 decl = BLOCK_NONLOCALIZED_VAR (block, i);
19557 if (TREE_CODE (decl) == FUNCTION_DECL
19558 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
19565 /* Hash table routines for file_hash. */
19568 file_table_eq (const void *p1_p, const void *p2_p)
19570 const struct dwarf_file_data *const p1 =
19571 (const struct dwarf_file_data *) p1_p;
19572 const char *const p2 = (const char *) p2_p;
19573 return filename_cmp (p1->filename, p2) == 0;
19577 file_table_hash (const void *p_p)
19579 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
19580 return htab_hash_string (p->filename);
19583 /* Lookup FILE_NAME (in the list of filenames that we know about here in
19584 dwarf2out.c) and return its "index". The index of each (known) filename is
19585 just a unique number which is associated with only that one filename. We
19586 need such numbers for the sake of generating labels (in the .debug_sfnames
19587 section) and references to those files numbers (in the .debug_srcinfo
19588 and.debug_macinfo sections). If the filename given as an argument is not
19589 found in our current list, add it to the list and assign it the next
19590 available unique index number. In order to speed up searches, we remember
19591 the index of the filename was looked up last. This handles the majority of
19594 static struct dwarf_file_data *
19595 lookup_filename (const char *file_name)
19598 struct dwarf_file_data * created;
19600 /* Check to see if the file name that was searched on the previous
19601 call matches this file name. If so, return the index. */
19602 if (file_table_last_lookup
19603 && (file_name == file_table_last_lookup->filename
19604 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
19605 return file_table_last_lookup;
19607 /* Didn't match the previous lookup, search the table. */
19608 slot = htab_find_slot_with_hash (file_table, file_name,
19609 htab_hash_string (file_name), INSERT);
19611 return (struct dwarf_file_data *) *slot;
19613 created = ggc_alloc_dwarf_file_data ();
19614 created->filename = file_name;
19615 created->emitted_number = 0;
19620 /* If the assembler will construct the file table, then translate the compiler
19621 internal file table number into the assembler file table number, and emit
19622 a .file directive if we haven't already emitted one yet. The file table
19623 numbers are different because we prune debug info for unused variables and
19624 types, which may include filenames. */
19627 maybe_emit_file (struct dwarf_file_data * fd)
19629 if (! fd->emitted_number)
19631 if (last_emitted_file)
19632 fd->emitted_number = last_emitted_file->emitted_number + 1;
19634 fd->emitted_number = 1;
19635 last_emitted_file = fd;
19637 if (DWARF2_ASM_LINE_DEBUG_INFO)
19639 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
19640 output_quoted_string (asm_out_file,
19641 remap_debug_filename (fd->filename));
19642 fputc ('\n', asm_out_file);
19646 return fd->emitted_number;
19649 /* Schedule generation of a DW_AT_const_value attribute to DIE.
19650 That generation should happen after function debug info has been
19651 generated. The value of the attribute is the constant value of ARG. */
19654 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
19656 die_arg_entry entry;
19661 if (!tmpl_value_parm_die_table)
19662 tmpl_value_parm_die_table
19663 = VEC_alloc (die_arg_entry, gc, 32);
19667 VEC_safe_push (die_arg_entry, gc,
19668 tmpl_value_parm_die_table,
19672 /* Return TRUE if T is an instance of generic type, FALSE
19676 generic_type_p (tree t)
19678 if (t == NULL_TREE || !TYPE_P (t))
19680 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
19683 /* Schedule the generation of the generic parameter dies for the
19684 instance of generic type T. The proper generation itself is later
19685 done by gen_scheduled_generic_parms_dies. */
19688 schedule_generic_params_dies_gen (tree t)
19690 if (!generic_type_p (t))
19693 if (generic_type_instances == NULL)
19694 generic_type_instances = VEC_alloc (tree, gc, 256);
19696 VEC_safe_push (tree, gc, generic_type_instances, t);
19699 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
19700 by append_entry_to_tmpl_value_parm_die_table. This function must
19701 be called after function DIEs have been generated. */
19704 gen_remaining_tmpl_value_param_die_attribute (void)
19706 if (tmpl_value_parm_die_table)
19711 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
19712 tree_add_const_value_attribute (e->die, e->arg);
19716 /* Generate generic parameters DIEs for instances of generic types
19717 that have been previously scheduled by
19718 schedule_generic_params_dies_gen. This function must be called
19719 after all the types of the CU have been laid out. */
19722 gen_scheduled_generic_parms_dies (void)
19727 if (generic_type_instances == NULL)
19730 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
19731 gen_generic_params_dies (t);
19735 /* Replace DW_AT_name for the decl with name. */
19738 dwarf2out_set_name (tree decl, tree name)
19744 die = TYPE_SYMTAB_DIE (decl);
19748 dname = dwarf2_name (name, 0);
19752 attr = get_AT (die, DW_AT_name);
19755 struct indirect_string_node *node;
19757 node = find_AT_string (dname);
19758 /* replace the string. */
19759 attr->dw_attr_val.v.val_str = node;
19763 add_name_attribute (die, dname);
19766 /* Called by the final INSN scan whenever we see a var location. We
19767 use it to drop labels in the right places, and throw the location in
19768 our lookup table. */
19771 dwarf2out_var_location (rtx loc_note)
19773 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
19774 struct var_loc_node *newloc;
19776 static const char *last_label;
19777 static const char *last_postcall_label;
19778 static bool last_in_cold_section_p;
19782 if (!NOTE_P (loc_note))
19784 if (CALL_P (loc_note))
19787 if (SIBLING_CALL_P (loc_note))
19788 tail_call_site_count++;
19793 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
19794 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
19797 next_real = next_real_insn (loc_note);
19799 /* If there are no instructions which would be affected by this note,
19800 don't do anything. */
19802 && next_real == NULL_RTX
19803 && !NOTE_DURING_CALL_P (loc_note))
19806 if (next_real == NULL_RTX)
19807 next_real = get_last_insn ();
19809 /* If there were any real insns between note we processed last time
19810 and this note (or if it is the first note), clear
19811 last_{,postcall_}label so that they are not reused this time. */
19812 if (last_var_location_insn == NULL_RTX
19813 || last_var_location_insn != next_real
19814 || last_in_cold_section_p != in_cold_section_p)
19817 last_postcall_label = NULL;
19822 decl = NOTE_VAR_LOCATION_DECL (loc_note);
19823 newloc = add_var_loc_to_decl (decl, loc_note,
19824 NOTE_DURING_CALL_P (loc_note)
19825 ? last_postcall_label : last_label);
19826 if (newloc == NULL)
19835 /* If there were no real insns between note we processed last time
19836 and this note, use the label we emitted last time. Otherwise
19837 create a new label and emit it. */
19838 if (last_label == NULL)
19840 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
19841 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
19843 last_label = ggc_strdup (loclabel);
19848 struct call_arg_loc_node *ca_loc
19849 = ggc_alloc_cleared_call_arg_loc_node ();
19850 rtx prev = prev_real_insn (loc_note), x;
19851 ca_loc->call_arg_loc_note = loc_note;
19852 ca_loc->next = NULL;
19853 ca_loc->label = last_label;
19856 || (NONJUMP_INSN_P (prev)
19857 && GET_CODE (PATTERN (prev)) == SEQUENCE
19858 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
19859 if (!CALL_P (prev))
19860 prev = XVECEXP (PATTERN (prev), 0, 0);
19861 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
19862 x = PATTERN (prev);
19863 if (GET_CODE (x) == PARALLEL)
19864 x = XVECEXP (x, 0, 0);
19865 if (GET_CODE (x) == SET)
19867 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
19869 x = XEXP (XEXP (x, 0), 0);
19870 if (GET_CODE (x) == SYMBOL_REF
19871 && SYMBOL_REF_DECL (x)
19872 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
19873 ca_loc->symbol_ref = x;
19875 ca_loc->block = insn_scope (prev);
19876 if (call_arg_locations)
19877 call_arg_loc_last->next = ca_loc;
19879 call_arg_locations = ca_loc;
19880 call_arg_loc_last = ca_loc;
19882 else if (!NOTE_DURING_CALL_P (loc_note))
19883 newloc->label = last_label;
19886 if (!last_postcall_label)
19888 sprintf (loclabel, "%s-1", last_label);
19889 last_postcall_label = ggc_strdup (loclabel);
19891 newloc->label = last_postcall_label;
19894 last_var_location_insn = next_real;
19895 last_in_cold_section_p = in_cold_section_p;
19898 /* Note in one location list that text section has changed. */
19901 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
19903 var_loc_list *list = (var_loc_list *) *slot;
19905 list->last_before_switch
19906 = list->last->next ? list->last->next : list->last;
19910 /* Note in all location lists that text section has changed. */
19913 var_location_switch_text_section (void)
19915 if (decl_loc_table == NULL)
19918 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
19921 /* Create a new line number table. */
19923 static dw_line_info_table *
19924 new_line_info_table (void)
19926 dw_line_info_table *table;
19928 table = ggc_alloc_cleared_dw_line_info_table_struct ();
19929 table->file_num = 1;
19930 table->line_num = 1;
19931 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
19936 /* Lookup the "current" table into which we emit line info, so
19937 that we don't have to do it for every source line. */
19940 set_cur_line_info_table (section *sec)
19942 dw_line_info_table *table;
19944 if (sec == text_section)
19945 table = text_section_line_info;
19946 else if (sec == cold_text_section)
19948 table = cold_text_section_line_info;
19951 cold_text_section_line_info = table = new_line_info_table ();
19952 table->end_label = cold_end_label;
19957 const char *end_label;
19959 if (flag_reorder_blocks_and_partition)
19961 if (in_cold_section_p)
19962 end_label = crtl->subsections.cold_section_end_label;
19964 end_label = crtl->subsections.hot_section_end_label;
19968 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19969 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
19970 current_function_funcdef_no);
19971 end_label = ggc_strdup (label);
19974 table = new_line_info_table ();
19975 table->end_label = end_label;
19977 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
19980 cur_line_info_table = table;
19984 /* We need to reset the locations at the beginning of each
19985 function. We can't do this in the end_function hook, because the
19986 declarations that use the locations won't have been output when
19987 that hook is called. Also compute have_multiple_function_sections here. */
19990 dwarf2out_begin_function (tree fun)
19992 section *sec = function_section (fun);
19994 if (sec != text_section)
19995 have_multiple_function_sections = true;
19997 if (flag_reorder_blocks_and_partition && !cold_text_section)
19999 gcc_assert (current_function_decl == fun);
20000 cold_text_section = unlikely_text_section ();
20001 switch_to_section (cold_text_section);
20002 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
20003 switch_to_section (sec);
20006 dwarf2out_note_section_used ();
20007 call_site_count = 0;
20008 tail_call_site_count = 0;
20010 set_cur_line_info_table (sec);
20013 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20016 push_dw_line_info_entry (dw_line_info_table *table,
20017 enum dw_line_info_opcode opcode, unsigned int val)
20019 dw_line_info_entry e;
20022 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
20025 /* Output a label to mark the beginning of a source code line entry
20026 and record information relating to this source line, in
20027 'line_info_table' for later output of the .debug_line section. */
20028 /* ??? The discriminator parameter ought to be unsigned. */
20031 dwarf2out_source_line (unsigned int line, const char *filename,
20032 int discriminator, bool is_stmt)
20034 unsigned int file_num;
20035 dw_line_info_table *table;
20037 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
20040 /* The discriminator column was added in dwarf4. Simplify the below
20041 by simply removing it if we're not supposed to output it. */
20042 if (dwarf_version < 4 && dwarf_strict)
20045 table = cur_line_info_table;
20046 file_num = maybe_emit_file (lookup_filename (filename));
20048 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20049 the debugger has used the second (possibly duplicate) line number
20050 at the beginning of the function to mark the end of the prologue.
20051 We could eliminate any other duplicates within the function. For
20052 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20053 that second line number entry. */
20054 /* Recall that this end-of-prologue indication is *not* the same thing
20055 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20056 to which the hook corresponds, follows the last insn that was
20057 emitted by gen_prologue. What we need is to preceed the first insn
20058 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20059 insn that corresponds to something the user wrote. These may be
20060 very different locations once scheduling is enabled. */
20062 if (0 && file_num == table->file_num
20063 && line == table->line_num
20064 && discriminator == table->discrim_num
20065 && is_stmt == table->is_stmt)
20068 switch_to_section (current_function_section ());
20070 /* If requested, emit something human-readable. */
20071 if (flag_debug_asm)
20072 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
20074 if (DWARF2_ASM_LINE_DEBUG_INFO)
20076 /* Emit the .loc directive understood by GNU as. */
20077 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
20078 if (is_stmt != table->is_stmt)
20079 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
20080 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
20081 fprintf (asm_out_file, " discriminator %d", discriminator);
20082 fputc ('\n', asm_out_file);
20086 unsigned int label_num = ++line_info_label_num;
20088 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
20090 push_dw_line_info_entry (table, LI_set_address, label_num);
20091 if (file_num != table->file_num)
20092 push_dw_line_info_entry (table, LI_set_file, file_num);
20093 if (discriminator != table->discrim_num)
20094 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
20095 if (is_stmt != table->is_stmt)
20096 push_dw_line_info_entry (table, LI_negate_stmt, 0);
20097 push_dw_line_info_entry (table, LI_set_line, line);
20100 table->file_num = file_num;
20101 table->line_num = line;
20102 table->discrim_num = discriminator;
20103 table->is_stmt = is_stmt;
20104 table->in_use = true;
20107 /* Record the beginning of a new source file. */
20110 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
20112 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20114 /* Record the beginning of the file for break_out_includes. */
20115 dw_die_ref bincl_die;
20117 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
20118 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
20121 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20124 e.code = DW_MACINFO_start_file;
20126 e.info = xstrdup (filename);
20127 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20131 /* Record the end of a source file. */
20134 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
20136 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20137 /* Record the end of the file for break_out_includes. */
20138 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
20140 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20143 e.code = DW_MACINFO_end_file;
20146 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20150 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20151 the tail part of the directive line, i.e. the part which is past the
20152 initial whitespace, #, whitespace, directive-name, whitespace part. */
20155 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
20156 const char *buffer ATTRIBUTE_UNUSED)
20158 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20161 e.code = DW_MACINFO_define;
20163 e.info = xstrdup (buffer);;
20164 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20168 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20169 the tail part of the directive line, i.e. the part which is past the
20170 initial whitespace, #, whitespace, directive-name, whitespace part. */
20173 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
20174 const char *buffer ATTRIBUTE_UNUSED)
20176 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20179 e.code = DW_MACINFO_undef;
20181 e.info = xstrdup (buffer);;
20182 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20187 output_macinfo (void)
20190 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
20191 macinfo_entry *ref;
20196 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
20200 case DW_MACINFO_start_file:
20202 int file_num = maybe_emit_file (lookup_filename (ref->info));
20203 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
20204 dw2_asm_output_data_uleb128
20205 (ref->lineno, "Included from line number %lu",
20206 (unsigned long)ref->lineno);
20207 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
20210 case DW_MACINFO_end_file:
20211 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
20213 case DW_MACINFO_define:
20214 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
20215 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20216 (unsigned long)ref->lineno);
20217 dw2_asm_output_nstring (ref->info, -1, "The macro");
20219 case DW_MACINFO_undef:
20220 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
20221 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20222 (unsigned long)ref->lineno);
20223 dw2_asm_output_nstring (ref->info, -1, "The macro");
20226 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
20227 ASM_COMMENT_START, (unsigned long)ref->code);
20233 /* Set up for Dwarf output at the start of compilation. */
20236 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
20238 /* Allocate the file_table. */
20239 file_table = htab_create_ggc (50, file_table_hash,
20240 file_table_eq, NULL);
20242 /* Allocate the decl_die_table. */
20243 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
20244 decl_die_table_eq, NULL);
20246 /* Allocate the decl_loc_table. */
20247 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
20248 decl_loc_table_eq, NULL);
20250 /* Allocate the cached_dw_loc_list_table. */
20251 cached_dw_loc_list_table
20252 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
20253 cached_dw_loc_list_table_eq, NULL);
20255 /* Allocate the initial hunk of the decl_scope_table. */
20256 decl_scope_table = VEC_alloc (tree, gc, 256);
20258 /* Allocate the initial hunk of the abbrev_die_table. */
20259 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
20260 (ABBREV_DIE_TABLE_INCREMENT);
20261 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
20262 /* Zero-th entry is allocated, but unused. */
20263 abbrev_die_table_in_use = 1;
20265 /* Allocate the pubtypes and pubnames vectors. */
20266 pubname_table = VEC_alloc (pubname_entry, gc, 32);
20267 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
20269 incomplete_types = VEC_alloc (tree, gc, 64);
20271 used_rtx_array = VEC_alloc (rtx, gc, 32);
20273 debug_info_section = get_section (DEBUG_INFO_SECTION,
20274 SECTION_DEBUG, NULL);
20275 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
20276 SECTION_DEBUG, NULL);
20277 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
20278 SECTION_DEBUG, NULL);
20279 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
20280 SECTION_DEBUG, NULL);
20281 debug_line_section = get_section (DEBUG_LINE_SECTION,
20282 SECTION_DEBUG, NULL);
20283 debug_loc_section = get_section (DEBUG_LOC_SECTION,
20284 SECTION_DEBUG, NULL);
20285 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
20286 SECTION_DEBUG, NULL);
20287 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
20288 SECTION_DEBUG, NULL);
20289 debug_str_section = get_section (DEBUG_STR_SECTION,
20290 DEBUG_STR_SECTION_FLAGS, NULL);
20291 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
20292 SECTION_DEBUG, NULL);
20293 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
20294 SECTION_DEBUG, NULL);
20296 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
20297 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
20298 DEBUG_ABBREV_SECTION_LABEL, 0);
20299 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
20300 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
20301 COLD_TEXT_SECTION_LABEL, 0);
20302 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
20304 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
20305 DEBUG_INFO_SECTION_LABEL, 0);
20306 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
20307 DEBUG_LINE_SECTION_LABEL, 0);
20308 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
20309 DEBUG_RANGES_SECTION_LABEL, 0);
20310 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
20311 DEBUG_MACINFO_SECTION_LABEL, 0);
20313 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20314 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
20316 switch_to_section (text_section);
20317 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
20319 /* Make sure the line number table for .text always exists. */
20320 text_section_line_info = new_line_info_table ();
20321 text_section_line_info->end_label = text_end_label;
20324 /* Called before cgraph_optimize starts outputtting functions, variables
20325 and toplevel asms into assembly. */
20328 dwarf2out_assembly_start (void)
20330 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
20331 && dwarf2out_do_cfi_asm ()
20332 && (!(flag_unwind_tables || flag_exceptions)
20333 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
20334 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
20337 /* A helper function for dwarf2out_finish called through
20338 htab_traverse. Emit one queued .debug_str string. */
20341 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
20343 struct indirect_string_node *node = (struct indirect_string_node *) *h;
20345 if (node->form == DW_FORM_strp)
20347 switch_to_section (debug_str_section);
20348 ASM_OUTPUT_LABEL (asm_out_file, node->label);
20349 assemble_string (node->str, strlen (node->str) + 1);
20355 #if ENABLE_ASSERT_CHECKING
20356 /* Verify that all marks are clear. */
20359 verify_marks_clear (dw_die_ref die)
20363 gcc_assert (! die->die_mark);
20364 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
20366 #endif /* ENABLE_ASSERT_CHECKING */
20368 /* Clear the marks for a die and its children.
20369 Be cool if the mark isn't set. */
20372 prune_unmark_dies (dw_die_ref die)
20378 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
20381 /* Given DIE that we're marking as used, find any other dies
20382 it references as attributes and mark them as used. */
20385 prune_unused_types_walk_attribs (dw_die_ref die)
20390 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
20392 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
20394 /* A reference to another DIE.
20395 Make sure that it will get emitted.
20396 If it was broken out into a comdat group, don't follow it. */
20397 if (! use_debug_types
20398 || a->dw_attr == DW_AT_specification
20399 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
20400 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
20402 /* Set the string's refcount to 0 so that prune_unused_types_mark
20403 accounts properly for it. */
20404 if (AT_class (a) == dw_val_class_str)
20405 a->dw_attr_val.v.val_str->refcount = 0;
20409 /* Mark the generic parameters and arguments children DIEs of DIE. */
20412 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
20416 if (die == NULL || die->die_child == NULL)
20418 c = die->die_child;
20421 switch (c->die_tag)
20423 case DW_TAG_template_type_param:
20424 case DW_TAG_template_value_param:
20425 case DW_TAG_GNU_template_template_param:
20426 case DW_TAG_GNU_template_parameter_pack:
20427 prune_unused_types_mark (c, 1);
20433 } while (c && c != die->die_child);
20436 /* Mark DIE as being used. If DOKIDS is true, then walk down
20437 to DIE's children. */
20440 prune_unused_types_mark (dw_die_ref die, int dokids)
20444 if (die->die_mark == 0)
20446 /* We haven't done this node yet. Mark it as used. */
20448 /* If this is the DIE of a generic type instantiation,
20449 mark the children DIEs that describe its generic parms and
20451 prune_unused_types_mark_generic_parms_dies (die);
20453 /* We also have to mark its parents as used.
20454 (But we don't want to mark our parents' kids due to this.) */
20455 if (die->die_parent)
20456 prune_unused_types_mark (die->die_parent, 0);
20458 /* Mark any referenced nodes. */
20459 prune_unused_types_walk_attribs (die);
20461 /* If this node is a specification,
20462 also mark the definition, if it exists. */
20463 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
20464 prune_unused_types_mark (die->die_definition, 1);
20467 if (dokids && die->die_mark != 2)
20469 /* We need to walk the children, but haven't done so yet.
20470 Remember that we've walked the kids. */
20473 /* If this is an array type, we need to make sure our
20474 kids get marked, even if they're types. If we're
20475 breaking out types into comdat sections, do this
20476 for all type definitions. */
20477 if (die->die_tag == DW_TAG_array_type
20478 || (use_debug_types
20479 && is_type_die (die) && ! is_declaration_die (die)))
20480 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
20482 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
20486 /* For local classes, look if any static member functions were emitted
20487 and if so, mark them. */
20490 prune_unused_types_walk_local_classes (dw_die_ref die)
20494 if (die->die_mark == 2)
20497 switch (die->die_tag)
20499 case DW_TAG_structure_type:
20500 case DW_TAG_union_type:
20501 case DW_TAG_class_type:
20504 case DW_TAG_subprogram:
20505 if (!get_AT_flag (die, DW_AT_declaration)
20506 || die->die_definition != NULL)
20507 prune_unused_types_mark (die, 1);
20514 /* Mark children. */
20515 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
20518 /* Walk the tree DIE and mark types that we actually use. */
20521 prune_unused_types_walk (dw_die_ref die)
20525 /* Don't do anything if this node is already marked and
20526 children have been marked as well. */
20527 if (die->die_mark == 2)
20530 switch (die->die_tag)
20532 case DW_TAG_structure_type:
20533 case DW_TAG_union_type:
20534 case DW_TAG_class_type:
20535 if (die->die_perennial_p)
20538 for (c = die->die_parent; c; c = c->die_parent)
20539 if (c->die_tag == DW_TAG_subprogram)
20542 /* Finding used static member functions inside of classes
20543 is needed just for local classes, because for other classes
20544 static member function DIEs with DW_AT_specification
20545 are emitted outside of the DW_TAG_*_type. If we ever change
20546 it, we'd need to call this even for non-local classes. */
20548 prune_unused_types_walk_local_classes (die);
20550 /* It's a type node --- don't mark it. */
20553 case DW_TAG_const_type:
20554 case DW_TAG_packed_type:
20555 case DW_TAG_pointer_type:
20556 case DW_TAG_reference_type:
20557 case DW_TAG_rvalue_reference_type:
20558 case DW_TAG_volatile_type:
20559 case DW_TAG_typedef:
20560 case DW_TAG_array_type:
20561 case DW_TAG_interface_type:
20562 case DW_TAG_friend:
20563 case DW_TAG_variant_part:
20564 case DW_TAG_enumeration_type:
20565 case DW_TAG_subroutine_type:
20566 case DW_TAG_string_type:
20567 case DW_TAG_set_type:
20568 case DW_TAG_subrange_type:
20569 case DW_TAG_ptr_to_member_type:
20570 case DW_TAG_file_type:
20571 if (die->die_perennial_p)
20574 /* It's a type node --- don't mark it. */
20578 /* Mark everything else. */
20582 if (die->die_mark == 0)
20586 /* Now, mark any dies referenced from here. */
20587 prune_unused_types_walk_attribs (die);
20592 /* Mark children. */
20593 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
20596 /* Increment the string counts on strings referred to from DIE's
20600 prune_unused_types_update_strings (dw_die_ref die)
20605 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
20606 if (AT_class (a) == dw_val_class_str)
20608 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
20610 /* Avoid unnecessarily putting strings that are used less than
20611 twice in the hash table. */
20613 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
20616 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
20617 htab_hash_string (s->str),
20619 gcc_assert (*slot == NULL);
20625 /* Remove from the tree DIE any dies that aren't marked. */
20628 prune_unused_types_prune (dw_die_ref die)
20632 gcc_assert (die->die_mark);
20633 prune_unused_types_update_strings (die);
20635 if (! die->die_child)
20638 c = die->die_child;
20640 dw_die_ref prev = c;
20641 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
20642 if (c == die->die_child)
20644 /* No marked children between 'prev' and the end of the list. */
20646 /* No marked children at all. */
20647 die->die_child = NULL;
20650 prev->die_sib = c->die_sib;
20651 die->die_child = prev;
20656 if (c != prev->die_sib)
20658 prune_unused_types_prune (c);
20659 } while (c != die->die_child);
20662 /* Remove dies representing declarations that we never use. */
20665 prune_unused_types (void)
20668 limbo_die_node *node;
20669 comdat_type_node *ctnode;
20671 dw_die_ref base_type;
20673 #if ENABLE_ASSERT_CHECKING
20674 /* All the marks should already be clear. */
20675 verify_marks_clear (comp_unit_die ());
20676 for (node = limbo_die_list; node; node = node->next)
20677 verify_marks_clear (node->die);
20678 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
20679 verify_marks_clear (ctnode->root_die);
20680 #endif /* ENABLE_ASSERT_CHECKING */
20682 /* Mark types that are used in global variables. */
20683 premark_types_used_by_global_vars ();
20685 /* Set the mark on nodes that are actually used. */
20686 prune_unused_types_walk (comp_unit_die ());
20687 for (node = limbo_die_list; node; node = node->next)
20688 prune_unused_types_walk (node->die);
20689 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
20691 prune_unused_types_walk (ctnode->root_die);
20692 prune_unused_types_mark (ctnode->type_die, 1);
20695 /* Also set the mark on nodes referenced from the
20697 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
20698 prune_unused_types_mark (pub->die, 1);
20699 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
20700 prune_unused_types_mark (base_type, 1);
20702 if (debug_str_hash)
20703 htab_empty (debug_str_hash);
20704 prune_unused_types_prune (comp_unit_die ());
20705 for (node = limbo_die_list; node; node = node->next)
20706 prune_unused_types_prune (node->die);
20707 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
20708 prune_unused_types_prune (ctnode->root_die);
20710 /* Leave the marks clear. */
20711 prune_unmark_dies (comp_unit_die ());
20712 for (node = limbo_die_list; node; node = node->next)
20713 prune_unmark_dies (node->die);
20714 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
20715 prune_unmark_dies (ctnode->root_die);
20718 /* Set the parameter to true if there are any relative pathnames in
20721 file_table_relative_p (void ** slot, void *param)
20723 bool *p = (bool *) param;
20724 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
20725 if (!IS_ABSOLUTE_PATH (d->filename))
20733 /* Routines to manipulate hash table of comdat type units. */
20736 htab_ct_hash (const void *of)
20739 const comdat_type_node *const type_node = (const comdat_type_node *) of;
20741 memcpy (&h, type_node->signature, sizeof (h));
20746 htab_ct_eq (const void *of1, const void *of2)
20748 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
20749 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
20751 return (! memcmp (type_node_1->signature, type_node_2->signature,
20752 DWARF_TYPE_SIGNATURE_SIZE));
20755 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
20756 to the location it would have been added, should we know its
20757 DECL_ASSEMBLER_NAME when we added other attributes. This will
20758 probably improve compactness of debug info, removing equivalent
20759 abbrevs, and hide any differences caused by deferring the
20760 computation of the assembler name, triggered by e.g. PCH. */
20763 move_linkage_attr (dw_die_ref die)
20765 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
20766 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
20768 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
20769 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
20773 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
20775 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
20779 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
20781 VEC_pop (dw_attr_node, die->die_attr);
20782 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
20786 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
20787 referenced from typed stack ops and count how often they are used. */
20790 mark_base_types (dw_loc_descr_ref loc)
20792 dw_die_ref base_type = NULL;
20794 for (; loc; loc = loc->dw_loc_next)
20796 switch (loc->dw_loc_opc)
20798 case DW_OP_GNU_regval_type:
20799 case DW_OP_GNU_deref_type:
20800 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
20802 case DW_OP_GNU_convert:
20803 case DW_OP_GNU_reinterpret:
20804 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
20807 case DW_OP_GNU_const_type:
20808 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
20810 case DW_OP_GNU_entry_value:
20811 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
20816 gcc_assert (base_type->die_parent == comp_unit_die ());
20817 if (base_type->die_mark)
20818 base_type->die_mark++;
20821 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
20822 base_type->die_mark = 1;
20827 /* Comparison function for sorting marked base types. */
20830 base_type_cmp (const void *x, const void *y)
20832 dw_die_ref dx = *(const dw_die_ref *) x;
20833 dw_die_ref dy = *(const dw_die_ref *) y;
20834 unsigned int byte_size1, byte_size2;
20835 unsigned int encoding1, encoding2;
20836 if (dx->die_mark > dy->die_mark)
20838 if (dx->die_mark < dy->die_mark)
20840 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
20841 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
20842 if (byte_size1 < byte_size2)
20844 if (byte_size1 > byte_size2)
20846 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
20847 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
20848 if (encoding1 < encoding2)
20850 if (encoding1 > encoding2)
20855 /* Move base types marked by mark_base_types as early as possible
20856 in the CU, sorted by decreasing usage count both to make the
20857 uleb128 references as small as possible and to make sure they
20858 will have die_offset already computed by calc_die_sizes when
20859 sizes of typed stack loc ops is computed. */
20862 move_marked_base_types (void)
20865 dw_die_ref base_type, die, c;
20867 if (VEC_empty (dw_die_ref, base_types))
20870 /* Sort by decreasing usage count, they will be added again in that
20872 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
20873 die = comp_unit_die ();
20874 c = die->die_child;
20877 dw_die_ref prev = c;
20879 while (c->die_mark)
20881 remove_child_with_prev (c, prev);
20882 /* As base types got marked, there must be at least
20883 one node other than DW_TAG_base_type. */
20884 gcc_assert (c != c->die_sib);
20888 while (c != die->die_child);
20889 gcc_assert (die->die_child);
20890 c = die->die_child;
20891 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
20893 base_type->die_mark = 0;
20894 base_type->die_sib = c->die_sib;
20895 c->die_sib = base_type;
20900 /* Helper function for resolve_addr, attempt to resolve
20901 one CONST_STRING, return non-zero if not successful. Similarly verify that
20902 SYMBOL_REFs refer to variables emitted in the current CU. */
20905 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
20909 if (GET_CODE (rtl) == CONST_STRING)
20911 size_t len = strlen (XSTR (rtl, 0)) + 1;
20912 tree t = build_string (len, XSTR (rtl, 0));
20913 tree tlen = size_int (len - 1);
20915 = build_array_type (char_type_node, build_index_type (tlen));
20916 rtl = lookup_constant_def (t);
20917 if (!rtl || !MEM_P (rtl))
20919 rtl = XEXP (rtl, 0);
20920 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
20925 if (GET_CODE (rtl) == SYMBOL_REF
20926 && SYMBOL_REF_DECL (rtl))
20928 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
20930 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
20933 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
20937 if (GET_CODE (rtl) == CONST
20938 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
20944 /* Helper function for resolve_addr, handle one location
20945 expression, return false if at least one CONST_STRING or SYMBOL_REF in
20946 the location list couldn't be resolved. */
20949 resolve_addr_in_expr (dw_loc_descr_ref loc)
20951 dw_loc_descr_ref keep = NULL;
20952 for (; loc; loc = loc->dw_loc_next)
20953 switch (loc->dw_loc_opc)
20956 if (resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
20959 case DW_OP_const4u:
20960 case DW_OP_const8u:
20962 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
20965 case DW_OP_implicit_value:
20966 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
20967 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL))
20970 case DW_OP_GNU_implicit_pointer:
20971 case DW_OP_GNU_parameter_ref:
20972 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
20975 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
20978 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
20979 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
20980 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
20983 case DW_OP_GNU_const_type:
20984 case DW_OP_GNU_regval_type:
20985 case DW_OP_GNU_deref_type:
20986 case DW_OP_GNU_convert:
20987 case DW_OP_GNU_reinterpret:
20988 while (loc->dw_loc_next
20989 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
20991 dw_die_ref base1, base2;
20992 unsigned enc1, enc2, size1, size2;
20993 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
20994 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
20995 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
20996 else if (loc->dw_loc_oprnd1.val_class
20997 == dw_val_class_unsigned_const)
21000 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
21001 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
21002 == dw_val_class_unsigned_const)
21004 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
21005 gcc_assert (base1->die_tag == DW_TAG_base_type
21006 && base2->die_tag == DW_TAG_base_type);
21007 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
21008 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
21009 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
21010 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
21012 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
21013 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
21017 /* Optimize away next DW_OP_GNU_convert after
21018 adjusting LOC's base type die reference. */
21019 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21020 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21021 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
21023 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
21024 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
21027 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21028 point typed stack entry. */
21029 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
21030 keep = loc->dw_loc_next;
21040 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21041 an address in .rodata section if the string literal is emitted there,
21042 or remove the containing location list or replace DW_AT_const_value
21043 with DW_AT_location and empty location expression, if it isn't found
21044 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21045 to something that has been emitted in the current CU. */
21048 resolve_addr (dw_die_ref die)
21052 dw_loc_list_ref *curr, *start, loc;
21055 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21056 switch (AT_class (a))
21058 case dw_val_class_loc_list:
21059 start = curr = AT_loc_list_ptr (a);
21062 /* The same list can be referenced more than once. See if we have
21063 already recorded the result from a previous pass. */
21065 *curr = loc->dw_loc_next;
21066 else if (!loc->resolved_addr)
21068 /* As things stand, we do not expect or allow one die to
21069 reference a suffix of another die's location list chain.
21070 References must be identical or completely separate.
21071 There is therefore no need to cache the result of this
21072 pass on any list other than the first; doing so
21073 would lead to unnecessary writes. */
21076 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
21077 if (!resolve_addr_in_expr ((*curr)->expr))
21079 dw_loc_list_ref next = (*curr)->dw_loc_next;
21080 if (next && (*curr)->ll_symbol)
21082 gcc_assert (!next->ll_symbol);
21083 next->ll_symbol = (*curr)->ll_symbol;
21089 mark_base_types ((*curr)->expr);
21090 curr = &(*curr)->dw_loc_next;
21094 loc->resolved_addr = 1;
21098 loc->dw_loc_next = *start;
21103 remove_AT (die, a->dw_attr);
21107 case dw_val_class_loc:
21108 if (!resolve_addr_in_expr (AT_loc (a)))
21110 remove_AT (die, a->dw_attr);
21114 mark_base_types (AT_loc (a));
21116 case dw_val_class_addr:
21117 if (a->dw_attr == DW_AT_const_value
21118 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
21120 remove_AT (die, a->dw_attr);
21123 if (die->die_tag == DW_TAG_GNU_call_site
21124 && a->dw_attr == DW_AT_abstract_origin)
21126 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
21127 dw_die_ref tdie = lookup_decl_die (tdecl);
21129 && DECL_EXTERNAL (tdecl)
21130 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
21132 force_decl_die (tdecl);
21133 tdie = lookup_decl_die (tdecl);
21137 a->dw_attr_val.val_class = dw_val_class_die_ref;
21138 a->dw_attr_val.v.val_die_ref.die = tdie;
21139 a->dw_attr_val.v.val_die_ref.external = 0;
21143 remove_AT (die, a->dw_attr);
21152 FOR_EACH_CHILD (die, c, resolve_addr (c));
21155 /* Helper routines for optimize_location_lists.
21156 This pass tries to share identical local lists in .debug_loc
21159 /* Iteratively hash operands of LOC opcode. */
21161 static inline hashval_t
21162 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
21164 dw_val_ref val1 = &loc->dw_loc_oprnd1;
21165 dw_val_ref val2 = &loc->dw_loc_oprnd2;
21167 switch (loc->dw_loc_opc)
21169 case DW_OP_const4u:
21170 case DW_OP_const8u:
21174 case DW_OP_const1u:
21175 case DW_OP_const1s:
21176 case DW_OP_const2u:
21177 case DW_OP_const2s:
21178 case DW_OP_const4s:
21179 case DW_OP_const8s:
21183 case DW_OP_plus_uconst:
21219 case DW_OP_deref_size:
21220 case DW_OP_xderef_size:
21221 hash = iterative_hash_object (val1->v.val_int, hash);
21228 gcc_assert (val1->val_class == dw_val_class_loc);
21229 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
21230 hash = iterative_hash_object (offset, hash);
21233 case DW_OP_implicit_value:
21234 hash = iterative_hash_object (val1->v.val_unsigned, hash);
21235 switch (val2->val_class)
21237 case dw_val_class_const:
21238 hash = iterative_hash_object (val2->v.val_int, hash);
21240 case dw_val_class_vec:
21242 unsigned int elt_size = val2->v.val_vec.elt_size;
21243 unsigned int len = val2->v.val_vec.length;
21245 hash = iterative_hash_object (elt_size, hash);
21246 hash = iterative_hash_object (len, hash);
21247 hash = iterative_hash (val2->v.val_vec.array,
21248 len * elt_size, hash);
21251 case dw_val_class_const_double:
21252 hash = iterative_hash_object (val2->v.val_double.low, hash);
21253 hash = iterative_hash_object (val2->v.val_double.high, hash);
21255 case dw_val_class_addr:
21256 hash = iterative_hash_rtx (val2->v.val_addr, hash);
21259 gcc_unreachable ();
21263 case DW_OP_bit_piece:
21264 hash = iterative_hash_object (val1->v.val_int, hash);
21265 hash = iterative_hash_object (val2->v.val_int, hash);
21271 unsigned char dtprel = 0xd1;
21272 hash = iterative_hash_object (dtprel, hash);
21274 hash = iterative_hash_rtx (val1->v.val_addr, hash);
21276 case DW_OP_GNU_implicit_pointer:
21277 hash = iterative_hash_object (val2->v.val_int, hash);
21279 case DW_OP_GNU_entry_value:
21280 hash = hash_loc_operands (val1->v.val_loc, hash);
21282 case DW_OP_GNU_regval_type:
21283 case DW_OP_GNU_deref_type:
21285 unsigned int byte_size
21286 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
21287 unsigned int encoding
21288 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
21289 hash = iterative_hash_object (val1->v.val_int, hash);
21290 hash = iterative_hash_object (byte_size, hash);
21291 hash = iterative_hash_object (encoding, hash);
21294 case DW_OP_GNU_convert:
21295 case DW_OP_GNU_reinterpret:
21296 if (val1->val_class == dw_val_class_unsigned_const)
21298 hash = iterative_hash_object (val1->v.val_unsigned, hash);
21302 case DW_OP_GNU_const_type:
21304 unsigned int byte_size
21305 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
21306 unsigned int encoding
21307 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
21308 hash = iterative_hash_object (byte_size, hash);
21309 hash = iterative_hash_object (encoding, hash);
21310 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
21312 hash = iterative_hash_object (val2->val_class, hash);
21313 switch (val2->val_class)
21315 case dw_val_class_const:
21316 hash = iterative_hash_object (val2->v.val_int, hash);
21318 case dw_val_class_vec:
21320 unsigned int elt_size = val2->v.val_vec.elt_size;
21321 unsigned int len = val2->v.val_vec.length;
21323 hash = iterative_hash_object (elt_size, hash);
21324 hash = iterative_hash_object (len, hash);
21325 hash = iterative_hash (val2->v.val_vec.array,
21326 len * elt_size, hash);
21329 case dw_val_class_const_double:
21330 hash = iterative_hash_object (val2->v.val_double.low, hash);
21331 hash = iterative_hash_object (val2->v.val_double.high, hash);
21334 gcc_unreachable ();
21340 /* Other codes have no operands. */
21346 /* Iteratively hash the whole DWARF location expression LOC. */
21348 static inline hashval_t
21349 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
21351 dw_loc_descr_ref l;
21352 bool sizes_computed = false;
21353 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
21354 size_of_locs (loc);
21356 for (l = loc; l != NULL; l = l->dw_loc_next)
21358 enum dwarf_location_atom opc = l->dw_loc_opc;
21359 hash = iterative_hash_object (opc, hash);
21360 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
21362 size_of_locs (loc);
21363 sizes_computed = true;
21365 hash = hash_loc_operands (l, hash);
21370 /* Compute hash of the whole location list LIST_HEAD. */
21373 hash_loc_list (dw_loc_list_ref list_head)
21375 dw_loc_list_ref curr = list_head;
21376 hashval_t hash = 0;
21378 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
21380 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
21381 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
21383 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
21385 hash = hash_locs (curr->expr, hash);
21387 list_head->hash = hash;
21390 /* Return true if X and Y opcodes have the same operands. */
21393 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
21395 dw_val_ref valx1 = &x->dw_loc_oprnd1;
21396 dw_val_ref valx2 = &x->dw_loc_oprnd2;
21397 dw_val_ref valy1 = &y->dw_loc_oprnd1;
21398 dw_val_ref valy2 = &y->dw_loc_oprnd2;
21400 switch (x->dw_loc_opc)
21402 case DW_OP_const4u:
21403 case DW_OP_const8u:
21407 case DW_OP_const1u:
21408 case DW_OP_const1s:
21409 case DW_OP_const2u:
21410 case DW_OP_const2s:
21411 case DW_OP_const4s:
21412 case DW_OP_const8s:
21416 case DW_OP_plus_uconst:
21452 case DW_OP_deref_size:
21453 case DW_OP_xderef_size:
21454 return valx1->v.val_int == valy1->v.val_int;
21457 gcc_assert (valx1->val_class == dw_val_class_loc
21458 && valy1->val_class == dw_val_class_loc
21459 && x->dw_loc_addr == y->dw_loc_addr);
21460 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
21461 case DW_OP_implicit_value:
21462 if (valx1->v.val_unsigned != valy1->v.val_unsigned
21463 || valx2->val_class != valy2->val_class)
21465 switch (valx2->val_class)
21467 case dw_val_class_const:
21468 return valx2->v.val_int == valy2->v.val_int;
21469 case dw_val_class_vec:
21470 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
21471 && valx2->v.val_vec.length == valy2->v.val_vec.length
21472 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
21473 valx2->v.val_vec.elt_size
21474 * valx2->v.val_vec.length) == 0;
21475 case dw_val_class_const_double:
21476 return valx2->v.val_double.low == valy2->v.val_double.low
21477 && valx2->v.val_double.high == valy2->v.val_double.high;
21478 case dw_val_class_addr:
21479 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
21481 gcc_unreachable ();
21484 case DW_OP_bit_piece:
21485 return valx1->v.val_int == valy1->v.val_int
21486 && valx2->v.val_int == valy2->v.val_int;
21489 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
21490 case DW_OP_GNU_implicit_pointer:
21491 return valx1->val_class == dw_val_class_die_ref
21492 && valx1->val_class == valy1->val_class
21493 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
21494 && valx2->v.val_int == valy2->v.val_int;
21495 case DW_OP_GNU_entry_value:
21496 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
21497 case DW_OP_GNU_const_type:
21498 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
21499 || valx2->val_class != valy2->val_class)
21501 switch (valx2->val_class)
21503 case dw_val_class_const:
21504 return valx2->v.val_int == valy2->v.val_int;
21505 case dw_val_class_vec:
21506 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
21507 && valx2->v.val_vec.length == valy2->v.val_vec.length
21508 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
21509 valx2->v.val_vec.elt_size
21510 * valx2->v.val_vec.length) == 0;
21511 case dw_val_class_const_double:
21512 return valx2->v.val_double.low == valy2->v.val_double.low
21513 && valx2->v.val_double.high == valy2->v.val_double.high;
21515 gcc_unreachable ();
21517 case DW_OP_GNU_regval_type:
21518 case DW_OP_GNU_deref_type:
21519 return valx1->v.val_int == valy1->v.val_int
21520 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
21521 case DW_OP_GNU_convert:
21522 case DW_OP_GNU_reinterpret:
21523 if (valx1->val_class != valy1->val_class)
21525 if (valx1->val_class == dw_val_class_unsigned_const)
21526 return valx1->v.val_unsigned == valy1->v.val_unsigned;
21527 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
21528 case DW_OP_GNU_parameter_ref:
21529 return valx1->val_class == dw_val_class_die_ref
21530 && valx1->val_class == valy1->val_class
21531 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
21533 /* Other codes have no operands. */
21538 /* Return true if DWARF location expressions X and Y are the same. */
21541 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
21543 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
21544 if (x->dw_loc_opc != y->dw_loc_opc
21545 || x->dtprel != y->dtprel
21546 || !compare_loc_operands (x, y))
21548 return x == NULL && y == NULL;
21551 /* Return precomputed hash of location list X. */
21554 loc_list_hash (const void *x)
21556 return ((const struct dw_loc_list_struct *) x)->hash;
21559 /* Return 1 if location lists X and Y are the same. */
21562 loc_list_eq (const void *x, const void *y)
21564 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
21565 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
21568 if (a->hash != b->hash)
21570 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
21571 if (strcmp (a->begin, b->begin) != 0
21572 || strcmp (a->end, b->end) != 0
21573 || (a->section == NULL) != (b->section == NULL)
21574 || (a->section && strcmp (a->section, b->section) != 0)
21575 || !compare_locs (a->expr, b->expr))
21577 return a == NULL && b == NULL;
21580 /* Recursively optimize location lists referenced from DIE
21581 children and share them whenever possible. */
21584 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
21591 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21592 if (AT_class (a) == dw_val_class_loc_list)
21594 dw_loc_list_ref list = AT_loc_list (a);
21595 /* TODO: perform some optimizations here, before hashing
21596 it and storing into the hash table. */
21597 hash_loc_list (list);
21598 slot = htab_find_slot_with_hash (htab, list, list->hash,
21601 *slot = (void *) list;
21603 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
21606 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
21609 /* Optimize location lists referenced from DIE
21610 children and share them whenever possible. */
21613 optimize_location_lists (dw_die_ref die)
21615 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
21616 optimize_location_lists_1 (die, htab);
21617 htab_delete (htab);
21620 /* Output stuff that dwarf requires at the end of every file,
21621 and generate the DWARF-2 debugging info. */
21624 dwarf2out_finish (const char *filename)
21626 limbo_die_node *node, *next_node;
21627 comdat_type_node *ctnode;
21628 htab_t comdat_type_table;
21631 gen_scheduled_generic_parms_dies ();
21632 gen_remaining_tmpl_value_param_die_attribute ();
21634 /* Add the name for the main input file now. We delayed this from
21635 dwarf2out_init to avoid complications with PCH. */
21636 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
21637 if (!IS_ABSOLUTE_PATH (filename))
21638 add_comp_dir_attribute (comp_unit_die ());
21639 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
21642 htab_traverse (file_table, file_table_relative_p, &p);
21644 add_comp_dir_attribute (comp_unit_die ());
21647 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
21649 add_location_or_const_value_attribute (
21650 VEC_index (deferred_locations, deferred_locations_list, i)->die,
21651 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
21656 /* Traverse the limbo die list, and add parent/child links. The only
21657 dies without parents that should be here are concrete instances of
21658 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
21659 For concrete instances, we can get the parent die from the abstract
21661 for (node = limbo_die_list; node; node = next_node)
21663 dw_die_ref die = node->die;
21664 next_node = node->next;
21666 if (die->die_parent == NULL)
21668 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
21670 if (origin && origin->die_parent)
21671 add_child_die (origin->die_parent, die);
21672 else if (is_cu_die (die))
21674 else if (seen_error ())
21675 /* It's OK to be confused by errors in the input. */
21676 add_child_die (comp_unit_die (), die);
21679 /* In certain situations, the lexical block containing a
21680 nested function can be optimized away, which results
21681 in the nested function die being orphaned. Likewise
21682 with the return type of that nested function. Force
21683 this to be a child of the containing function.
21685 It may happen that even the containing function got fully
21686 inlined and optimized out. In that case we are lost and
21687 assign the empty child. This should not be big issue as
21688 the function is likely unreachable too. */
21689 tree context = NULL_TREE;
21691 gcc_assert (node->created_for);
21693 if (DECL_P (node->created_for))
21694 context = DECL_CONTEXT (node->created_for);
21695 else if (TYPE_P (node->created_for))
21696 context = TYPE_CONTEXT (node->created_for);
21698 gcc_assert (context
21699 && (TREE_CODE (context) == FUNCTION_DECL
21700 || TREE_CODE (context) == NAMESPACE_DECL));
21702 origin = lookup_decl_die (context);
21704 add_child_die (origin, die);
21706 add_child_die (comp_unit_die (), die);
21711 limbo_die_list = NULL;
21713 #if ENABLE_ASSERT_CHECKING
21715 dw_die_ref die = comp_unit_die (), c;
21716 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
21719 resolve_addr (comp_unit_die ());
21720 move_marked_base_types ();
21722 for (node = deferred_asm_name; node; node = node->next)
21724 tree decl = node->created_for;
21725 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
21727 add_linkage_attr (node->die, decl);
21728 move_linkage_attr (node->die);
21732 deferred_asm_name = NULL;
21734 /* Walk through the list of incomplete types again, trying once more to
21735 emit full debugging info for them. */
21736 retry_incomplete_types ();
21738 if (flag_eliminate_unused_debug_types)
21739 prune_unused_types ();
21741 /* Generate separate CUs for each of the include files we've seen.
21742 They will go into limbo_die_list. */
21743 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
21744 break_out_includes (comp_unit_die ());
21746 /* Generate separate COMDAT sections for type DIEs. */
21747 if (use_debug_types)
21749 break_out_comdat_types (comp_unit_die ());
21751 /* Each new type_unit DIE was added to the limbo die list when created.
21752 Since these have all been added to comdat_type_list, clear the
21754 limbo_die_list = NULL;
21756 /* For each new comdat type unit, copy declarations for incomplete
21757 types to make the new unit self-contained (i.e., no direct
21758 references to the main compile unit). */
21759 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
21760 copy_decls_for_unworthy_types (ctnode->root_die);
21761 copy_decls_for_unworthy_types (comp_unit_die ());
21763 /* In the process of copying declarations from one unit to another,
21764 we may have left some declarations behind that are no longer
21765 referenced. Prune them. */
21766 prune_unused_types ();
21769 /* Traverse the DIE's and add add sibling attributes to those DIE's
21770 that have children. */
21771 add_sibling_attributes (comp_unit_die ());
21772 for (node = limbo_die_list; node; node = node->next)
21773 add_sibling_attributes (node->die);
21774 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
21775 add_sibling_attributes (ctnode->root_die);
21777 /* Output a terminator label for the .text section. */
21778 switch_to_section (text_section);
21779 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
21780 if (cold_text_section)
21782 switch_to_section (cold_text_section);
21783 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
21786 /* We can only use the low/high_pc attributes if all of the code was
21788 if (!have_multiple_function_sections
21789 || (dwarf_version < 3 && dwarf_strict))
21791 /* Don't add if the CU has no associated code. */
21792 if (text_section_used)
21794 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
21795 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
21802 bool range_list_added = false;
21804 if (text_section_used)
21805 add_ranges_by_labels (comp_unit_die (), text_section_label,
21806 text_end_label, &range_list_added);
21807 if (cold_text_section_used)
21808 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
21809 cold_end_label, &range_list_added);
21811 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
21813 if (!fde->in_std_section)
21814 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
21815 fde->dw_fde_end, &range_list_added);
21816 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
21817 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
21818 fde->dw_fde_second_end, &range_list_added);
21821 if (range_list_added)
21823 /* We need to give .debug_loc and .debug_ranges an appropriate
21824 "base address". Use zero so that these addresses become
21825 absolute. Historically, we've emitted the unexpected
21826 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
21827 Emit both to give time for other tools to adapt. */
21828 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
21829 if (! dwarf_strict && dwarf_version < 4)
21830 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
21836 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21837 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
21838 debug_line_section_label);
21840 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21841 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
21843 if (have_location_lists)
21844 optimize_location_lists (comp_unit_die ());
21846 /* Output all of the compilation units. We put the main one last so that
21847 the offsets are available to output_pubnames. */
21848 for (node = limbo_die_list; node; node = node->next)
21849 output_comp_unit (node->die, 0);
21851 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
21852 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
21854 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
21856 /* Don't output duplicate types. */
21857 if (*slot != HTAB_EMPTY_ENTRY)
21860 /* Add a pointer to the line table for the main compilation unit
21861 so that the debugger can make sense of DW_AT_decl_file
21863 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21864 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
21865 debug_line_section_label);
21867 output_comdat_type_unit (ctnode);
21870 htab_delete (comdat_type_table);
21872 /* Output the main compilation unit if non-empty or if .debug_macinfo
21873 will be emitted. */
21874 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
21876 /* Output the abbreviation table. */
21877 if (abbrev_die_table_in_use != 1)
21879 switch_to_section (debug_abbrev_section);
21880 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
21881 output_abbrev_section ();
21884 /* Output location list section if necessary. */
21885 if (have_location_lists)
21887 /* Output the location lists info. */
21888 switch_to_section (debug_loc_section);
21889 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
21890 DEBUG_LOC_SECTION_LABEL, 0);
21891 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
21892 output_location_lists (comp_unit_die ());
21895 /* Output public names table if necessary. */
21896 if (!VEC_empty (pubname_entry, pubname_table))
21898 gcc_assert (info_section_emitted);
21899 switch_to_section (debug_pubnames_section);
21900 output_pubnames (pubname_table);
21903 /* Output public types table if necessary. */
21904 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
21905 It shouldn't hurt to emit it always, since pure DWARF2 consumers
21906 simply won't look for the section. */
21907 if (!VEC_empty (pubname_entry, pubtype_table))
21909 bool empty = false;
21911 if (flag_eliminate_unused_debug_types)
21913 /* The pubtypes table might be emptied by pruning unused items. */
21917 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
21918 if (p->die->die_offset != 0)
21926 gcc_assert (info_section_emitted);
21927 switch_to_section (debug_pubtypes_section);
21928 output_pubnames (pubtype_table);
21932 /* Output the address range information if a CU (.debug_info section)
21933 was emitted. We output an empty table even if we had no functions
21934 to put in it. This because the consumer has no way to tell the
21935 difference between an empty table that we omitted and failure to
21936 generate a table that would have contained data. */
21937 if (info_section_emitted)
21939 unsigned long aranges_length = size_of_aranges ();
21941 switch_to_section (debug_aranges_section);
21942 output_aranges (aranges_length);
21945 /* Output ranges section if necessary. */
21946 if (ranges_table_in_use)
21948 switch_to_section (debug_ranges_section);
21949 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
21953 /* Output the source line correspondence table. We must do this
21954 even if there is no line information. Otherwise, on an empty
21955 translation unit, we will generate a present, but empty,
21956 .debug_info section. IRIX 6.5 `nm' will then complain when
21957 examining the file. This is done late so that any filenames
21958 used by the debug_info section are marked as 'used'. */
21959 switch_to_section (debug_line_section);
21960 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
21961 if (! DWARF2_ASM_LINE_DEBUG_INFO)
21962 output_line_info ();
21964 /* Have to end the macro section. */
21965 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21967 switch_to_section (debug_macinfo_section);
21968 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
21969 if (!VEC_empty (macinfo_entry, macinfo_table))
21971 dw2_asm_output_data (1, 0, "End compilation unit");
21974 /* If we emitted any DW_FORM_strp form attribute, output the string
21976 if (debug_str_hash)
21977 htab_traverse (debug_str_hash, output_indirect_string, NULL);
21980 #include "gt-dwarf2out.h"