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"
99 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
100 static rtx last_var_location_insn;
102 #ifdef VMS_DEBUGGING_INFO
103 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
105 /* Define this macro to be a nonzero value if the directory specifications
106 which are output in the debug info should end with a separator. */
107 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
108 /* Define this macro to evaluate to a nonzero value if GCC should refrain
109 from generating indirect strings in DWARF2 debug information, for instance
110 if your target is stuck with an old version of GDB that is unable to
111 process them properly or uses VMS Debug. */
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
114 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
115 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
118 /* ??? Poison these here until it can be done generically. They've been
119 totally replaced in this file; make sure it stays that way. */
120 #undef DWARF2_UNWIND_INFO
121 #undef DWARF2_FRAME_INFO
122 #if (GCC_VERSION >= 3000)
123 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
126 /* The size of the target's pointer type. */
128 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
131 /* Array of RTXes referenced by the debugging information, which therefore
132 must be kept around forever. */
133 static GTY(()) VEC(rtx,gc) *used_rtx_array;
135 /* A pointer to the base of a list of incomplete types which might be
136 completed at some later time. incomplete_types_list needs to be a
137 VEC(tree,gc) because we want to tell the garbage collector about
139 static GTY(()) VEC(tree,gc) *incomplete_types;
141 /* A pointer to the base of a table of references to declaration
142 scopes. This table is a display which tracks the nesting
143 of declaration scopes at the current scope and containing
144 scopes. This table is used to find the proper place to
145 define type declaration DIE's. */
146 static GTY(()) VEC(tree,gc) *decl_scope_table;
148 /* Pointers to various DWARF2 sections. */
149 static GTY(()) section *debug_info_section;
150 static GTY(()) section *debug_abbrev_section;
151 static GTY(()) section *debug_aranges_section;
152 static GTY(()) section *debug_macinfo_section;
153 static GTY(()) section *debug_line_section;
154 static GTY(()) section *debug_loc_section;
155 static GTY(()) section *debug_pubnames_section;
156 static GTY(()) section *debug_pubtypes_section;
157 static GTY(()) section *debug_str_section;
158 static GTY(()) section *debug_ranges_section;
159 static GTY(()) section *debug_frame_section;
161 /* Maximum size (in bytes) of an artificially generated label. */
162 #define MAX_ARTIFICIAL_LABEL_BYTES 30
164 /* According to the (draft) DWARF 3 specification, the initial length
165 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
166 bytes are 0xffffffff, followed by the length stored in the next 8
169 However, the SGI/MIPS ABI uses an initial length which is equal to
170 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
172 #ifndef DWARF_INITIAL_LENGTH_SIZE
173 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
176 /* Round SIZE up to the nearest BOUNDARY. */
177 #define DWARF_ROUND(SIZE,BOUNDARY) \
178 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
180 /* CIE identifier. */
181 #if HOST_BITS_PER_WIDE_INT >= 64
182 #define DWARF_CIE_ID \
183 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
185 #define DWARF_CIE_ID DW_CIE_ID
188 DEF_VEC_P (dw_fde_ref);
189 DEF_VEC_ALLOC_P (dw_fde_ref, gc);
191 /* A vector for a table that contains frame description
192 information for each routine. */
193 static GTY(()) VEC(dw_fde_ref, gc) *fde_vec;
195 struct GTY(()) indirect_string_node {
197 unsigned int refcount;
198 enum dwarf_form form;
202 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
204 static GTY(()) int dw2_string_counter;
206 /* True if the compilation unit places functions in more than one section. */
207 static GTY(()) bool have_multiple_function_sections = false;
209 /* Whether the default text and cold text sections have been used at all. */
211 static GTY(()) bool text_section_used = false;
212 static GTY(()) bool cold_text_section_used = false;
214 /* The default cold text section. */
215 static GTY(()) section *cold_text_section;
217 /* Forward declarations for functions defined in this file. */
219 static char *stripattributes (const char *);
220 static void output_call_frame_info (int);
221 static void dwarf2out_note_section_used (void);
223 /* Personality decl of current unit. Used only when assembler does not support
225 static GTY(()) rtx current_unit_personality;
227 /* Data and reference forms for relocatable data. */
228 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
229 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
231 #ifndef DEBUG_FRAME_SECTION
232 #define DEBUG_FRAME_SECTION ".debug_frame"
235 #ifndef FUNC_BEGIN_LABEL
236 #define FUNC_BEGIN_LABEL "LFB"
239 #ifndef FUNC_END_LABEL
240 #define FUNC_END_LABEL "LFE"
243 #ifndef PROLOGUE_END_LABEL
244 #define PROLOGUE_END_LABEL "LPE"
247 #ifndef EPILOGUE_BEGIN_LABEL
248 #define EPILOGUE_BEGIN_LABEL "LEB"
251 #ifndef FRAME_BEGIN_LABEL
252 #define FRAME_BEGIN_LABEL "Lframe"
254 #define CIE_AFTER_SIZE_LABEL "LSCIE"
255 #define CIE_END_LABEL "LECIE"
256 #define FDE_LABEL "LSFDE"
257 #define FDE_AFTER_SIZE_LABEL "LASFDE"
258 #define FDE_END_LABEL "LEFDE"
259 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
260 #define LINE_NUMBER_END_LABEL "LELT"
261 #define LN_PROLOG_AS_LABEL "LASLTP"
262 #define LN_PROLOG_END_LABEL "LELTP"
263 #define DIE_LABEL_PREFIX "DW"
265 /* Match the base name of a file to the base name of a compilation unit. */
268 matches_main_base (const char *path)
270 /* Cache the last query. */
271 static const char *last_path = NULL;
272 static int last_match = 0;
273 if (path != last_path)
276 int length = base_of_path (path, &base);
278 last_match = (length == main_input_baselength
279 && memcmp (base, main_input_basename, length) == 0);
284 #ifdef DEBUG_DEBUG_STRUCT
287 dump_struct_debug (tree type, enum debug_info_usage usage,
288 enum debug_struct_file criterion, int generic,
289 int matches, int result)
291 /* Find the type name. */
292 tree type_decl = TYPE_STUB_DECL (type);
294 const char *name = 0;
295 if (TREE_CODE (t) == TYPE_DECL)
298 name = IDENTIFIER_POINTER (t);
300 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
302 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
303 matches ? "bas" : "hdr",
304 generic ? "gen" : "ord",
305 usage == DINFO_USAGE_DFN ? ";" :
306 usage == DINFO_USAGE_DIR_USE ? "." : "*",
308 (void*) type_decl, name);
311 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
312 dump_struct_debug (type, usage, criterion, generic, matches, result)
316 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
322 should_emit_struct_debug (tree type, enum debug_info_usage usage)
324 enum debug_struct_file criterion;
326 bool generic = lang_hooks.types.generic_p (type);
329 criterion = debug_struct_generic[usage];
331 criterion = debug_struct_ordinary[usage];
333 if (criterion == DINFO_STRUCT_FILE_NONE)
334 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
335 if (criterion == DINFO_STRUCT_FILE_ANY)
336 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
338 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
340 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
341 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
343 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
344 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
345 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
348 /* Return a pointer to a copy of the section string name S with all
349 attributes stripped off, and an asterisk prepended (for assemble_name). */
352 stripattributes (const char *s)
354 char *stripped = XNEWVEC (char, strlen (s) + 2);
359 while (*s && *s != ',')
366 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
367 switch to the data section instead, and write out a synthetic start label
368 for collect2 the first time around. */
371 switch_to_eh_frame_section (bool back)
375 #ifdef EH_FRAME_SECTION_NAME
376 if (eh_frame_section == 0)
380 if (EH_TABLES_CAN_BE_READ_ONLY)
386 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
388 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
390 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
393 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
394 && (fde_encoding & 0x70) != DW_EH_PE_aligned
395 && (per_encoding & 0x70) != DW_EH_PE_absptr
396 && (per_encoding & 0x70) != DW_EH_PE_aligned
397 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
398 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
399 ? 0 : SECTION_WRITE);
402 flags = SECTION_WRITE;
403 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
405 #endif /* EH_FRAME_SECTION_NAME */
407 if (eh_frame_section)
408 switch_to_section (eh_frame_section);
411 /* We have no special eh_frame section. Put the information in
412 the data section and emit special labels to guide collect2. */
413 switch_to_section (data_section);
417 label = get_file_function_name ("F");
418 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
419 targetm.asm_out.globalize_label (asm_out_file,
420 IDENTIFIER_POINTER (label));
421 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
426 /* Switch [BACK] to the eh or debug frame table section, depending on
430 switch_to_frame_table_section (int for_eh, bool back)
433 switch_to_eh_frame_section (back);
436 if (!debug_frame_section)
437 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
438 SECTION_DEBUG, NULL);
439 switch_to_section (debug_frame_section);
443 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
445 enum dw_cfi_oprnd_type
446 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
451 case DW_CFA_GNU_window_save:
452 case DW_CFA_remember_state:
453 case DW_CFA_restore_state:
454 return dw_cfi_oprnd_unused;
457 case DW_CFA_advance_loc1:
458 case DW_CFA_advance_loc2:
459 case DW_CFA_advance_loc4:
460 case DW_CFA_MIPS_advance_loc8:
461 return dw_cfi_oprnd_addr;
464 case DW_CFA_offset_extended:
466 case DW_CFA_offset_extended_sf:
467 case DW_CFA_def_cfa_sf:
469 case DW_CFA_restore_extended:
470 case DW_CFA_undefined:
471 case DW_CFA_same_value:
472 case DW_CFA_def_cfa_register:
473 case DW_CFA_register:
474 case DW_CFA_expression:
475 return dw_cfi_oprnd_reg_num;
477 case DW_CFA_def_cfa_offset:
478 case DW_CFA_GNU_args_size:
479 case DW_CFA_def_cfa_offset_sf:
480 return dw_cfi_oprnd_offset;
482 case DW_CFA_def_cfa_expression:
483 return dw_cfi_oprnd_loc;
490 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
492 enum dw_cfi_oprnd_type
493 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
498 case DW_CFA_def_cfa_sf:
500 case DW_CFA_offset_extended_sf:
501 case DW_CFA_offset_extended:
502 return dw_cfi_oprnd_offset;
504 case DW_CFA_register:
505 return dw_cfi_oprnd_reg_num;
507 case DW_CFA_expression:
508 return dw_cfi_oprnd_loc;
511 return dw_cfi_oprnd_unused;
515 /* Output one FDE. */
518 output_fde (dw_fde_ref fde, bool for_eh, bool second,
519 char *section_start_label, int fde_encoding, char *augmentation,
520 bool any_lsda_needed, int lsda_encoding)
523 const char *begin, *end;
524 static unsigned int j;
528 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
530 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
532 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
533 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
534 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
535 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
536 " indicating 64-bit DWARF extension");
537 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
539 ASM_OUTPUT_LABEL (asm_out_file, l1);
542 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
544 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
545 debug_frame_section, "FDE CIE offset");
547 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
548 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
552 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
553 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
554 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
555 "FDE initial location");
556 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
557 end, begin, "FDE address range");
561 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
562 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
569 int size = size_of_encoded_value (lsda_encoding);
571 if (lsda_encoding == DW_EH_PE_aligned)
573 int offset = ( 4 /* Length */
575 + 2 * size_of_encoded_value (fde_encoding)
576 + 1 /* Augmentation size */ );
577 int pad = -offset & (PTR_SIZE - 1);
580 gcc_assert (size_of_uleb128 (size) == 1);
583 dw2_asm_output_data_uleb128 (size, "Augmentation size");
585 if (fde->uses_eh_lsda)
587 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
588 fde->funcdef_number);
589 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
590 gen_rtx_SYMBOL_REF (Pmode, l1),
592 "Language Specific Data Area");
596 if (lsda_encoding == DW_EH_PE_aligned)
597 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
598 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
599 "Language Specific Data Area (none)");
603 dw2_asm_output_data_uleb128 (0, "Augmentation size");
606 /* Loop through the Call Frame Instructions associated with
608 fde->dw_fde_current_label = begin;
609 if (fde->dw_fde_second_begin == NULL)
610 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
611 output_cfi (cfi, fde, for_eh);
614 if (fde->dw_fde_switch_cfi_index > 0)
615 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
617 if (ix == fde->dw_fde_switch_cfi_index)
619 output_cfi (cfi, fde, for_eh);
625 int until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
627 if (fde->dw_fde_switch_cfi_index > 0)
629 from = fde->dw_fde_switch_cfi_index;
630 output_cfis (fde->dw_fde_cfi, from, false, fde, for_eh);
632 for (i = from; i < until; i++)
633 output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i),
637 /* If we are to emit a ref/link from function bodies to their frame tables,
638 do it now. This is typically performed to make sure that tables
639 associated with functions are dragged with them and not discarded in
640 garbage collecting links. We need to do this on a per function basis to
641 cope with -ffunction-sections. */
643 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
644 /* Switch to the function section, emit the ref to the tables, and
645 switch *back* into the table section. */
646 switch_to_section (function_section (fde->decl));
647 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
648 switch_to_frame_table_section (for_eh, true);
651 /* Pad the FDE out to an address sized boundary. */
652 ASM_OUTPUT_ALIGN (asm_out_file,
653 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
654 ASM_OUTPUT_LABEL (asm_out_file, l2);
659 /* Return true if frame description entry FDE is needed for EH. */
662 fde_needed_for_eh_p (dw_fde_ref fde)
664 if (flag_asynchronous_unwind_tables)
667 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
670 if (fde->uses_eh_lsda)
673 /* If exceptions are enabled, we have collected nothrow info. */
674 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
680 /* Output the call frame information used to record information
681 that relates to calculating the frame pointer, and records the
682 location of saved registers. */
685 output_call_frame_info (int for_eh)
690 char l1[20], l2[20], section_start_label[20];
691 bool any_lsda_needed = false;
692 char augmentation[6];
693 int augmentation_size;
694 int fde_encoding = DW_EH_PE_absptr;
695 int per_encoding = DW_EH_PE_absptr;
696 int lsda_encoding = DW_EH_PE_absptr;
698 rtx personality = NULL;
701 /* Don't emit a CIE if there won't be any FDEs. */
705 /* Nothing to do if the assembler's doing it all. */
706 if (dwarf2out_do_cfi_asm ())
709 /* If we don't have any functions we'll want to unwind out of, don't emit
710 any EH unwind information. If we make FDEs linkonce, we may have to
711 emit an empty label for an FDE that wouldn't otherwise be emitted. We
712 want to avoid having an FDE kept around when the function it refers to
713 is discarded. Example where this matters: a primary function template
714 in C++ requires EH information, an explicit specialization doesn't. */
717 bool any_eh_needed = false;
719 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, i, fde)
721 if (fde->uses_eh_lsda)
722 any_eh_needed = any_lsda_needed = true;
723 else if (fde_needed_for_eh_p (fde))
724 any_eh_needed = true;
725 else if (TARGET_USES_WEAK_UNWIND_INFO)
726 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, 1, 1);
733 /* We're going to be generating comments, so turn on app. */
737 /* Switch to the proper frame section, first time. */
738 switch_to_frame_table_section (for_eh, false);
740 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
741 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
743 /* Output the CIE. */
744 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
745 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
746 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
747 dw2_asm_output_data (4, 0xffffffff,
748 "Initial length escape value indicating 64-bit DWARF extension");
749 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
750 "Length of Common Information Entry");
751 ASM_OUTPUT_LABEL (asm_out_file, l1);
753 /* Now that the CIE pointer is PC-relative for EH,
754 use 0 to identify the CIE. */
755 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
756 (for_eh ? 0 : DWARF_CIE_ID),
757 "CIE Identifier Tag");
759 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
760 use CIE version 1, unless that would produce incorrect results
761 due to overflowing the return register column. */
762 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
764 if (return_reg >= 256 || dwarf_version > 2)
766 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
769 augmentation_size = 0;
771 personality = current_unit_personality;
777 z Indicates that a uleb128 is present to size the
778 augmentation section.
779 L Indicates the encoding (and thus presence) of
780 an LSDA pointer in the FDE augmentation.
781 R Indicates a non-default pointer encoding for
783 P Indicates the presence of an encoding + language
784 personality routine in the CIE augmentation. */
786 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
787 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
788 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
790 p = augmentation + 1;
794 augmentation_size += 1 + size_of_encoded_value (per_encoding);
795 assemble_external_libcall (personality);
800 augmentation_size += 1;
802 if (fde_encoding != DW_EH_PE_absptr)
805 augmentation_size += 1;
807 if (p > augmentation + 1)
809 augmentation[0] = 'z';
813 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
814 if (personality && per_encoding == DW_EH_PE_aligned)
816 int offset = ( 4 /* Length */
818 + 1 /* CIE version */
819 + strlen (augmentation) + 1 /* Augmentation */
820 + size_of_uleb128 (1) /* Code alignment */
821 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
823 + 1 /* Augmentation size */
824 + 1 /* Personality encoding */ );
825 int pad = -offset & (PTR_SIZE - 1);
827 augmentation_size += pad;
829 /* Augmentations should be small, so there's scarce need to
830 iterate for a solution. Die if we exceed one uleb128 byte. */
831 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
835 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
836 if (dw_cie_version >= 4)
838 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
839 dw2_asm_output_data (1, 0, "CIE Segment Size");
841 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
842 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
843 "CIE Data Alignment Factor");
845 if (dw_cie_version == 1)
846 dw2_asm_output_data (1, return_reg, "CIE RA Column");
848 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
852 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
855 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
856 eh_data_format_name (per_encoding));
857 dw2_asm_output_encoded_addr_rtx (per_encoding,
863 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
864 eh_data_format_name (lsda_encoding));
866 if (fde_encoding != DW_EH_PE_absptr)
867 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
868 eh_data_format_name (fde_encoding));
871 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, i, cfi)
872 output_cfi (cfi, NULL, for_eh);
874 /* Pad the CIE out to an address sized boundary. */
875 ASM_OUTPUT_ALIGN (asm_out_file,
876 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
877 ASM_OUTPUT_LABEL (asm_out_file, l2);
879 /* Loop through all of the FDE's. */
880 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, i, fde)
884 /* Don't emit EH unwind info for leaf functions that don't need it. */
885 if (for_eh && !fde_needed_for_eh_p (fde))
888 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
889 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
890 augmentation, any_lsda_needed, lsda_encoding);
893 if (for_eh && targetm.terminate_dw2_eh_frame_info)
894 dw2_asm_output_data (4, 0, "End of Table");
895 #ifdef MIPS_DEBUGGING_INFO
896 /* Work around Irix 6 assembler bug whereby labels at the end of a section
897 get a value of 0. Putting .align 0 after the label fixes it. */
898 ASM_OUTPUT_ALIGN (asm_out_file, 0);
901 /* Turn off app to make assembly quicker. */
906 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
909 dwarf2out_do_cfi_startproc (bool second)
913 rtx personality = get_personality_function (current_function_decl);
915 fprintf (asm_out_file, "\t.cfi_startproc\n");
919 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
922 /* ??? The GAS support isn't entirely consistent. We have to
923 handle indirect support ourselves, but PC-relative is done
924 in the assembler. Further, the assembler can't handle any
925 of the weirder relocation types. */
926 if (enc & DW_EH_PE_indirect)
927 ref = dw2_force_const_mem (ref, true);
929 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
930 output_addr_const (asm_out_file, ref);
931 fputc ('\n', asm_out_file);
934 if (crtl->uses_eh_lsda)
938 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
939 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
940 current_function_funcdef_no);
941 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
942 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
944 if (enc & DW_EH_PE_indirect)
945 ref = dw2_force_const_mem (ref, true);
947 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
948 output_addr_const (asm_out_file, ref);
949 fputc ('\n', asm_out_file);
953 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
954 this allocation may be done before pass_final. */
957 dwarf2out_alloc_current_fde (void)
961 fde = ggc_alloc_cleared_dw_fde_node ();
962 fde->decl = current_function_decl;
963 fde->funcdef_number = current_function_funcdef_no;
964 fde->fde_index = VEC_length (dw_fde_ref, fde_vec);
965 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
966 fde->uses_eh_lsda = crtl->uses_eh_lsda;
967 fde->nothrow = crtl->nothrow;
968 fde->drap_reg = INVALID_REGNUM;
969 fde->vdrap_reg = INVALID_REGNUM;
971 /* Record the FDE associated with this function. */
973 VEC_safe_push (dw_fde_ref, gc, fde_vec, fde);
978 /* Output a marker (i.e. a label) for the beginning of a function, before
982 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
983 const char *file ATTRIBUTE_UNUSED)
985 char label[MAX_ARTIFICIAL_LABEL_BYTES];
991 current_function_func_begin_label = NULL;
993 do_frame = dwarf2out_do_frame ();
995 /* ??? current_function_func_begin_label is also used by except.c for
996 call-site information. We must emit this label if it might be used. */
999 || targetm_common.except_unwind_info (&global_options) != UI_TARGET))
1002 fnsec = function_section (current_function_decl);
1003 switch_to_section (fnsec);
1004 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1005 current_function_funcdef_no);
1006 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1007 current_function_funcdef_no);
1008 dup_label = xstrdup (label);
1009 current_function_func_begin_label = dup_label;
1011 /* We can elide the fde allocation if we're not emitting debug info. */
1015 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1016 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1017 would include pass_dwarf2_frame. If we've not created the FDE yet,
1021 fde = dwarf2out_alloc_current_fde ();
1023 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1024 fde->dw_fde_begin = dup_label;
1025 fde->dw_fde_current_label = dup_label;
1026 fde->in_std_section = (fnsec == text_section
1027 || (cold_text_section && fnsec == cold_text_section));
1029 /* We only want to output line number information for the genuine dwarf2
1030 prologue case, not the eh frame case. */
1031 #ifdef DWARF2_DEBUGGING_INFO
1033 dwarf2out_source_line (line, file, 0, true);
1036 if (dwarf2out_do_cfi_asm ())
1037 dwarf2out_do_cfi_startproc (false);
1040 rtx personality = get_personality_function (current_function_decl);
1041 if (!current_unit_personality)
1042 current_unit_personality = personality;
1044 /* We cannot keep a current personality per function as without CFI
1045 asm, at the point where we emit the CFI data, there is no current
1046 function anymore. */
1047 if (personality && current_unit_personality != personality)
1048 sorry ("multiple EH personalities are supported only with assemblers "
1049 "supporting .cfi_personality directive");
1053 /* Output a marker (i.e. a label) for the end of the generated code
1054 for a function prologue. This gets called *after* the prologue code has
1058 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
1059 const char *file ATTRIBUTE_UNUSED)
1061 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1063 /* Output a label to mark the endpoint of the code generated for this
1065 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
1066 current_function_funcdef_no);
1067 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
1068 current_function_funcdef_no);
1069 cfun->fde->dw_fde_vms_end_prologue = xstrdup (label);
1072 /* Output a marker (i.e. a label) for the beginning of the generated code
1073 for a function epilogue. This gets called *before* the prologue code has
1077 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1078 const char *file ATTRIBUTE_UNUSED)
1080 dw_fde_ref fde = cfun->fde;
1081 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1083 if (fde->dw_fde_vms_begin_epilogue)
1086 /* Output a label to mark the endpoint of the code generated for this
1088 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
1089 current_function_funcdef_no);
1090 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
1091 current_function_funcdef_no);
1092 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
1095 /* Output a marker (i.e. a label) for the absolute end of the generated code
1096 for a function definition. This gets called *after* the epilogue code has
1100 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1101 const char *file ATTRIBUTE_UNUSED)
1104 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1106 last_var_location_insn = NULL_RTX;
1108 if (dwarf2out_do_cfi_asm ())
1109 fprintf (asm_out_file, "\t.cfi_endproc\n");
1111 /* Output a label to mark the endpoint of the code generated for this
1113 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1114 current_function_funcdef_no);
1115 ASM_OUTPUT_LABEL (asm_out_file, label);
1117 gcc_assert (fde != NULL);
1118 if (fde->dw_fde_second_begin == NULL)
1119 fde->dw_fde_end = xstrdup (label);
1123 dwarf2out_frame_finish (void)
1125 /* Output call frame information. */
1126 if (targetm.debug_unwind_info () == UI_DWARF2)
1127 output_call_frame_info (0);
1129 /* Output another copy for the unwinder. */
1130 if ((flag_unwind_tables || flag_exceptions)
1131 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
1132 output_call_frame_info (1);
1135 /* Note that the current function section is being used for code. */
1138 dwarf2out_note_section_used (void)
1140 section *sec = current_function_section ();
1141 if (sec == text_section)
1142 text_section_used = true;
1143 else if (sec == cold_text_section)
1144 cold_text_section_used = true;
1147 static void var_location_switch_text_section (void);
1148 static void set_cur_line_info_table (section *);
1151 dwarf2out_switch_text_section (void)
1154 dw_fde_ref fde = cfun->fde;
1156 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1158 if (!in_cold_section_p)
1160 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
1161 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
1162 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
1166 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1167 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
1168 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1170 have_multiple_function_sections = true;
1172 /* There is no need to mark used sections when not debugging. */
1173 if (cold_text_section != NULL)
1174 dwarf2out_note_section_used ();
1176 if (dwarf2out_do_cfi_asm ())
1177 fprintf (asm_out_file, "\t.cfi_endproc\n");
1179 /* Now do the real section switch. */
1180 sect = current_function_section ();
1181 switch_to_section (sect);
1183 fde->second_in_std_section
1184 = (sect == text_section
1185 || (cold_text_section && sect == cold_text_section));
1187 fde->dw_fde_switch_cfi_index = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
1189 if (dwarf2out_do_cfi_asm ())
1191 dwarf2out_do_cfi_startproc (true);
1192 /* As this is a different FDE, insert all current CFI instructions
1194 output_cfis (fde->dw_fde_cfi, fde->dw_fde_switch_cfi_index,
1198 var_location_switch_text_section ();
1200 set_cur_line_info_table (sect);
1203 /* And now, the subset of the debugging information support code necessary
1204 for emitting location expressions. */
1206 /* Data about a single source file. */
1207 struct GTY(()) dwarf_file_data {
1208 const char * filename;
1212 typedef struct GTY(()) deferred_locations_struct
1216 } deferred_locations;
1218 DEF_VEC_O(deferred_locations);
1219 DEF_VEC_ALLOC_O(deferred_locations,gc);
1221 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
1223 DEF_VEC_P(dw_die_ref);
1224 DEF_VEC_ALLOC_P(dw_die_ref,heap);
1226 /* Location lists are ranges + location descriptions for that range,
1227 so you can track variables that are in different places over
1228 their entire life. */
1229 typedef struct GTY(()) dw_loc_list_struct {
1230 dw_loc_list_ref dw_loc_next;
1231 const char *begin; /* Label for begin address of range */
1232 const char *end; /* Label for end address of range */
1233 char *ll_symbol; /* Label for beginning of location list.
1234 Only on head of list */
1235 const char *section; /* Section this loclist is relative to */
1236 dw_loc_descr_ref expr;
1238 /* True if all addresses in this and subsequent lists are known to be
1241 /* True if this list has been replaced by dw_loc_next. */
1244 /* True if the range should be emitted even if begin and end
1249 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
1251 /* Convert a DWARF stack opcode into its string name. */
1254 dwarf_stack_op_name (unsigned int op)
1259 return "DW_OP_addr";
1261 return "DW_OP_deref";
1263 return "DW_OP_const1u";
1265 return "DW_OP_const1s";
1267 return "DW_OP_const2u";
1269 return "DW_OP_const2s";
1271 return "DW_OP_const4u";
1273 return "DW_OP_const4s";
1275 return "DW_OP_const8u";
1277 return "DW_OP_const8s";
1279 return "DW_OP_constu";
1281 return "DW_OP_consts";
1285 return "DW_OP_drop";
1287 return "DW_OP_over";
1289 return "DW_OP_pick";
1291 return "DW_OP_swap";
1295 return "DW_OP_xderef";
1303 return "DW_OP_minus";
1315 return "DW_OP_plus";
1316 case DW_OP_plus_uconst:
1317 return "DW_OP_plus_uconst";
1323 return "DW_OP_shra";
1341 return "DW_OP_skip";
1343 return "DW_OP_lit0";
1345 return "DW_OP_lit1";
1347 return "DW_OP_lit2";
1349 return "DW_OP_lit3";
1351 return "DW_OP_lit4";
1353 return "DW_OP_lit5";
1355 return "DW_OP_lit6";
1357 return "DW_OP_lit7";
1359 return "DW_OP_lit8";
1361 return "DW_OP_lit9";
1363 return "DW_OP_lit10";
1365 return "DW_OP_lit11";
1367 return "DW_OP_lit12";
1369 return "DW_OP_lit13";
1371 return "DW_OP_lit14";
1373 return "DW_OP_lit15";
1375 return "DW_OP_lit16";
1377 return "DW_OP_lit17";
1379 return "DW_OP_lit18";
1381 return "DW_OP_lit19";
1383 return "DW_OP_lit20";
1385 return "DW_OP_lit21";
1387 return "DW_OP_lit22";
1389 return "DW_OP_lit23";
1391 return "DW_OP_lit24";
1393 return "DW_OP_lit25";
1395 return "DW_OP_lit26";
1397 return "DW_OP_lit27";
1399 return "DW_OP_lit28";
1401 return "DW_OP_lit29";
1403 return "DW_OP_lit30";
1405 return "DW_OP_lit31";
1407 return "DW_OP_reg0";
1409 return "DW_OP_reg1";
1411 return "DW_OP_reg2";
1413 return "DW_OP_reg3";
1415 return "DW_OP_reg4";
1417 return "DW_OP_reg5";
1419 return "DW_OP_reg6";
1421 return "DW_OP_reg7";
1423 return "DW_OP_reg8";
1425 return "DW_OP_reg9";
1427 return "DW_OP_reg10";
1429 return "DW_OP_reg11";
1431 return "DW_OP_reg12";
1433 return "DW_OP_reg13";
1435 return "DW_OP_reg14";
1437 return "DW_OP_reg15";
1439 return "DW_OP_reg16";
1441 return "DW_OP_reg17";
1443 return "DW_OP_reg18";
1445 return "DW_OP_reg19";
1447 return "DW_OP_reg20";
1449 return "DW_OP_reg21";
1451 return "DW_OP_reg22";
1453 return "DW_OP_reg23";
1455 return "DW_OP_reg24";
1457 return "DW_OP_reg25";
1459 return "DW_OP_reg26";
1461 return "DW_OP_reg27";
1463 return "DW_OP_reg28";
1465 return "DW_OP_reg29";
1467 return "DW_OP_reg30";
1469 return "DW_OP_reg31";
1471 return "DW_OP_breg0";
1473 return "DW_OP_breg1";
1475 return "DW_OP_breg2";
1477 return "DW_OP_breg3";
1479 return "DW_OP_breg4";
1481 return "DW_OP_breg5";
1483 return "DW_OP_breg6";
1485 return "DW_OP_breg7";
1487 return "DW_OP_breg8";
1489 return "DW_OP_breg9";
1491 return "DW_OP_breg10";
1493 return "DW_OP_breg11";
1495 return "DW_OP_breg12";
1497 return "DW_OP_breg13";
1499 return "DW_OP_breg14";
1501 return "DW_OP_breg15";
1503 return "DW_OP_breg16";
1505 return "DW_OP_breg17";
1507 return "DW_OP_breg18";
1509 return "DW_OP_breg19";
1511 return "DW_OP_breg20";
1513 return "DW_OP_breg21";
1515 return "DW_OP_breg22";
1517 return "DW_OP_breg23";
1519 return "DW_OP_breg24";
1521 return "DW_OP_breg25";
1523 return "DW_OP_breg26";
1525 return "DW_OP_breg27";
1527 return "DW_OP_breg28";
1529 return "DW_OP_breg29";
1531 return "DW_OP_breg30";
1533 return "DW_OP_breg31";
1535 return "DW_OP_regx";
1537 return "DW_OP_fbreg";
1539 return "DW_OP_bregx";
1541 return "DW_OP_piece";
1542 case DW_OP_deref_size:
1543 return "DW_OP_deref_size";
1544 case DW_OP_xderef_size:
1545 return "DW_OP_xderef_size";
1549 case DW_OP_push_object_address:
1550 return "DW_OP_push_object_address";
1552 return "DW_OP_call2";
1554 return "DW_OP_call4";
1555 case DW_OP_call_ref:
1556 return "DW_OP_call_ref";
1557 case DW_OP_implicit_value:
1558 return "DW_OP_implicit_value";
1559 case DW_OP_stack_value:
1560 return "DW_OP_stack_value";
1561 case DW_OP_form_tls_address:
1562 return "DW_OP_form_tls_address";
1563 case DW_OP_call_frame_cfa:
1564 return "DW_OP_call_frame_cfa";
1565 case DW_OP_bit_piece:
1566 return "DW_OP_bit_piece";
1568 case DW_OP_GNU_push_tls_address:
1569 return "DW_OP_GNU_push_tls_address";
1570 case DW_OP_GNU_uninit:
1571 return "DW_OP_GNU_uninit";
1572 case DW_OP_GNU_encoded_addr:
1573 return "DW_OP_GNU_encoded_addr";
1574 case DW_OP_GNU_implicit_pointer:
1575 return "DW_OP_GNU_implicit_pointer";
1576 case DW_OP_GNU_entry_value:
1577 return "DW_OP_GNU_entry_value";
1578 case DW_OP_GNU_const_type:
1579 return "DW_OP_GNU_const_type";
1580 case DW_OP_GNU_regval_type:
1581 return "DW_OP_GNU_regval_type";
1582 case DW_OP_GNU_deref_type:
1583 return "DW_OP_GNU_deref_type";
1584 case DW_OP_GNU_convert:
1585 return "DW_OP_GNU_convert";
1586 case DW_OP_GNU_reinterpret:
1587 return "DW_OP_GNU_reinterpret";
1588 case DW_OP_GNU_parameter_ref:
1589 return "DW_OP_GNU_parameter_ref";
1592 return "OP_<unknown>";
1596 /* Return a pointer to a newly allocated location description. Location
1597 descriptions are simple expression terms that can be strung
1598 together to form more complicated location (address) descriptions. */
1600 static inline dw_loc_descr_ref
1601 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
1602 unsigned HOST_WIDE_INT oprnd2)
1604 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
1606 descr->dw_loc_opc = op;
1607 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
1608 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
1609 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
1610 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
1615 /* Return a pointer to a newly allocated location description for
1618 static inline dw_loc_descr_ref
1619 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
1622 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
1625 return new_loc_descr (DW_OP_bregx, reg, offset);
1628 /* Add a location description term to a location description expression. */
1631 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
1633 dw_loc_descr_ref *d;
1635 /* Find the end of the chain. */
1636 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
1642 /* Add a constant OFFSET to a location expression. */
1645 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
1647 dw_loc_descr_ref loc;
1650 gcc_assert (*list_head != NULL);
1655 /* Find the end of the chain. */
1656 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
1660 if (loc->dw_loc_opc == DW_OP_fbreg
1661 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
1662 p = &loc->dw_loc_oprnd1.v.val_int;
1663 else if (loc->dw_loc_opc == DW_OP_bregx)
1664 p = &loc->dw_loc_oprnd2.v.val_int;
1666 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1667 offset. Don't optimize if an signed integer overflow would happen. */
1669 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
1670 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
1673 else if (offset > 0)
1674 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
1678 loc->dw_loc_next = int_loc_descriptor (-offset);
1679 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
1683 /* Add a constant OFFSET to a location list. */
1686 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
1689 for (d = list_head; d != NULL; d = d->dw_loc_next)
1690 loc_descr_plus_const (&d->expr, offset);
1693 #define DWARF_REF_SIZE \
1694 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1696 static unsigned long int get_base_type_offset (dw_die_ref);
1698 /* Return the size of a location descriptor. */
1700 static unsigned long
1701 size_of_loc_descr (dw_loc_descr_ref loc)
1703 unsigned long size = 1;
1705 switch (loc->dw_loc_opc)
1708 size += DWARF2_ADDR_SIZE;
1727 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1730 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1735 case DW_OP_plus_uconst:
1736 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1774 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1777 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1780 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1783 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1784 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1787 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1789 case DW_OP_bit_piece:
1790 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1791 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
1793 case DW_OP_deref_size:
1794 case DW_OP_xderef_size:
1803 case DW_OP_call_ref:
1804 size += DWARF_REF_SIZE;
1806 case DW_OP_implicit_value:
1807 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1808 + loc->dw_loc_oprnd1.v.val_unsigned;
1810 case DW_OP_GNU_implicit_pointer:
1811 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1813 case DW_OP_GNU_entry_value:
1815 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
1816 size += size_of_uleb128 (op_size) + op_size;
1819 case DW_OP_GNU_const_type:
1822 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1823 size += size_of_uleb128 (o) + 1;
1824 switch (loc->dw_loc_oprnd2.val_class)
1826 case dw_val_class_vec:
1827 size += loc->dw_loc_oprnd2.v.val_vec.length
1828 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
1830 case dw_val_class_const:
1831 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1833 case dw_val_class_const_double:
1834 size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1841 case DW_OP_GNU_regval_type:
1844 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1845 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1846 + size_of_uleb128 (o);
1849 case DW_OP_GNU_deref_type:
1852 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1853 size += 1 + size_of_uleb128 (o);
1856 case DW_OP_GNU_convert:
1857 case DW_OP_GNU_reinterpret:
1858 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
1859 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1863 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1864 size += size_of_uleb128 (o);
1867 case DW_OP_GNU_parameter_ref:
1877 /* Return the size of a series of location descriptors. */
1880 size_of_locs (dw_loc_descr_ref loc)
1885 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1886 field, to avoid writing to a PCH file. */
1887 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1889 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
1891 size += size_of_loc_descr (l);
1896 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
1898 l->dw_loc_addr = size;
1899 size += size_of_loc_descr (l);
1905 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
1906 static void get_ref_die_offset_label (char *, dw_die_ref);
1907 static unsigned long int get_ref_die_offset (dw_die_ref);
1909 /* Output location description stack opcode's operands (if any).
1910 The for_eh_or_skip parameter controls whether register numbers are
1911 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1912 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1913 info). This should be suppressed for the cases that have not been converted
1914 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1917 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
1919 dw_val_ref val1 = &loc->dw_loc_oprnd1;
1920 dw_val_ref val2 = &loc->dw_loc_oprnd2;
1922 switch (loc->dw_loc_opc)
1924 #ifdef DWARF2_DEBUGGING_INFO
1927 dw2_asm_output_data (2, val1->v.val_int, NULL);
1932 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
1933 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
1935 fputc ('\n', asm_out_file);
1940 dw2_asm_output_data (4, val1->v.val_int, NULL);
1945 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
1946 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
1948 fputc ('\n', asm_out_file);
1953 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
1954 dw2_asm_output_data (8, val1->v.val_int, NULL);
1961 gcc_assert (val1->val_class == dw_val_class_loc);
1962 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
1964 dw2_asm_output_data (2, offset, NULL);
1967 case DW_OP_implicit_value:
1968 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
1969 switch (val2->val_class)
1971 case dw_val_class_const:
1972 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
1974 case dw_val_class_vec:
1976 unsigned int elt_size = val2->v.val_vec.elt_size;
1977 unsigned int len = val2->v.val_vec.length;
1981 if (elt_size > sizeof (HOST_WIDE_INT))
1986 for (i = 0, p = val2->v.val_vec.array;
1989 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
1990 "fp or vector constant word %u", i);
1993 case dw_val_class_const_double:
1995 unsigned HOST_WIDE_INT first, second;
1997 if (WORDS_BIG_ENDIAN)
1999 first = val2->v.val_double.high;
2000 second = val2->v.val_double.low;
2004 first = val2->v.val_double.low;
2005 second = val2->v.val_double.high;
2007 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2009 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2013 case dw_val_class_addr:
2014 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
2015 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
2030 case DW_OP_implicit_value:
2031 /* We currently don't make any attempt to make sure these are
2032 aligned properly like we do for the main unwind info, so
2033 don't support emitting things larger than a byte if we're
2034 only doing unwinding. */
2039 dw2_asm_output_data (1, val1->v.val_int, NULL);
2042 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2045 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2048 dw2_asm_output_data (1, val1->v.val_int, NULL);
2050 case DW_OP_plus_uconst:
2051 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2085 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2089 unsigned r = val1->v.val_unsigned;
2090 if (for_eh_or_skip >= 0)
2091 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2092 gcc_assert (size_of_uleb128 (r)
2093 == size_of_uleb128 (val1->v.val_unsigned));
2094 dw2_asm_output_data_uleb128 (r, NULL);
2098 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2102 unsigned r = val1->v.val_unsigned;
2103 if (for_eh_or_skip >= 0)
2104 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2105 gcc_assert (size_of_uleb128 (r)
2106 == size_of_uleb128 (val1->v.val_unsigned));
2107 dw2_asm_output_data_uleb128 (r, NULL);
2108 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2112 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2114 case DW_OP_bit_piece:
2115 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2116 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
2118 case DW_OP_deref_size:
2119 case DW_OP_xderef_size:
2120 dw2_asm_output_data (1, val1->v.val_int, NULL);
2126 if (targetm.asm_out.output_dwarf_dtprel)
2128 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
2131 fputc ('\n', asm_out_file);
2138 #ifdef DWARF2_DEBUGGING_INFO
2139 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2146 case DW_OP_GNU_implicit_pointer:
2148 char label[MAX_ARTIFICIAL_LABEL_BYTES
2149 + HOST_BITS_PER_WIDE_INT / 2 + 2];
2150 gcc_assert (val1->val_class == dw_val_class_die_ref);
2151 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2152 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2153 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2157 case DW_OP_GNU_entry_value:
2158 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2159 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2162 case DW_OP_GNU_const_type:
2164 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2166 dw2_asm_output_data_uleb128 (o, NULL);
2167 switch (val2->val_class)
2169 case dw_val_class_const:
2170 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2171 dw2_asm_output_data (1, l, NULL);
2172 dw2_asm_output_data (l, val2->v.val_int, NULL);
2174 case dw_val_class_vec:
2176 unsigned int elt_size = val2->v.val_vec.elt_size;
2177 unsigned int len = val2->v.val_vec.length;
2182 dw2_asm_output_data (1, l, NULL);
2183 if (elt_size > sizeof (HOST_WIDE_INT))
2188 for (i = 0, p = val2->v.val_vec.array;
2191 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2192 "fp or vector constant word %u", i);
2195 case dw_val_class_const_double:
2197 unsigned HOST_WIDE_INT first, second;
2198 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2200 dw2_asm_output_data (1, 2 * l, NULL);
2201 if (WORDS_BIG_ENDIAN)
2203 first = val2->v.val_double.high;
2204 second = val2->v.val_double.low;
2208 first = val2->v.val_double.low;
2209 second = val2->v.val_double.high;
2211 dw2_asm_output_data (l, first, NULL);
2212 dw2_asm_output_data (l, second, NULL);
2220 case DW_OP_GNU_regval_type:
2222 unsigned r = val1->v.val_unsigned;
2223 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2225 if (for_eh_or_skip >= 0)
2227 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2228 gcc_assert (size_of_uleb128 (r)
2229 == size_of_uleb128 (val1->v.val_unsigned));
2231 dw2_asm_output_data_uleb128 (r, NULL);
2232 dw2_asm_output_data_uleb128 (o, NULL);
2235 case DW_OP_GNU_deref_type:
2237 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2239 dw2_asm_output_data (1, val1->v.val_int, NULL);
2240 dw2_asm_output_data_uleb128 (o, NULL);
2243 case DW_OP_GNU_convert:
2244 case DW_OP_GNU_reinterpret:
2245 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2246 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2249 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2251 dw2_asm_output_data_uleb128 (o, NULL);
2255 case DW_OP_GNU_parameter_ref:
2258 gcc_assert (val1->val_class == dw_val_class_die_ref);
2259 o = get_ref_die_offset (val1->v.val_die_ref.die);
2260 dw2_asm_output_data (4, o, NULL);
2265 /* Other codes have no operands. */
2270 /* Output a sequence of location operations.
2271 The for_eh_or_skip parameter controls whether register numbers are
2272 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2273 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2274 info). This should be suppressed for the cases that have not been converted
2275 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2278 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2280 for (; loc != NULL; loc = loc->dw_loc_next)
2282 enum dwarf_location_atom opc = loc->dw_loc_opc;
2283 /* Output the opcode. */
2284 if (for_eh_or_skip >= 0
2285 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2287 unsigned r = (opc - DW_OP_breg0);
2288 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2289 gcc_assert (r <= 31);
2290 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2292 else if (for_eh_or_skip >= 0
2293 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2295 unsigned r = (opc - DW_OP_reg0);
2296 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2297 gcc_assert (r <= 31);
2298 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2301 dw2_asm_output_data (1, opc,
2302 "%s", dwarf_stack_op_name (opc));
2304 /* Output the operand(s) (if any). */
2305 output_loc_operands (loc, for_eh_or_skip);
2309 /* Output location description stack opcode's operands (if any).
2310 The output is single bytes on a line, suitable for .cfi_escape. */
2313 output_loc_operands_raw (dw_loc_descr_ref loc)
2315 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2316 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2318 switch (loc->dw_loc_opc)
2321 case DW_OP_implicit_value:
2322 /* We cannot output addresses in .cfi_escape, only bytes. */
2328 case DW_OP_deref_size:
2329 case DW_OP_xderef_size:
2330 fputc (',', asm_out_file);
2331 dw2_asm_output_data_raw (1, val1->v.val_int);
2336 fputc (',', asm_out_file);
2337 dw2_asm_output_data_raw (2, val1->v.val_int);
2342 fputc (',', asm_out_file);
2343 dw2_asm_output_data_raw (4, val1->v.val_int);
2348 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2349 fputc (',', asm_out_file);
2350 dw2_asm_output_data_raw (8, val1->v.val_int);
2358 gcc_assert (val1->val_class == dw_val_class_loc);
2359 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2361 fputc (',', asm_out_file);
2362 dw2_asm_output_data_raw (2, offset);
2368 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2369 gcc_assert (size_of_uleb128 (r)
2370 == size_of_uleb128 (val1->v.val_unsigned));
2371 fputc (',', asm_out_file);
2372 dw2_asm_output_data_uleb128_raw (r);
2377 case DW_OP_plus_uconst:
2379 fputc (',', asm_out_file);
2380 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2383 case DW_OP_bit_piece:
2384 fputc (',', asm_out_file);
2385 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2386 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
2423 fputc (',', asm_out_file);
2424 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
2429 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2430 gcc_assert (size_of_uleb128 (r)
2431 == size_of_uleb128 (val1->v.val_unsigned));
2432 fputc (',', asm_out_file);
2433 dw2_asm_output_data_uleb128_raw (r);
2434 fputc (',', asm_out_file);
2435 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
2439 case DW_OP_GNU_implicit_pointer:
2440 case DW_OP_GNU_entry_value:
2441 case DW_OP_GNU_const_type:
2442 case DW_OP_GNU_regval_type:
2443 case DW_OP_GNU_deref_type:
2444 case DW_OP_GNU_convert:
2445 case DW_OP_GNU_reinterpret:
2446 case DW_OP_GNU_parameter_ref:
2451 /* Other codes have no operands. */
2457 output_loc_sequence_raw (dw_loc_descr_ref loc)
2461 enum dwarf_location_atom opc = loc->dw_loc_opc;
2462 /* Output the opcode. */
2463 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2465 unsigned r = (opc - DW_OP_breg0);
2466 r = DWARF2_FRAME_REG_OUT (r, 1);
2467 gcc_assert (r <= 31);
2468 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2470 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2472 unsigned r = (opc - DW_OP_reg0);
2473 r = DWARF2_FRAME_REG_OUT (r, 1);
2474 gcc_assert (r <= 31);
2475 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2477 /* Output the opcode. */
2478 fprintf (asm_out_file, "%#x", opc);
2479 output_loc_operands_raw (loc);
2481 if (!loc->dw_loc_next)
2483 loc = loc->dw_loc_next;
2485 fputc (',', asm_out_file);
2489 /* This function builds a dwarf location descriptor sequence from a
2490 dw_cfa_location, adding the given OFFSET to the result of the
2493 struct dw_loc_descr_struct *
2494 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
2496 struct dw_loc_descr_struct *head, *tmp;
2498 offset += cfa->offset;
2502 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
2503 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2504 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2505 add_loc_descr (&head, tmp);
2508 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
2509 add_loc_descr (&head, tmp);
2513 head = new_reg_loc_descr (cfa->reg, offset);
2518 /* This function builds a dwarf location descriptor sequence for
2519 the address at OFFSET from the CFA when stack is aligned to
2522 struct dw_loc_descr_struct *
2523 build_cfa_aligned_loc (dw_cfa_location *cfa,
2524 HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
2526 struct dw_loc_descr_struct *head;
2527 unsigned int dwarf_fp
2528 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
2530 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2531 if (cfa->reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
2533 head = new_reg_loc_descr (dwarf_fp, 0);
2534 add_loc_descr (&head, int_loc_descriptor (alignment));
2535 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
2536 loc_descr_plus_const (&head, offset);
2539 head = new_reg_loc_descr (dwarf_fp, offset);
2543 /* And now, the support for symbolic debugging information. */
2545 /* .debug_str support. */
2546 static int output_indirect_string (void **, void *);
2548 static void dwarf2out_init (const char *);
2549 static void dwarf2out_finish (const char *);
2550 static void dwarf2out_assembly_start (void);
2551 static void dwarf2out_define (unsigned int, const char *);
2552 static void dwarf2out_undef (unsigned int, const char *);
2553 static void dwarf2out_start_source_file (unsigned, const char *);
2554 static void dwarf2out_end_source_file (unsigned);
2555 static void dwarf2out_function_decl (tree);
2556 static void dwarf2out_begin_block (unsigned, unsigned);
2557 static void dwarf2out_end_block (unsigned, unsigned);
2558 static bool dwarf2out_ignore_block (const_tree);
2559 static void dwarf2out_global_decl (tree);
2560 static void dwarf2out_type_decl (tree, int);
2561 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
2562 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
2564 static void dwarf2out_abstract_function (tree);
2565 static void dwarf2out_var_location (rtx);
2566 static void dwarf2out_begin_function (tree);
2567 static void dwarf2out_set_name (tree, tree);
2569 /* The debug hooks structure. */
2571 const struct gcc_debug_hooks dwarf2_debug_hooks =
2575 dwarf2out_assembly_start,
2578 dwarf2out_start_source_file,
2579 dwarf2out_end_source_file,
2580 dwarf2out_begin_block,
2581 dwarf2out_end_block,
2582 dwarf2out_ignore_block,
2583 dwarf2out_source_line,
2584 dwarf2out_begin_prologue,
2585 #if VMS_DEBUGGING_INFO
2586 dwarf2out_vms_end_prologue,
2587 dwarf2out_vms_begin_epilogue,
2589 debug_nothing_int_charstar,
2590 debug_nothing_int_charstar,
2592 dwarf2out_end_epilogue,
2593 dwarf2out_begin_function,
2594 debug_nothing_int, /* end_function */
2595 dwarf2out_function_decl, /* function_decl */
2596 dwarf2out_global_decl,
2597 dwarf2out_type_decl, /* type_decl */
2598 dwarf2out_imported_module_or_decl,
2599 debug_nothing_tree, /* deferred_inline_function */
2600 /* The DWARF 2 backend tries to reduce debugging bloat by not
2601 emitting the abstract description of inline functions until
2602 something tries to reference them. */
2603 dwarf2out_abstract_function, /* outlining_inline_function */
2604 debug_nothing_rtx, /* label */
2605 debug_nothing_int, /* handle_pch */
2606 dwarf2out_var_location,
2607 dwarf2out_switch_text_section,
2609 1, /* start_end_main_source_file */
2610 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
2613 /* NOTE: In the comments in this file, many references are made to
2614 "Debugging Information Entries". This term is abbreviated as `DIE'
2615 throughout the remainder of this file. */
2617 /* An internal representation of the DWARF output is built, and then
2618 walked to generate the DWARF debugging info. The walk of the internal
2619 representation is done after the entire program has been compiled.
2620 The types below are used to describe the internal representation. */
2622 /* Whether to put type DIEs into their own section .debug_types instead
2623 of making them part of the .debug_info section. Only supported for
2624 Dwarf V4 or higher and the user didn't disable them through
2625 -fno-debug-types-section. It is more efficient to put them in a
2626 separate comdat sections since the linker will then be able to
2627 remove duplicates. But not all tools support .debug_types sections
2630 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2632 /* Various DIE's use offsets relative to the beginning of the
2633 .debug_info section to refer to each other. */
2635 typedef long int dw_offset;
2637 /* Define typedefs here to avoid circular dependencies. */
2639 typedef struct dw_attr_struct *dw_attr_ref;
2640 typedef struct dw_line_info_struct *dw_line_info_ref;
2641 typedef struct pubname_struct *pubname_ref;
2642 typedef struct dw_ranges_struct *dw_ranges_ref;
2643 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
2644 typedef struct comdat_type_struct *comdat_type_node_ref;
2646 /* The entries in the line_info table more-or-less mirror the opcodes
2647 that are used in the real dwarf line table. Arrays of these entries
2648 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2651 enum dw_line_info_opcode {
2652 /* Emit DW_LNE_set_address; the operand is the label index. */
2655 /* Emit a row to the matrix with the given line. This may be done
2656 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2660 /* Emit a DW_LNS_set_file. */
2663 /* Emit a DW_LNS_set_column. */
2666 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2669 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2670 LI_set_prologue_end,
2671 LI_set_epilogue_begin,
2673 /* Emit a DW_LNE_set_discriminator. */
2674 LI_set_discriminator
2677 typedef struct GTY(()) dw_line_info_struct {
2678 enum dw_line_info_opcode opcode;
2680 } dw_line_info_entry;
2682 DEF_VEC_O(dw_line_info_entry);
2683 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
2685 typedef struct GTY(()) dw_line_info_table_struct {
2686 /* The label that marks the end of this section. */
2687 const char *end_label;
2689 /* The values for the last row of the matrix, as collected in the table.
2690 These are used to minimize the changes to the next row. */
2691 unsigned int file_num;
2692 unsigned int line_num;
2693 unsigned int column_num;
2698 VEC(dw_line_info_entry, gc) *entries;
2699 } dw_line_info_table;
2701 typedef dw_line_info_table *dw_line_info_table_p;
2703 DEF_VEC_P(dw_line_info_table_p);
2704 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
2706 /* Each DIE attribute has a field specifying the attribute kind,
2707 a link to the next attribute in the chain, and an attribute value.
2708 Attributes are typically linked below the DIE they modify. */
2710 typedef struct GTY(()) dw_attr_struct {
2711 enum dwarf_attribute dw_attr;
2712 dw_val_node dw_attr_val;
2716 DEF_VEC_O(dw_attr_node);
2717 DEF_VEC_ALLOC_O(dw_attr_node,gc);
2719 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2720 The children of each node form a circular list linked by
2721 die_sib. die_child points to the node *before* the "first" child node. */
2723 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
2724 union die_symbol_or_type_node
2726 char * GTY ((tag ("0"))) die_symbol;
2727 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
2729 GTY ((desc ("use_debug_types"))) die_id;
2730 VEC(dw_attr_node,gc) * die_attr;
2731 dw_die_ref die_parent;
2732 dw_die_ref die_child;
2734 dw_die_ref die_definition; /* ref from a specification to its definition */
2735 dw_offset die_offset;
2736 unsigned long die_abbrev;
2738 /* Die is used and must not be pruned as unused. */
2739 int die_perennial_p;
2740 unsigned int decl_id;
2741 enum dwarf_tag die_tag;
2745 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2746 #define FOR_EACH_CHILD(die, c, expr) do { \
2747 c = die->die_child; \
2751 } while (c != die->die_child); \
2754 /* The pubname structure */
2756 typedef struct GTY(()) pubname_struct {
2762 DEF_VEC_O(pubname_entry);
2763 DEF_VEC_ALLOC_O(pubname_entry, gc);
2765 struct GTY(()) dw_ranges_struct {
2766 /* If this is positive, it's a block number, otherwise it's a
2767 bitwise-negated index into dw_ranges_by_label. */
2771 /* A structure to hold a macinfo entry. */
2773 typedef struct GTY(()) macinfo_struct {
2775 unsigned HOST_WIDE_INT lineno;
2780 DEF_VEC_O(macinfo_entry);
2781 DEF_VEC_ALLOC_O(macinfo_entry, gc);
2783 struct GTY(()) dw_ranges_by_label_struct {
2788 /* The comdat type node structure. */
2789 typedef struct GTY(()) comdat_type_struct
2791 dw_die_ref root_die;
2792 dw_die_ref type_die;
2793 char signature[DWARF_TYPE_SIGNATURE_SIZE];
2794 struct comdat_type_struct *next;
2798 /* The limbo die list structure. */
2799 typedef struct GTY(()) limbo_die_struct {
2802 struct limbo_die_struct *next;
2806 typedef struct skeleton_chain_struct
2810 struct skeleton_chain_struct *parent;
2812 skeleton_chain_node;
2814 /* Define a macro which returns nonzero for a TYPE_DECL which was
2815 implicitly generated for a type.
2817 Note that, unlike the C front-end (which generates a NULL named
2818 TYPE_DECL node for each complete tagged type, each array type,
2819 and each function type node created) the C++ front-end generates
2820 a _named_ TYPE_DECL node for each tagged type node created.
2821 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2822 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2823 front-end, but for each type, tagged or not. */
2825 #define TYPE_DECL_IS_STUB(decl) \
2826 (DECL_NAME (decl) == NULL_TREE \
2827 || (DECL_ARTIFICIAL (decl) \
2828 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2829 /* This is necessary for stub decls that \
2830 appear in nested inline functions. */ \
2831 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2832 && (decl_ultimate_origin (decl) \
2833 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2835 /* Information concerning the compilation unit's programming
2836 language, and compiler version. */
2838 /* Fixed size portion of the DWARF compilation unit header. */
2839 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2840 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2842 /* Fixed size portion of the DWARF comdat type unit header. */
2843 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2844 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2845 + DWARF_OFFSET_SIZE)
2847 /* Fixed size portion of public names info. */
2848 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2850 /* Fixed size portion of the address range info. */
2851 #define DWARF_ARANGES_HEADER_SIZE \
2852 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2853 DWARF2_ADDR_SIZE * 2) \
2854 - DWARF_INITIAL_LENGTH_SIZE)
2856 /* Size of padding portion in the address range info. It must be
2857 aligned to twice the pointer size. */
2858 #define DWARF_ARANGES_PAD_SIZE \
2859 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2860 DWARF2_ADDR_SIZE * 2) \
2861 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2863 /* Use assembler line directives if available. */
2864 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2865 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2866 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2868 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2872 /* Minimum line offset in a special line info. opcode.
2873 This value was chosen to give a reasonable range of values. */
2874 #define DWARF_LINE_BASE -10
2876 /* First special line opcode - leave room for the standard opcodes. */
2877 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2879 /* Range of line offsets in a special line info. opcode. */
2880 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2882 /* Flag that indicates the initial value of the is_stmt_start flag.
2883 In the present implementation, we do not mark any lines as
2884 the beginning of a source statement, because that information
2885 is not made available by the GCC front-end. */
2886 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2888 /* Maximum number of operations per instruction bundle. */
2889 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2890 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2893 /* This location is used by calc_die_sizes() to keep track
2894 the offset of each DIE within the .debug_info section. */
2895 static unsigned long next_die_offset;
2897 /* Record the root of the DIE's built for the current compilation unit. */
2898 static GTY(()) dw_die_ref single_comp_unit_die;
2900 /* A list of type DIEs that have been separated into comdat sections. */
2901 static GTY(()) comdat_type_node *comdat_type_list;
2903 /* A list of DIEs with a NULL parent waiting to be relocated. */
2904 static GTY(()) limbo_die_node *limbo_die_list;
2906 /* A list of DIEs for which we may have to generate
2907 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2908 static GTY(()) limbo_die_node *deferred_asm_name;
2910 /* Filenames referenced by this compilation unit. */
2911 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
2913 /* A hash table of references to DIE's that describe declarations.
2914 The key is a DECL_UID() which is a unique number identifying each decl. */
2915 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
2917 /* A hash table of references to DIE's that describe COMMON blocks.
2918 The key is DECL_UID() ^ die_parent. */
2919 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
2921 typedef struct GTY(()) die_arg_entry_struct {
2926 DEF_VEC_O(die_arg_entry);
2927 DEF_VEC_ALLOC_O(die_arg_entry,gc);
2929 /* Node of the variable location list. */
2930 struct GTY ((chain_next ("%h.next"))) var_loc_node {
2931 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2932 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2933 in mode of the EXPR_LIST node and first EXPR_LIST operand
2934 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2935 location or NULL for padding. For larger bitsizes,
2936 mode is 0 and first operand is a CONCAT with bitsize
2937 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2938 NULL as second operand. */
2940 const char * GTY (()) label;
2941 struct var_loc_node * GTY (()) next;
2944 /* Variable location list. */
2945 struct GTY (()) var_loc_list_def {
2946 struct var_loc_node * GTY (()) first;
2948 /* Pointer to the last but one or last element of the
2949 chained list. If the list is empty, both first and
2950 last are NULL, if the list contains just one node
2951 or the last node certainly is not redundant, it points
2952 to the last node, otherwise points to the last but one.
2953 Do not mark it for GC because it is marked through the chain. */
2954 struct var_loc_node * GTY ((skip ("%h"))) last;
2956 /* Pointer to the last element before section switch,
2957 if NULL, either sections weren't switched or first
2958 is after section switch. */
2959 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
2961 /* DECL_UID of the variable decl. */
2962 unsigned int decl_id;
2964 typedef struct var_loc_list_def var_loc_list;
2966 /* Call argument location list. */
2967 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
2968 rtx GTY (()) call_arg_loc_note;
2969 const char * GTY (()) label;
2970 tree GTY (()) block;
2972 rtx GTY (()) symbol_ref;
2973 struct call_arg_loc_node * GTY (()) next;
2977 /* Table of decl location linked lists. */
2978 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
2980 /* Head and tail of call_arg_loc chain. */
2981 static GTY (()) struct call_arg_loc_node *call_arg_locations;
2982 static struct call_arg_loc_node *call_arg_loc_last;
2984 /* Number of call sites in the current function. */
2985 static int call_site_count = -1;
2986 /* Number of tail call sites in the current function. */
2987 static int tail_call_site_count = -1;
2989 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2991 static VEC (dw_die_ref, heap) *block_map;
2993 /* A cached location list. */
2994 struct GTY (()) cached_dw_loc_list_def {
2995 /* The DECL_UID of the decl that this entry describes. */
2996 unsigned int decl_id;
2998 /* The cached location list. */
2999 dw_loc_list_ref loc_list;
3001 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
3003 /* Table of cached location lists. */
3004 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
3006 /* A pointer to the base of a list of references to DIE's that
3007 are uniquely identified by their tag, presence/absence of
3008 children DIE's, and list of attribute/value pairs. */
3009 static GTY((length ("abbrev_die_table_allocated")))
3010 dw_die_ref *abbrev_die_table;
3012 /* Number of elements currently allocated for abbrev_die_table. */
3013 static GTY(()) unsigned abbrev_die_table_allocated;
3015 /* Number of elements in type_die_table currently in use. */
3016 static GTY(()) unsigned abbrev_die_table_in_use;
3018 /* Size (in elements) of increments by which we may expand the
3019 abbrev_die_table. */
3020 #define ABBREV_DIE_TABLE_INCREMENT 256
3022 /* A global counter for generating labels for line number data. */
3023 static unsigned int line_info_label_num;
3025 /* The current table to which we should emit line number information
3026 for the current function. This will be set up at the beginning of
3027 assembly for the function. */
3028 static dw_line_info_table *cur_line_info_table;
3030 /* The two default tables of line number info. */
3031 static GTY(()) dw_line_info_table *text_section_line_info;
3032 static GTY(()) dw_line_info_table *cold_text_section_line_info;
3034 /* The set of all non-default tables of line number info. */
3035 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
3037 /* A flag to tell pubnames/types export if there is an info section to
3039 static bool info_section_emitted;
3041 /* A pointer to the base of a table that contains a list of publicly
3042 accessible names. */
3043 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
3045 /* A pointer to the base of a table that contains a list of publicly
3046 accessible types. */
3047 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
3049 /* A pointer to the base of a table that contains a list of macro
3050 defines/undefines (and file start/end markers). */
3051 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
3053 /* Array of dies for which we should generate .debug_ranges info. */
3054 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3056 /* Number of elements currently allocated for ranges_table. */
3057 static GTY(()) unsigned ranges_table_allocated;
3059 /* Number of elements in ranges_table currently in use. */
3060 static GTY(()) unsigned ranges_table_in_use;
3062 /* Array of pairs of labels referenced in ranges_table. */
3063 static GTY ((length ("ranges_by_label_allocated")))
3064 dw_ranges_by_label_ref ranges_by_label;
3066 /* Number of elements currently allocated for ranges_by_label. */
3067 static GTY(()) unsigned ranges_by_label_allocated;
3069 /* Number of elements in ranges_by_label currently in use. */
3070 static GTY(()) unsigned ranges_by_label_in_use;
3072 /* Size (in elements) of increments by which we may expand the
3074 #define RANGES_TABLE_INCREMENT 64
3076 /* Whether we have location lists that need outputting */
3077 static GTY(()) bool have_location_lists;
3079 /* Unique label counter. */
3080 static GTY(()) unsigned int loclabel_num;
3082 /* Unique label counter for point-of-call tables. */
3083 static GTY(()) unsigned int poc_label_num;
3085 /* Record whether the function being analyzed contains inlined functions. */
3086 static int current_function_has_inlines;
3088 /* The last file entry emitted by maybe_emit_file(). */
3089 static GTY(()) struct dwarf_file_data * last_emitted_file;
3091 /* Number of internal labels generated by gen_internal_sym(). */
3092 static GTY(()) int label_num;
3094 /* Cached result of previous call to lookup_filename. */
3095 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
3097 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
3099 /* Instances of generic types for which we need to generate debug
3100 info that describe their generic parameters and arguments. That
3101 generation needs to happen once all types are properly laid out so
3102 we do it at the end of compilation. */
3103 static GTY(()) VEC(tree,gc) *generic_type_instances;
3105 /* Offset from the "steady-state frame pointer" to the frame base,
3106 within the current function. */
3107 static HOST_WIDE_INT frame_pointer_fb_offset;
3108 static bool frame_pointer_fb_offset_valid;
3110 static VEC (dw_die_ref, heap) *base_types;
3112 /* Forward declarations for functions defined in this file. */
3114 static int is_pseudo_reg (const_rtx);
3115 static tree type_main_variant (tree);
3116 static int is_tagged_type (const_tree);
3117 static const char *dwarf_tag_name (unsigned);
3118 static const char *dwarf_attr_name (unsigned);
3119 static const char *dwarf_form_name (unsigned);
3120 static tree decl_ultimate_origin (const_tree);
3121 static tree decl_class_context (tree);
3122 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3123 static inline enum dw_val_class AT_class (dw_attr_ref);
3124 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3125 static inline unsigned AT_flag (dw_attr_ref);
3126 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3127 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3128 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3129 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3130 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3131 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3132 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3133 unsigned int, unsigned char *);
3134 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3135 static hashval_t debug_str_do_hash (const void *);
3136 static int debug_str_eq (const void *, const void *);
3137 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3138 static inline const char *AT_string (dw_attr_ref);
3139 static enum dwarf_form AT_string_form (dw_attr_ref);
3140 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3141 static void add_AT_specification (dw_die_ref, dw_die_ref);
3142 static inline dw_die_ref AT_ref (dw_attr_ref);
3143 static inline int AT_ref_external (dw_attr_ref);
3144 static inline void set_AT_ref_external (dw_attr_ref, int);
3145 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3146 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3147 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3148 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3150 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3151 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3152 static inline rtx AT_addr (dw_attr_ref);
3153 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3154 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3155 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3156 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3157 unsigned HOST_WIDE_INT);
3158 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3160 static inline const char *AT_lbl (dw_attr_ref);
3161 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3162 static const char *get_AT_low_pc (dw_die_ref);
3163 static const char *get_AT_hi_pc (dw_die_ref);
3164 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3165 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3166 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3167 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3168 static bool is_cxx (void);
3169 static bool is_fortran (void);
3170 static bool is_ada (void);
3171 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3172 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3173 static void add_child_die (dw_die_ref, dw_die_ref);
3174 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3175 static dw_die_ref lookup_type_die (tree);
3176 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3177 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3178 static void equate_type_number_to_die (tree, dw_die_ref);
3179 static hashval_t decl_die_table_hash (const void *);
3180 static int decl_die_table_eq (const void *, const void *);
3181 static dw_die_ref lookup_decl_die (tree);
3182 static hashval_t common_block_die_table_hash (const void *);
3183 static int common_block_die_table_eq (const void *, const void *);
3184 static hashval_t decl_loc_table_hash (const void *);
3185 static int decl_loc_table_eq (const void *, const void *);
3186 static var_loc_list *lookup_decl_loc (const_tree);
3187 static void equate_decl_number_to_die (tree, dw_die_ref);
3188 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
3189 static void print_spaces (FILE *);
3190 static void print_die (dw_die_ref, FILE *);
3191 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3192 static dw_die_ref pop_compile_unit (dw_die_ref);
3193 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3194 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3195 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3196 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3197 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3198 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3199 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
3200 struct md5_ctx *, int *);
3201 struct checksum_attributes;
3202 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3203 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3204 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3205 static void generate_type_signature (dw_die_ref, comdat_type_node *);
3206 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3207 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3208 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3209 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3210 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3211 static void compute_section_prefix (dw_die_ref);
3212 static int is_type_die (dw_die_ref);
3213 static int is_comdat_die (dw_die_ref);
3214 static int is_symbol_die (dw_die_ref);
3215 static void assign_symbol_names (dw_die_ref);
3216 static void break_out_includes (dw_die_ref);
3217 static int is_declaration_die (dw_die_ref);
3218 static int should_move_die_to_comdat (dw_die_ref);
3219 static dw_die_ref clone_as_declaration (dw_die_ref);
3220 static dw_die_ref clone_die (dw_die_ref);
3221 static dw_die_ref clone_tree (dw_die_ref);
3222 static void copy_declaration_context (dw_die_ref, dw_die_ref);
3223 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3224 static void generate_skeleton_bottom_up (skeleton_chain_node *);
3225 static dw_die_ref generate_skeleton (dw_die_ref);
3226 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3228 static void break_out_comdat_types (dw_die_ref);
3229 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
3230 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
3231 static void copy_decls_for_unworthy_types (dw_die_ref);
3233 static hashval_t htab_cu_hash (const void *);
3234 static int htab_cu_eq (const void *, const void *);
3235 static void htab_cu_del (void *);
3236 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3237 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3238 static void add_sibling_attributes (dw_die_ref);
3239 static void build_abbrev_table (dw_die_ref);
3240 static void output_location_lists (dw_die_ref);
3241 static int constant_size (unsigned HOST_WIDE_INT);
3242 static unsigned long size_of_die (dw_die_ref);
3243 static void calc_die_sizes (dw_die_ref);
3244 static void calc_base_type_die_sizes (void);
3245 static void mark_dies (dw_die_ref);
3246 static void unmark_dies (dw_die_ref);
3247 static void unmark_all_dies (dw_die_ref);
3248 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
3249 static unsigned long size_of_aranges (void);
3250 static enum dwarf_form value_format (dw_attr_ref);
3251 static void output_value_format (dw_attr_ref);
3252 static void output_abbrev_section (void);
3253 static void output_die_symbol (dw_die_ref);
3254 static void output_die (dw_die_ref);
3255 static void output_compilation_unit_header (void);
3256 static void output_comp_unit (dw_die_ref, int);
3257 static void output_comdat_type_unit (comdat_type_node *);
3258 static const char *dwarf2_name (tree, int);
3259 static void add_pubname (tree, dw_die_ref);
3260 static void add_pubname_string (const char *, dw_die_ref);
3261 static void add_pubtype (tree, dw_die_ref);
3262 static void output_pubnames (VEC (pubname_entry,gc) *);
3263 static void output_aranges (unsigned long);
3264 static unsigned int add_ranges_num (int);
3265 static unsigned int add_ranges (const_tree);
3266 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3268 static void output_ranges (void);
3269 static dw_line_info_table *new_line_info_table (void);
3270 static void output_line_info (void);
3271 static void output_file_names (void);
3272 static dw_die_ref base_type_die (tree);
3273 static int is_base_type (tree);
3274 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
3275 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3276 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3277 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3278 static int type_is_enum (const_tree);
3279 static unsigned int dbx_reg_number (const_rtx);
3280 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3281 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3282 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3283 enum var_init_status);
3284 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3285 enum var_init_status);
3286 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
3287 enum var_init_status);
3288 static int is_based_loc (const_rtx);
3289 static int resolve_one_addr (rtx *, void *);
3290 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3291 enum var_init_status);
3292 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
3293 enum var_init_status);
3294 static dw_loc_list_ref loc_list_from_tree (tree, int);
3295 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3296 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3297 static tree field_type (const_tree);
3298 static unsigned int simple_type_align_in_bits (const_tree);
3299 static unsigned int simple_decl_align_in_bits (const_tree);
3300 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3301 static HOST_WIDE_INT field_byte_offset (const_tree);
3302 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3304 static void add_data_member_location_attribute (dw_die_ref, tree);
3305 static bool add_const_value_attribute (dw_die_ref, rtx);
3306 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3307 static void insert_double (double_int, unsigned char *);
3308 static void insert_float (const_rtx, unsigned char *);
3309 static rtx rtl_for_decl_location (tree);
3310 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
3311 enum dwarf_attribute);
3312 static bool tree_add_const_value_attribute (dw_die_ref, tree);
3313 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3314 static void add_name_attribute (dw_die_ref, const char *);
3315 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3316 static void add_comp_dir_attribute (dw_die_ref);
3317 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3318 static void add_subscript_info (dw_die_ref, tree, bool);
3319 static void add_byte_size_attribute (dw_die_ref, tree);
3320 static void add_bit_offset_attribute (dw_die_ref, tree);
3321 static void add_bit_size_attribute (dw_die_ref, tree);
3322 static void add_prototyped_attribute (dw_die_ref, tree);
3323 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
3324 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3325 static void add_src_coords_attributes (dw_die_ref, tree);
3326 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3327 static void push_decl_scope (tree);
3328 static void pop_decl_scope (void);
3329 static dw_die_ref scope_die_for (tree, dw_die_ref);
3330 static inline int local_scope_p (dw_die_ref);
3331 static inline int class_scope_p (dw_die_ref);
3332 static inline int class_or_namespace_scope_p (dw_die_ref);
3333 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3334 static void add_calling_convention_attribute (dw_die_ref, tree);
3335 static const char *type_tag (const_tree);
3336 static tree member_declared_type (const_tree);
3338 static const char *decl_start_label (tree);
3340 static void gen_array_type_die (tree, dw_die_ref);
3341 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
3343 static void gen_entry_point_die (tree, dw_die_ref);
3345 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
3346 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
3347 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
3348 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3349 static void gen_formal_types_die (tree, dw_die_ref);
3350 static void gen_subprogram_die (tree, dw_die_ref);
3351 static void gen_variable_die (tree, tree, dw_die_ref);
3352 static void gen_const_die (tree, dw_die_ref);
3353 static void gen_label_die (tree, dw_die_ref);
3354 static void gen_lexical_block_die (tree, dw_die_ref, int);
3355 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3356 static void gen_field_die (tree, dw_die_ref);
3357 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3358 static dw_die_ref gen_compile_unit_die (const char *);
3359 static void gen_inheritance_die (tree, tree, dw_die_ref);
3360 static void gen_member_die (tree, dw_die_ref);
3361 static void gen_struct_or_union_type_die (tree, dw_die_ref,
3362 enum debug_info_usage);
3363 static void gen_subroutine_type_die (tree, dw_die_ref);
3364 static void gen_typedef_die (tree, dw_die_ref);
3365 static void gen_type_die (tree, dw_die_ref);
3366 static void gen_block_die (tree, dw_die_ref, int);
3367 static void decls_for_scope (tree, dw_die_ref, int);
3368 static inline int is_redundant_typedef (const_tree);
3369 static bool is_naming_typedef_decl (const_tree);
3370 static inline dw_die_ref get_context_die (tree);
3371 static void gen_namespace_die (tree, dw_die_ref);
3372 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
3373 static dw_die_ref force_decl_die (tree);
3374 static dw_die_ref force_type_die (tree);
3375 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3376 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
3377 static struct dwarf_file_data * lookup_filename (const char *);
3378 static void retry_incomplete_types (void);
3379 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3380 static void gen_generic_params_dies (tree);
3381 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
3382 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
3383 static void splice_child_die (dw_die_ref, dw_die_ref);
3384 static int file_info_cmp (const void *, const void *);
3385 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3386 const char *, const char *);
3387 static void output_loc_list (dw_loc_list_ref);
3388 static char *gen_internal_sym (const char *);
3390 static void prune_unmark_dies (dw_die_ref);
3391 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
3392 static void prune_unused_types_mark (dw_die_ref, int);
3393 static void prune_unused_types_walk (dw_die_ref);
3394 static void prune_unused_types_walk_attribs (dw_die_ref);
3395 static void prune_unused_types_prune (dw_die_ref);
3396 static void prune_unused_types (void);
3397 static int maybe_emit_file (struct dwarf_file_data *fd);
3398 static inline const char *AT_vms_delta1 (dw_attr_ref);
3399 static inline const char *AT_vms_delta2 (dw_attr_ref);
3400 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
3401 const char *, const char *);
3402 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
3403 static void gen_remaining_tmpl_value_param_die_attribute (void);
3404 static bool generic_type_p (tree);
3405 static void schedule_generic_params_dies_gen (tree t);
3406 static void gen_scheduled_generic_parms_dies (void);
3408 /* Section names used to hold DWARF debugging information. */
3409 #ifndef DEBUG_INFO_SECTION
3410 #define DEBUG_INFO_SECTION ".debug_info"
3412 #ifndef DEBUG_ABBREV_SECTION
3413 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3415 #ifndef DEBUG_ARANGES_SECTION
3416 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3418 #ifndef DEBUG_MACINFO_SECTION
3419 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3421 #ifndef DEBUG_MACRO_SECTION
3422 #define DEBUG_MACRO_SECTION ".debug_macro"
3424 #ifndef DEBUG_LINE_SECTION
3425 #define DEBUG_LINE_SECTION ".debug_line"
3427 #ifndef DEBUG_LOC_SECTION
3428 #define DEBUG_LOC_SECTION ".debug_loc"
3430 #ifndef DEBUG_PUBNAMES_SECTION
3431 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3433 #ifndef DEBUG_PUBTYPES_SECTION
3434 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3436 #ifndef DEBUG_STR_SECTION
3437 #define DEBUG_STR_SECTION ".debug_str"
3439 #ifndef DEBUG_RANGES_SECTION
3440 #define DEBUG_RANGES_SECTION ".debug_ranges"
3443 /* Standard ELF section names for compiled code and data. */
3444 #ifndef TEXT_SECTION_NAME
3445 #define TEXT_SECTION_NAME ".text"
3448 /* Section flags for .debug_str section. */
3449 #define DEBUG_STR_SECTION_FLAGS \
3450 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3451 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3454 /* Labels we insert at beginning sections we can reference instead of
3455 the section names themselves. */
3457 #ifndef TEXT_SECTION_LABEL
3458 #define TEXT_SECTION_LABEL "Ltext"
3460 #ifndef COLD_TEXT_SECTION_LABEL
3461 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3463 #ifndef DEBUG_LINE_SECTION_LABEL
3464 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3466 #ifndef DEBUG_INFO_SECTION_LABEL
3467 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3469 #ifndef DEBUG_ABBREV_SECTION_LABEL
3470 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3472 #ifndef DEBUG_LOC_SECTION_LABEL
3473 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3475 #ifndef DEBUG_RANGES_SECTION_LABEL
3476 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3478 #ifndef DEBUG_MACINFO_SECTION_LABEL
3479 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3481 #ifndef DEBUG_MACRO_SECTION_LABEL
3482 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3486 /* Definitions of defaults for formats and names of various special
3487 (artificial) labels which may be generated within this file (when the -g
3488 options is used and DWARF2_DEBUGGING_INFO is in effect.
3489 If necessary, these may be overridden from within the tm.h file, but
3490 typically, overriding these defaults is unnecessary. */
3492 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3493 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3494 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3495 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3496 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3497 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3498 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3499 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3500 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3501 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3503 #ifndef TEXT_END_LABEL
3504 #define TEXT_END_LABEL "Letext"
3506 #ifndef COLD_END_LABEL
3507 #define COLD_END_LABEL "Letext_cold"
3509 #ifndef BLOCK_BEGIN_LABEL
3510 #define BLOCK_BEGIN_LABEL "LBB"
3512 #ifndef BLOCK_END_LABEL
3513 #define BLOCK_END_LABEL "LBE"
3515 #ifndef LINE_CODE_LABEL
3516 #define LINE_CODE_LABEL "LM"
3520 /* Return the root of the DIE's built for the current compilation unit. */
3522 comp_unit_die (void)
3524 if (!single_comp_unit_die)
3525 single_comp_unit_die = gen_compile_unit_die (NULL);
3526 return single_comp_unit_die;
3529 /* We allow a language front-end to designate a function that is to be
3530 called to "demangle" any name before it is put into a DIE. */
3532 static const char *(*demangle_name_func) (const char *);
3535 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3537 demangle_name_func = func;
3540 /* Test if rtl node points to a pseudo register. */
3543 is_pseudo_reg (const_rtx rtl)
3545 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3546 || (GET_CODE (rtl) == SUBREG
3547 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3550 /* Return a reference to a type, with its const and volatile qualifiers
3554 type_main_variant (tree type)
3556 type = TYPE_MAIN_VARIANT (type);
3558 /* ??? There really should be only one main variant among any group of
3559 variants of a given type (and all of the MAIN_VARIANT values for all
3560 members of the group should point to that one type) but sometimes the C
3561 front-end messes this up for array types, so we work around that bug
3563 if (TREE_CODE (type) == ARRAY_TYPE)
3564 while (type != TYPE_MAIN_VARIANT (type))
3565 type = TYPE_MAIN_VARIANT (type);
3570 /* Return nonzero if the given type node represents a tagged type. */
3573 is_tagged_type (const_tree type)
3575 enum tree_code code = TREE_CODE (type);
3577 return (code == RECORD_TYPE || code == UNION_TYPE
3578 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3581 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3584 get_ref_die_offset_label (char *label, dw_die_ref ref)
3586 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
3589 /* Return die_offset of a DIE reference to a base type. */
3591 static unsigned long int
3592 get_base_type_offset (dw_die_ref ref)
3594 if (ref->die_offset)
3595 return ref->die_offset;
3596 if (comp_unit_die ()->die_abbrev)
3598 calc_base_type_die_sizes ();
3599 gcc_assert (ref->die_offset);
3601 return ref->die_offset;
3604 /* Return die_offset of a DIE reference other than base type. */
3606 static unsigned long int
3607 get_ref_die_offset (dw_die_ref ref)
3609 gcc_assert (ref->die_offset);
3610 return ref->die_offset;
3613 /* Convert a DIE tag into its string name. */
3616 dwarf_tag_name (unsigned int tag)
3620 case DW_TAG_padding:
3621 return "DW_TAG_padding";
3622 case DW_TAG_array_type:
3623 return "DW_TAG_array_type";
3624 case DW_TAG_class_type:
3625 return "DW_TAG_class_type";
3626 case DW_TAG_entry_point:
3627 return "DW_TAG_entry_point";
3628 case DW_TAG_enumeration_type:
3629 return "DW_TAG_enumeration_type";
3630 case DW_TAG_formal_parameter:
3631 return "DW_TAG_formal_parameter";
3632 case DW_TAG_imported_declaration:
3633 return "DW_TAG_imported_declaration";
3635 return "DW_TAG_label";
3636 case DW_TAG_lexical_block:
3637 return "DW_TAG_lexical_block";
3639 return "DW_TAG_member";
3640 case DW_TAG_pointer_type:
3641 return "DW_TAG_pointer_type";
3642 case DW_TAG_reference_type:
3643 return "DW_TAG_reference_type";
3644 case DW_TAG_compile_unit:
3645 return "DW_TAG_compile_unit";
3646 case DW_TAG_string_type:
3647 return "DW_TAG_string_type";
3648 case DW_TAG_structure_type:
3649 return "DW_TAG_structure_type";
3650 case DW_TAG_subroutine_type:
3651 return "DW_TAG_subroutine_type";
3652 case DW_TAG_typedef:
3653 return "DW_TAG_typedef";
3654 case DW_TAG_union_type:
3655 return "DW_TAG_union_type";
3656 case DW_TAG_unspecified_parameters:
3657 return "DW_TAG_unspecified_parameters";
3658 case DW_TAG_variant:
3659 return "DW_TAG_variant";
3660 case DW_TAG_common_block:
3661 return "DW_TAG_common_block";
3662 case DW_TAG_common_inclusion:
3663 return "DW_TAG_common_inclusion";
3664 case DW_TAG_inheritance:
3665 return "DW_TAG_inheritance";
3666 case DW_TAG_inlined_subroutine:
3667 return "DW_TAG_inlined_subroutine";
3669 return "DW_TAG_module";
3670 case DW_TAG_ptr_to_member_type:
3671 return "DW_TAG_ptr_to_member_type";
3672 case DW_TAG_set_type:
3673 return "DW_TAG_set_type";
3674 case DW_TAG_subrange_type:
3675 return "DW_TAG_subrange_type";
3676 case DW_TAG_with_stmt:
3677 return "DW_TAG_with_stmt";
3678 case DW_TAG_access_declaration:
3679 return "DW_TAG_access_declaration";
3680 case DW_TAG_base_type:
3681 return "DW_TAG_base_type";
3682 case DW_TAG_catch_block:
3683 return "DW_TAG_catch_block";
3684 case DW_TAG_const_type:
3685 return "DW_TAG_const_type";
3686 case DW_TAG_constant:
3687 return "DW_TAG_constant";
3688 case DW_TAG_enumerator:
3689 return "DW_TAG_enumerator";
3690 case DW_TAG_file_type:
3691 return "DW_TAG_file_type";
3693 return "DW_TAG_friend";
3694 case DW_TAG_namelist:
3695 return "DW_TAG_namelist";
3696 case DW_TAG_namelist_item:
3697 return "DW_TAG_namelist_item";
3698 case DW_TAG_packed_type:
3699 return "DW_TAG_packed_type";
3700 case DW_TAG_subprogram:
3701 return "DW_TAG_subprogram";
3702 case DW_TAG_template_type_param:
3703 return "DW_TAG_template_type_param";
3704 case DW_TAG_template_value_param:
3705 return "DW_TAG_template_value_param";
3706 case DW_TAG_thrown_type:
3707 return "DW_TAG_thrown_type";
3708 case DW_TAG_try_block:
3709 return "DW_TAG_try_block";
3710 case DW_TAG_variant_part:
3711 return "DW_TAG_variant_part";
3712 case DW_TAG_variable:
3713 return "DW_TAG_variable";
3714 case DW_TAG_volatile_type:
3715 return "DW_TAG_volatile_type";
3716 case DW_TAG_dwarf_procedure:
3717 return "DW_TAG_dwarf_procedure";
3718 case DW_TAG_restrict_type:
3719 return "DW_TAG_restrict_type";
3720 case DW_TAG_interface_type:
3721 return "DW_TAG_interface_type";
3722 case DW_TAG_namespace:
3723 return "DW_TAG_namespace";
3724 case DW_TAG_imported_module:
3725 return "DW_TAG_imported_module";
3726 case DW_TAG_unspecified_type:
3727 return "DW_TAG_unspecified_type";
3728 case DW_TAG_partial_unit:
3729 return "DW_TAG_partial_unit";
3730 case DW_TAG_imported_unit:
3731 return "DW_TAG_imported_unit";
3732 case DW_TAG_condition:
3733 return "DW_TAG_condition";
3734 case DW_TAG_shared_type:
3735 return "DW_TAG_shared_type";
3736 case DW_TAG_type_unit:
3737 return "DW_TAG_type_unit";
3738 case DW_TAG_rvalue_reference_type:
3739 return "DW_TAG_rvalue_reference_type";
3740 case DW_TAG_template_alias:
3741 return "DW_TAG_template_alias";
3742 case DW_TAG_GNU_template_parameter_pack:
3743 return "DW_TAG_GNU_template_parameter_pack";
3744 case DW_TAG_GNU_formal_parameter_pack:
3745 return "DW_TAG_GNU_formal_parameter_pack";
3746 case DW_TAG_MIPS_loop:
3747 return "DW_TAG_MIPS_loop";
3748 case DW_TAG_format_label:
3749 return "DW_TAG_format_label";
3750 case DW_TAG_function_template:
3751 return "DW_TAG_function_template";
3752 case DW_TAG_class_template:
3753 return "DW_TAG_class_template";
3754 case DW_TAG_GNU_BINCL:
3755 return "DW_TAG_GNU_BINCL";
3756 case DW_TAG_GNU_EINCL:
3757 return "DW_TAG_GNU_EINCL";
3758 case DW_TAG_GNU_template_template_param:
3759 return "DW_TAG_GNU_template_template_param";
3760 case DW_TAG_GNU_call_site:
3761 return "DW_TAG_GNU_call_site";
3762 case DW_TAG_GNU_call_site_parameter:
3763 return "DW_TAG_GNU_call_site_parameter";
3765 return "DW_TAG_<unknown>";
3769 /* Convert a DWARF attribute code into its string name. */
3772 dwarf_attr_name (unsigned int attr)
3777 return "DW_AT_sibling";
3778 case DW_AT_location:
3779 return "DW_AT_location";
3781 return "DW_AT_name";
3782 case DW_AT_ordering:
3783 return "DW_AT_ordering";
3784 case DW_AT_subscr_data:
3785 return "DW_AT_subscr_data";
3786 case DW_AT_byte_size:
3787 return "DW_AT_byte_size";
3788 case DW_AT_bit_offset:
3789 return "DW_AT_bit_offset";
3790 case DW_AT_bit_size:
3791 return "DW_AT_bit_size";
3792 case DW_AT_element_list:
3793 return "DW_AT_element_list";
3794 case DW_AT_stmt_list:
3795 return "DW_AT_stmt_list";
3797 return "DW_AT_low_pc";
3799 return "DW_AT_high_pc";
3800 case DW_AT_language:
3801 return "DW_AT_language";
3803 return "DW_AT_member";
3805 return "DW_AT_discr";
3806 case DW_AT_discr_value:
3807 return "DW_AT_discr_value";
3808 case DW_AT_visibility:
3809 return "DW_AT_visibility";
3811 return "DW_AT_import";
3812 case DW_AT_string_length:
3813 return "DW_AT_string_length";
3814 case DW_AT_common_reference:
3815 return "DW_AT_common_reference";
3816 case DW_AT_comp_dir:
3817 return "DW_AT_comp_dir";
3818 case DW_AT_const_value:
3819 return "DW_AT_const_value";
3820 case DW_AT_containing_type:
3821 return "DW_AT_containing_type";
3822 case DW_AT_default_value:
3823 return "DW_AT_default_value";
3825 return "DW_AT_inline";
3826 case DW_AT_is_optional:
3827 return "DW_AT_is_optional";
3828 case DW_AT_lower_bound:
3829 return "DW_AT_lower_bound";
3830 case DW_AT_producer:
3831 return "DW_AT_producer";
3832 case DW_AT_prototyped:
3833 return "DW_AT_prototyped";
3834 case DW_AT_return_addr:
3835 return "DW_AT_return_addr";
3836 case DW_AT_start_scope:
3837 return "DW_AT_start_scope";
3838 case DW_AT_bit_stride:
3839 return "DW_AT_bit_stride";
3840 case DW_AT_upper_bound:
3841 return "DW_AT_upper_bound";
3842 case DW_AT_abstract_origin:
3843 return "DW_AT_abstract_origin";
3844 case DW_AT_accessibility:
3845 return "DW_AT_accessibility";
3846 case DW_AT_address_class:
3847 return "DW_AT_address_class";
3848 case DW_AT_artificial:
3849 return "DW_AT_artificial";
3850 case DW_AT_base_types:
3851 return "DW_AT_base_types";
3852 case DW_AT_calling_convention:
3853 return "DW_AT_calling_convention";
3855 return "DW_AT_count";
3856 case DW_AT_data_member_location:
3857 return "DW_AT_data_member_location";
3858 case DW_AT_decl_column:
3859 return "DW_AT_decl_column";
3860 case DW_AT_decl_file:
3861 return "DW_AT_decl_file";
3862 case DW_AT_decl_line:
3863 return "DW_AT_decl_line";
3864 case DW_AT_declaration:
3865 return "DW_AT_declaration";
3866 case DW_AT_discr_list:
3867 return "DW_AT_discr_list";
3868 case DW_AT_encoding:
3869 return "DW_AT_encoding";
3870 case DW_AT_external:
3871 return "DW_AT_external";
3872 case DW_AT_explicit:
3873 return "DW_AT_explicit";
3874 case DW_AT_frame_base:
3875 return "DW_AT_frame_base";
3877 return "DW_AT_friend";
3878 case DW_AT_identifier_case:
3879 return "DW_AT_identifier_case";
3880 case DW_AT_macro_info:
3881 return "DW_AT_macro_info";
3882 case DW_AT_namelist_items:
3883 return "DW_AT_namelist_items";
3884 case DW_AT_priority:
3885 return "DW_AT_priority";
3887 return "DW_AT_segment";
3888 case DW_AT_specification:
3889 return "DW_AT_specification";
3890 case DW_AT_static_link:
3891 return "DW_AT_static_link";
3893 return "DW_AT_type";
3894 case DW_AT_use_location:
3895 return "DW_AT_use_location";
3896 case DW_AT_variable_parameter:
3897 return "DW_AT_variable_parameter";
3898 case DW_AT_virtuality:
3899 return "DW_AT_virtuality";
3900 case DW_AT_vtable_elem_location:
3901 return "DW_AT_vtable_elem_location";
3903 case DW_AT_allocated:
3904 return "DW_AT_allocated";
3905 case DW_AT_associated:
3906 return "DW_AT_associated";
3907 case DW_AT_data_location:
3908 return "DW_AT_data_location";
3909 case DW_AT_byte_stride:
3910 return "DW_AT_byte_stride";
3911 case DW_AT_entry_pc:
3912 return "DW_AT_entry_pc";
3913 case DW_AT_use_UTF8:
3914 return "DW_AT_use_UTF8";
3915 case DW_AT_extension:
3916 return "DW_AT_extension";
3918 return "DW_AT_ranges";
3919 case DW_AT_trampoline:
3920 return "DW_AT_trampoline";
3921 case DW_AT_call_column:
3922 return "DW_AT_call_column";
3923 case DW_AT_call_file:
3924 return "DW_AT_call_file";
3925 case DW_AT_call_line:
3926 return "DW_AT_call_line";
3927 case DW_AT_object_pointer:
3928 return "DW_AT_object_pointer";
3930 case DW_AT_signature:
3931 return "DW_AT_signature";
3932 case DW_AT_main_subprogram:
3933 return "DW_AT_main_subprogram";
3934 case DW_AT_data_bit_offset:
3935 return "DW_AT_data_bit_offset";
3936 case DW_AT_const_expr:
3937 return "DW_AT_const_expr";
3938 case DW_AT_enum_class:
3939 return "DW_AT_enum_class";
3940 case DW_AT_linkage_name:
3941 return "DW_AT_linkage_name";
3943 case DW_AT_MIPS_fde:
3944 return "DW_AT_MIPS_fde";
3945 case DW_AT_MIPS_loop_begin:
3946 return "DW_AT_MIPS_loop_begin";
3947 case DW_AT_MIPS_tail_loop_begin:
3948 return "DW_AT_MIPS_tail_loop_begin";
3949 case DW_AT_MIPS_epilog_begin:
3950 return "DW_AT_MIPS_epilog_begin";
3951 #if VMS_DEBUGGING_INFO
3952 case DW_AT_HP_prologue:
3953 return "DW_AT_HP_prologue";
3955 case DW_AT_MIPS_loop_unroll_factor:
3956 return "DW_AT_MIPS_loop_unroll_factor";
3958 case DW_AT_MIPS_software_pipeline_depth:
3959 return "DW_AT_MIPS_software_pipeline_depth";
3960 case DW_AT_MIPS_linkage_name:
3961 return "DW_AT_MIPS_linkage_name";
3962 #if VMS_DEBUGGING_INFO
3963 case DW_AT_HP_epilogue:
3964 return "DW_AT_HP_epilogue";
3966 case DW_AT_MIPS_stride:
3967 return "DW_AT_MIPS_stride";
3969 case DW_AT_MIPS_abstract_name:
3970 return "DW_AT_MIPS_abstract_name";
3971 case DW_AT_MIPS_clone_origin:
3972 return "DW_AT_MIPS_clone_origin";
3973 case DW_AT_MIPS_has_inlines:
3974 return "DW_AT_MIPS_has_inlines";
3976 case DW_AT_sf_names:
3977 return "DW_AT_sf_names";
3978 case DW_AT_src_info:
3979 return "DW_AT_src_info";
3980 case DW_AT_mac_info:
3981 return "DW_AT_mac_info";
3982 case DW_AT_src_coords:
3983 return "DW_AT_src_coords";
3984 case DW_AT_body_begin:
3985 return "DW_AT_body_begin";
3986 case DW_AT_body_end:
3987 return "DW_AT_body_end";
3989 case DW_AT_GNU_vector:
3990 return "DW_AT_GNU_vector";
3991 case DW_AT_GNU_guarded_by:
3992 return "DW_AT_GNU_guarded_by";
3993 case DW_AT_GNU_pt_guarded_by:
3994 return "DW_AT_GNU_pt_guarded_by";
3995 case DW_AT_GNU_guarded:
3996 return "DW_AT_GNU_guarded";
3997 case DW_AT_GNU_pt_guarded:
3998 return "DW_AT_GNU_pt_guarded";
3999 case DW_AT_GNU_locks_excluded:
4000 return "DW_AT_GNU_locks_excluded";
4001 case DW_AT_GNU_exclusive_locks_required:
4002 return "DW_AT_GNU_exclusive_locks_required";
4003 case DW_AT_GNU_shared_locks_required:
4004 return "DW_AT_GNU_shared_locks_required";
4005 case DW_AT_GNU_odr_signature:
4006 return "DW_AT_GNU_odr_signature";
4007 case DW_AT_GNU_template_name:
4008 return "DW_AT_GNU_template_name";
4009 case DW_AT_GNU_call_site_value:
4010 return "DW_AT_GNU_call_site_value";
4011 case DW_AT_GNU_call_site_data_value:
4012 return "DW_AT_GNU_call_site_data_value";
4013 case DW_AT_GNU_call_site_target:
4014 return "DW_AT_GNU_call_site_target";
4015 case DW_AT_GNU_call_site_target_clobbered:
4016 return "DW_AT_GNU_call_site_target_clobbered";
4017 case DW_AT_GNU_tail_call:
4018 return "DW_AT_GNU_tail_call";
4019 case DW_AT_GNU_all_tail_call_sites:
4020 return "DW_AT_GNU_all_tail_call_sites";
4021 case DW_AT_GNU_all_call_sites:
4022 return "DW_AT_GNU_all_call_sites";
4023 case DW_AT_GNU_all_source_call_sites:
4024 return "DW_AT_GNU_all_source_call_sites";
4025 case DW_AT_GNU_macros:
4026 return "DW_AT_GNU_macros";
4028 case DW_AT_GNAT_descriptive_type:
4029 return "DW_AT_GNAT_descriptive_type";
4031 case DW_AT_VMS_rtnbeg_pd_address:
4032 return "DW_AT_VMS_rtnbeg_pd_address";
4035 return "DW_AT_<unknown>";
4039 /* Convert a DWARF value form code into its string name. */
4042 dwarf_form_name (unsigned int form)
4047 return "DW_FORM_addr";
4048 case DW_FORM_block2:
4049 return "DW_FORM_block2";
4050 case DW_FORM_block4:
4051 return "DW_FORM_block4";
4053 return "DW_FORM_data2";
4055 return "DW_FORM_data4";
4057 return "DW_FORM_data8";
4058 case DW_FORM_string:
4059 return "DW_FORM_string";
4061 return "DW_FORM_block";
4062 case DW_FORM_block1:
4063 return "DW_FORM_block1";
4065 return "DW_FORM_data1";
4067 return "DW_FORM_flag";
4069 return "DW_FORM_sdata";
4071 return "DW_FORM_strp";
4073 return "DW_FORM_udata";
4074 case DW_FORM_ref_addr:
4075 return "DW_FORM_ref_addr";
4077 return "DW_FORM_ref1";
4079 return "DW_FORM_ref2";
4081 return "DW_FORM_ref4";
4083 return "DW_FORM_ref8";
4084 case DW_FORM_ref_udata:
4085 return "DW_FORM_ref_udata";
4086 case DW_FORM_indirect:
4087 return "DW_FORM_indirect";
4088 case DW_FORM_sec_offset:
4089 return "DW_FORM_sec_offset";
4090 case DW_FORM_exprloc:
4091 return "DW_FORM_exprloc";
4092 case DW_FORM_flag_present:
4093 return "DW_FORM_flag_present";
4094 case DW_FORM_ref_sig8:
4095 return "DW_FORM_ref_sig8";
4097 return "DW_FORM_<unknown>";
4101 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4102 instance of an inlined instance of a decl which is local to an inline
4103 function, so we have to trace all of the way back through the origin chain
4104 to find out what sort of node actually served as the original seed for the
4108 decl_ultimate_origin (const_tree decl)
4110 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4113 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4114 nodes in the function to point to themselves; ignore that if
4115 we're trying to output the abstract instance of this function. */
4116 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4119 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4120 most distant ancestor, this should never happen. */
4121 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4123 return DECL_ABSTRACT_ORIGIN (decl);
4126 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4127 of a virtual function may refer to a base class, so we check the 'this'
4131 decl_class_context (tree decl)
4133 tree context = NULL_TREE;
4135 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4136 context = DECL_CONTEXT (decl);
4138 context = TYPE_MAIN_VARIANT
4139 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4141 if (context && !TYPE_P (context))
4142 context = NULL_TREE;
4147 /* Add an attribute/value pair to a DIE. */
4150 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4152 /* Maybe this should be an assert? */
4156 if (die->die_attr == NULL)
4157 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4158 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4161 static inline enum dw_val_class
4162 AT_class (dw_attr_ref a)
4164 return a->dw_attr_val.val_class;
4167 /* Add a flag value attribute to a DIE. */
4170 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4174 attr.dw_attr = attr_kind;
4175 attr.dw_attr_val.val_class = dw_val_class_flag;
4176 attr.dw_attr_val.v.val_flag = flag;
4177 add_dwarf_attr (die, &attr);
4180 static inline unsigned
4181 AT_flag (dw_attr_ref a)
4183 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4184 return a->dw_attr_val.v.val_flag;
4187 /* Add a signed integer attribute value to a DIE. */
4190 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4194 attr.dw_attr = attr_kind;
4195 attr.dw_attr_val.val_class = dw_val_class_const;
4196 attr.dw_attr_val.v.val_int = int_val;
4197 add_dwarf_attr (die, &attr);
4200 static inline HOST_WIDE_INT
4201 AT_int (dw_attr_ref a)
4203 gcc_assert (a && AT_class (a) == dw_val_class_const);
4204 return a->dw_attr_val.v.val_int;
4207 /* Add an unsigned integer attribute value to a DIE. */
4210 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4211 unsigned HOST_WIDE_INT unsigned_val)
4215 attr.dw_attr = attr_kind;
4216 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4217 attr.dw_attr_val.v.val_unsigned = unsigned_val;
4218 add_dwarf_attr (die, &attr);
4221 static inline unsigned HOST_WIDE_INT
4222 AT_unsigned (dw_attr_ref a)
4224 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4225 return a->dw_attr_val.v.val_unsigned;
4228 /* Add an unsigned double integer attribute value to a DIE. */
4231 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
4232 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
4236 attr.dw_attr = attr_kind;
4237 attr.dw_attr_val.val_class = dw_val_class_const_double;
4238 attr.dw_attr_val.v.val_double.high = high;
4239 attr.dw_attr_val.v.val_double.low = low;
4240 add_dwarf_attr (die, &attr);
4243 /* Add a floating point attribute value to a DIE and return it. */
4246 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4247 unsigned int length, unsigned int elt_size, unsigned char *array)
4251 attr.dw_attr = attr_kind;
4252 attr.dw_attr_val.val_class = dw_val_class_vec;
4253 attr.dw_attr_val.v.val_vec.length = length;
4254 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4255 attr.dw_attr_val.v.val_vec.array = array;
4256 add_dwarf_attr (die, &attr);
4259 /* Add an 8-byte data attribute value to a DIE. */
4262 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
4263 unsigned char data8[8])
4267 attr.dw_attr = attr_kind;
4268 attr.dw_attr_val.val_class = dw_val_class_data8;
4269 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
4270 add_dwarf_attr (die, &attr);
4273 /* Hash and equality functions for debug_str_hash. */
4276 debug_str_do_hash (const void *x)
4278 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4282 debug_str_eq (const void *x1, const void *x2)
4284 return strcmp ((((const struct indirect_string_node *)x1)->str),
4285 (const char *)x2) == 0;
4288 /* Add STR to the indirect string hash table. */
4290 static struct indirect_string_node *
4291 find_AT_string (const char *str)
4293 struct indirect_string_node *node;
4296 if (! debug_str_hash)
4297 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4298 debug_str_eq, NULL);
4300 slot = htab_find_slot_with_hash (debug_str_hash, str,
4301 htab_hash_string (str), INSERT);
4304 node = ggc_alloc_cleared_indirect_string_node ();
4305 node->str = ggc_strdup (str);
4309 node = (struct indirect_string_node *) *slot;
4315 /* Add a string attribute value to a DIE. */
4318 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4321 struct indirect_string_node *node;
4323 node = find_AT_string (str);
4325 attr.dw_attr = attr_kind;
4326 attr.dw_attr_val.val_class = dw_val_class_str;
4327 attr.dw_attr_val.v.val_str = node;
4328 add_dwarf_attr (die, &attr);
4331 static inline const char *
4332 AT_string (dw_attr_ref a)
4334 gcc_assert (a && AT_class (a) == dw_val_class_str);
4335 return a->dw_attr_val.v.val_str->str;
4338 /* Find out whether a string should be output inline in DIE
4339 or out-of-line in .debug_str section. */
4341 static enum dwarf_form
4342 AT_string_form (dw_attr_ref a)
4344 struct indirect_string_node *node;
4348 gcc_assert (a && AT_class (a) == dw_val_class_str);
4350 node = a->dw_attr_val.v.val_str;
4354 len = strlen (node->str) + 1;
4356 /* If the string is shorter or equal to the size of the reference, it is
4357 always better to put it inline. */
4358 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4359 return node->form = DW_FORM_string;
4361 /* If we cannot expect the linker to merge strings in .debug_str
4362 section, only put it into .debug_str if it is worth even in this
4364 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4365 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
4366 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
4367 return node->form = DW_FORM_string;
4369 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4370 ++dw2_string_counter;
4371 node->label = xstrdup (label);
4373 return node->form = DW_FORM_strp;
4376 /* Add a DIE reference attribute value to a DIE. */
4379 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4383 #ifdef ENABLE_CHECKING
4384 gcc_assert (targ_die != NULL);
4386 /* With LTO we can end up trying to reference something we didn't create
4387 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4388 if (targ_die == NULL)
4392 attr.dw_attr = attr_kind;
4393 attr.dw_attr_val.val_class = dw_val_class_die_ref;
4394 attr.dw_attr_val.v.val_die_ref.die = targ_die;
4395 attr.dw_attr_val.v.val_die_ref.external = 0;
4396 add_dwarf_attr (die, &attr);
4399 /* Add an AT_specification attribute to a DIE, and also make the back
4400 pointer from the specification to the definition. */
4403 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4405 add_AT_die_ref (die, DW_AT_specification, targ_die);
4406 gcc_assert (!targ_die->die_definition);
4407 targ_die->die_definition = die;
4410 static inline dw_die_ref
4411 AT_ref (dw_attr_ref a)
4413 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4414 return a->dw_attr_val.v.val_die_ref.die;
4418 AT_ref_external (dw_attr_ref a)
4420 if (a && AT_class (a) == dw_val_class_die_ref)
4421 return a->dw_attr_val.v.val_die_ref.external;
4427 set_AT_ref_external (dw_attr_ref a, int i)
4429 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4430 a->dw_attr_val.v.val_die_ref.external = i;
4433 /* Add an FDE reference attribute value to a DIE. */
4436 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4440 attr.dw_attr = attr_kind;
4441 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
4442 attr.dw_attr_val.v.val_fde_index = targ_fde;
4443 add_dwarf_attr (die, &attr);
4446 /* Add a location description attribute value to a DIE. */
4449 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4453 attr.dw_attr = attr_kind;
4454 attr.dw_attr_val.val_class = dw_val_class_loc;
4455 attr.dw_attr_val.v.val_loc = loc;
4456 add_dwarf_attr (die, &attr);
4459 static inline dw_loc_descr_ref
4460 AT_loc (dw_attr_ref a)
4462 gcc_assert (a && AT_class (a) == dw_val_class_loc);
4463 return a->dw_attr_val.v.val_loc;
4467 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4471 attr.dw_attr = attr_kind;
4472 attr.dw_attr_val.val_class = dw_val_class_loc_list;
4473 attr.dw_attr_val.v.val_loc_list = loc_list;
4474 add_dwarf_attr (die, &attr);
4475 have_location_lists = true;
4478 static inline dw_loc_list_ref
4479 AT_loc_list (dw_attr_ref a)
4481 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4482 return a->dw_attr_val.v.val_loc_list;
4485 static inline dw_loc_list_ref *
4486 AT_loc_list_ptr (dw_attr_ref a)
4488 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4489 return &a->dw_attr_val.v.val_loc_list;
4492 /* Add an address constant attribute value to a DIE. */
4495 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
4499 attr.dw_attr = attr_kind;
4500 attr.dw_attr_val.val_class = dw_val_class_addr;
4501 attr.dw_attr_val.v.val_addr = addr;
4502 add_dwarf_attr (die, &attr);
4505 /* Get the RTX from to an address DIE attribute. */
4508 AT_addr (dw_attr_ref a)
4510 gcc_assert (a && AT_class (a) == dw_val_class_addr);
4511 return a->dw_attr_val.v.val_addr;
4514 /* Add a file attribute value to a DIE. */
4517 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
4518 struct dwarf_file_data *fd)
4522 attr.dw_attr = attr_kind;
4523 attr.dw_attr_val.val_class = dw_val_class_file;
4524 attr.dw_attr_val.v.val_file = fd;
4525 add_dwarf_attr (die, &attr);
4528 /* Get the dwarf_file_data from a file DIE attribute. */
4530 static inline struct dwarf_file_data *
4531 AT_file (dw_attr_ref a)
4533 gcc_assert (a && AT_class (a) == dw_val_class_file);
4534 return a->dw_attr_val.v.val_file;
4537 /* Add a vms delta attribute value to a DIE. */
4540 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
4541 const char *lbl1, const char *lbl2)
4545 attr.dw_attr = attr_kind;
4546 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
4547 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
4548 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
4549 add_dwarf_attr (die, &attr);
4552 /* Add a label identifier attribute value to a DIE. */
4555 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
4559 attr.dw_attr = attr_kind;
4560 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4561 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4562 add_dwarf_attr (die, &attr);
4565 /* Add a section offset attribute value to a DIE, an offset into the
4566 debug_line section. */
4569 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4574 attr.dw_attr = attr_kind;
4575 attr.dw_attr_val.val_class = dw_val_class_lineptr;
4576 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4577 add_dwarf_attr (die, &attr);
4580 /* Add a section offset attribute value to a DIE, an offset into the
4581 debug_macinfo section. */
4584 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4589 attr.dw_attr = attr_kind;
4590 attr.dw_attr_val.val_class = dw_val_class_macptr;
4591 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4592 add_dwarf_attr (die, &attr);
4595 /* Add an offset attribute value to a DIE. */
4598 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
4599 unsigned HOST_WIDE_INT offset)
4603 attr.dw_attr = attr_kind;
4604 attr.dw_attr_val.val_class = dw_val_class_offset;
4605 attr.dw_attr_val.v.val_offset = offset;
4606 add_dwarf_attr (die, &attr);
4609 /* Add an range_list attribute value to a DIE. */
4612 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4613 long unsigned int offset)
4617 attr.dw_attr = attr_kind;
4618 attr.dw_attr_val.val_class = dw_val_class_range_list;
4619 attr.dw_attr_val.v.val_offset = offset;
4620 add_dwarf_attr (die, &attr);
4623 /* Return the start label of a delta attribute. */
4625 static inline const char *
4626 AT_vms_delta1 (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.lbl1;
4632 /* Return the end label of a delta attribute. */
4634 static inline const char *
4635 AT_vms_delta2 (dw_attr_ref a)
4637 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4638 return a->dw_attr_val.v.val_vms_delta.lbl2;
4641 static inline const char *
4642 AT_lbl (dw_attr_ref a)
4644 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
4645 || AT_class (a) == dw_val_class_lineptr
4646 || AT_class (a) == dw_val_class_macptr));
4647 return a->dw_attr_val.v.val_lbl_id;
4650 /* Get the attribute of type attr_kind. */
4653 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4657 dw_die_ref spec = NULL;
4662 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
4663 if (a->dw_attr == attr_kind)
4665 else if (a->dw_attr == DW_AT_specification
4666 || a->dw_attr == DW_AT_abstract_origin)
4670 return get_AT (spec, attr_kind);
4675 /* Return the "low pc" attribute value, typically associated with a subprogram
4676 DIE. Return null if the "low pc" attribute is either not present, or if it
4677 cannot be represented as an assembler label identifier. */
4679 static inline const char *
4680 get_AT_low_pc (dw_die_ref die)
4682 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4684 return a ? AT_lbl (a) : NULL;
4687 /* Return the "high pc" attribute value, typically associated with a subprogram
4688 DIE. Return null if the "high pc" attribute is either not present, or if it
4689 cannot be represented as an assembler label identifier. */
4691 static inline const char *
4692 get_AT_hi_pc (dw_die_ref die)
4694 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4696 return a ? AT_lbl (a) : NULL;
4699 /* Return the value of the string attribute designated by ATTR_KIND, or
4700 NULL if it is not present. */
4702 static inline const char *
4703 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4705 dw_attr_ref a = get_AT (die, attr_kind);
4707 return a ? AT_string (a) : NULL;
4710 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4711 if it is not present. */
4714 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4716 dw_attr_ref a = get_AT (die, attr_kind);
4718 return a ? AT_flag (a) : 0;
4721 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4722 if it is not present. */
4724 static inline unsigned
4725 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4727 dw_attr_ref a = get_AT (die, attr_kind);
4729 return a ? AT_unsigned (a) : 0;
4732 static inline dw_die_ref
4733 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4735 dw_attr_ref a = get_AT (die, attr_kind);
4737 return a ? AT_ref (a) : NULL;
4740 static inline struct dwarf_file_data *
4741 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
4743 dw_attr_ref a = get_AT (die, attr_kind);
4745 return a ? AT_file (a) : NULL;
4748 /* Return TRUE if the language is C++. */
4753 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4755 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
4758 /* Return TRUE if the language is Fortran. */
4763 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4765 return (lang == DW_LANG_Fortran77
4766 || lang == DW_LANG_Fortran90
4767 || lang == DW_LANG_Fortran95);
4770 /* Return TRUE if the language is Ada. */
4775 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4777 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4780 /* Remove the specified attribute if present. */
4783 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4791 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
4792 if (a->dw_attr == attr_kind)
4794 if (AT_class (a) == dw_val_class_str)
4795 if (a->dw_attr_val.v.val_str->refcount)
4796 a->dw_attr_val.v.val_str->refcount--;
4798 /* VEC_ordered_remove should help reduce the number of abbrevs
4800 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
4805 /* Remove CHILD from its parent. PREV must have the property that
4806 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4809 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
4811 gcc_assert (child->die_parent == prev->die_parent);
4812 gcc_assert (prev->die_sib == child);
4815 gcc_assert (child->die_parent->die_child == child);
4819 prev->die_sib = child->die_sib;
4820 if (child->die_parent->die_child == child)
4821 child->die_parent->die_child = prev;
4824 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4825 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4828 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
4830 dw_die_ref parent = old_child->die_parent;
4832 gcc_assert (parent == prev->die_parent);
4833 gcc_assert (prev->die_sib == old_child);
4835 new_child->die_parent = parent;
4836 if (prev == old_child)
4838 gcc_assert (parent->die_child == old_child);
4839 new_child->die_sib = new_child;
4843 prev->die_sib = new_child;
4844 new_child->die_sib = old_child->die_sib;
4846 if (old_child->die_parent->die_child == old_child)
4847 old_child->die_parent->die_child = new_child;
4850 /* Move all children from OLD_PARENT to NEW_PARENT. */
4853 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
4856 new_parent->die_child = old_parent->die_child;
4857 old_parent->die_child = NULL;
4858 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
4861 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4865 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
4871 dw_die_ref prev = c;
4873 while (c->die_tag == tag)
4875 remove_child_with_prev (c, prev);
4876 /* Might have removed every child. */
4877 if (c == c->die_sib)
4881 } while (c != die->die_child);
4884 /* Add a CHILD_DIE as the last child of DIE. */
4887 add_child_die (dw_die_ref die, dw_die_ref child_die)
4889 /* FIXME this should probably be an assert. */
4890 if (! die || ! child_die)
4892 gcc_assert (die != child_die);
4894 child_die->die_parent = die;
4897 child_die->die_sib = die->die_child->die_sib;
4898 die->die_child->die_sib = child_die;
4901 child_die->die_sib = child_die;
4902 die->die_child = child_die;
4905 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4906 is the specification, to the end of PARENT's list of children.
4907 This is done by removing and re-adding it. */
4910 splice_child_die (dw_die_ref parent, dw_die_ref child)
4914 /* We want the declaration DIE from inside the class, not the
4915 specification DIE at toplevel. */
4916 if (child->die_parent != parent)
4918 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4924 gcc_assert (child->die_parent == parent
4925 || (child->die_parent
4926 == get_AT_ref (parent, DW_AT_specification)));
4928 for (p = child->die_parent->die_child; ; p = p->die_sib)
4929 if (p->die_sib == child)
4931 remove_child_with_prev (child, p);
4935 add_child_die (parent, child);
4938 /* Return a pointer to a newly created DIE node. */
4940 static inline dw_die_ref
4941 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
4943 dw_die_ref die = ggc_alloc_cleared_die_node ();
4945 die->die_tag = tag_value;
4947 if (parent_die != NULL)
4948 add_child_die (parent_die, die);
4951 limbo_die_node *limbo_node;
4953 limbo_node = ggc_alloc_cleared_limbo_die_node ();
4954 limbo_node->die = die;
4955 limbo_node->created_for = t;
4956 limbo_node->next = limbo_die_list;
4957 limbo_die_list = limbo_node;
4963 /* Return the DIE associated with the given type specifier. */
4965 static inline dw_die_ref
4966 lookup_type_die (tree type)
4968 return TYPE_SYMTAB_DIE (type);
4971 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4972 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4973 anonymous type instead the one of the naming typedef. */
4975 static inline dw_die_ref
4976 strip_naming_typedef (tree type, dw_die_ref type_die)
4979 && TREE_CODE (type) == RECORD_TYPE
4981 && type_die->die_tag == DW_TAG_typedef
4982 && is_naming_typedef_decl (TYPE_NAME (type)))
4983 type_die = get_AT_ref (type_die, DW_AT_type);
4987 /* Like lookup_type_die, but if type is an anonymous type named by a
4988 typedef[1], return the DIE of the anonymous type instead the one of
4989 the naming typedef. This is because in gen_typedef_die, we did
4990 equate the anonymous struct named by the typedef with the DIE of
4991 the naming typedef. So by default, lookup_type_die on an anonymous
4992 struct yields the DIE of the naming typedef.
4994 [1]: Read the comment of is_naming_typedef_decl to learn about what
4995 a naming typedef is. */
4997 static inline dw_die_ref
4998 lookup_type_die_strip_naming_typedef (tree type)
5000 dw_die_ref die = lookup_type_die (type);
5001 return strip_naming_typedef (type, die);
5004 /* Equate a DIE to a given type specifier. */
5007 equate_type_number_to_die (tree type, dw_die_ref type_die)
5009 TYPE_SYMTAB_DIE (type) = type_die;
5012 /* Returns a hash value for X (which really is a die_struct). */
5015 decl_die_table_hash (const void *x)
5017 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5020 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5023 decl_die_table_eq (const void *x, const void *y)
5025 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5028 /* Return the DIE associated with a given declaration. */
5030 static inline dw_die_ref
5031 lookup_decl_die (tree decl)
5033 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5036 /* Returns a hash value for X (which really is a var_loc_list). */
5039 decl_loc_table_hash (const void *x)
5041 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5044 /* Return nonzero if decl_id of var_loc_list X is the same as
5048 decl_loc_table_eq (const void *x, const void *y)
5050 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5053 /* Return the var_loc list associated with a given declaration. */
5055 static inline var_loc_list *
5056 lookup_decl_loc (const_tree decl)
5058 if (!decl_loc_table)
5060 return (var_loc_list *)
5061 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5064 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5067 cached_dw_loc_list_table_hash (const void *x)
5069 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
5072 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5076 cached_dw_loc_list_table_eq (const void *x, const void *y)
5078 return (((const cached_dw_loc_list *) x)->decl_id
5079 == DECL_UID ((const_tree) y));
5082 /* Equate a DIE to a particular declaration. */
5085 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5087 unsigned int decl_id = DECL_UID (decl);
5090 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5092 decl_die->decl_id = decl_id;
5095 /* Return how many bits covers PIECE EXPR_LIST. */
5098 decl_piece_bitsize (rtx piece)
5100 int ret = (int) GET_MODE (piece);
5103 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
5104 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
5105 return INTVAL (XEXP (XEXP (piece, 0), 0));
5108 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5111 decl_piece_varloc_ptr (rtx piece)
5113 if ((int) GET_MODE (piece))
5114 return &XEXP (piece, 0);
5116 return &XEXP (XEXP (piece, 0), 1);
5119 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5120 Next is the chain of following piece nodes. */
5123 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
5125 if (bitsize <= (int) MAX_MACHINE_MODE)
5126 return alloc_EXPR_LIST (bitsize, loc_note, next);
5128 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
5133 /* Return rtx that should be stored into loc field for
5134 LOC_NOTE and BITPOS/BITSIZE. */
5137 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
5138 HOST_WIDE_INT bitsize)
5142 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
5144 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
5149 /* This function either modifies location piece list *DEST in
5150 place (if SRC and INNER is NULL), or copies location piece list
5151 *SRC to *DEST while modifying it. Location BITPOS is modified
5152 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5153 not copied and if needed some padding around it is added.
5154 When modifying in place, DEST should point to EXPR_LIST where
5155 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5156 to the start of the whole list and INNER points to the EXPR_LIST
5157 where earlier pieces cover PIECE_BITPOS bits. */
5160 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
5161 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
5162 HOST_WIDE_INT bitsize, rtx loc_note)
5165 bool copy = inner != NULL;
5169 /* First copy all nodes preceeding the current bitpos. */
5170 while (src != inner)
5172 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5173 decl_piece_bitsize (*src), NULL_RTX);
5174 dest = &XEXP (*dest, 1);
5175 src = &XEXP (*src, 1);
5178 /* Add padding if needed. */
5179 if (bitpos != piece_bitpos)
5181 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
5182 copy ? NULL_RTX : *dest);
5183 dest = &XEXP (*dest, 1);
5185 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
5188 /* A piece with correct bitpos and bitsize already exist,
5189 just update the location for it and return. */
5190 *decl_piece_varloc_ptr (*dest) = loc_note;
5193 /* Add the piece that changed. */
5194 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
5195 dest = &XEXP (*dest, 1);
5196 /* Skip over pieces that overlap it. */
5197 diff = bitpos - piece_bitpos + bitsize;
5200 while (diff > 0 && *src)
5203 diff -= decl_piece_bitsize (piece);
5205 src = &XEXP (piece, 1);
5208 *src = XEXP (piece, 1);
5209 free_EXPR_LIST_node (piece);
5212 /* Add padding if needed. */
5213 if (diff < 0 && *src)
5217 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
5218 dest = &XEXP (*dest, 1);
5222 /* Finally copy all nodes following it. */
5225 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5226 decl_piece_bitsize (*src), NULL_RTX);
5227 dest = &XEXP (*dest, 1);
5228 src = &XEXP (*src, 1);
5232 /* Add a variable location node to the linked list for DECL. */
5234 static struct var_loc_node *
5235 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
5237 unsigned int decl_id;
5240 struct var_loc_node *loc = NULL;
5241 HOST_WIDE_INT bitsize = -1, bitpos = -1;
5243 if (DECL_DEBUG_EXPR_IS_FROM (decl))
5245 tree realdecl = DECL_DEBUG_EXPR (decl);
5246 if (realdecl && handled_component_p (realdecl))
5248 HOST_WIDE_INT maxsize;
5251 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
5252 if (!DECL_P (innerdecl)
5253 || DECL_IGNORED_P (innerdecl)
5254 || TREE_STATIC (innerdecl)
5256 || bitpos + bitsize > 256
5257 || bitsize != maxsize)
5263 decl_id = DECL_UID (decl);
5264 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5267 temp = ggc_alloc_cleared_var_loc_list ();
5268 temp->decl_id = decl_id;
5272 temp = (var_loc_list *) *slot;
5274 /* For PARM_DECLs try to keep around the original incoming value,
5275 even if that means we'll emit a zero-range .debug_loc entry. */
5277 && temp->first == temp->last
5278 && TREE_CODE (decl) == PARM_DECL
5279 && GET_CODE (temp->first->loc) == NOTE
5280 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
5281 && DECL_INCOMING_RTL (decl)
5282 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
5283 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
5284 == GET_CODE (DECL_INCOMING_RTL (decl))
5285 && prev_real_insn (temp->first->loc) == NULL_RTX
5287 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
5288 NOTE_VAR_LOCATION_LOC (loc_note))
5289 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
5290 != NOTE_VAR_LOCATION_STATUS (loc_note))))
5292 loc = ggc_alloc_cleared_var_loc_node ();
5293 temp->first->next = loc;
5295 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5297 else if (temp->last)
5299 struct var_loc_node *last = temp->last, *unused = NULL;
5300 rtx *piece_loc = NULL, last_loc_note;
5301 int piece_bitpos = 0;
5305 gcc_assert (last->next == NULL);
5307 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
5309 piece_loc = &last->loc;
5312 int cur_bitsize = decl_piece_bitsize (*piece_loc);
5313 if (piece_bitpos + cur_bitsize > bitpos)
5315 piece_bitpos += cur_bitsize;
5316 piece_loc = &XEXP (*piece_loc, 1);
5320 /* TEMP->LAST here is either pointer to the last but one or
5321 last element in the chained list, LAST is pointer to the
5323 if (label && strcmp (last->label, label) == 0)
5325 /* For SRA optimized variables if there weren't any real
5326 insns since last note, just modify the last node. */
5327 if (piece_loc != NULL)
5329 adjust_piece_list (piece_loc, NULL, NULL,
5330 bitpos, piece_bitpos, bitsize, loc_note);
5333 /* If the last note doesn't cover any instructions, remove it. */
5334 if (temp->last != last)
5336 temp->last->next = NULL;
5339 gcc_assert (strcmp (last->label, label) != 0);
5343 gcc_assert (temp->first == temp->last
5344 || (temp->first->next == temp->last
5345 && TREE_CODE (decl) == PARM_DECL));
5346 memset (temp->last, '\0', sizeof (*temp->last));
5347 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
5351 if (bitsize == -1 && NOTE_P (last->loc))
5352 last_loc_note = last->loc;
5353 else if (piece_loc != NULL
5354 && *piece_loc != NULL_RTX
5355 && piece_bitpos == bitpos
5356 && decl_piece_bitsize (*piece_loc) == bitsize)
5357 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
5359 last_loc_note = NULL_RTX;
5360 /* If the current location is the same as the end of the list,
5361 and either both or neither of the locations is uninitialized,
5362 we have nothing to do. */
5363 if (last_loc_note == NULL_RTX
5364 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
5365 NOTE_VAR_LOCATION_LOC (loc_note)))
5366 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5367 != NOTE_VAR_LOCATION_STATUS (loc_note))
5368 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5369 == VAR_INIT_STATUS_UNINITIALIZED)
5370 || (NOTE_VAR_LOCATION_STATUS (loc_note)
5371 == VAR_INIT_STATUS_UNINITIALIZED))))
5373 /* Add LOC to the end of list and update LAST. If the last
5374 element of the list has been removed above, reuse its
5375 memory for the new node, otherwise allocate a new one. */
5379 memset (loc, '\0', sizeof (*loc));
5382 loc = ggc_alloc_cleared_var_loc_node ();
5383 if (bitsize == -1 || piece_loc == NULL)
5384 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5386 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
5387 bitpos, piece_bitpos, bitsize, loc_note);
5389 /* Ensure TEMP->LAST will point either to the new last but one
5390 element of the chain, or to the last element in it. */
5391 if (last != temp->last)
5399 loc = ggc_alloc_cleared_var_loc_node ();
5402 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5407 /* Keep track of the number of spaces used to indent the
5408 output of the debugging routines that print the structure of
5409 the DIE internal representation. */
5410 static int print_indent;
5412 /* Indent the line the number of spaces given by print_indent. */
5415 print_spaces (FILE *outfile)
5417 fprintf (outfile, "%*s", print_indent, "");
5420 /* Print a type signature in hex. */
5423 print_signature (FILE *outfile, char *sig)
5427 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
5428 fprintf (outfile, "%02x", sig[i] & 0xff);
5431 /* Print the information associated with a given DIE, and its children.
5432 This routine is a debugging aid only. */
5435 print_die (dw_die_ref die, FILE *outfile)
5441 print_spaces (outfile);
5442 fprintf (outfile, "DIE %4ld: %s (%p)\n",
5443 die->die_offset, dwarf_tag_name (die->die_tag),
5445 print_spaces (outfile);
5446 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5447 fprintf (outfile, " offset: %ld", die->die_offset);
5448 fprintf (outfile, " mark: %d\n", die->die_mark);
5450 if (use_debug_types && die->die_id.die_type_node)
5452 print_spaces (outfile);
5453 fprintf (outfile, " signature: ");
5454 print_signature (outfile, die->die_id.die_type_node->signature);
5455 fprintf (outfile, "\n");
5458 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5460 print_spaces (outfile);
5461 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5463 switch (AT_class (a))
5465 case dw_val_class_addr:
5466 fprintf (outfile, "address");
5468 case dw_val_class_offset:
5469 fprintf (outfile, "offset");
5471 case dw_val_class_loc:
5472 fprintf (outfile, "location descriptor");
5474 case dw_val_class_loc_list:
5475 fprintf (outfile, "location list -> label:%s",
5476 AT_loc_list (a)->ll_symbol);
5478 case dw_val_class_range_list:
5479 fprintf (outfile, "range list");
5481 case dw_val_class_const:
5482 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5484 case dw_val_class_unsigned_const:
5485 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5487 case dw_val_class_const_double:
5488 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
5489 HOST_WIDE_INT_PRINT_UNSIGNED")",
5490 a->dw_attr_val.v.val_double.high,
5491 a->dw_attr_val.v.val_double.low);
5493 case dw_val_class_vec:
5494 fprintf (outfile, "floating-point or vector constant");
5496 case dw_val_class_flag:
5497 fprintf (outfile, "%u", AT_flag (a));
5499 case dw_val_class_die_ref:
5500 if (AT_ref (a) != NULL)
5502 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
5504 fprintf (outfile, "die -> signature: ");
5505 print_signature (outfile,
5506 AT_ref (a)->die_id.die_type_node->signature);
5508 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
5509 fprintf (outfile, "die -> label: %s",
5510 AT_ref (a)->die_id.die_symbol);
5512 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5513 fprintf (outfile, " (%p)", (void *) AT_ref (a));
5516 fprintf (outfile, "die -> <null>");
5518 case dw_val_class_vms_delta:
5519 fprintf (outfile, "delta: @slotcount(%s-%s)",
5520 AT_vms_delta2 (a), AT_vms_delta1 (a));
5522 case dw_val_class_lbl_id:
5523 case dw_val_class_lineptr:
5524 case dw_val_class_macptr:
5525 fprintf (outfile, "label: %s", AT_lbl (a));
5527 case dw_val_class_str:
5528 if (AT_string (a) != NULL)
5529 fprintf (outfile, "\"%s\"", AT_string (a));
5531 fprintf (outfile, "<null>");
5533 case dw_val_class_file:
5534 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
5535 AT_file (a)->emitted_number);
5537 case dw_val_class_data8:
5541 for (i = 0; i < 8; i++)
5542 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
5549 fprintf (outfile, "\n");
5552 if (die->die_child != NULL)
5555 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5558 if (print_indent == 0)
5559 fprintf (outfile, "\n");
5562 /* Print the information collected for a given DIE. */
5565 debug_dwarf_die (dw_die_ref die)
5567 print_die (die, stderr);
5570 /* Print all DWARF information collected for the compilation unit.
5571 This routine is a debugging aid only. */
5577 print_die (comp_unit_die (), stderr);
5580 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5581 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5582 DIE that marks the start of the DIEs for this include file. */
5585 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5587 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5588 dw_die_ref new_unit = gen_compile_unit_die (filename);
5590 new_unit->die_sib = old_unit;
5594 /* Close an include-file CU and reopen the enclosing one. */
5597 pop_compile_unit (dw_die_ref old_unit)
5599 dw_die_ref new_unit = old_unit->die_sib;
5601 old_unit->die_sib = NULL;
5605 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5606 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5608 /* Calculate the checksum of a location expression. */
5611 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5615 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
5617 CHECKSUM (loc->dw_loc_oprnd1);
5618 CHECKSUM (loc->dw_loc_oprnd2);
5621 /* Calculate the checksum of an attribute. */
5624 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5626 dw_loc_descr_ref loc;
5629 CHECKSUM (at->dw_attr);
5631 /* We don't care that this was compiled with a different compiler
5632 snapshot; if the output is the same, that's what matters. */
5633 if (at->dw_attr == DW_AT_producer)
5636 switch (AT_class (at))
5638 case dw_val_class_const:
5639 CHECKSUM (at->dw_attr_val.v.val_int);
5641 case dw_val_class_unsigned_const:
5642 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5644 case dw_val_class_const_double:
5645 CHECKSUM (at->dw_attr_val.v.val_double);
5647 case dw_val_class_vec:
5648 CHECKSUM (at->dw_attr_val.v.val_vec);
5650 case dw_val_class_flag:
5651 CHECKSUM (at->dw_attr_val.v.val_flag);
5653 case dw_val_class_str:
5654 CHECKSUM_STRING (AT_string (at));
5657 case dw_val_class_addr:
5659 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5660 CHECKSUM_STRING (XSTR (r, 0));
5663 case dw_val_class_offset:
5664 CHECKSUM (at->dw_attr_val.v.val_offset);
5667 case dw_val_class_loc:
5668 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5669 loc_checksum (loc, ctx);
5672 case dw_val_class_die_ref:
5673 die_checksum (AT_ref (at), ctx, mark);
5676 case dw_val_class_fde_ref:
5677 case dw_val_class_vms_delta:
5678 case dw_val_class_lbl_id:
5679 case dw_val_class_lineptr:
5680 case dw_val_class_macptr:
5683 case dw_val_class_file:
5684 CHECKSUM_STRING (AT_file (at)->filename);
5687 case dw_val_class_data8:
5688 CHECKSUM (at->dw_attr_val.v.val_data8);
5696 /* Calculate the checksum of a DIE. */
5699 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5705 /* To avoid infinite recursion. */
5708 CHECKSUM (die->die_mark);
5711 die->die_mark = ++(*mark);
5713 CHECKSUM (die->die_tag);
5715 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5716 attr_checksum (a, ctx, mark);
5718 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
5722 #undef CHECKSUM_STRING
5724 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5725 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5726 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5727 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5728 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5729 #define CHECKSUM_ATTR(FOO) \
5730 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5732 /* Calculate the checksum of a number in signed LEB128 format. */
5735 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
5742 byte = (value & 0x7f);
5744 more = !((value == 0 && (byte & 0x40) == 0)
5745 || (value == -1 && (byte & 0x40) != 0));
5754 /* Calculate the checksum of a number in unsigned LEB128 format. */
5757 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
5761 unsigned char byte = (value & 0x7f);
5764 /* More bytes to follow. */
5772 /* Checksum the context of the DIE. This adds the names of any
5773 surrounding namespaces or structures to the checksum. */
5776 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
5780 int tag = die->die_tag;
5782 if (tag != DW_TAG_namespace
5783 && tag != DW_TAG_structure_type
5784 && tag != DW_TAG_class_type)
5787 name = get_AT_string (die, DW_AT_name);
5789 spec = get_AT_ref (die, DW_AT_specification);
5793 if (die->die_parent != NULL)
5794 checksum_die_context (die->die_parent, ctx);
5796 CHECKSUM_ULEB128 ('C');
5797 CHECKSUM_ULEB128 (tag);
5799 CHECKSUM_STRING (name);
5802 /* Calculate the checksum of a location expression. */
5805 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5807 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5808 were emitted as a DW_FORM_sdata instead of a location expression. */
5809 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
5811 CHECKSUM_ULEB128 (DW_FORM_sdata);
5812 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
5816 /* Otherwise, just checksum the raw location expression. */
5819 CHECKSUM_ULEB128 (loc->dw_loc_opc);
5820 CHECKSUM (loc->dw_loc_oprnd1);
5821 CHECKSUM (loc->dw_loc_oprnd2);
5822 loc = loc->dw_loc_next;
5826 /* Calculate the checksum of an attribute. */
5829 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
5830 struct md5_ctx *ctx, int *mark)
5832 dw_loc_descr_ref loc;
5835 if (AT_class (at) == dw_val_class_die_ref)
5837 dw_die_ref target_die = AT_ref (at);
5839 /* For pointer and reference types, we checksum only the (qualified)
5840 name of the target type (if there is a name). For friend entries,
5841 we checksum only the (qualified) name of the target type or function.
5842 This allows the checksum to remain the same whether the target type
5843 is complete or not. */
5844 if ((at->dw_attr == DW_AT_type
5845 && (tag == DW_TAG_pointer_type
5846 || tag == DW_TAG_reference_type
5847 || tag == DW_TAG_rvalue_reference_type
5848 || tag == DW_TAG_ptr_to_member_type))
5849 || (at->dw_attr == DW_AT_friend
5850 && tag == DW_TAG_friend))
5852 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
5854 if (name_attr != NULL)
5856 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
5860 CHECKSUM_ULEB128 ('N');
5861 CHECKSUM_ULEB128 (at->dw_attr);
5862 if (decl->die_parent != NULL)
5863 checksum_die_context (decl->die_parent, ctx);
5864 CHECKSUM_ULEB128 ('E');
5865 CHECKSUM_STRING (AT_string (name_attr));
5870 /* For all other references to another DIE, we check to see if the
5871 target DIE has already been visited. If it has, we emit a
5872 backward reference; if not, we descend recursively. */
5873 if (target_die->die_mark > 0)
5875 CHECKSUM_ULEB128 ('R');
5876 CHECKSUM_ULEB128 (at->dw_attr);
5877 CHECKSUM_ULEB128 (target_die->die_mark);
5881 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
5885 target_die->die_mark = ++(*mark);
5886 CHECKSUM_ULEB128 ('T');
5887 CHECKSUM_ULEB128 (at->dw_attr);
5888 if (decl->die_parent != NULL)
5889 checksum_die_context (decl->die_parent, ctx);
5890 die_checksum_ordered (target_die, ctx, mark);
5895 CHECKSUM_ULEB128 ('A');
5896 CHECKSUM_ULEB128 (at->dw_attr);
5898 switch (AT_class (at))
5900 case dw_val_class_const:
5901 CHECKSUM_ULEB128 (DW_FORM_sdata);
5902 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
5905 case dw_val_class_unsigned_const:
5906 CHECKSUM_ULEB128 (DW_FORM_sdata);
5907 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
5910 case dw_val_class_const_double:
5911 CHECKSUM_ULEB128 (DW_FORM_block);
5912 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
5913 CHECKSUM (at->dw_attr_val.v.val_double);
5916 case dw_val_class_vec:
5917 CHECKSUM_ULEB128 (DW_FORM_block);
5918 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
5919 CHECKSUM (at->dw_attr_val.v.val_vec);
5922 case dw_val_class_flag:
5923 CHECKSUM_ULEB128 (DW_FORM_flag);
5924 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
5927 case dw_val_class_str:
5928 CHECKSUM_ULEB128 (DW_FORM_string);
5929 CHECKSUM_STRING (AT_string (at));
5932 case dw_val_class_addr:
5934 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5935 CHECKSUM_ULEB128 (DW_FORM_string);
5936 CHECKSUM_STRING (XSTR (r, 0));
5939 case dw_val_class_offset:
5940 CHECKSUM_ULEB128 (DW_FORM_sdata);
5941 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
5944 case dw_val_class_loc:
5945 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5946 loc_checksum_ordered (loc, ctx);
5949 case dw_val_class_fde_ref:
5950 case dw_val_class_lbl_id:
5951 case dw_val_class_lineptr:
5952 case dw_val_class_macptr:
5955 case dw_val_class_file:
5956 CHECKSUM_ULEB128 (DW_FORM_string);
5957 CHECKSUM_STRING (AT_file (at)->filename);
5960 case dw_val_class_data8:
5961 CHECKSUM (at->dw_attr_val.v.val_data8);
5969 struct checksum_attributes
5971 dw_attr_ref at_name;
5972 dw_attr_ref at_type;
5973 dw_attr_ref at_friend;
5974 dw_attr_ref at_accessibility;
5975 dw_attr_ref at_address_class;
5976 dw_attr_ref at_allocated;
5977 dw_attr_ref at_artificial;
5978 dw_attr_ref at_associated;
5979 dw_attr_ref at_binary_scale;
5980 dw_attr_ref at_bit_offset;
5981 dw_attr_ref at_bit_size;
5982 dw_attr_ref at_bit_stride;
5983 dw_attr_ref at_byte_size;
5984 dw_attr_ref at_byte_stride;
5985 dw_attr_ref at_const_value;
5986 dw_attr_ref at_containing_type;
5987 dw_attr_ref at_count;
5988 dw_attr_ref at_data_location;
5989 dw_attr_ref at_data_member_location;
5990 dw_attr_ref at_decimal_scale;
5991 dw_attr_ref at_decimal_sign;
5992 dw_attr_ref at_default_value;
5993 dw_attr_ref at_digit_count;
5994 dw_attr_ref at_discr;
5995 dw_attr_ref at_discr_list;
5996 dw_attr_ref at_discr_value;
5997 dw_attr_ref at_encoding;
5998 dw_attr_ref at_endianity;
5999 dw_attr_ref at_explicit;
6000 dw_attr_ref at_is_optional;
6001 dw_attr_ref at_location;
6002 dw_attr_ref at_lower_bound;
6003 dw_attr_ref at_mutable;
6004 dw_attr_ref at_ordering;
6005 dw_attr_ref at_picture_string;
6006 dw_attr_ref at_prototyped;
6007 dw_attr_ref at_small;
6008 dw_attr_ref at_segment;
6009 dw_attr_ref at_string_length;
6010 dw_attr_ref at_threads_scaled;
6011 dw_attr_ref at_upper_bound;
6012 dw_attr_ref at_use_location;
6013 dw_attr_ref at_use_UTF8;
6014 dw_attr_ref at_variable_parameter;
6015 dw_attr_ref at_virtuality;
6016 dw_attr_ref at_visibility;
6017 dw_attr_ref at_vtable_elem_location;
6020 /* Collect the attributes that we will want to use for the checksum. */
6023 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
6028 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6039 attrs->at_friend = a;
6041 case DW_AT_accessibility:
6042 attrs->at_accessibility = a;
6044 case DW_AT_address_class:
6045 attrs->at_address_class = a;
6047 case DW_AT_allocated:
6048 attrs->at_allocated = a;
6050 case DW_AT_artificial:
6051 attrs->at_artificial = a;
6053 case DW_AT_associated:
6054 attrs->at_associated = a;
6056 case DW_AT_binary_scale:
6057 attrs->at_binary_scale = a;
6059 case DW_AT_bit_offset:
6060 attrs->at_bit_offset = a;
6062 case DW_AT_bit_size:
6063 attrs->at_bit_size = a;
6065 case DW_AT_bit_stride:
6066 attrs->at_bit_stride = a;
6068 case DW_AT_byte_size:
6069 attrs->at_byte_size = a;
6071 case DW_AT_byte_stride:
6072 attrs->at_byte_stride = a;
6074 case DW_AT_const_value:
6075 attrs->at_const_value = a;
6077 case DW_AT_containing_type:
6078 attrs->at_containing_type = a;
6081 attrs->at_count = a;
6083 case DW_AT_data_location:
6084 attrs->at_data_location = a;
6086 case DW_AT_data_member_location:
6087 attrs->at_data_member_location = a;
6089 case DW_AT_decimal_scale:
6090 attrs->at_decimal_scale = a;
6092 case DW_AT_decimal_sign:
6093 attrs->at_decimal_sign = a;
6095 case DW_AT_default_value:
6096 attrs->at_default_value = a;
6098 case DW_AT_digit_count:
6099 attrs->at_digit_count = a;
6102 attrs->at_discr = a;
6104 case DW_AT_discr_list:
6105 attrs->at_discr_list = a;
6107 case DW_AT_discr_value:
6108 attrs->at_discr_value = a;
6110 case DW_AT_encoding:
6111 attrs->at_encoding = a;
6113 case DW_AT_endianity:
6114 attrs->at_endianity = a;
6116 case DW_AT_explicit:
6117 attrs->at_explicit = a;
6119 case DW_AT_is_optional:
6120 attrs->at_is_optional = a;
6122 case DW_AT_location:
6123 attrs->at_location = a;
6125 case DW_AT_lower_bound:
6126 attrs->at_lower_bound = a;
6129 attrs->at_mutable = a;
6131 case DW_AT_ordering:
6132 attrs->at_ordering = a;
6134 case DW_AT_picture_string:
6135 attrs->at_picture_string = a;
6137 case DW_AT_prototyped:
6138 attrs->at_prototyped = a;
6141 attrs->at_small = a;
6144 attrs->at_segment = a;
6146 case DW_AT_string_length:
6147 attrs->at_string_length = a;
6149 case DW_AT_threads_scaled:
6150 attrs->at_threads_scaled = a;
6152 case DW_AT_upper_bound:
6153 attrs->at_upper_bound = a;
6155 case DW_AT_use_location:
6156 attrs->at_use_location = a;
6158 case DW_AT_use_UTF8:
6159 attrs->at_use_UTF8 = a;
6161 case DW_AT_variable_parameter:
6162 attrs->at_variable_parameter = a;
6164 case DW_AT_virtuality:
6165 attrs->at_virtuality = a;
6167 case DW_AT_visibility:
6168 attrs->at_visibility = a;
6170 case DW_AT_vtable_elem_location:
6171 attrs->at_vtable_elem_location = a;
6179 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6182 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6186 struct checksum_attributes attrs;
6188 CHECKSUM_ULEB128 ('D');
6189 CHECKSUM_ULEB128 (die->die_tag);
6191 memset (&attrs, 0, sizeof (attrs));
6193 decl = get_AT_ref (die, DW_AT_specification);
6195 collect_checksum_attributes (&attrs, decl);
6196 collect_checksum_attributes (&attrs, die);
6198 CHECKSUM_ATTR (attrs.at_name);
6199 CHECKSUM_ATTR (attrs.at_accessibility);
6200 CHECKSUM_ATTR (attrs.at_address_class);
6201 CHECKSUM_ATTR (attrs.at_allocated);
6202 CHECKSUM_ATTR (attrs.at_artificial);
6203 CHECKSUM_ATTR (attrs.at_associated);
6204 CHECKSUM_ATTR (attrs.at_binary_scale);
6205 CHECKSUM_ATTR (attrs.at_bit_offset);
6206 CHECKSUM_ATTR (attrs.at_bit_size);
6207 CHECKSUM_ATTR (attrs.at_bit_stride);
6208 CHECKSUM_ATTR (attrs.at_byte_size);
6209 CHECKSUM_ATTR (attrs.at_byte_stride);
6210 CHECKSUM_ATTR (attrs.at_const_value);
6211 CHECKSUM_ATTR (attrs.at_containing_type);
6212 CHECKSUM_ATTR (attrs.at_count);
6213 CHECKSUM_ATTR (attrs.at_data_location);
6214 CHECKSUM_ATTR (attrs.at_data_member_location);
6215 CHECKSUM_ATTR (attrs.at_decimal_scale);
6216 CHECKSUM_ATTR (attrs.at_decimal_sign);
6217 CHECKSUM_ATTR (attrs.at_default_value);
6218 CHECKSUM_ATTR (attrs.at_digit_count);
6219 CHECKSUM_ATTR (attrs.at_discr);
6220 CHECKSUM_ATTR (attrs.at_discr_list);
6221 CHECKSUM_ATTR (attrs.at_discr_value);
6222 CHECKSUM_ATTR (attrs.at_encoding);
6223 CHECKSUM_ATTR (attrs.at_endianity);
6224 CHECKSUM_ATTR (attrs.at_explicit);
6225 CHECKSUM_ATTR (attrs.at_is_optional);
6226 CHECKSUM_ATTR (attrs.at_location);
6227 CHECKSUM_ATTR (attrs.at_lower_bound);
6228 CHECKSUM_ATTR (attrs.at_mutable);
6229 CHECKSUM_ATTR (attrs.at_ordering);
6230 CHECKSUM_ATTR (attrs.at_picture_string);
6231 CHECKSUM_ATTR (attrs.at_prototyped);
6232 CHECKSUM_ATTR (attrs.at_small);
6233 CHECKSUM_ATTR (attrs.at_segment);
6234 CHECKSUM_ATTR (attrs.at_string_length);
6235 CHECKSUM_ATTR (attrs.at_threads_scaled);
6236 CHECKSUM_ATTR (attrs.at_upper_bound);
6237 CHECKSUM_ATTR (attrs.at_use_location);
6238 CHECKSUM_ATTR (attrs.at_use_UTF8);
6239 CHECKSUM_ATTR (attrs.at_variable_parameter);
6240 CHECKSUM_ATTR (attrs.at_virtuality);
6241 CHECKSUM_ATTR (attrs.at_visibility);
6242 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
6243 CHECKSUM_ATTR (attrs.at_type);
6244 CHECKSUM_ATTR (attrs.at_friend);
6246 /* Checksum the child DIEs, except for nested types and member functions. */
6249 dw_attr_ref name_attr;
6252 name_attr = get_AT (c, DW_AT_name);
6253 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
6254 && name_attr != NULL)
6256 CHECKSUM_ULEB128 ('S');
6257 CHECKSUM_ULEB128 (c->die_tag);
6258 CHECKSUM_STRING (AT_string (name_attr));
6262 /* Mark this DIE so it gets processed when unmarking. */
6263 if (c->die_mark == 0)
6265 die_checksum_ordered (c, ctx, mark);
6267 } while (c != die->die_child);
6269 CHECKSUM_ULEB128 (0);
6273 #undef CHECKSUM_STRING
6274 #undef CHECKSUM_ATTR
6275 #undef CHECKSUM_LEB128
6276 #undef CHECKSUM_ULEB128
6278 /* Generate the type signature for DIE. This is computed by generating an
6279 MD5 checksum over the DIE's tag, its relevant attributes, and its
6280 children. Attributes that are references to other DIEs are processed
6281 by recursion, using the MARK field to prevent infinite recursion.
6282 If the DIE is nested inside a namespace or another type, we also
6283 need to include that context in the signature. The lower 64 bits
6284 of the resulting MD5 checksum comprise the signature. */
6287 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
6291 unsigned char checksum[16];
6295 name = get_AT_string (die, DW_AT_name);
6296 decl = get_AT_ref (die, DW_AT_specification);
6298 /* First, compute a signature for just the type name (and its surrounding
6299 context, if any. This is stored in the type unit DIE for link-time
6300 ODR (one-definition rule) checking. */
6302 if (is_cxx() && name != NULL)
6304 md5_init_ctx (&ctx);
6306 /* Checksum the names of surrounding namespaces and structures. */
6307 if (decl != NULL && decl->die_parent != NULL)
6308 checksum_die_context (decl->die_parent, &ctx);
6310 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
6311 md5_process_bytes (name, strlen (name) + 1, &ctx);
6312 md5_finish_ctx (&ctx, checksum);
6314 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
6317 /* Next, compute the complete type signature. */
6319 md5_init_ctx (&ctx);
6321 die->die_mark = mark;
6323 /* Checksum the names of surrounding namespaces and structures. */
6324 if (decl != NULL && decl->die_parent != NULL)
6325 checksum_die_context (decl->die_parent, &ctx);
6327 /* Checksum the DIE and its children. */
6328 die_checksum_ordered (die, &ctx, &mark);
6329 unmark_all_dies (die);
6330 md5_finish_ctx (&ctx, checksum);
6332 /* Store the signature in the type node and link the type DIE and the
6333 type node together. */
6334 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
6335 DWARF_TYPE_SIGNATURE_SIZE);
6336 die->die_id.die_type_node = type_node;
6337 type_node->type_die = die;
6339 /* If the DIE is a specification, link its declaration to the type node
6342 decl->die_id.die_type_node = type_node;
6345 /* Do the location expressions look same? */
6347 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6349 return loc1->dw_loc_opc == loc2->dw_loc_opc
6350 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6351 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6354 /* Do the values look the same? */
6356 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6358 dw_loc_descr_ref loc1, loc2;
6361 if (v1->val_class != v2->val_class)
6364 switch (v1->val_class)
6366 case dw_val_class_const:
6367 return v1->v.val_int == v2->v.val_int;
6368 case dw_val_class_unsigned_const:
6369 return v1->v.val_unsigned == v2->v.val_unsigned;
6370 case dw_val_class_const_double:
6371 return v1->v.val_double.high == v2->v.val_double.high
6372 && v1->v.val_double.low == v2->v.val_double.low;
6373 case dw_val_class_vec:
6374 if (v1->v.val_vec.length != v2->v.val_vec.length
6375 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6377 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6378 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6381 case dw_val_class_flag:
6382 return v1->v.val_flag == v2->v.val_flag;
6383 case dw_val_class_str:
6384 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6386 case dw_val_class_addr:
6387 r1 = v1->v.val_addr;
6388 r2 = v2->v.val_addr;
6389 if (GET_CODE (r1) != GET_CODE (r2))
6391 return !rtx_equal_p (r1, r2);
6393 case dw_val_class_offset:
6394 return v1->v.val_offset == v2->v.val_offset;
6396 case dw_val_class_loc:
6397 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6399 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6400 if (!same_loc_p (loc1, loc2, mark))
6402 return !loc1 && !loc2;
6404 case dw_val_class_die_ref:
6405 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6407 case dw_val_class_fde_ref:
6408 case dw_val_class_vms_delta:
6409 case dw_val_class_lbl_id:
6410 case dw_val_class_lineptr:
6411 case dw_val_class_macptr:
6414 case dw_val_class_file:
6415 return v1->v.val_file == v2->v.val_file;
6417 case dw_val_class_data8:
6418 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
6425 /* Do the attributes look the same? */
6428 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6430 if (at1->dw_attr != at2->dw_attr)
6433 /* We don't care that this was compiled with a different compiler
6434 snapshot; if the output is the same, that's what matters. */
6435 if (at1->dw_attr == DW_AT_producer)
6438 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6441 /* Do the dies look the same? */
6444 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6450 /* To avoid infinite recursion. */
6452 return die1->die_mark == die2->die_mark;
6453 die1->die_mark = die2->die_mark = ++(*mark);
6455 if (die1->die_tag != die2->die_tag)
6458 if (VEC_length (dw_attr_node, die1->die_attr)
6459 != VEC_length (dw_attr_node, die2->die_attr))
6462 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
6463 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6466 c1 = die1->die_child;
6467 c2 = die2->die_child;
6476 if (!same_die_p (c1, c2, mark))
6480 if (c1 == die1->die_child)
6482 if (c2 == die2->die_child)
6492 /* Do the dies look the same? Wrapper around same_die_p. */
6495 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6498 int ret = same_die_p (die1, die2, &mark);
6500 unmark_all_dies (die1);
6501 unmark_all_dies (die2);
6506 /* The prefix to attach to symbols on DIEs in the current comdat debug
6508 static char *comdat_symbol_id;
6510 /* The index of the current symbol within the current comdat CU. */
6511 static unsigned int comdat_symbol_number;
6513 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6514 children, and set comdat_symbol_id accordingly. */
6517 compute_section_prefix (dw_die_ref unit_die)
6519 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6520 const char *base = die_name ? lbasename (die_name) : "anonymous";
6521 char *name = XALLOCAVEC (char, strlen (base) + 64);
6524 unsigned char checksum[16];
6527 /* Compute the checksum of the DIE, then append part of it as hex digits to
6528 the name filename of the unit. */
6530 md5_init_ctx (&ctx);
6532 die_checksum (unit_die, &ctx, &mark);
6533 unmark_all_dies (unit_die);
6534 md5_finish_ctx (&ctx, checksum);
6536 sprintf (name, "%s.", base);
6537 clean_symbol_name (name);
6539 p = name + strlen (name);
6540 for (i = 0; i < 4; i++)
6542 sprintf (p, "%.2x", checksum[i]);
6546 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
6547 comdat_symbol_number = 0;
6550 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6553 is_type_die (dw_die_ref die)
6555 switch (die->die_tag)
6557 case DW_TAG_array_type:
6558 case DW_TAG_class_type:
6559 case DW_TAG_interface_type:
6560 case DW_TAG_enumeration_type:
6561 case DW_TAG_pointer_type:
6562 case DW_TAG_reference_type:
6563 case DW_TAG_rvalue_reference_type:
6564 case DW_TAG_string_type:
6565 case DW_TAG_structure_type:
6566 case DW_TAG_subroutine_type:
6567 case DW_TAG_union_type:
6568 case DW_TAG_ptr_to_member_type:
6569 case DW_TAG_set_type:
6570 case DW_TAG_subrange_type:
6571 case DW_TAG_base_type:
6572 case DW_TAG_const_type:
6573 case DW_TAG_file_type:
6574 case DW_TAG_packed_type:
6575 case DW_TAG_volatile_type:
6576 case DW_TAG_typedef:
6583 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6584 Basically, we want to choose the bits that are likely to be shared between
6585 compilations (types) and leave out the bits that are specific to individual
6586 compilations (functions). */
6589 is_comdat_die (dw_die_ref c)
6591 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6592 we do for stabs. The advantage is a greater likelihood of sharing between
6593 objects that don't include headers in the same order (and therefore would
6594 put the base types in a different comdat). jason 8/28/00 */
6596 if (c->die_tag == DW_TAG_base_type)
6599 if (c->die_tag == DW_TAG_pointer_type
6600 || c->die_tag == DW_TAG_reference_type
6601 || c->die_tag == DW_TAG_rvalue_reference_type
6602 || c->die_tag == DW_TAG_const_type
6603 || c->die_tag == DW_TAG_volatile_type)
6605 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6607 return t ? is_comdat_die (t) : 0;
6610 return is_type_die (c);
6613 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6614 compilation unit. */
6617 is_symbol_die (dw_die_ref c)
6619 return (is_type_die (c)
6620 || is_declaration_die (c)
6621 || c->die_tag == DW_TAG_namespace
6622 || c->die_tag == DW_TAG_module);
6625 /* Returns true iff C is a compile-unit DIE. */
6628 is_cu_die (dw_die_ref c)
6630 return c && c->die_tag == DW_TAG_compile_unit;
6634 gen_internal_sym (const char *prefix)
6638 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6639 return xstrdup (buf);
6642 /* Assign symbols to all worthy DIEs under DIE. */
6645 assign_symbol_names (dw_die_ref die)
6649 if (is_symbol_die (die))
6651 if (comdat_symbol_id)
6653 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
6655 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6656 comdat_symbol_id, comdat_symbol_number++);
6657 die->die_id.die_symbol = xstrdup (p);
6660 die->die_id.die_symbol = gen_internal_sym ("LDIE");
6663 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6666 struct cu_hash_table_entry
6669 unsigned min_comdat_num, max_comdat_num;
6670 struct cu_hash_table_entry *next;
6673 /* Routines to manipulate hash table of CUs. */
6675 htab_cu_hash (const void *of)
6677 const struct cu_hash_table_entry *const entry =
6678 (const struct cu_hash_table_entry *) of;
6680 return htab_hash_string (entry->cu->die_id.die_symbol);
6684 htab_cu_eq (const void *of1, const void *of2)
6686 const struct cu_hash_table_entry *const entry1 =
6687 (const struct cu_hash_table_entry *) of1;
6688 const struct die_struct *const entry2 = (const struct die_struct *) of2;
6690 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
6694 htab_cu_del (void *what)
6696 struct cu_hash_table_entry *next,
6697 *entry = (struct cu_hash_table_entry *) what;
6707 /* Check whether we have already seen this CU and set up SYM_NUM
6710 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6712 struct cu_hash_table_entry dummy;
6713 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6715 dummy.max_comdat_num = 0;
6717 slot = (struct cu_hash_table_entry **)
6718 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
6722 for (; entry; last = entry, entry = entry->next)
6724 if (same_die_p_wrap (cu, entry->cu))
6730 *sym_num = entry->min_comdat_num;
6734 entry = XCNEW (struct cu_hash_table_entry);
6736 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6737 entry->next = *slot;
6743 /* Record SYM_NUM to record of CU in HTABLE. */
6745 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6747 struct cu_hash_table_entry **slot, *entry;
6749 slot = (struct cu_hash_table_entry **)
6750 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
6754 entry->max_comdat_num = sym_num;
6757 /* Traverse the DIE (which is always comp_unit_die), and set up
6758 additional compilation units for each of the include files we see
6759 bracketed by BINCL/EINCL. */
6762 break_out_includes (dw_die_ref die)
6765 dw_die_ref unit = NULL;
6766 limbo_die_node *node, **pnode;
6767 htab_t cu_hash_table;
6771 dw_die_ref prev = c;
6773 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6774 || (unit && is_comdat_die (c)))
6776 dw_die_ref next = c->die_sib;
6778 /* This DIE is for a secondary CU; remove it from the main one. */
6779 remove_child_with_prev (c, prev);
6781 if (c->die_tag == DW_TAG_GNU_BINCL)
6782 unit = push_new_compile_unit (unit, c);
6783 else if (c->die_tag == DW_TAG_GNU_EINCL)
6784 unit = pop_compile_unit (unit);
6786 add_child_die (unit, c);
6788 if (c == die->die_child)
6791 } while (c != die->die_child);
6794 /* We can only use this in debugging, since the frontend doesn't check
6795 to make sure that we leave every include file we enter. */
6799 assign_symbol_names (die);
6800 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6801 for (node = limbo_die_list, pnode = &limbo_die_list;
6807 compute_section_prefix (node->die);
6808 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6809 &comdat_symbol_number);
6810 assign_symbol_names (node->die);
6812 *pnode = node->next;
6815 pnode = &node->next;
6816 record_comdat_symbol_number (node->die, cu_hash_table,
6817 comdat_symbol_number);
6820 htab_delete (cu_hash_table);
6823 /* Return non-zero if this DIE is a declaration. */
6826 is_declaration_die (dw_die_ref die)
6831 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6832 if (a->dw_attr == DW_AT_declaration)
6838 /* Return non-zero if this DIE is nested inside a subprogram. */
6841 is_nested_in_subprogram (dw_die_ref die)
6843 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
6847 return local_scope_p (decl);
6850 /* Return non-zero if this DIE contains a defining declaration of a
6854 contains_subprogram_definition (dw_die_ref die)
6858 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
6860 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
6864 /* Return non-zero if this is a type DIE that should be moved to a
6865 COMDAT .debug_types section. */
6868 should_move_die_to_comdat (dw_die_ref die)
6870 switch (die->die_tag)
6872 case DW_TAG_class_type:
6873 case DW_TAG_structure_type:
6874 case DW_TAG_enumeration_type:
6875 case DW_TAG_union_type:
6876 /* Don't move declarations, inlined instances, or types nested in a
6878 if (is_declaration_die (die)
6879 || get_AT (die, DW_AT_abstract_origin)
6880 || is_nested_in_subprogram (die))
6882 /* A type definition should never contain a subprogram definition. */
6883 gcc_assert (!contains_subprogram_definition (die));
6885 case DW_TAG_array_type:
6886 case DW_TAG_interface_type:
6887 case DW_TAG_pointer_type:
6888 case DW_TAG_reference_type:
6889 case DW_TAG_rvalue_reference_type:
6890 case DW_TAG_string_type:
6891 case DW_TAG_subroutine_type:
6892 case DW_TAG_ptr_to_member_type:
6893 case DW_TAG_set_type:
6894 case DW_TAG_subrange_type:
6895 case DW_TAG_base_type:
6896 case DW_TAG_const_type:
6897 case DW_TAG_file_type:
6898 case DW_TAG_packed_type:
6899 case DW_TAG_volatile_type:
6900 case DW_TAG_typedef:
6906 /* Make a clone of DIE. */
6909 clone_die (dw_die_ref die)
6915 clone = ggc_alloc_cleared_die_node ();
6916 clone->die_tag = die->die_tag;
6918 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6919 add_dwarf_attr (clone, a);
6924 /* Make a clone of the tree rooted at DIE. */
6927 clone_tree (dw_die_ref die)
6930 dw_die_ref clone = clone_die (die);
6932 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
6937 /* Make a clone of DIE as a declaration. */
6940 clone_as_declaration (dw_die_ref die)
6947 /* If the DIE is already a declaration, just clone it. */
6948 if (is_declaration_die (die))
6949 return clone_die (die);
6951 /* If the DIE is a specification, just clone its declaration DIE. */
6952 decl = get_AT_ref (die, DW_AT_specification);
6954 return clone_die (decl);
6956 clone = ggc_alloc_cleared_die_node ();
6957 clone->die_tag = die->die_tag;
6959 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6961 /* We don't want to copy over all attributes.
6962 For example we don't want DW_AT_byte_size because otherwise we will no
6963 longer have a declaration and GDB will treat it as a definition. */
6967 case DW_AT_artificial:
6968 case DW_AT_containing_type:
6969 case DW_AT_external:
6972 case DW_AT_virtuality:
6973 case DW_AT_linkage_name:
6974 case DW_AT_MIPS_linkage_name:
6975 add_dwarf_attr (clone, a);
6977 case DW_AT_byte_size:
6983 if (die->die_id.die_type_node)
6984 add_AT_die_ref (clone, DW_AT_signature, die);
6986 add_AT_flag (clone, DW_AT_declaration, 1);
6990 /* Copy the declaration context to the new compile unit DIE. This includes
6991 any surrounding namespace or type declarations. If the DIE has an
6992 AT_specification attribute, it also includes attributes and children
6993 attached to the specification. */
6996 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
6999 dw_die_ref new_decl;
7001 decl = get_AT_ref (die, DW_AT_specification);
7010 /* Copy the type node pointer from the new DIE to the original
7011 declaration DIE so we can forward references later. */
7012 decl->die_id.die_type_node = die->die_id.die_type_node;
7014 remove_AT (die, DW_AT_specification);
7016 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
7018 if (a->dw_attr != DW_AT_name
7019 && a->dw_attr != DW_AT_declaration
7020 && a->dw_attr != DW_AT_external)
7021 add_dwarf_attr (die, a);
7024 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
7027 if (decl->die_parent != NULL
7028 && decl->die_parent->die_tag != DW_TAG_compile_unit
7029 && decl->die_parent->die_tag != DW_TAG_type_unit)
7031 new_decl = copy_ancestor_tree (unit, decl, NULL);
7032 if (new_decl != NULL)
7034 remove_AT (new_decl, DW_AT_signature);
7035 add_AT_specification (die, new_decl);
7040 /* Generate the skeleton ancestor tree for the given NODE, then clone
7041 the DIE and add the clone into the tree. */
7044 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
7046 if (node->new_die != NULL)
7049 node->new_die = clone_as_declaration (node->old_die);
7051 if (node->parent != NULL)
7053 generate_skeleton_ancestor_tree (node->parent);
7054 add_child_die (node->parent->new_die, node->new_die);
7058 /* Generate a skeleton tree of DIEs containing any declarations that are
7059 found in the original tree. We traverse the tree looking for declaration
7060 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7063 generate_skeleton_bottom_up (skeleton_chain_node *parent)
7065 skeleton_chain_node node;
7068 dw_die_ref prev = NULL;
7069 dw_die_ref next = NULL;
7071 node.parent = parent;
7073 first = c = parent->old_die->die_child;
7077 if (prev == NULL || prev->die_sib == c)
7080 next = (c == first ? NULL : c->die_sib);
7082 node.new_die = NULL;
7083 if (is_declaration_die (c))
7085 /* Clone the existing DIE, move the original to the skeleton
7086 tree (which is in the main CU), and put the clone, with
7087 all the original's children, where the original came from. */
7088 dw_die_ref clone = clone_die (c);
7089 move_all_children (c, clone);
7091 replace_child (c, clone, prev);
7092 generate_skeleton_ancestor_tree (parent);
7093 add_child_die (parent->new_die, c);
7097 generate_skeleton_bottom_up (&node);
7098 } while (next != NULL);
7101 /* Wrapper function for generate_skeleton_bottom_up. */
7104 generate_skeleton (dw_die_ref die)
7106 skeleton_chain_node node;
7109 node.new_die = NULL;
7112 /* If this type definition is nested inside another type,
7113 always leave at least a declaration in its place. */
7114 if (die->die_parent != NULL && is_type_die (die->die_parent))
7115 node.new_die = clone_as_declaration (die);
7117 generate_skeleton_bottom_up (&node);
7118 return node.new_die;
7121 /* Remove the DIE from its parent, possibly replacing it with a cloned
7122 declaration. The original DIE will be moved to a new compile unit
7123 so that existing references to it follow it to the new location. If
7124 any of the original DIE's descendants is a declaration, we need to
7125 replace the original DIE with a skeleton tree and move the
7126 declarations back into the skeleton tree. */
7129 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
7131 dw_die_ref skeleton;
7133 skeleton = generate_skeleton (child);
7134 if (skeleton == NULL)
7135 remove_child_with_prev (child, prev);
7138 skeleton->die_id.die_type_node = child->die_id.die_type_node;
7139 replace_child (child, skeleton, prev);
7145 /* Traverse the DIE and set up additional .debug_types sections for each
7146 type worthy of being placed in a COMDAT section. */
7149 break_out_comdat_types (dw_die_ref die)
7153 dw_die_ref prev = NULL;
7154 dw_die_ref next = NULL;
7155 dw_die_ref unit = NULL;
7157 first = c = die->die_child;
7161 if (prev == NULL || prev->die_sib == c)
7164 next = (c == first ? NULL : c->die_sib);
7165 if (should_move_die_to_comdat (c))
7167 dw_die_ref replacement;
7168 comdat_type_node_ref type_node;
7170 /* Create a new type unit DIE as the root for the new tree, and
7171 add it to the list of comdat types. */
7172 unit = new_die (DW_TAG_type_unit, NULL, NULL);
7173 add_AT_unsigned (unit, DW_AT_language,
7174 get_AT_unsigned (comp_unit_die (), DW_AT_language));
7175 type_node = ggc_alloc_cleared_comdat_type_node ();
7176 type_node->root_die = unit;
7177 type_node->next = comdat_type_list;
7178 comdat_type_list = type_node;
7180 /* Generate the type signature. */
7181 generate_type_signature (c, type_node);
7183 /* Copy the declaration context, attributes, and children of the
7184 declaration into the new compile unit DIE. */
7185 copy_declaration_context (unit, c);
7187 /* Remove this DIE from the main CU. */
7188 replacement = remove_child_or_replace_with_skeleton (c, prev);
7190 /* Break out nested types into their own type units. */
7191 break_out_comdat_types (c);
7193 /* Add the DIE to the new compunit. */
7194 add_child_die (unit, c);
7196 if (replacement != NULL)
7199 else if (c->die_tag == DW_TAG_namespace
7200 || c->die_tag == DW_TAG_class_type
7201 || c->die_tag == DW_TAG_structure_type
7202 || c->die_tag == DW_TAG_union_type)
7204 /* Look for nested types that can be broken out. */
7205 break_out_comdat_types (c);
7207 } while (next != NULL);
7210 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7212 struct decl_table_entry
7218 /* Routines to manipulate hash table of copied declarations. */
7221 htab_decl_hash (const void *of)
7223 const struct decl_table_entry *const entry =
7224 (const struct decl_table_entry *) of;
7226 return htab_hash_pointer (entry->orig);
7230 htab_decl_eq (const void *of1, const void *of2)
7232 const struct decl_table_entry *const entry1 =
7233 (const struct decl_table_entry *) of1;
7234 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7236 return entry1->orig == entry2;
7240 htab_decl_del (void *what)
7242 struct decl_table_entry *entry = (struct decl_table_entry *) what;
7247 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7248 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7249 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7250 to check if the ancestor has already been copied into UNIT. */
7253 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7255 dw_die_ref parent = die->die_parent;
7256 dw_die_ref new_parent = unit;
7259 struct decl_table_entry *entry = NULL;
7263 /* Check if the entry has already been copied to UNIT. */
7264 slot = htab_find_slot_with_hash (decl_table, die,
7265 htab_hash_pointer (die), INSERT);
7266 if (*slot != HTAB_EMPTY_ENTRY)
7268 entry = (struct decl_table_entry *) *slot;
7272 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7273 entry = XCNEW (struct decl_table_entry);
7281 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
7284 if (parent->die_tag != DW_TAG_compile_unit
7285 && parent->die_tag != DW_TAG_type_unit)
7286 new_parent = copy_ancestor_tree (unit, parent, decl_table);
7289 copy = clone_as_declaration (die);
7290 add_child_die (new_parent, copy);
7292 if (decl_table != NULL)
7294 /* Record the pointer to the copy. */
7301 /* Walk the DIE and its children, looking for references to incomplete
7302 or trivial types that are unmarked (i.e., that are not in the current
7306 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7312 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7314 if (AT_class (a) == dw_val_class_die_ref)
7316 dw_die_ref targ = AT_ref (a);
7317 comdat_type_node_ref type_node = targ->die_id.die_type_node;
7319 struct decl_table_entry *entry;
7321 if (targ->die_mark != 0 || type_node != NULL)
7324 slot = htab_find_slot_with_hash (decl_table, targ,
7325 htab_hash_pointer (targ), INSERT);
7327 if (*slot != HTAB_EMPTY_ENTRY)
7329 /* TARG has already been copied, so we just need to
7330 modify the reference to point to the copy. */
7331 entry = (struct decl_table_entry *) *slot;
7332 a->dw_attr_val.v.val_die_ref.die = entry->copy;
7336 dw_die_ref parent = unit;
7337 dw_die_ref copy = clone_tree (targ);
7339 /* Make sure the cloned tree is marked as part of the
7343 /* Record in DECL_TABLE that TARG has been copied.
7344 Need to do this now, before the recursive call,
7345 because DECL_TABLE may be expanded and SLOT
7346 would no longer be a valid pointer. */
7347 entry = XCNEW (struct decl_table_entry);
7352 /* If TARG has surrounding context, copy its ancestor tree
7353 into the new type unit. */
7354 if (targ->die_parent != NULL
7355 && targ->die_parent->die_tag != DW_TAG_compile_unit
7356 && targ->die_parent->die_tag != DW_TAG_type_unit)
7357 parent = copy_ancestor_tree (unit, targ->die_parent,
7360 add_child_die (parent, copy);
7361 a->dw_attr_val.v.val_die_ref.die = copy;
7363 /* Make sure the newly-copied DIE is walked. If it was
7364 installed in a previously-added context, it won't
7365 get visited otherwise. */
7368 /* Find the highest point of the newly-added tree,
7369 mark each node along the way, and walk from there. */
7370 parent->die_mark = 1;
7371 while (parent->die_parent
7372 && parent->die_parent->die_mark == 0)
7374 parent = parent->die_parent;
7375 parent->die_mark = 1;
7377 copy_decls_walk (unit, parent, decl_table);
7383 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
7386 /* Copy declarations for "unworthy" types into the new comdat section.
7387 Incomplete types, modified types, and certain other types aren't broken
7388 out into comdat sections of their own, so they don't have a signature,
7389 and we need to copy the declaration into the same section so that we
7390 don't have an external reference. */
7393 copy_decls_for_unworthy_types (dw_die_ref unit)
7398 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
7399 copy_decls_walk (unit, unit, decl_table);
7400 htab_delete (decl_table);
7404 /* Traverse the DIE and add a sibling attribute if it may have the
7405 effect of speeding up access to siblings. To save some space,
7406 avoid generating sibling attributes for DIE's without children. */
7409 add_sibling_attributes (dw_die_ref die)
7413 if (! die->die_child)
7416 if (die->die_parent && die != die->die_parent->die_child)
7417 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7419 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7422 /* Output all location lists for the DIE and its children. */
7425 output_location_lists (dw_die_ref die)
7431 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7432 if (AT_class (a) == dw_val_class_loc_list)
7433 output_loc_list (AT_loc_list (a));
7435 FOR_EACH_CHILD (die, c, output_location_lists (c));
7438 /* The format of each DIE (and its attribute value pairs) is encoded in an
7439 abbreviation table. This routine builds the abbreviation table and assigns
7440 a unique abbreviation id for each abbreviation entry. The children of each
7441 die are visited recursively. */
7444 build_abbrev_table (dw_die_ref die)
7446 unsigned long abbrev_id;
7447 unsigned int n_alloc;
7452 /* Scan the DIE references, and mark as external any that refer to
7453 DIEs from other CUs (i.e. those which are not marked). */
7454 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7455 if (AT_class (a) == dw_val_class_die_ref
7456 && AT_ref (a)->die_mark == 0)
7458 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
7459 set_AT_ref_external (a, 1);
7462 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7464 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7465 dw_attr_ref die_a, abbrev_a;
7469 if (abbrev->die_tag != die->die_tag)
7471 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7474 if (VEC_length (dw_attr_node, abbrev->die_attr)
7475 != VEC_length (dw_attr_node, die->die_attr))
7478 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
7480 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7481 if ((abbrev_a->dw_attr != die_a->dw_attr)
7482 || (value_format (abbrev_a) != value_format (die_a)))
7492 if (abbrev_id >= abbrev_die_table_in_use)
7494 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7496 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7497 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7500 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7501 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7502 abbrev_die_table_allocated = n_alloc;
7505 ++abbrev_die_table_in_use;
7506 abbrev_die_table[abbrev_id] = die;
7509 die->die_abbrev = abbrev_id;
7510 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7513 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7516 constant_size (unsigned HOST_WIDE_INT value)
7523 log = floor_log2 (value);
7526 log = 1 << (floor_log2 (log) + 1);
7531 /* Return the size of a DIE as it is represented in the
7532 .debug_info section. */
7534 static unsigned long
7535 size_of_die (dw_die_ref die)
7537 unsigned long size = 0;
7541 size += size_of_uleb128 (die->die_abbrev);
7542 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7544 switch (AT_class (a))
7546 case dw_val_class_addr:
7547 size += DWARF2_ADDR_SIZE;
7549 case dw_val_class_offset:
7550 size += DWARF_OFFSET_SIZE;
7552 case dw_val_class_loc:
7554 unsigned long lsize = size_of_locs (AT_loc (a));
7557 if (dwarf_version >= 4)
7558 size += size_of_uleb128 (lsize);
7560 size += constant_size (lsize);
7564 case dw_val_class_loc_list:
7565 size += DWARF_OFFSET_SIZE;
7567 case dw_val_class_range_list:
7568 size += DWARF_OFFSET_SIZE;
7570 case dw_val_class_const:
7571 size += size_of_sleb128 (AT_int (a));
7573 case dw_val_class_unsigned_const:
7574 size += constant_size (AT_unsigned (a));
7576 case dw_val_class_const_double:
7577 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
7578 if (HOST_BITS_PER_WIDE_INT >= 64)
7581 case dw_val_class_vec:
7582 size += constant_size (a->dw_attr_val.v.val_vec.length
7583 * a->dw_attr_val.v.val_vec.elt_size)
7584 + a->dw_attr_val.v.val_vec.length
7585 * a->dw_attr_val.v.val_vec.elt_size; /* block */
7587 case dw_val_class_flag:
7588 if (dwarf_version >= 4)
7589 /* Currently all add_AT_flag calls pass in 1 as last argument,
7590 so DW_FORM_flag_present can be used. If that ever changes,
7591 we'll need to use DW_FORM_flag and have some optimization
7592 in build_abbrev_table that will change those to
7593 DW_FORM_flag_present if it is set to 1 in all DIEs using
7594 the same abbrev entry. */
7595 gcc_assert (a->dw_attr_val.v.val_flag == 1);
7599 case dw_val_class_die_ref:
7600 if (AT_ref_external (a))
7602 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7603 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7604 is sized by target address length, whereas in DWARF3
7605 it's always sized as an offset. */
7606 if (use_debug_types)
7607 size += DWARF_TYPE_SIGNATURE_SIZE;
7608 else if (dwarf_version == 2)
7609 size += DWARF2_ADDR_SIZE;
7611 size += DWARF_OFFSET_SIZE;
7614 size += DWARF_OFFSET_SIZE;
7616 case dw_val_class_fde_ref:
7617 size += DWARF_OFFSET_SIZE;
7619 case dw_val_class_lbl_id:
7620 size += DWARF2_ADDR_SIZE;
7622 case dw_val_class_lineptr:
7623 case dw_val_class_macptr:
7624 size += DWARF_OFFSET_SIZE;
7626 case dw_val_class_str:
7627 if (AT_string_form (a) == DW_FORM_strp)
7628 size += DWARF_OFFSET_SIZE;
7630 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7632 case dw_val_class_file:
7633 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7635 case dw_val_class_data8:
7638 case dw_val_class_vms_delta:
7639 size += DWARF_OFFSET_SIZE;
7649 /* Size the debugging information associated with a given DIE. Visits the
7650 DIE's children recursively. Updates the global variable next_die_offset, on
7651 each time through. Uses the current value of next_die_offset to update the
7652 die_offset field in each DIE. */
7655 calc_die_sizes (dw_die_ref die)
7659 gcc_assert (die->die_offset == 0
7660 || (unsigned long int) die->die_offset == next_die_offset);
7661 die->die_offset = next_die_offset;
7662 next_die_offset += size_of_die (die);
7664 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7666 if (die->die_child != NULL)
7667 /* Count the null byte used to terminate sibling lists. */
7668 next_die_offset += 1;
7671 /* Size just the base type children at the start of the CU.
7672 This is needed because build_abbrev needs to size locs
7673 and sizing of type based stack ops needs to know die_offset
7674 values for the base types. */
7677 calc_base_type_die_sizes (void)
7679 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7681 dw_die_ref base_type;
7682 #if ENABLE_ASSERT_CHECKING
7683 dw_die_ref prev = comp_unit_die ()->die_child;
7686 die_offset += size_of_die (comp_unit_die ());
7687 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
7689 #if ENABLE_ASSERT_CHECKING
7690 gcc_assert (base_type->die_offset == 0
7691 && prev->die_sib == base_type
7692 && base_type->die_child == NULL
7693 && base_type->die_abbrev);
7696 base_type->die_offset = die_offset;
7697 die_offset += size_of_die (base_type);
7701 /* Set the marks for a die and its children. We do this so
7702 that we know whether or not a reference needs to use FORM_ref_addr; only
7703 DIEs in the same CU will be marked. We used to clear out the offset
7704 and use that as the flag, but ran into ordering problems. */
7707 mark_dies (dw_die_ref die)
7711 gcc_assert (!die->die_mark);
7714 FOR_EACH_CHILD (die, c, mark_dies (c));
7717 /* Clear the marks for a die and its children. */
7720 unmark_dies (dw_die_ref die)
7724 if (! use_debug_types)
7725 gcc_assert (die->die_mark);
7728 FOR_EACH_CHILD (die, c, unmark_dies (c));
7731 /* Clear the marks for a die, its children and referred dies. */
7734 unmark_all_dies (dw_die_ref die)
7744 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7746 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7747 if (AT_class (a) == dw_val_class_die_ref)
7748 unmark_all_dies (AT_ref (a));
7751 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7752 generated for the compilation unit. */
7754 static unsigned long
7755 size_of_pubnames (VEC (pubname_entry, gc) * names)
7761 size = DWARF_PUBNAMES_HEADER_SIZE;
7762 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
7763 if (names != pubtype_table
7764 || p->die->die_offset != 0
7765 || !flag_eliminate_unused_debug_types)
7766 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7768 size += DWARF_OFFSET_SIZE;
7772 /* Return the size of the information in the .debug_aranges section. */
7774 static unsigned long
7775 size_of_aranges (void)
7779 size = DWARF_ARANGES_HEADER_SIZE;
7781 /* Count the address/length pair for this compilation unit. */
7782 if (text_section_used)
7783 size += 2 * DWARF2_ADDR_SIZE;
7784 if (cold_text_section_used)
7785 size += 2 * DWARF2_ADDR_SIZE;
7786 if (have_multiple_function_sections)
7791 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
7793 if (!fde->in_std_section)
7794 size += 2 * DWARF2_ADDR_SIZE;
7795 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
7796 size += 2 * DWARF2_ADDR_SIZE;
7800 /* Count the two zero words used to terminated the address range table. */
7801 size += 2 * DWARF2_ADDR_SIZE;
7805 /* Select the encoding of an attribute value. */
7807 static enum dwarf_form
7808 value_format (dw_attr_ref a)
7810 switch (a->dw_attr_val.val_class)
7812 case dw_val_class_addr:
7813 /* Only very few attributes allow DW_FORM_addr. */
7818 case DW_AT_entry_pc:
7819 case DW_AT_trampoline:
7820 return DW_FORM_addr;
7824 switch (DWARF2_ADDR_SIZE)
7827 return DW_FORM_data1;
7829 return DW_FORM_data2;
7831 return DW_FORM_data4;
7833 return DW_FORM_data8;
7837 case dw_val_class_range_list:
7838 case dw_val_class_loc_list:
7839 if (dwarf_version >= 4)
7840 return DW_FORM_sec_offset;
7842 case dw_val_class_vms_delta:
7843 case dw_val_class_offset:
7844 switch (DWARF_OFFSET_SIZE)
7847 return DW_FORM_data4;
7849 return DW_FORM_data8;
7853 case dw_val_class_loc:
7854 if (dwarf_version >= 4)
7855 return DW_FORM_exprloc;
7856 switch (constant_size (size_of_locs (AT_loc (a))))
7859 return DW_FORM_block1;
7861 return DW_FORM_block2;
7865 case dw_val_class_const:
7866 return DW_FORM_sdata;
7867 case dw_val_class_unsigned_const:
7868 switch (constant_size (AT_unsigned (a)))
7871 return DW_FORM_data1;
7873 return DW_FORM_data2;
7875 return DW_FORM_data4;
7877 return DW_FORM_data8;
7881 case dw_val_class_const_double:
7882 switch (HOST_BITS_PER_WIDE_INT)
7885 return DW_FORM_data2;
7887 return DW_FORM_data4;
7889 return DW_FORM_data8;
7892 return DW_FORM_block1;
7894 case dw_val_class_vec:
7895 switch (constant_size (a->dw_attr_val.v.val_vec.length
7896 * a->dw_attr_val.v.val_vec.elt_size))
7899 return DW_FORM_block1;
7901 return DW_FORM_block2;
7903 return DW_FORM_block4;
7907 case dw_val_class_flag:
7908 if (dwarf_version >= 4)
7910 /* Currently all add_AT_flag calls pass in 1 as last argument,
7911 so DW_FORM_flag_present can be used. If that ever changes,
7912 we'll need to use DW_FORM_flag and have some optimization
7913 in build_abbrev_table that will change those to
7914 DW_FORM_flag_present if it is set to 1 in all DIEs using
7915 the same abbrev entry. */
7916 gcc_assert (a->dw_attr_val.v.val_flag == 1);
7917 return DW_FORM_flag_present;
7919 return DW_FORM_flag;
7920 case dw_val_class_die_ref:
7921 if (AT_ref_external (a))
7922 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
7925 case dw_val_class_fde_ref:
7926 return DW_FORM_data;
7927 case dw_val_class_lbl_id:
7928 return DW_FORM_addr;
7929 case dw_val_class_lineptr:
7930 case dw_val_class_macptr:
7931 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
7932 case dw_val_class_str:
7933 return AT_string_form (a);
7934 case dw_val_class_file:
7935 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7938 return DW_FORM_data1;
7940 return DW_FORM_data2;
7942 return DW_FORM_data4;
7947 case dw_val_class_data8:
7948 return DW_FORM_data8;
7955 /* Output the encoding of an attribute value. */
7958 output_value_format (dw_attr_ref a)
7960 enum dwarf_form form = value_format (a);
7962 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7965 /* Output the .debug_abbrev section which defines the DIE abbreviation
7969 output_abbrev_section (void)
7971 unsigned long abbrev_id;
7973 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7975 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7979 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7980 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7981 dwarf_tag_name (abbrev->die_tag));
7983 if (abbrev->die_child != NULL)
7984 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7986 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7988 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7991 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7992 dwarf_attr_name (a_attr->dw_attr));
7993 output_value_format (a_attr);
7996 dw2_asm_output_data (1, 0, NULL);
7997 dw2_asm_output_data (1, 0, NULL);
8000 /* Terminate the table. */
8001 dw2_asm_output_data (1, 0, NULL);
8004 /* Output a symbol we can use to refer to this DIE from another CU. */
8007 output_die_symbol (dw_die_ref die)
8009 char *sym = die->die_id.die_symbol;
8014 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8015 /* We make these global, not weak; if the target doesn't support
8016 .linkonce, it doesn't support combining the sections, so debugging
8018 targetm.asm_out.globalize_label (asm_out_file, sym);
8020 ASM_OUTPUT_LABEL (asm_out_file, sym);
8023 /* Return a new location list, given the begin and end range, and the
8026 static inline dw_loc_list_ref
8027 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8028 const char *section)
8030 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
8032 retlist->begin = begin;
8034 retlist->expr = expr;
8035 retlist->section = section;
8040 /* Generate a new internal symbol for this location list node, if it
8041 hasn't got one yet. */
8044 gen_llsym (dw_loc_list_ref list)
8046 gcc_assert (!list->ll_symbol);
8047 list->ll_symbol = gen_internal_sym ("LLST");
8050 /* Output the location list given to us. */
8053 output_loc_list (dw_loc_list_ref list_head)
8055 dw_loc_list_ref curr = list_head;
8057 if (list_head->emitted)
8059 list_head->emitted = true;
8061 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8063 /* Walk the location list, and output each range + expression. */
8064 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8067 /* Don't output an entry that starts and ends at the same address. */
8068 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
8070 if (!have_multiple_function_sections)
8072 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8073 "Location list begin address (%s)",
8074 list_head->ll_symbol);
8075 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8076 "Location list end address (%s)",
8077 list_head->ll_symbol);
8081 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8082 "Location list begin address (%s)",
8083 list_head->ll_symbol);
8084 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8085 "Location list end address (%s)",
8086 list_head->ll_symbol);
8088 size = size_of_locs (curr->expr);
8090 /* Output the block length for this list of location operations. */
8091 gcc_assert (size <= 0xffff);
8092 dw2_asm_output_data (2, size, "%s", "Location expression size");
8094 output_loc_sequence (curr->expr, -1);
8097 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8098 "Location list terminator begin (%s)",
8099 list_head->ll_symbol);
8100 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8101 "Location list terminator end (%s)",
8102 list_head->ll_symbol);
8105 /* Output a type signature. */
8108 output_signature (const char *sig, const char *name)
8112 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8113 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
8116 /* Output the DIE and its attributes. Called recursively to generate
8117 the definitions of each child DIE. */
8120 output_die (dw_die_ref die)
8127 /* If someone in another CU might refer to us, set up a symbol for
8128 them to point to. */
8129 if (! use_debug_types && die->die_id.die_symbol)
8130 output_die_symbol (die);
8132 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
8133 (unsigned long)die->die_offset,
8134 dwarf_tag_name (die->die_tag));
8136 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8138 const char *name = dwarf_attr_name (a->dw_attr);
8140 switch (AT_class (a))
8142 case dw_val_class_addr:
8143 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8146 case dw_val_class_offset:
8147 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8151 case dw_val_class_range_list:
8153 char *p = strchr (ranges_section_label, '\0');
8155 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8156 a->dw_attr_val.v.val_offset);
8157 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8158 debug_ranges_section, "%s", name);
8163 case dw_val_class_loc:
8164 size = size_of_locs (AT_loc (a));
8166 /* Output the block length for this list of location operations. */
8167 if (dwarf_version >= 4)
8168 dw2_asm_output_data_uleb128 (size, "%s", name);
8170 dw2_asm_output_data (constant_size (size), size, "%s", name);
8172 output_loc_sequence (AT_loc (a), -1);
8175 case dw_val_class_const:
8176 /* ??? It would be slightly more efficient to use a scheme like is
8177 used for unsigned constants below, but gdb 4.x does not sign
8178 extend. Gdb 5.x does sign extend. */
8179 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8182 case dw_val_class_unsigned_const:
8183 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8184 AT_unsigned (a), "%s", name);
8187 case dw_val_class_const_double:
8189 unsigned HOST_WIDE_INT first, second;
8191 if (HOST_BITS_PER_WIDE_INT >= 64)
8192 dw2_asm_output_data (1,
8193 2 * HOST_BITS_PER_WIDE_INT
8194 / HOST_BITS_PER_CHAR,
8197 if (WORDS_BIG_ENDIAN)
8199 first = a->dw_attr_val.v.val_double.high;
8200 second = a->dw_attr_val.v.val_double.low;
8204 first = a->dw_attr_val.v.val_double.low;
8205 second = a->dw_attr_val.v.val_double.high;
8208 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8210 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8215 case dw_val_class_vec:
8217 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8218 unsigned int len = a->dw_attr_val.v.val_vec.length;
8222 dw2_asm_output_data (constant_size (len * elt_size),
8223 len * elt_size, "%s", name);
8224 if (elt_size > sizeof (HOST_WIDE_INT))
8229 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8232 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8233 "fp or vector constant word %u", i);
8237 case dw_val_class_flag:
8238 if (dwarf_version >= 4)
8240 /* Currently all add_AT_flag calls pass in 1 as last argument,
8241 so DW_FORM_flag_present can be used. If that ever changes,
8242 we'll need to use DW_FORM_flag and have some optimization
8243 in build_abbrev_table that will change those to
8244 DW_FORM_flag_present if it is set to 1 in all DIEs using
8245 the same abbrev entry. */
8246 gcc_assert (AT_flag (a) == 1);
8248 fprintf (asm_out_file, "\t\t\t%s %s\n",
8249 ASM_COMMENT_START, name);
8252 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8255 case dw_val_class_loc_list:
8257 char *sym = AT_loc_list (a)->ll_symbol;
8260 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8265 case dw_val_class_die_ref:
8266 if (AT_ref_external (a))
8268 if (use_debug_types)
8270 comdat_type_node_ref type_node =
8271 AT_ref (a)->die_id.die_type_node;
8273 gcc_assert (type_node);
8274 output_signature (type_node->signature, name);
8278 char *sym = AT_ref (a)->die_id.die_symbol;
8282 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8283 length, whereas in DWARF3 it's always sized as an
8285 if (dwarf_version == 2)
8286 size = DWARF2_ADDR_SIZE;
8288 size = DWARF_OFFSET_SIZE;
8289 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
8295 gcc_assert (AT_ref (a)->die_offset);
8296 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8301 case dw_val_class_fde_ref:
8305 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8306 a->dw_attr_val.v.val_fde_index * 2);
8307 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8312 case dw_val_class_vms_delta:
8313 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
8314 AT_vms_delta2 (a), AT_vms_delta1 (a),
8318 case dw_val_class_lbl_id:
8319 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8322 case dw_val_class_lineptr:
8323 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8324 debug_line_section, "%s", name);
8327 case dw_val_class_macptr:
8328 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8329 debug_macinfo_section, "%s", name);
8332 case dw_val_class_str:
8333 if (AT_string_form (a) == DW_FORM_strp)
8334 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8335 a->dw_attr_val.v.val_str->label,
8337 "%s: \"%s\"", name, AT_string (a));
8339 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8342 case dw_val_class_file:
8344 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8346 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8347 a->dw_attr_val.v.val_file->filename);
8351 case dw_val_class_data8:
8355 for (i = 0; i < 8; i++)
8356 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
8357 i == 0 ? "%s" : NULL, name);
8366 FOR_EACH_CHILD (die, c, output_die (c));
8368 /* Add null byte to terminate sibling list. */
8369 if (die->die_child != NULL)
8370 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8371 (unsigned long) die->die_offset);
8374 /* Output the compilation unit that appears at the beginning of the
8375 .debug_info section, and precedes the DIE descriptions. */
8378 output_compilation_unit_header (void)
8380 int ver = dwarf_version;
8382 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8383 dw2_asm_output_data (4, 0xffffffff,
8384 "Initial length escape value indicating 64-bit DWARF extension");
8385 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8386 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8387 "Length of Compilation Unit Info");
8388 dw2_asm_output_data (2, ver, "DWARF version number");
8389 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8390 debug_abbrev_section,
8391 "Offset Into Abbrev. Section");
8392 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8395 /* Output the compilation unit DIE and its children. */
8398 output_comp_unit (dw_die_ref die, int output_if_empty)
8400 const char *secname;
8403 /* Unless we are outputting main CU, we may throw away empty ones. */
8404 if (!output_if_empty && die->die_child == NULL)
8407 /* Even if there are no children of this DIE, we must output the information
8408 about the compilation unit. Otherwise, on an empty translation unit, we
8409 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8410 will then complain when examining the file. First mark all the DIEs in
8411 this CU so we know which get local refs. */
8414 build_abbrev_table (die);
8416 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8417 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8418 calc_die_sizes (die);
8420 oldsym = die->die_id.die_symbol;
8423 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8425 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8427 die->die_id.die_symbol = NULL;
8428 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8432 switch_to_section (debug_info_section);
8433 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
8434 info_section_emitted = true;
8437 /* Output debugging information. */
8438 output_compilation_unit_header ();
8441 /* Leave the marks on the main CU, so we can check them in
8446 die->die_id.die_symbol = oldsym;
8450 /* Output a comdat type unit DIE and its children. */
8453 output_comdat_type_unit (comdat_type_node *node)
8455 const char *secname;
8458 #if defined (OBJECT_FORMAT_ELF)
8462 /* First mark all the DIEs in this CU so we know which get local refs. */
8463 mark_dies (node->root_die);
8465 build_abbrev_table (node->root_die);
8467 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8468 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
8469 calc_die_sizes (node->root_die);
8471 #if defined (OBJECT_FORMAT_ELF)
8472 secname = ".debug_types";
8473 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
8474 sprintf (tmp, "wt.");
8475 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8476 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
8477 comdat_key = get_identifier (tmp);
8478 targetm.asm_out.named_section (secname,
8479 SECTION_DEBUG | SECTION_LINKONCE,
8482 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
8483 sprintf (tmp, ".gnu.linkonce.wt.");
8484 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8485 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
8487 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8490 /* Output debugging information. */
8491 output_compilation_unit_header ();
8492 output_signature (node->signature, "Type Signature");
8493 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
8494 "Offset to Type DIE");
8495 output_die (node->root_die);
8497 unmark_dies (node->root_die);
8500 /* Return the DWARF2/3 pubname associated with a decl. */
8503 dwarf2_name (tree decl, int scope)
8505 if (DECL_NAMELESS (decl))
8507 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8510 /* Add a new entry to .debug_pubnames if appropriate. */
8513 add_pubname_string (const char *str, dw_die_ref die)
8515 if (targetm.want_debug_pub_sections)
8520 e.name = xstrdup (str);
8521 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8526 add_pubname (tree decl, dw_die_ref die)
8528 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
8530 const char *name = dwarf2_name (decl, 1);
8532 add_pubname_string (name, die);
8536 /* Add a new entry to .debug_pubtypes if appropriate. */
8539 add_pubtype (tree decl, dw_die_ref die)
8543 if (!targetm.want_debug_pub_sections)
8547 if ((TREE_PUBLIC (decl)
8548 || is_cu_die (die->die_parent))
8549 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8554 if (TYPE_NAME (decl))
8556 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8557 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8558 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8559 && DECL_NAME (TYPE_NAME (decl)))
8560 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8562 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8567 e.name = dwarf2_name (decl, 1);
8569 e.name = xstrdup (e.name);
8572 /* If we don't have a name for the type, there's no point in adding
8574 if (e.name && e.name[0] != '\0')
8575 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8579 /* Output the public names table used to speed up access to externally
8580 visible names; or the public types table used to find type definitions. */
8583 output_pubnames (VEC (pubname_entry, gc) * names)
8586 unsigned long pubnames_length = size_of_pubnames (names);
8589 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8590 dw2_asm_output_data (4, 0xffffffff,
8591 "Initial length escape value indicating 64-bit DWARF extension");
8592 if (names == pubname_table)
8593 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8594 "Length of Public Names Info");
8596 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8597 "Length of Public Type Names Info");
8598 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8599 dw2_asm_output_data (2, 2, "DWARF Version");
8600 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8602 "Offset of Compilation Unit Info");
8603 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8604 "Compilation Unit Length");
8606 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
8608 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8609 if (names == pubname_table)
8610 gcc_assert (pub->die->die_mark);
8612 if (names != pubtype_table
8613 || pub->die->die_offset != 0
8614 || !flag_eliminate_unused_debug_types)
8616 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8619 dw2_asm_output_nstring (pub->name, -1, "external name");
8623 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8626 /* Output the information that goes into the .debug_aranges table.
8627 Namely, define the beginning and ending address range of the
8628 text section generated for this compilation unit. */
8631 output_aranges (unsigned long aranges_length)
8635 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8636 dw2_asm_output_data (4, 0xffffffff,
8637 "Initial length escape value indicating 64-bit DWARF extension");
8638 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8639 "Length of Address Ranges Info");
8640 /* Version number for aranges is still 2, even in DWARF3. */
8641 dw2_asm_output_data (2, 2, "DWARF Version");
8642 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8644 "Offset of Compilation Unit Info");
8645 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8646 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8648 /* We need to align to twice the pointer size here. */
8649 if (DWARF_ARANGES_PAD_SIZE)
8651 /* Pad using a 2 byte words so that padding is correct for any
8653 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8654 2 * DWARF2_ADDR_SIZE);
8655 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8656 dw2_asm_output_data (2, 0, NULL);
8659 /* It is necessary not to output these entries if the sections were
8660 not used; if the sections were not used, the length will be 0 and
8661 the address may end up as 0 if the section is discarded by ld
8662 --gc-sections, leaving an invalid (0, 0) entry that can be
8663 confused with the terminator. */
8664 if (text_section_used)
8666 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8667 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8668 text_section_label, "Length");
8670 if (cold_text_section_used)
8672 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8674 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8675 cold_text_section_label, "Length");
8678 if (have_multiple_function_sections)
8683 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
8685 if (!fde->in_std_section)
8687 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
8689 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
8690 fde->dw_fde_begin, "Length");
8692 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
8694 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
8696 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
8697 fde->dw_fde_second_begin, "Length");
8702 /* Output the terminator words. */
8703 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8704 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8707 /* Add a new entry to .debug_ranges. Return the offset at which it
8711 add_ranges_num (int num)
8713 unsigned int in_use = ranges_table_in_use;
8715 if (in_use == ranges_table_allocated)
8717 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8718 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8719 ranges_table_allocated);
8720 memset (ranges_table + ranges_table_in_use, 0,
8721 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8724 ranges_table[in_use].num = num;
8725 ranges_table_in_use = in_use + 1;
8727 return in_use * 2 * DWARF2_ADDR_SIZE;
8730 /* Add a new entry to .debug_ranges corresponding to a block, or a
8731 range terminator if BLOCK is NULL. */
8734 add_ranges (const_tree block)
8736 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8739 /* Add a new entry to .debug_ranges corresponding to a pair of
8743 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
8746 unsigned int in_use = ranges_by_label_in_use;
8747 unsigned int offset;
8749 if (in_use == ranges_by_label_allocated)
8751 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8752 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8754 ranges_by_label_allocated);
8755 memset (ranges_by_label + ranges_by_label_in_use, 0,
8756 RANGES_TABLE_INCREMENT
8757 * sizeof (struct dw_ranges_by_label_struct));
8760 ranges_by_label[in_use].begin = begin;
8761 ranges_by_label[in_use].end = end;
8762 ranges_by_label_in_use = in_use + 1;
8764 offset = add_ranges_num (-(int)in_use - 1);
8767 add_AT_range_list (die, DW_AT_ranges, offset);
8773 output_ranges (void)
8776 static const char *const start_fmt = "Offset %#x";
8777 const char *fmt = start_fmt;
8779 for (i = 0; i < ranges_table_in_use; i++)
8781 int block_num = ranges_table[i].num;
8785 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8786 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8788 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8789 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8791 /* If all code is in the text section, then the compilation
8792 unit base address defaults to DW_AT_low_pc, which is the
8793 base of the text section. */
8794 if (!have_multiple_function_sections)
8796 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8798 fmt, i * 2 * DWARF2_ADDR_SIZE);
8799 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8800 text_section_label, NULL);
8803 /* Otherwise, the compilation unit base address is zero,
8804 which allows us to use absolute addresses, and not worry
8805 about whether the target supports cross-section
8809 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8810 fmt, i * 2 * DWARF2_ADDR_SIZE);
8811 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8817 /* Negative block_num stands for an index into ranges_by_label. */
8818 else if (block_num < 0)
8820 int lab_idx = - block_num - 1;
8822 if (!have_multiple_function_sections)
8826 /* If we ever use add_ranges_by_labels () for a single
8827 function section, all we have to do is to take out
8829 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8830 ranges_by_label[lab_idx].begin,
8832 fmt, i * 2 * DWARF2_ADDR_SIZE);
8833 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8834 ranges_by_label[lab_idx].end,
8835 text_section_label, NULL);
8840 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8841 ranges_by_label[lab_idx].begin,
8842 fmt, i * 2 * DWARF2_ADDR_SIZE);
8843 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8844 ranges_by_label[lab_idx].end,
8850 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8851 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8857 /* Data structure containing information about input files. */
8860 const char *path; /* Complete file name. */
8861 const char *fname; /* File name part. */
8862 int length; /* Length of entire string. */
8863 struct dwarf_file_data * file_idx; /* Index in input file table. */
8864 int dir_idx; /* Index in directory table. */
8867 /* Data structure containing information about directories with source
8871 const char *path; /* Path including directory name. */
8872 int length; /* Path length. */
8873 int prefix; /* Index of directory entry which is a prefix. */
8874 int count; /* Number of files in this directory. */
8875 int dir_idx; /* Index of directory used as base. */
8878 /* Callback function for file_info comparison. We sort by looking at
8879 the directories in the path. */
8882 file_info_cmp (const void *p1, const void *p2)
8884 const struct file_info *const s1 = (const struct file_info *) p1;
8885 const struct file_info *const s2 = (const struct file_info *) p2;
8886 const unsigned char *cp1;
8887 const unsigned char *cp2;
8889 /* Take care of file names without directories. We need to make sure that
8890 we return consistent values to qsort since some will get confused if
8891 we return the same value when identical operands are passed in opposite
8892 orders. So if neither has a directory, return 0 and otherwise return
8893 1 or -1 depending on which one has the directory. */
8894 if ((s1->path == s1->fname || s2->path == s2->fname))
8895 return (s2->path == s2->fname) - (s1->path == s1->fname);
8897 cp1 = (const unsigned char *) s1->path;
8898 cp2 = (const unsigned char *) s2->path;
8904 /* Reached the end of the first path? If so, handle like above. */
8905 if ((cp1 == (const unsigned char *) s1->fname)
8906 || (cp2 == (const unsigned char *) s2->fname))
8907 return ((cp2 == (const unsigned char *) s2->fname)
8908 - (cp1 == (const unsigned char *) s1->fname));
8910 /* Character of current path component the same? */
8911 else if (*cp1 != *cp2)
8916 struct file_name_acquire_data
8918 struct file_info *files;
8923 /* Traversal function for the hash table. */
8926 file_name_acquire (void ** slot, void *data)
8928 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
8929 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
8930 struct file_info *fi;
8933 gcc_assert (fnad->max_files >= d->emitted_number);
8935 if (! d->emitted_number)
8938 gcc_assert (fnad->max_files != fnad->used_files);
8940 fi = fnad->files + fnad->used_files++;
8942 /* Skip all leading "./". */
8944 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
8947 /* Create a new array entry. */
8949 fi->length = strlen (f);
8952 /* Search for the file name part. */
8953 f = strrchr (f, DIR_SEPARATOR);
8954 #if defined (DIR_SEPARATOR_2)
8956 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
8960 if (f == NULL || f < g)
8966 fi->fname = f == NULL ? fi->path : f + 1;
8970 /* Output the directory table and the file name table. We try to minimize
8971 the total amount of memory needed. A heuristic is used to avoid large
8972 slowdowns with many input files. */
8975 output_file_names (void)
8977 struct file_name_acquire_data fnad;
8979 struct file_info *files;
8980 struct dir_info *dirs;
8988 if (!last_emitted_file)
8990 dw2_asm_output_data (1, 0, "End directory table");
8991 dw2_asm_output_data (1, 0, "End file name table");
8995 numfiles = last_emitted_file->emitted_number;
8997 /* Allocate the various arrays we need. */
8998 files = XALLOCAVEC (struct file_info, numfiles);
8999 dirs = XALLOCAVEC (struct dir_info, numfiles);
9002 fnad.used_files = 0;
9003 fnad.max_files = numfiles;
9004 htab_traverse (file_table, file_name_acquire, &fnad);
9005 gcc_assert (fnad.used_files == fnad.max_files);
9007 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9009 /* Find all the different directories used. */
9010 dirs[0].path = files[0].path;
9011 dirs[0].length = files[0].fname - files[0].path;
9012 dirs[0].prefix = -1;
9014 dirs[0].dir_idx = 0;
9015 files[0].dir_idx = 0;
9018 for (i = 1; i < numfiles; i++)
9019 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9020 && memcmp (dirs[ndirs - 1].path, files[i].path,
9021 dirs[ndirs - 1].length) == 0)
9023 /* Same directory as last entry. */
9024 files[i].dir_idx = ndirs - 1;
9025 ++dirs[ndirs - 1].count;
9031 /* This is a new directory. */
9032 dirs[ndirs].path = files[i].path;
9033 dirs[ndirs].length = files[i].fname - files[i].path;
9034 dirs[ndirs].count = 1;
9035 dirs[ndirs].dir_idx = ndirs;
9036 files[i].dir_idx = ndirs;
9038 /* Search for a prefix. */
9039 dirs[ndirs].prefix = -1;
9040 for (j = 0; j < ndirs; j++)
9041 if (dirs[j].length < dirs[ndirs].length
9042 && dirs[j].length > 1
9043 && (dirs[ndirs].prefix == -1
9044 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9045 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9046 dirs[ndirs].prefix = j;
9051 /* Now to the actual work. We have to find a subset of the directories which
9052 allow expressing the file name using references to the directory table
9053 with the least amount of characters. We do not do an exhaustive search
9054 where we would have to check out every combination of every single
9055 possible prefix. Instead we use a heuristic which provides nearly optimal
9056 results in most cases and never is much off. */
9057 saved = XALLOCAVEC (int, ndirs);
9058 savehere = XALLOCAVEC (int, ndirs);
9060 memset (saved, '\0', ndirs * sizeof (saved[0]));
9061 for (i = 0; i < ndirs; i++)
9066 /* We can always save some space for the current directory. But this
9067 does not mean it will be enough to justify adding the directory. */
9068 savehere[i] = dirs[i].length;
9069 total = (savehere[i] - saved[i]) * dirs[i].count;
9071 for (j = i + 1; j < ndirs; j++)
9074 if (saved[j] < dirs[i].length)
9076 /* Determine whether the dirs[i] path is a prefix of the
9081 while (k != -1 && k != (int) i)
9086 /* Yes it is. We can possibly save some memory by
9087 writing the filenames in dirs[j] relative to
9089 savehere[j] = dirs[i].length;
9090 total += (savehere[j] - saved[j]) * dirs[j].count;
9095 /* Check whether we can save enough to justify adding the dirs[i]
9097 if (total > dirs[i].length + 1)
9099 /* It's worthwhile adding. */
9100 for (j = i; j < ndirs; j++)
9101 if (savehere[j] > 0)
9103 /* Remember how much we saved for this directory so far. */
9104 saved[j] = savehere[j];
9106 /* Remember the prefix directory. */
9107 dirs[j].dir_idx = i;
9112 /* Emit the directory name table. */
9113 idx_offset = dirs[0].length > 0 ? 1 : 0;
9114 for (i = 1 - idx_offset; i < ndirs; i++)
9115 dw2_asm_output_nstring (dirs[i].path,
9117 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9118 "Directory Entry: %#x", i + idx_offset);
9120 dw2_asm_output_data (1, 0, "End directory table");
9122 /* We have to emit them in the order of emitted_number since that's
9123 used in the debug info generation. To do this efficiently we
9124 generate a back-mapping of the indices first. */
9125 backmap = XALLOCAVEC (int, numfiles);
9126 for (i = 0; i < numfiles; i++)
9127 backmap[files[i].file_idx->emitted_number - 1] = i;
9129 /* Now write all the file names. */
9130 for (i = 0; i < numfiles; i++)
9132 int file_idx = backmap[i];
9133 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9135 #ifdef VMS_DEBUGGING_INFO
9136 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9138 /* Setting these fields can lead to debugger miscomparisons,
9139 but VMS Debug requires them to be set correctly. */
9144 int maxfilelen = strlen (files[file_idx].path)
9145 + dirs[dir_idx].length
9146 + MAX_VMS_VERSION_LEN + 1;
9147 char *filebuf = XALLOCAVEC (char, maxfilelen);
9149 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9150 snprintf (filebuf, maxfilelen, "%s;%d",
9151 files[file_idx].path + dirs[dir_idx].length, ver);
9153 dw2_asm_output_nstring
9154 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
9156 /* Include directory index. */
9157 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9159 /* Modification time. */
9160 dw2_asm_output_data_uleb128
9161 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9165 /* File length in bytes. */
9166 dw2_asm_output_data_uleb128
9167 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9171 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9172 "File Entry: %#x", (unsigned) i + 1);
9174 /* Include directory index. */
9175 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9177 /* Modification time. */
9178 dw2_asm_output_data_uleb128 (0, NULL);
9180 /* File length in bytes. */
9181 dw2_asm_output_data_uleb128 (0, NULL);
9182 #endif /* VMS_DEBUGGING_INFO */
9185 dw2_asm_output_data (1, 0, "End file name table");
9189 /* Output one line number table into the .debug_line section. */
9192 output_one_line_info_table (dw_line_info_table *table)
9194 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9195 unsigned int current_line = 1;
9196 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
9197 dw_line_info_entry *ent;
9200 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
9202 switch (ent->opcode)
9204 case LI_set_address:
9205 /* ??? Unfortunately, we have little choice here currently, and
9206 must always use the most general form. GCC does not know the
9207 address delta itself, so we can't use DW_LNS_advance_pc. Many
9208 ports do have length attributes which will give an upper bound
9209 on the address range. We could perhaps use length attributes
9210 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9211 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
9213 /* This can handle any delta. This takes
9214 4+DWARF2_ADDR_SIZE bytes. */
9215 dw2_asm_output_data (1, 0, "set address %s", line_label);
9216 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9217 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9218 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9222 if (ent->val == current_line)
9224 /* We still need to start a new row, so output a copy insn. */
9225 dw2_asm_output_data (1, DW_LNS_copy,
9226 "copy line %u", current_line);
9230 int line_offset = ent->val - current_line;
9231 int line_delta = line_offset - DWARF_LINE_BASE;
9233 current_line = ent->val;
9234 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9236 /* This can handle deltas from -10 to 234, using the current
9237 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9238 This takes 1 byte. */
9239 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9240 "line %u", current_line);
9244 /* This can handle any delta. This takes at least 4 bytes,
9245 depending on the value being encoded. */
9246 dw2_asm_output_data (1, DW_LNS_advance_line,
9247 "advance to line %u", current_line);
9248 dw2_asm_output_data_sleb128 (line_offset, NULL);
9249 dw2_asm_output_data (1, DW_LNS_copy, NULL);
9255 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
9256 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9260 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
9261 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9264 case LI_negate_stmt:
9265 current_is_stmt = !current_is_stmt;
9266 dw2_asm_output_data (1, DW_LNS_negate_stmt,
9267 "is_stmt %d", current_is_stmt);
9270 case LI_set_prologue_end:
9271 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
9272 "set prologue end");
9275 case LI_set_epilogue_begin:
9276 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
9277 "set epilogue begin");
9280 case LI_set_discriminator:
9281 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
9282 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
9283 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
9284 dw2_asm_output_data_uleb128 (ent->val, NULL);
9289 /* Emit debug info for the address of the end of the table. */
9290 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
9291 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9292 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9293 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
9295 dw2_asm_output_data (1, 0, "end sequence");
9296 dw2_asm_output_data_uleb128 (1, NULL);
9297 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9300 /* Output the source line number correspondence information. This
9301 information goes into the .debug_line section. */
9304 output_line_info (void)
9306 char l1[20], l2[20], p1[20], p2[20];
9307 int ver = dwarf_version;
9308 bool saw_one = false;
9311 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9312 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9313 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9314 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9316 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9317 dw2_asm_output_data (4, 0xffffffff,
9318 "Initial length escape value indicating 64-bit DWARF extension");
9319 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9320 "Length of Source Line Info");
9321 ASM_OUTPUT_LABEL (asm_out_file, l1);
9323 dw2_asm_output_data (2, ver, "DWARF Version");
9324 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9325 ASM_OUTPUT_LABEL (asm_out_file, p1);
9327 /* Define the architecture-dependent minimum instruction length (in bytes).
9328 In this implementation of DWARF, this field is used for information
9329 purposes only. Since GCC generates assembly language, we have no
9330 a priori knowledge of how many instruction bytes are generated for each
9331 source line, and therefore can use only the DW_LNE_set_address and
9332 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9333 this as '1', which is "correct enough" for all architectures,
9334 and don't let the target override. */
9335 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9338 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
9339 "Maximum Operations Per Instruction");
9340 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9341 "Default is_stmt_start flag");
9342 dw2_asm_output_data (1, DWARF_LINE_BASE,
9343 "Line Base Value (Special Opcodes)");
9344 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9345 "Line Range Value (Special Opcodes)");
9346 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9347 "Special Opcode Base");
9349 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9354 case DW_LNS_advance_pc:
9355 case DW_LNS_advance_line:
9356 case DW_LNS_set_file:
9357 case DW_LNS_set_column:
9358 case DW_LNS_fixed_advance_pc:
9359 case DW_LNS_set_isa:
9367 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
9371 /* Write out the information about the files we use. */
9372 output_file_names ();
9373 ASM_OUTPUT_LABEL (asm_out_file, p2);
9375 if (separate_line_info)
9377 dw_line_info_table *table;
9380 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
9383 output_one_line_info_table (table);
9387 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
9389 output_one_line_info_table (cold_text_section_line_info);
9393 /* ??? Some Darwin linkers crash on a .debug_line section with no
9394 sequences. Further, merely a DW_LNE_end_sequence entry is not
9395 sufficient -- the address column must also be initialized.
9396 Make sure to output at least one set_address/end_sequence pair,
9397 choosing .text since that section is always present. */
9398 if (text_section_line_info->in_use || !saw_one)
9399 output_one_line_info_table (text_section_line_info);
9401 /* Output the marker for the end of the line number info. */
9402 ASM_OUTPUT_LABEL (asm_out_file, l2);
9405 /* Given a pointer to a tree node for some base type, return a pointer to
9406 a DIE that describes the given type.
9408 This routine must only be called for GCC type nodes that correspond to
9409 Dwarf base (fundamental) types. */
9412 base_type_die (tree type)
9414 dw_die_ref base_type_result;
9415 enum dwarf_type encoding;
9417 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9420 /* If this is a subtype that should not be emitted as a subrange type,
9421 use the base type. See subrange_type_for_debug_p. */
9422 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
9423 type = TREE_TYPE (type);
9425 switch (TREE_CODE (type))
9428 if ((dwarf_version >= 4 || !dwarf_strict)
9430 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9431 && DECL_IS_BUILTIN (TYPE_NAME (type))
9432 && DECL_NAME (TYPE_NAME (type)))
9434 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
9435 if (strcmp (name, "char16_t") == 0
9436 || strcmp (name, "char32_t") == 0)
9438 encoding = DW_ATE_UTF;
9442 if (TYPE_STRING_FLAG (type))
9444 if (TYPE_UNSIGNED (type))
9445 encoding = DW_ATE_unsigned_char;
9447 encoding = DW_ATE_signed_char;
9449 else if (TYPE_UNSIGNED (type))
9450 encoding = DW_ATE_unsigned;
9452 encoding = DW_ATE_signed;
9456 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9458 if (dwarf_version >= 3 || !dwarf_strict)
9459 encoding = DW_ATE_decimal_float;
9461 encoding = DW_ATE_lo_user;
9464 encoding = DW_ATE_float;
9467 case FIXED_POINT_TYPE:
9468 if (!(dwarf_version >= 3 || !dwarf_strict))
9469 encoding = DW_ATE_lo_user;
9470 else if (TYPE_UNSIGNED (type))
9471 encoding = DW_ATE_unsigned_fixed;
9473 encoding = DW_ATE_signed_fixed;
9476 /* Dwarf2 doesn't know anything about complex ints, so use
9477 a user defined type for it. */
9479 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9480 encoding = DW_ATE_complex_float;
9482 encoding = DW_ATE_lo_user;
9486 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9487 encoding = DW_ATE_boolean;
9491 /* No other TREE_CODEs are Dwarf fundamental types. */
9495 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
9497 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9498 int_size_in_bytes (type));
9499 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9501 return base_type_result;
9504 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9505 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9508 is_base_type (tree type)
9510 switch (TREE_CODE (type))
9516 case FIXED_POINT_TYPE:
9524 case QUAL_UNION_TYPE:
9529 case REFERENCE_TYPE:
9543 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9544 node, return the size in bits for the type if it is a constant, or else
9545 return the alignment for the type if the type's size is not constant, or
9546 else return BITS_PER_WORD if the type actually turns out to be an
9549 static inline unsigned HOST_WIDE_INT
9550 simple_type_size_in_bits (const_tree type)
9552 if (TREE_CODE (type) == ERROR_MARK)
9553 return BITS_PER_WORD;
9554 else if (TYPE_SIZE (type) == NULL_TREE)
9556 else if (host_integerp (TYPE_SIZE (type), 1))
9557 return tree_low_cst (TYPE_SIZE (type), 1);
9559 return TYPE_ALIGN (type);
9562 /* Similarly, but return a double_int instead of UHWI. */
9564 static inline double_int
9565 double_int_type_size_in_bits (const_tree type)
9567 if (TREE_CODE (type) == ERROR_MARK)
9568 return uhwi_to_double_int (BITS_PER_WORD);
9569 else if (TYPE_SIZE (type) == NULL_TREE)
9570 return double_int_zero;
9571 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
9572 return tree_to_double_int (TYPE_SIZE (type));
9574 return uhwi_to_double_int (TYPE_ALIGN (type));
9577 /* Given a pointer to a tree node for a subrange type, return a pointer
9578 to a DIE that describes the given type. */
9581 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
9583 dw_die_ref subrange_die;
9584 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9586 if (context_die == NULL)
9587 context_die = comp_unit_die ();
9589 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9591 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9593 /* The size of the subrange type and its base type do not match,
9594 so we need to generate a size attribute for the subrange type. */
9595 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9599 add_bound_info (subrange_die, DW_AT_lower_bound, low);
9601 add_bound_info (subrange_die, DW_AT_upper_bound, high);
9603 return subrange_die;
9606 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9607 entry that chains various modifiers in front of the given type. */
9610 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9611 dw_die_ref context_die)
9613 enum tree_code code = TREE_CODE (type);
9614 dw_die_ref mod_type_die;
9615 dw_die_ref sub_die = NULL;
9616 tree item_type = NULL;
9617 tree qualified_type;
9618 tree name, low, high;
9620 if (code == ERROR_MARK)
9623 /* See if we already have the appropriately qualified variant of
9626 = get_qualified_type (type,
9627 ((is_const_type ? TYPE_QUAL_CONST : 0)
9628 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9630 if (qualified_type == sizetype
9631 && TYPE_NAME (qualified_type)
9632 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
9634 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
9636 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
9637 && TYPE_PRECISION (t)
9638 == TYPE_PRECISION (qualified_type)
9639 && TYPE_UNSIGNED (t)
9640 == TYPE_UNSIGNED (qualified_type));
9644 /* If we do, then we can just use its DIE, if it exists. */
9647 mod_type_die = lookup_type_die (qualified_type);
9649 return mod_type_die;
9652 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9654 /* Handle C typedef types. */
9655 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
9656 && !DECL_ARTIFICIAL (name))
9658 tree dtype = TREE_TYPE (name);
9660 if (qualified_type == dtype)
9662 /* For a named type, use the typedef. */
9663 gen_type_die (qualified_type, context_die);
9664 return lookup_type_die (qualified_type);
9666 else if (is_const_type < TYPE_READONLY (dtype)
9667 || is_volatile_type < TYPE_VOLATILE (dtype)
9668 || (is_const_type <= TYPE_READONLY (dtype)
9669 && is_volatile_type <= TYPE_VOLATILE (dtype)
9670 && DECL_ORIGINAL_TYPE (name) != type))
9671 /* cv-unqualified version of named type. Just use the unnamed
9672 type to which it refers. */
9673 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9674 is_const_type, is_volatile_type,
9676 /* Else cv-qualified version of named type; fall through. */
9680 /* If both is_const_type and is_volatile_type, prefer the path
9681 which leads to a qualified type. */
9682 && (!is_volatile_type
9683 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
9684 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
9686 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
9687 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9689 else if (is_volatile_type)
9691 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
9692 sub_die = modified_type_die (type, is_const_type, 0, context_die);
9694 else if (code == POINTER_TYPE)
9696 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
9697 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9698 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9699 item_type = TREE_TYPE (type);
9700 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
9701 add_AT_unsigned (mod_type_die, DW_AT_address_class,
9702 TYPE_ADDR_SPACE (item_type));
9704 else if (code == REFERENCE_TYPE)
9706 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
9707 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
9710 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
9711 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9712 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9713 item_type = TREE_TYPE (type);
9714 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
9715 add_AT_unsigned (mod_type_die, DW_AT_address_class,
9716 TYPE_ADDR_SPACE (item_type));
9718 else if (code == INTEGER_TYPE
9719 && TREE_TYPE (type) != NULL_TREE
9720 && subrange_type_for_debug_p (type, &low, &high))
9722 mod_type_die = subrange_type_die (type, low, high, context_die);
9723 item_type = TREE_TYPE (type);
9725 else if (is_base_type (type))
9726 mod_type_die = base_type_die (type);
9729 gen_type_die (type, context_die);
9731 /* We have to get the type_main_variant here (and pass that to the
9732 `lookup_type_die' routine) because the ..._TYPE node we have
9733 might simply be a *copy* of some original type node (where the
9734 copy was created to help us keep track of typedef names) and
9735 that copy might have a different TYPE_UID from the original
9737 if (TREE_CODE (type) != VECTOR_TYPE)
9738 return lookup_type_die (type_main_variant (type));
9740 /* Vectors have the debugging information in the type,
9741 not the main variant. */
9742 return lookup_type_die (type);
9745 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9746 don't output a DW_TAG_typedef, since there isn't one in the
9747 user's program; just attach a DW_AT_name to the type.
9748 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
9749 if the base type already has the same name. */
9751 && ((TREE_CODE (name) != TYPE_DECL
9752 && (qualified_type == TYPE_MAIN_VARIANT (type)
9753 || (!is_const_type && !is_volatile_type)))
9754 || (TREE_CODE (name) == TYPE_DECL
9755 && TREE_TYPE (name) == qualified_type
9756 && DECL_NAME (name))))
9758 if (TREE_CODE (name) == TYPE_DECL)
9759 /* Could just call add_name_and_src_coords_attributes here,
9760 but since this is a builtin type it doesn't have any
9761 useful source coordinates anyway. */
9762 name = DECL_NAME (name);
9763 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9764 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
9765 if (TYPE_ARTIFICIAL (type))
9766 add_AT_flag (mod_type_die, DW_AT_artificial, 1);
9768 /* This probably indicates a bug. */
9769 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
9770 add_name_attribute (mod_type_die, "__unknown__");
9773 equate_type_number_to_die (qualified_type, mod_type_die);
9776 /* We must do this after the equate_type_number_to_die call, in case
9777 this is a recursive type. This ensures that the modified_type_die
9778 recursion will terminate even if the type is recursive. Recursive
9779 types are possible in Ada. */
9780 sub_die = modified_type_die (item_type,
9781 TYPE_READONLY (item_type),
9782 TYPE_VOLATILE (item_type),
9785 if (sub_die != NULL)
9786 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9788 return mod_type_die;
9791 /* Generate DIEs for the generic parameters of T.
9792 T must be either a generic type or a generic function.
9793 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
9796 gen_generic_params_dies (tree t)
9800 dw_die_ref die = NULL;
9802 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
9806 die = lookup_type_die (t);
9807 else if (DECL_P (t))
9808 die = lookup_decl_die (t);
9812 parms = lang_hooks.get_innermost_generic_parms (t);
9814 /* T has no generic parameter. It means T is neither a generic type
9815 or function. End of story. */
9818 parms_num = TREE_VEC_LENGTH (parms);
9819 args = lang_hooks.get_innermost_generic_args (t);
9820 for (i = 0; i < parms_num; i++)
9822 tree parm, arg, arg_pack_elems;
9824 parm = TREE_VEC_ELT (parms, i);
9825 arg = TREE_VEC_ELT (args, i);
9826 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
9827 gcc_assert (parm && TREE_VALUE (parm) && arg);
9829 if (parm && TREE_VALUE (parm) && arg)
9831 /* If PARM represents a template parameter pack,
9832 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
9833 by DW_TAG_template_*_parameter DIEs for the argument
9834 pack elements of ARG. Note that ARG would then be
9835 an argument pack. */
9837 template_parameter_pack_die (TREE_VALUE (parm),
9841 generic_parameter_die (TREE_VALUE (parm), arg,
9842 true /* Emit DW_AT_name */, die);
9847 /* Create and return a DIE for PARM which should be
9848 the representation of a generic type parameter.
9849 For instance, in the C++ front end, PARM would be a template parameter.
9850 ARG is the argument to PARM.
9851 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
9853 PARENT_DIE is the parent DIE which the new created DIE should be added to,
9857 generic_parameter_die (tree parm, tree arg,
9859 dw_die_ref parent_die)
9861 dw_die_ref tmpl_die = NULL;
9862 const char *name = NULL;
9864 if (!parm || !DECL_NAME (parm) || !arg)
9867 /* We support non-type generic parameters and arguments,
9868 type generic parameters and arguments, as well as
9869 generic generic parameters (a.k.a. template template parameters in C++)
9871 if (TREE_CODE (parm) == PARM_DECL)
9872 /* PARM is a nontype generic parameter */
9873 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
9874 else if (TREE_CODE (parm) == TYPE_DECL)
9875 /* PARM is a type generic parameter. */
9876 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
9877 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
9878 /* PARM is a generic generic parameter.
9879 Its DIE is a GNU extension. It shall have a
9880 DW_AT_name attribute to represent the name of the template template
9881 parameter, and a DW_AT_GNU_template_name attribute to represent the
9882 name of the template template argument. */
9883 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
9892 /* If PARM is a generic parameter pack, it means we are
9893 emitting debug info for a template argument pack element.
9894 In other terms, ARG is a template argument pack element.
9895 In that case, we don't emit any DW_AT_name attribute for
9899 name = IDENTIFIER_POINTER (DECL_NAME (parm));
9901 add_AT_string (tmpl_die, DW_AT_name, name);
9904 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
9906 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
9907 TMPL_DIE should have a child DW_AT_type attribute that is set
9908 to the type of the argument to PARM, which is ARG.
9909 If PARM is a type generic parameter, TMPL_DIE should have a
9910 child DW_AT_type that is set to ARG. */
9911 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
9912 add_type_attribute (tmpl_die, tmpl_type, 0,
9913 TREE_THIS_VOLATILE (tmpl_type),
9918 /* So TMPL_DIE is a DIE representing a
9919 a generic generic template parameter, a.k.a template template
9920 parameter in C++ and arg is a template. */
9922 /* The DW_AT_GNU_template_name attribute of the DIE must be set
9923 to the name of the argument. */
9924 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
9926 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
9929 if (TREE_CODE (parm) == PARM_DECL)
9930 /* So PARM is a non-type generic parameter.
9931 DWARF3 5.6.8 says we must set a DW_AT_const_value child
9932 attribute of TMPL_DIE which value represents the value
9934 We must be careful here:
9935 The value of ARG might reference some function decls.
9936 We might currently be emitting debug info for a generic
9937 type and types are emitted before function decls, we don't
9938 know if the function decls referenced by ARG will actually be
9939 emitted after cgraph computations.
9940 So must defer the generation of the DW_AT_const_value to
9941 after cgraph is ready. */
9942 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
9948 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
9949 PARM_PACK must be a template parameter pack. The returned DIE
9950 will be child DIE of PARENT_DIE. */
9953 template_parameter_pack_die (tree parm_pack,
9954 tree parm_pack_args,
9955 dw_die_ref parent_die)
9960 gcc_assert (parent_die && parm_pack);
9962 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
9963 add_name_and_src_coords_attributes (die, parm_pack);
9964 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
9965 generic_parameter_die (parm_pack,
9966 TREE_VEC_ELT (parm_pack_args, j),
9967 false /* Don't emit DW_AT_name */,
9972 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9973 an enumerated type. */
9976 type_is_enum (const_tree type)
9978 return TREE_CODE (type) == ENUMERAL_TYPE;
9981 /* Return the DBX register number described by a given RTL node. */
9984 dbx_reg_number (const_rtx rtl)
9986 unsigned regno = REGNO (rtl);
9988 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
9990 #ifdef LEAF_REG_REMAP
9991 if (current_function_uses_only_leaf_regs)
9993 int leaf_reg = LEAF_REG_REMAP (regno);
9995 regno = (unsigned) leaf_reg;
9999 return DBX_REGISTER_NUMBER (regno);
10002 /* Optionally add a DW_OP_piece term to a location description expression.
10003 DW_OP_piece is only added if the location description expression already
10004 doesn't end with DW_OP_piece. */
10007 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10009 dw_loc_descr_ref loc;
10011 if (*list_head != NULL)
10013 /* Find the end of the chain. */
10014 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10017 if (loc->dw_loc_opc != DW_OP_piece)
10018 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10022 /* Return a location descriptor that designates a machine register or
10023 zero if there is none. */
10025 static dw_loc_descr_ref
10026 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10030 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10033 /* We only use "frame base" when we're sure we're talking about the
10034 post-prologue local stack frame. We do this by *not* running
10035 register elimination until this point, and recognizing the special
10036 argument pointer and soft frame pointer rtx's.
10037 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10038 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
10039 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
10041 dw_loc_descr_ref result = NULL;
10043 if (dwarf_version >= 4 || !dwarf_strict)
10045 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
10048 add_loc_descr (&result,
10049 new_loc_descr (DW_OP_stack_value, 0, 0));
10054 regs = targetm.dwarf_register_span (rtl);
10056 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10057 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10059 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10062 /* Return a location descriptor that designates a machine register for
10063 a given hard register number. */
10065 static dw_loc_descr_ref
10066 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10068 dw_loc_descr_ref reg_loc_descr;
10072 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10074 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10076 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10077 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10079 return reg_loc_descr;
10082 /* Given an RTL of a register, return a location descriptor that
10083 designates a value that spans more than one register. */
10085 static dw_loc_descr_ref
10086 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10087 enum var_init_status initialized)
10089 int nregs, size, i;
10091 dw_loc_descr_ref loc_result = NULL;
10094 #ifdef LEAF_REG_REMAP
10095 if (current_function_uses_only_leaf_regs)
10097 int leaf_reg = LEAF_REG_REMAP (reg);
10098 if (leaf_reg != -1)
10099 reg = (unsigned) leaf_reg;
10102 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10103 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10105 /* Simple, contiguous registers. */
10106 if (regs == NULL_RTX)
10108 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10113 dw_loc_descr_ref t;
10115 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10116 VAR_INIT_STATUS_INITIALIZED);
10117 add_loc_descr (&loc_result, t);
10118 add_loc_descr_op_piece (&loc_result, size);
10124 /* Now onto stupid register sets in non contiguous locations. */
10126 gcc_assert (GET_CODE (regs) == PARALLEL);
10128 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10131 for (i = 0; i < XVECLEN (regs, 0); ++i)
10133 dw_loc_descr_ref t;
10135 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10136 VAR_INIT_STATUS_INITIALIZED);
10137 add_loc_descr (&loc_result, t);
10138 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10139 add_loc_descr_op_piece (&loc_result, size);
10142 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10143 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10147 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
10149 /* Return a location descriptor that designates a constant i,
10150 as a compound operation from constant (i >> shift), constant shift
10153 static dw_loc_descr_ref
10154 int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
10156 dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
10157 add_loc_descr (&ret, int_loc_descriptor (shift));
10158 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
10162 /* Return a location descriptor that designates a constant. */
10164 static dw_loc_descr_ref
10165 int_loc_descriptor (HOST_WIDE_INT i)
10167 enum dwarf_location_atom op;
10169 /* Pick the smallest representation of a constant, rather than just
10170 defaulting to the LEB encoding. */
10173 int clz = clz_hwi (i);
10174 int ctz = ctz_hwi (i);
10176 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10177 else if (i <= 0xff)
10178 op = DW_OP_const1u;
10179 else if (i <= 0xffff)
10180 op = DW_OP_const2u;
10181 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
10182 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
10183 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10184 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10185 while DW_OP_const4u is 5 bytes. */
10186 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
10187 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10188 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
10189 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10190 while DW_OP_const4u is 5 bytes. */
10191 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
10192 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
10193 op = DW_OP_const4u;
10194 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10195 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
10196 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10197 while DW_OP_constu of constant >= 0x100000000 takes at least
10199 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
10200 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
10201 && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
10202 >= HOST_BITS_PER_WIDE_INT)
10203 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10204 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10205 while DW_OP_constu takes in this case at least 6 bytes. */
10206 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
10207 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
10208 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
10209 && size_of_uleb128 (i) > 6)
10210 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10211 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
10218 op = DW_OP_const1s;
10219 else if (i >= -0x8000)
10220 op = DW_OP_const2s;
10221 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
10223 if (size_of_int_loc_descriptor (i) < 5)
10225 dw_loc_descr_ref ret = int_loc_descriptor (-i);
10226 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
10229 op = DW_OP_const4s;
10233 if (size_of_int_loc_descriptor (i)
10234 < (unsigned long) 1 + size_of_sleb128 (i))
10236 dw_loc_descr_ref ret = int_loc_descriptor (-i);
10237 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
10244 return new_loc_descr (op, i, 0);
10247 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10248 without actually allocating it. */
10250 static unsigned long
10251 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
10253 return size_of_int_loc_descriptor (i >> shift)
10254 + size_of_int_loc_descriptor (shift)
10258 /* Return size_of_locs (int_loc_descriptor (i)) without
10259 actually allocating it. */
10261 static unsigned long
10262 size_of_int_loc_descriptor (HOST_WIDE_INT i)
10271 else if (i <= 0xff)
10273 else if (i <= 0xffff)
10277 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
10278 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
10279 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10281 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10282 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
10283 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10285 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
10287 s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
10288 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10289 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
10290 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10292 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
10293 && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
10294 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10296 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
10297 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
10299 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10308 else if (i >= -0x8000)
10310 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
10312 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
10314 s = size_of_int_loc_descriptor (-i) + 1;
10322 unsigned long r = 1 + size_of_sleb128 (i);
10323 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
10325 s = size_of_int_loc_descriptor (-i) + 1;
10334 /* Return loc description representing "address" of integer value.
10335 This can appear only as toplevel expression. */
10337 static dw_loc_descr_ref
10338 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
10341 dw_loc_descr_ref loc_result = NULL;
10343 if (!(dwarf_version >= 4 || !dwarf_strict))
10346 litsize = size_of_int_loc_descriptor (i);
10347 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10348 is more compact. For DW_OP_stack_value we need:
10349 litsize + 1 (DW_OP_stack_value)
10350 and for DW_OP_implicit_value:
10351 1 (DW_OP_implicit_value) + 1 (length) + size. */
10352 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
10354 loc_result = int_loc_descriptor (i);
10355 add_loc_descr (&loc_result,
10356 new_loc_descr (DW_OP_stack_value, 0, 0));
10360 loc_result = new_loc_descr (DW_OP_implicit_value,
10362 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
10363 loc_result->dw_loc_oprnd2.v.val_int = i;
10367 /* Return a location descriptor that designates a base+offset location. */
10369 static dw_loc_descr_ref
10370 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10371 enum var_init_status initialized)
10373 unsigned int regno;
10374 dw_loc_descr_ref result;
10375 dw_fde_ref fde = cfun->fde;
10377 /* We only use "frame base" when we're sure we're talking about the
10378 post-prologue local stack frame. We do this by *not* running
10379 register elimination until this point, and recognizing the special
10380 argument pointer and soft frame pointer rtx's. */
10381 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10383 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10387 if (GET_CODE (elim) == PLUS)
10389 offset += INTVAL (XEXP (elim, 1));
10390 elim = XEXP (elim, 0);
10392 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10393 && (elim == hard_frame_pointer_rtx
10394 || elim == stack_pointer_rtx))
10395 || elim == (frame_pointer_needed
10396 ? hard_frame_pointer_rtx
10397 : stack_pointer_rtx));
10399 /* If drap register is used to align stack, use frame
10400 pointer + offset to access stack variables. If stack
10401 is aligned without drap, use stack pointer + offset to
10402 access stack variables. */
10403 if (crtl->stack_realign_tried
10404 && reg == frame_pointer_rtx)
10407 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10408 ? HARD_FRAME_POINTER_REGNUM
10410 return new_reg_loc_descr (base_reg, offset);
10413 gcc_assert (frame_pointer_fb_offset_valid);
10414 offset += frame_pointer_fb_offset;
10415 return new_loc_descr (DW_OP_fbreg, offset, 0);
10419 regno = DWARF_FRAME_REGNUM (REGNO (reg));
10421 if (!optimize && fde
10422 && (fde->drap_reg == regno || fde->vdrap_reg == regno))
10424 /* Use cfa+offset to represent the location of arguments passed
10425 on the stack when drap is used to align stack.
10426 Only do this when not optimizing, for optimized code var-tracking
10427 is supposed to track where the arguments live and the register
10428 used as vdrap or drap in some spot might be used for something
10429 else in other part of the routine. */
10430 return new_loc_descr (DW_OP_fbreg, offset, 0);
10434 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10437 result = new_loc_descr (DW_OP_bregx, regno, offset);
10439 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10440 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10445 /* Return true if this RTL expression describes a base+offset calculation. */
10448 is_based_loc (const_rtx rtl)
10450 return (GET_CODE (rtl) == PLUS
10451 && ((REG_P (XEXP (rtl, 0))
10452 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10453 && CONST_INT_P (XEXP (rtl, 1)))));
10456 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10459 static dw_loc_descr_ref
10460 tls_mem_loc_descriptor (rtx mem)
10463 dw_loc_descr_ref loc_result;
10465 if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
10468 base = get_base_address (MEM_EXPR (mem));
10470 || TREE_CODE (base) != VAR_DECL
10471 || !DECL_THREAD_LOCAL_P (base))
10474 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
10475 if (loc_result == NULL)
10478 if (MEM_OFFSET (mem))
10479 loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
10484 /* Output debug info about reason why we failed to expand expression as dwarf
10488 expansion_failed (tree expr, rtx rtl, char const *reason)
10490 if (dump_file && (dump_flags & TDF_DETAILS))
10492 fprintf (dump_file, "Failed to expand as dwarf: ");
10494 print_generic_expr (dump_file, expr, dump_flags);
10497 fprintf (dump_file, "\n");
10498 print_rtl (dump_file, rtl);
10500 fprintf (dump_file, "\nReason: %s\n", reason);
10504 /* Helper function for const_ok_for_output, called either directly
10505 or via for_each_rtx. */
10508 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
10512 if (GET_CODE (rtl) == UNSPEC)
10514 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10515 we can't express it in the debug info. */
10516 #ifdef ENABLE_CHECKING
10517 /* Don't complain about TLS UNSPECs, those are just too hard to
10519 if (XVECLEN (rtl, 0) != 1
10520 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
10521 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
10522 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
10523 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
10524 inform (current_function_decl
10525 ? DECL_SOURCE_LOCATION (current_function_decl)
10526 : UNKNOWN_LOCATION,
10527 #if NUM_UNSPEC_VALUES > 0
10528 "non-delegitimized UNSPEC %s (%d) found in variable location",
10529 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
10530 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
10533 "non-delegitimized UNSPEC %d found in variable location",
10537 expansion_failed (NULL_TREE, rtl,
10538 "UNSPEC hasn't been delegitimized.\n");
10542 if (GET_CODE (rtl) != SYMBOL_REF)
10545 if (CONSTANT_POOL_ADDRESS_P (rtl))
10548 get_pool_constant_mark (rtl, &marked);
10549 /* If all references to this pool constant were optimized away,
10550 it was not output and thus we can't represent it. */
10553 expansion_failed (NULL_TREE, rtl,
10554 "Constant was removed from constant pool.\n");
10559 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
10562 /* Avoid references to external symbols in debug info, on several targets
10563 the linker might even refuse to link when linking a shared library,
10564 and in many other cases the relocations for .debug_info/.debug_loc are
10565 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
10566 to be defined within the same shared library or executable are fine. */
10567 if (SYMBOL_REF_EXTERNAL_P (rtl))
10569 tree decl = SYMBOL_REF_DECL (rtl);
10571 if (decl == NULL || !targetm.binds_local_p (decl))
10573 expansion_failed (NULL_TREE, rtl,
10574 "Symbol not defined in current TU.\n");
10582 /* Return true if constant RTL can be emitted in DW_OP_addr or
10583 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
10584 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
10587 const_ok_for_output (rtx rtl)
10589 if (GET_CODE (rtl) == SYMBOL_REF)
10590 return const_ok_for_output_1 (&rtl, NULL) == 0;
10592 if (GET_CODE (rtl) == CONST)
10593 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
10598 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
10599 if possible, NULL otherwise. */
10602 base_type_for_mode (enum machine_mode mode, bool unsignedp)
10604 dw_die_ref type_die;
10605 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
10609 switch (TREE_CODE (type))
10617 type_die = lookup_type_die (type);
10619 type_die = modified_type_die (type, false, false, comp_unit_die ());
10620 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
10625 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
10626 type matching MODE, or, if MODE is narrower than or as wide as
10627 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
10630 static dw_loc_descr_ref
10631 convert_descriptor_to_mode (enum machine_mode mode, dw_loc_descr_ref op)
10633 enum machine_mode outer_mode = mode;
10634 dw_die_ref type_die;
10635 dw_loc_descr_ref cvt;
10637 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
10639 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
10642 type_die = base_type_for_mode (outer_mode, 1);
10643 if (type_die == NULL)
10645 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10646 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10647 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10648 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10649 add_loc_descr (&op, cvt);
10653 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
10655 static dw_loc_descr_ref
10656 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
10657 dw_loc_descr_ref op1)
10659 dw_loc_descr_ref ret = op0;
10660 add_loc_descr (&ret, op1);
10661 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10662 if (STORE_FLAG_VALUE != 1)
10664 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
10665 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
10670 /* Return location descriptor for signed comparison OP RTL. */
10672 static dw_loc_descr_ref
10673 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
10674 enum machine_mode mem_mode)
10676 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
10677 dw_loc_descr_ref op0, op1;
10680 if (op_mode == VOIDmode)
10681 op_mode = GET_MODE (XEXP (rtl, 1));
10682 if (op_mode == VOIDmode)
10686 && (GET_MODE_CLASS (op_mode) != MODE_INT
10687 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
10690 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
10691 VAR_INIT_STATUS_INITIALIZED);
10692 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
10693 VAR_INIT_STATUS_INITIALIZED);
10695 if (op0 == NULL || op1 == NULL)
10698 if (GET_MODE_CLASS (op_mode) != MODE_INT
10699 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
10700 return compare_loc_descriptor (op, op0, op1);
10702 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
10704 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
10705 dw_loc_descr_ref cvt;
10707 if (type_die == NULL)
10709 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10710 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10711 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10712 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10713 add_loc_descr (&op0, cvt);
10714 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10715 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10716 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10717 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10718 add_loc_descr (&op1, cvt);
10719 return compare_loc_descriptor (op, op0, op1);
10722 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
10723 /* For eq/ne, if the operands are known to be zero-extended,
10724 there is no need to do the fancy shifting up. */
10725 if (op == DW_OP_eq || op == DW_OP_ne)
10727 dw_loc_descr_ref last0, last1;
10728 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
10730 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
10732 /* deref_size zero extends, and for constants we can check
10733 whether they are zero extended or not. */
10734 if (((last0->dw_loc_opc == DW_OP_deref_size
10735 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
10736 || (CONST_INT_P (XEXP (rtl, 0))
10737 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
10738 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
10739 && ((last1->dw_loc_opc == DW_OP_deref_size
10740 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
10741 || (CONST_INT_P (XEXP (rtl, 1))
10742 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
10743 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
10744 return compare_loc_descriptor (op, op0, op1);
10746 /* EQ/NE comparison against constant in narrower type than
10747 DWARF2_ADDR_SIZE can be performed either as
10748 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
10751 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
10752 DW_OP_{eq,ne}. Pick whatever is shorter. */
10753 if (CONST_INT_P (XEXP (rtl, 1))
10754 && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
10755 && (size_of_int_loc_descriptor (shift) + 1
10756 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift)
10757 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
10758 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
10759 & GET_MODE_MASK (op_mode))))
10761 add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
10762 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10763 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
10764 & GET_MODE_MASK (op_mode));
10765 return compare_loc_descriptor (op, op0, op1);
10768 add_loc_descr (&op0, int_loc_descriptor (shift));
10769 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
10770 if (CONST_INT_P (XEXP (rtl, 1)))
10771 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
10774 add_loc_descr (&op1, int_loc_descriptor (shift));
10775 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
10777 return compare_loc_descriptor (op, op0, op1);
10780 /* Return location descriptor for unsigned comparison OP RTL. */
10782 static dw_loc_descr_ref
10783 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
10784 enum machine_mode mem_mode)
10786 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
10787 dw_loc_descr_ref op0, op1;
10789 if (op_mode == VOIDmode)
10790 op_mode = GET_MODE (XEXP (rtl, 1));
10791 if (op_mode == VOIDmode)
10793 if (GET_MODE_CLASS (op_mode) != MODE_INT)
10796 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
10799 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
10800 VAR_INIT_STATUS_INITIALIZED);
10801 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
10802 VAR_INIT_STATUS_INITIALIZED);
10804 if (op0 == NULL || op1 == NULL)
10807 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
10809 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
10810 dw_loc_descr_ref last0, last1;
10811 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
10813 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
10815 if (CONST_INT_P (XEXP (rtl, 0)))
10816 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
10817 /* deref_size zero extends, so no need to mask it again. */
10818 else if (last0->dw_loc_opc != DW_OP_deref_size
10819 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
10821 add_loc_descr (&op0, int_loc_descriptor (mask));
10822 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10824 if (CONST_INT_P (XEXP (rtl, 1)))
10825 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
10826 /* deref_size zero extends, so no need to mask it again. */
10827 else if (last1->dw_loc_opc != DW_OP_deref_size
10828 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
10830 add_loc_descr (&op1, int_loc_descriptor (mask));
10831 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
10834 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
10836 HOST_WIDE_INT bias = 1;
10837 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
10838 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
10839 if (CONST_INT_P (XEXP (rtl, 1)))
10840 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
10841 + INTVAL (XEXP (rtl, 1)));
10843 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
10846 return compare_loc_descriptor (op, op0, op1);
10849 /* Return location descriptor for {U,S}{MIN,MAX}. */
10851 static dw_loc_descr_ref
10852 minmax_loc_descriptor (rtx rtl, enum machine_mode mode,
10853 enum machine_mode mem_mode)
10855 enum dwarf_location_atom op;
10856 dw_loc_descr_ref op0, op1, ret;
10857 dw_loc_descr_ref bra_node, drop_node;
10860 && (GET_MODE_CLASS (mode) != MODE_INT
10861 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
10864 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
10865 VAR_INIT_STATUS_INITIALIZED);
10866 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
10867 VAR_INIT_STATUS_INITIALIZED);
10869 if (op0 == NULL || op1 == NULL)
10872 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
10873 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
10874 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
10875 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
10877 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
10879 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
10880 add_loc_descr (&op0, int_loc_descriptor (mask));
10881 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10882 add_loc_descr (&op1, int_loc_descriptor (mask));
10883 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
10885 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
10887 HOST_WIDE_INT bias = 1;
10888 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
10889 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
10890 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
10893 else if (GET_MODE_CLASS (mode) == MODE_INT
10894 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
10896 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
10897 add_loc_descr (&op0, int_loc_descriptor (shift));
10898 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
10899 add_loc_descr (&op1, int_loc_descriptor (shift));
10900 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
10902 else if (GET_MODE_CLASS (mode) == MODE_INT
10903 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
10905 dw_die_ref type_die = base_type_for_mode (mode, 0);
10906 dw_loc_descr_ref cvt;
10907 if (type_die == NULL)
10909 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10910 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10911 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10912 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10913 add_loc_descr (&op0, cvt);
10914 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10915 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10916 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10917 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10918 add_loc_descr (&op1, cvt);
10921 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
10926 add_loc_descr (&ret, op1);
10927 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10928 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
10929 add_loc_descr (&ret, bra_node);
10930 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
10931 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
10932 add_loc_descr (&ret, drop_node);
10933 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10934 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
10935 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
10936 && GET_MODE_CLASS (mode) == MODE_INT
10937 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
10938 ret = convert_descriptor_to_mode (mode, ret);
10942 /* Helper function for mem_loc_descriptor. Perform OP binary op,
10943 but after converting arguments to type_die, afterwards
10944 convert back to unsigned. */
10946 static dw_loc_descr_ref
10947 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
10948 enum machine_mode mode, enum machine_mode mem_mode)
10950 dw_loc_descr_ref cvt, op0, op1;
10952 if (type_die == NULL)
10954 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
10955 VAR_INIT_STATUS_INITIALIZED);
10956 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
10957 VAR_INIT_STATUS_INITIALIZED);
10958 if (op0 == NULL || op1 == NULL)
10960 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10961 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10962 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10963 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10964 add_loc_descr (&op0, cvt);
10965 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10966 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10967 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10968 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10969 add_loc_descr (&op1, cvt);
10970 add_loc_descr (&op0, op1);
10971 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
10972 return convert_descriptor_to_mode (mode, op0);
10975 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
10976 const0 is DW_OP_lit0 or corresponding typed constant,
10977 const1 is DW_OP_lit1 or corresponding typed constant
10978 and constMSB is constant with just the MSB bit set
10980 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10981 L1: const0 DW_OP_swap
10982 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
10983 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10988 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10989 L1: const0 DW_OP_swap
10990 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
10991 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
10996 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
10997 L1: const1 DW_OP_swap
10998 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
10999 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11003 static dw_loc_descr_ref
11004 clz_loc_descriptor (rtx rtl, enum machine_mode mode,
11005 enum machine_mode mem_mode)
11007 dw_loc_descr_ref op0, ret, tmp;
11008 HOST_WIDE_INT valv;
11009 dw_loc_descr_ref l1jump, l1label;
11010 dw_loc_descr_ref l2jump, l2label;
11011 dw_loc_descr_ref l3jump, l3label;
11012 dw_loc_descr_ref l4jump, l4label;
11015 if (GET_MODE_CLASS (mode) != MODE_INT
11016 || GET_MODE (XEXP (rtl, 0)) != mode
11017 || (GET_CODE (rtl) == CLZ
11018 && GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT))
11021 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11022 VAR_INIT_STATUS_INITIALIZED);
11026 if (GET_CODE (rtl) == CLZ)
11028 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11029 valv = GET_MODE_BITSIZE (mode);
11031 else if (GET_CODE (rtl) == FFS)
11033 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11034 valv = GET_MODE_BITSIZE (mode);
11035 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11036 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
11037 add_loc_descr (&ret, l1jump);
11038 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11039 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
11040 VAR_INIT_STATUS_INITIALIZED);
11043 add_loc_descr (&ret, tmp);
11044 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
11045 add_loc_descr (&ret, l4jump);
11046 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
11047 ? const1_rtx : const0_rtx,
11049 VAR_INIT_STATUS_INITIALIZED);
11050 if (l1label == NULL)
11052 add_loc_descr (&ret, l1label);
11053 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11054 l2label = new_loc_descr (DW_OP_dup, 0, 0);
11055 add_loc_descr (&ret, l2label);
11056 if (GET_CODE (rtl) != CLZ)
11058 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
11059 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
11060 << (GET_MODE_BITSIZE (mode) - 1));
11062 msb = immed_double_const (0, (unsigned HOST_WIDE_INT) 1
11063 << (GET_MODE_BITSIZE (mode)
11064 - HOST_BITS_PER_WIDE_INT - 1), mode);
11065 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
11066 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11067 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
11068 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
11070 tmp = mem_loc_descriptor (msb, mode, mem_mode,
11071 VAR_INIT_STATUS_INITIALIZED);
11074 add_loc_descr (&ret, tmp);
11075 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11076 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
11077 add_loc_descr (&ret, l3jump);
11078 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11079 VAR_INIT_STATUS_INITIALIZED);
11082 add_loc_descr (&ret, tmp);
11083 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
11084 ? DW_OP_shl : DW_OP_shr, 0, 0));
11085 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11086 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
11087 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11088 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
11089 add_loc_descr (&ret, l2jump);
11090 l3label = new_loc_descr (DW_OP_drop, 0, 0);
11091 add_loc_descr (&ret, l3label);
11092 l4label = new_loc_descr (DW_OP_nop, 0, 0);
11093 add_loc_descr (&ret, l4label);
11094 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11095 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11096 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11097 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11098 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11099 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
11100 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11101 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
11105 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11106 const1 is DW_OP_lit1 or corresponding typed constant):
11108 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11109 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11113 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11114 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11117 static dw_loc_descr_ref
11118 popcount_loc_descriptor (rtx rtl, enum machine_mode mode,
11119 enum machine_mode mem_mode)
11121 dw_loc_descr_ref op0, ret, tmp;
11122 dw_loc_descr_ref l1jump, l1label;
11123 dw_loc_descr_ref l2jump, l2label;
11125 if (GET_MODE_CLASS (mode) != MODE_INT
11126 || GET_MODE (XEXP (rtl, 0)) != mode)
11129 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11130 VAR_INIT_STATUS_INITIALIZED);
11134 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11135 VAR_INIT_STATUS_INITIALIZED);
11138 add_loc_descr (&ret, tmp);
11139 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11140 l1label = new_loc_descr (DW_OP_dup, 0, 0);
11141 add_loc_descr (&ret, l1label);
11142 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11143 add_loc_descr (&ret, l2jump);
11144 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11145 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11146 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11147 VAR_INIT_STATUS_INITIALIZED);
11150 add_loc_descr (&ret, tmp);
11151 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11152 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
11153 ? DW_OP_plus : DW_OP_xor, 0, 0));
11154 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11155 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11156 VAR_INIT_STATUS_INITIALIZED);
11157 add_loc_descr (&ret, tmp);
11158 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11159 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11160 add_loc_descr (&ret, l1jump);
11161 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11162 add_loc_descr (&ret, l2label);
11163 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11164 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11165 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11166 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11170 /* BSWAP (constS is initial shift count, either 56 or 24):
11172 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11173 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11174 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11175 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11176 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11178 static dw_loc_descr_ref
11179 bswap_loc_descriptor (rtx rtl, enum machine_mode mode,
11180 enum machine_mode mem_mode)
11182 dw_loc_descr_ref op0, ret, tmp;
11183 dw_loc_descr_ref l1jump, l1label;
11184 dw_loc_descr_ref l2jump, l2label;
11186 if (GET_MODE_CLASS (mode) != MODE_INT
11187 || BITS_PER_UNIT != 8
11188 || (GET_MODE_BITSIZE (mode) != 32
11189 && GET_MODE_BITSIZE (mode) != 64))
11192 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11193 VAR_INIT_STATUS_INITIALIZED);
11198 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11200 VAR_INIT_STATUS_INITIALIZED);
11203 add_loc_descr (&ret, tmp);
11204 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11205 VAR_INIT_STATUS_INITIALIZED);
11208 add_loc_descr (&ret, tmp);
11209 l1label = new_loc_descr (DW_OP_pick, 2, 0);
11210 add_loc_descr (&ret, l1label);
11211 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11213 VAR_INIT_STATUS_INITIALIZED);
11214 add_loc_descr (&ret, tmp);
11215 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
11216 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11217 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11218 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
11219 VAR_INIT_STATUS_INITIALIZED);
11222 add_loc_descr (&ret, tmp);
11223 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11224 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
11225 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11226 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11227 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11228 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11229 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11230 VAR_INIT_STATUS_INITIALIZED);
11231 add_loc_descr (&ret, tmp);
11232 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
11233 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11234 add_loc_descr (&ret, l2jump);
11235 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
11236 VAR_INIT_STATUS_INITIALIZED);
11237 add_loc_descr (&ret, tmp);
11238 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11239 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11240 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11241 add_loc_descr (&ret, l1jump);
11242 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11243 add_loc_descr (&ret, l2label);
11244 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11245 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11246 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11247 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11248 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11249 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11253 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11254 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11255 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11256 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11258 ROTATERT is similar:
11259 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11260 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11261 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11263 static dw_loc_descr_ref
11264 rotate_loc_descriptor (rtx rtl, enum machine_mode mode,
11265 enum machine_mode mem_mode)
11267 rtx rtlop1 = XEXP (rtl, 1);
11268 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
11271 if (GET_MODE_CLASS (mode) != MODE_INT)
11274 if (GET_MODE (rtlop1) != VOIDmode
11275 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
11276 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11277 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11278 VAR_INIT_STATUS_INITIALIZED);
11279 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11280 VAR_INIT_STATUS_INITIALIZED);
11281 if (op0 == NULL || op1 == NULL)
11283 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11284 for (i = 0; i < 2; i++)
11286 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
11287 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
11289 VAR_INIT_STATUS_INITIALIZED);
11290 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
11291 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11293 : HOST_BITS_PER_WIDE_INT == 64
11294 ? DW_OP_const8u : DW_OP_constu,
11295 GET_MODE_MASK (mode), 0);
11298 if (mask[i] == NULL)
11300 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
11303 add_loc_descr (&ret, op1);
11304 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11305 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11306 if (GET_CODE (rtl) == ROTATERT)
11308 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11309 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11310 GET_MODE_BITSIZE (mode), 0));
11312 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11313 if (mask[0] != NULL)
11314 add_loc_descr (&ret, mask[0]);
11315 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11316 if (mask[1] != NULL)
11318 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11319 add_loc_descr (&ret, mask[1]);
11320 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11322 if (GET_CODE (rtl) == ROTATE)
11324 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11325 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11326 GET_MODE_BITSIZE (mode), 0));
11328 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11329 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11333 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11334 for DEBUG_PARAMETER_REF RTL. */
11336 static dw_loc_descr_ref
11337 parameter_ref_descriptor (rtx rtl)
11339 dw_loc_descr_ref ret;
11344 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
11345 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
11346 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
11349 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11350 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
11351 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
11355 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
11356 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
11361 /* Helper function to get mode of MEM's address. */
11364 get_address_mode (rtx mem)
11366 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
11367 if (mode != VOIDmode)
11369 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
11372 /* The following routine converts the RTL for a variable or parameter
11373 (resident in memory) into an equivalent Dwarf representation of a
11374 mechanism for getting the address of that same variable onto the top of a
11375 hypothetical "address evaluation" stack.
11377 When creating memory location descriptors, we are effectively transforming
11378 the RTL for a memory-resident object into its Dwarf postfix expression
11379 equivalent. This routine recursively descends an RTL tree, turning
11380 it into Dwarf postfix code as it goes.
11382 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11384 MEM_MODE is the mode of the memory reference, needed to handle some
11385 autoincrement addressing modes.
11387 Return 0 if we can't represent the location. */
11390 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11391 enum machine_mode mem_mode,
11392 enum var_init_status initialized)
11394 dw_loc_descr_ref mem_loc_result = NULL;
11395 enum dwarf_location_atom op;
11396 dw_loc_descr_ref op0, op1;
11398 if (mode == VOIDmode)
11399 mode = GET_MODE (rtl);
11401 /* Note that for a dynamically sized array, the location we will generate a
11402 description of here will be the lowest numbered location which is
11403 actually within the array. That's *not* necessarily the same as the
11404 zeroth element of the array. */
11406 rtl = targetm.delegitimize_address (rtl);
11408 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
11411 switch (GET_CODE (rtl))
11416 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
11419 /* The case of a subreg may arise when we have a local (register)
11420 variable or a formal (register) parameter which doesn't quite fill
11421 up an entire register. For now, just assume that it is
11422 legitimate to make the Dwarf info refer to the whole register which
11423 contains the given subreg. */
11424 if (!subreg_lowpart_p (rtl))
11426 if (GET_MODE_CLASS (mode) == MODE_INT
11427 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
11428 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11429 #ifdef POINTERS_EXTEND_UNSIGNED
11430 || (mode == Pmode && mem_mode != VOIDmode)
11433 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
11435 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11436 GET_MODE (SUBREG_REG (rtl)),
11437 mem_mode, initialized);
11442 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11444 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
11445 && (GET_MODE_CLASS (mode) != MODE_INT
11446 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
11450 dw_die_ref type_die;
11451 dw_loc_descr_ref cvt;
11453 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11454 GET_MODE (SUBREG_REG (rtl)),
11455 mem_mode, initialized);
11456 if (mem_loc_result == NULL)
11458 type_die = base_type_for_mode (mode,
11459 GET_MODE_CLASS (mode) == MODE_INT);
11460 if (type_die == NULL)
11462 mem_loc_result = NULL;
11465 if (GET_MODE_SIZE (mode)
11466 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11467 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11469 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
11470 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11471 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11472 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11473 add_loc_descr (&mem_loc_result, cvt);
11478 if (GET_MODE_CLASS (mode) != MODE_INT
11479 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11480 #ifdef POINTERS_EXTEND_UNSIGNED
11481 && (mode != Pmode || mem_mode == VOIDmode)
11485 dw_die_ref type_die;
11489 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
11491 type_die = base_type_for_mode (mode,
11492 GET_MODE_CLASS (mode) == MODE_INT);
11493 if (type_die == NULL)
11495 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
11496 dbx_reg_number (rtl), 0);
11497 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
11498 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
11499 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
11502 /* Whenever a register number forms a part of the description of the
11503 method for calculating the (dynamic) address of a memory resident
11504 object, DWARF rules require the register number be referred to as
11505 a "base register". This distinction is not based in any way upon
11506 what category of register the hardware believes the given register
11507 belongs to. This is strictly DWARF terminology we're dealing with
11508 here. Note that in cases where the location of a memory-resident
11509 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11510 OP_CONST (0)) the actual DWARF location descriptor that we generate
11511 may just be OP_BASEREG (basereg). This may look deceptively like
11512 the object in question was allocated to a register (rather than in
11513 memory) so DWARF consumers need to be aware of the subtle
11514 distinction between OP_REG and OP_BASEREG. */
11515 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
11516 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
11517 else if (stack_realign_drap
11519 && crtl->args.internal_arg_pointer == rtl
11520 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
11522 /* If RTL is internal_arg_pointer, which has been optimized
11523 out, use DRAP instead. */
11524 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
11525 VAR_INIT_STATUS_INITIALIZED);
11531 if (GET_MODE_CLASS (mode) != MODE_INT)
11533 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
11534 mem_mode, VAR_INIT_STATUS_INITIALIZED);
11537 else if (GET_CODE (rtl) == ZERO_EXTEND
11538 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11539 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
11540 < HOST_BITS_PER_WIDE_INT
11541 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11542 to expand zero extend as two shifts instead of
11544 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
11546 enum machine_mode imode = GET_MODE (XEXP (rtl, 0));
11547 mem_loc_result = op0;
11548 add_loc_descr (&mem_loc_result,
11549 int_loc_descriptor (GET_MODE_MASK (imode)));
11550 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
11552 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11554 int shift = DWARF2_ADDR_SIZE
11555 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11556 shift *= BITS_PER_UNIT;
11557 if (GET_CODE (rtl) == SIGN_EXTEND)
11561 mem_loc_result = op0;
11562 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11563 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11564 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11565 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11567 else if (!dwarf_strict)
11569 dw_die_ref type_die1, type_die2;
11570 dw_loc_descr_ref cvt;
11572 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
11573 GET_CODE (rtl) == ZERO_EXTEND);
11574 if (type_die1 == NULL)
11576 type_die2 = base_type_for_mode (mode, 1);
11577 if (type_die2 == NULL)
11579 mem_loc_result = op0;
11580 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11581 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11582 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
11583 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11584 add_loc_descr (&mem_loc_result, cvt);
11585 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11586 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11587 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
11588 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11589 add_loc_descr (&mem_loc_result, cvt);
11594 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
11595 get_address_mode (rtl), mode,
11596 VAR_INIT_STATUS_INITIALIZED);
11597 if (mem_loc_result == NULL)
11598 mem_loc_result = tls_mem_loc_descriptor (rtl);
11599 if (mem_loc_result != 0)
11601 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11602 || GET_MODE_CLASS (mode) != MODE_INT)
11604 dw_die_ref type_die;
11605 dw_loc_descr_ref deref;
11610 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
11611 if (type_die == NULL)
11613 deref = new_loc_descr (DW_OP_GNU_deref_type,
11614 GET_MODE_SIZE (mode), 0);
11615 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
11616 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
11617 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
11618 add_loc_descr (&mem_loc_result, deref);
11620 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
11621 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
11623 add_loc_descr (&mem_loc_result,
11624 new_loc_descr (DW_OP_deref_size,
11625 GET_MODE_SIZE (mode), 0));
11629 rtx new_rtl = avoid_constant_pool_reference (rtl);
11630 if (new_rtl != rtl)
11631 return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized);
11636 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
11639 /* Some ports can transform a symbol ref into a label ref, because
11640 the symbol ref is too far away and has to be dumped into a constant
11644 if (GET_MODE_CLASS (mode) != MODE_INT
11645 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11646 #ifdef POINTERS_EXTEND_UNSIGNED
11647 && (mode != Pmode || mem_mode == VOIDmode)
11651 if (GET_CODE (rtl) == SYMBOL_REF
11652 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11654 dw_loc_descr_ref temp;
11656 /* If this is not defined, we have no way to emit the data. */
11657 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
11660 /* We used to emit DW_OP_addr here, but that's wrong, since
11661 DW_OP_addr should be relocated by the debug info consumer,
11662 while DW_OP_GNU_push_tls_address operand should not. */
11663 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
11664 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
11665 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
11666 temp->dw_loc_oprnd1.v.val_addr = rtl;
11667 temp->dtprel = true;
11669 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
11670 add_loc_descr (&mem_loc_result, temp);
11675 if (!const_ok_for_output (rtl))
11679 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
11680 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
11681 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
11682 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11688 case DEBUG_IMPLICIT_PTR:
11689 expansion_failed (NULL_TREE, rtl,
11690 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11696 if (REG_P (ENTRY_VALUE_EXP (rtl)))
11698 if (GET_MODE_CLASS (mode) != MODE_INT
11699 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11700 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
11701 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11704 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
11705 VAR_INIT_STATUS_INITIALIZED);
11707 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
11708 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
11710 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
11711 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11712 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
11716 gcc_unreachable ();
11719 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
11720 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
11721 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
11724 case DEBUG_PARAMETER_REF:
11725 mem_loc_result = parameter_ref_descriptor (rtl);
11729 /* Extract the PLUS expression nested inside and fall into
11730 PLUS code below. */
11731 rtl = XEXP (rtl, 1);
11736 /* Turn these into a PLUS expression and fall into the PLUS code
11738 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
11739 GEN_INT (GET_CODE (rtl) == PRE_INC
11740 ? GET_MODE_UNIT_SIZE (mem_mode)
11741 : -GET_MODE_UNIT_SIZE (mem_mode)));
11743 /* ... fall through ... */
11747 if (is_based_loc (rtl)
11748 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11749 && GET_MODE_CLASS (mode) == MODE_INT)
11750 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
11751 INTVAL (XEXP (rtl, 1)),
11752 VAR_INIT_STATUS_INITIALIZED);
11755 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11756 VAR_INIT_STATUS_INITIALIZED);
11757 if (mem_loc_result == 0)
11760 if (CONST_INT_P (XEXP (rtl, 1))
11761 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11762 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
11765 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11766 VAR_INIT_STATUS_INITIALIZED);
11769 add_loc_descr (&mem_loc_result, op1);
11770 add_loc_descr (&mem_loc_result,
11771 new_loc_descr (DW_OP_plus, 0, 0));
11776 /* If a pseudo-reg is optimized away, it is possible for it to
11777 be replaced with a MEM containing a multiply or shift. */
11788 && GET_MODE_CLASS (mode) == MODE_INT
11789 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11791 mem_loc_result = typed_binop (DW_OP_div, rtl,
11792 base_type_for_mode (mode, 0),
11816 if (GET_MODE_CLASS (mode) != MODE_INT)
11818 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11819 VAR_INIT_STATUS_INITIALIZED);
11821 rtx rtlop1 = XEXP (rtl, 1);
11822 if (GET_MODE (rtlop1) != VOIDmode
11823 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
11824 < GET_MODE_BITSIZE (mode))
11825 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11826 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11827 VAR_INIT_STATUS_INITIALIZED);
11830 if (op0 == 0 || op1 == 0)
11833 mem_loc_result = op0;
11834 add_loc_descr (&mem_loc_result, op1);
11835 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11851 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11852 VAR_INIT_STATUS_INITIALIZED);
11853 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11854 VAR_INIT_STATUS_INITIALIZED);
11856 if (op0 == 0 || op1 == 0)
11859 mem_loc_result = op0;
11860 add_loc_descr (&mem_loc_result, op1);
11861 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11865 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
11867 mem_loc_result = typed_binop (DW_OP_mod, rtl,
11868 base_type_for_mode (mode, 0),
11873 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11874 VAR_INIT_STATUS_INITIALIZED);
11875 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11876 VAR_INIT_STATUS_INITIALIZED);
11878 if (op0 == 0 || op1 == 0)
11881 mem_loc_result = op0;
11882 add_loc_descr (&mem_loc_result, op1);
11883 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
11884 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
11885 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
11886 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
11887 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
11891 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
11893 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
11898 mem_loc_result = typed_binop (DW_OP_div, rtl,
11899 base_type_for_mode (mode, 1),
11917 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11918 VAR_INIT_STATUS_INITIALIZED);
11923 mem_loc_result = op0;
11924 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11928 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11929 #ifdef POINTERS_EXTEND_UNSIGNED
11931 && mem_mode != VOIDmode
11932 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
11936 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
11940 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
11941 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
11943 dw_die_ref type_die = base_type_for_mode (mode, 1);
11944 enum machine_mode amode;
11945 if (type_die == NULL)
11947 amode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
11949 if (INTVAL (rtl) >= 0
11950 && amode != BLKmode
11951 && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
11952 /* const DW_OP_GNU_convert <XXX> vs.
11953 DW_OP_GNU_const_type <XXX, 1, const>. */
11954 && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
11955 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode))
11957 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
11958 op0 = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11959 op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11960 op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11961 op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
11962 add_loc_descr (&mem_loc_result, op0);
11963 return mem_loc_result;
11965 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
11967 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11968 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11969 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
11970 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
11971 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
11974 mem_loc_result->dw_loc_oprnd2.val_class
11975 = dw_val_class_const_double;
11976 mem_loc_result->dw_loc_oprnd2.v.val_double
11977 = shwi_to_double_int (INTVAL (rtl));
11985 dw_die_ref type_die;
11987 /* Note that a CONST_DOUBLE rtx could represent either an integer
11988 or a floating-point constant. A CONST_DOUBLE is used whenever
11989 the constant requires more than one word in order to be
11990 adequately represented. We output CONST_DOUBLEs as blocks. */
11991 if (mode == VOIDmode
11992 || (GET_MODE (rtl) == VOIDmode
11993 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
11995 type_die = base_type_for_mode (mode,
11996 GET_MODE_CLASS (mode) == MODE_INT);
11997 if (type_die == NULL)
11999 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
12000 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12001 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12002 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
12003 if (SCALAR_FLOAT_MODE_P (mode))
12005 unsigned int length = GET_MODE_SIZE (mode);
12006 unsigned char *array
12007 = (unsigned char*) ggc_alloc_atomic (length);
12009 insert_float (rtl, array);
12010 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12011 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12012 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12013 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12017 mem_loc_result->dw_loc_oprnd2.val_class
12018 = dw_val_class_const_double;
12019 mem_loc_result->dw_loc_oprnd2.v.val_double
12020 = rtx_to_double_int (rtl);
12026 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
12030 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12034 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12038 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12042 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12046 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
12050 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12054 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12058 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12062 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12067 if (GET_MODE_CLASS (mode) != MODE_INT)
12072 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
12077 if (CONST_INT_P (XEXP (rtl, 1))
12078 && CONST_INT_P (XEXP (rtl, 2))
12079 && ((unsigned) INTVAL (XEXP (rtl, 1))
12080 + (unsigned) INTVAL (XEXP (rtl, 2))
12081 <= GET_MODE_BITSIZE (mode))
12082 && GET_MODE_CLASS (mode) == MODE_INT
12083 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12084 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
12087 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12088 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12091 if (GET_CODE (rtl) == SIGN_EXTRACT)
12095 mem_loc_result = op0;
12096 size = INTVAL (XEXP (rtl, 1));
12097 shift = INTVAL (XEXP (rtl, 2));
12098 if (BITS_BIG_ENDIAN)
12099 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
12101 if (shift + size != (int) DWARF2_ADDR_SIZE)
12103 add_loc_descr (&mem_loc_result,
12104 int_loc_descriptor (DWARF2_ADDR_SIZE
12106 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
12108 if (size != (int) DWARF2_ADDR_SIZE)
12110 add_loc_descr (&mem_loc_result,
12111 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
12112 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12119 dw_loc_descr_ref op2, bra_node, drop_node;
12120 op0 = mem_loc_descriptor (XEXP (rtl, 0),
12121 GET_MODE (XEXP (rtl, 0)) == VOIDmode
12122 ? word_mode : GET_MODE (XEXP (rtl, 0)),
12123 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12124 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12125 VAR_INIT_STATUS_INITIALIZED);
12126 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
12127 VAR_INIT_STATUS_INITIALIZED);
12128 if (op0 == NULL || op1 == NULL || op2 == NULL)
12131 mem_loc_result = op1;
12132 add_loc_descr (&mem_loc_result, op2);
12133 add_loc_descr (&mem_loc_result, op0);
12134 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12135 add_loc_descr (&mem_loc_result, bra_node);
12136 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
12137 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
12138 add_loc_descr (&mem_loc_result, drop_node);
12139 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12140 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
12145 case FLOAT_TRUNCATE:
12147 case UNSIGNED_FLOAT:
12152 dw_die_ref type_die;
12153 dw_loc_descr_ref cvt;
12155 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12156 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12159 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
12160 && (GET_CODE (rtl) == FLOAT
12161 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
12162 <= DWARF2_ADDR_SIZE))
12164 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12165 GET_CODE (rtl) == UNSIGNED_FLOAT);
12166 if (type_die == NULL)
12168 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12169 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12170 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12171 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12172 add_loc_descr (&op0, cvt);
12174 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
12175 if (type_die == NULL)
12177 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12178 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12179 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12180 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12181 add_loc_descr (&op0, cvt);
12182 if (GET_MODE_CLASS (mode) == MODE_INT
12183 && (GET_CODE (rtl) == FIX
12184 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
12186 op0 = convert_descriptor_to_mode (mode, op0);
12190 mem_loc_result = op0;
12197 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
12202 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
12206 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
12211 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
12216 /* In theory, we could implement the above. */
12217 /* DWARF cannot represent the unsigned compare operations
12242 case FRACT_CONVERT:
12243 case UNSIGNED_FRACT_CONVERT:
12245 case UNSIGNED_SAT_FRACT:
12251 case VEC_DUPLICATE:
12255 case STRICT_LOW_PART:
12259 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12260 can't express it in the debug info. This can happen e.g. with some
12265 resolve_one_addr (&rtl, NULL);
12269 #ifdef ENABLE_CHECKING
12270 print_rtl (stderr, rtl);
12271 gcc_unreachable ();
12277 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12278 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12280 return mem_loc_result;
12283 /* Return a descriptor that describes the concatenation of two locations.
12284 This is typically a complex variable. */
12286 static dw_loc_descr_ref
12287 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
12289 dw_loc_descr_ref cc_loc_result = NULL;
12290 dw_loc_descr_ref x0_ref
12291 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12292 dw_loc_descr_ref x1_ref
12293 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12295 if (x0_ref == 0 || x1_ref == 0)
12298 cc_loc_result = x0_ref;
12299 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
12301 add_loc_descr (&cc_loc_result, x1_ref);
12302 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
12304 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
12305 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12307 return cc_loc_result;
12310 /* Return a descriptor that describes the concatenation of N
12313 static dw_loc_descr_ref
12314 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
12317 dw_loc_descr_ref cc_loc_result = NULL;
12318 unsigned int n = XVECLEN (concatn, 0);
12320 for (i = 0; i < n; ++i)
12322 dw_loc_descr_ref ref;
12323 rtx x = XVECEXP (concatn, 0, i);
12325 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12329 add_loc_descr (&cc_loc_result, ref);
12330 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
12333 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12334 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12336 return cc_loc_result;
12339 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12340 for DEBUG_IMPLICIT_PTR RTL. */
12342 static dw_loc_descr_ref
12343 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
12345 dw_loc_descr_ref ret;
12350 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
12351 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
12352 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
12353 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
12354 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
12355 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
12358 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12359 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
12360 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
12364 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
12365 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
12370 /* Output a proper Dwarf location descriptor for a variable or parameter
12371 which is either allocated in a register or in a memory location. For a
12372 register, we just generate an OP_REG and the register number. For a
12373 memory location we provide a Dwarf postfix expression describing how to
12374 generate the (dynamic) address of the object onto the address stack.
12376 MODE is mode of the decl if this loc_descriptor is going to be used in
12377 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12378 allowed, VOIDmode otherwise.
12380 If we don't know how to describe it, return 0. */
12382 static dw_loc_descr_ref
12383 loc_descriptor (rtx rtl, enum machine_mode mode,
12384 enum var_init_status initialized)
12386 dw_loc_descr_ref loc_result = NULL;
12388 switch (GET_CODE (rtl))
12391 /* The case of a subreg may arise when we have a local (register)
12392 variable or a formal (register) parameter which doesn't quite fill
12393 up an entire register. For now, just assume that it is
12394 legitimate to make the Dwarf info refer to the whole register which
12395 contains the given subreg. */
12396 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
12397 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
12403 loc_result = reg_loc_descriptor (rtl, initialized);
12407 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
12408 GET_MODE (rtl), initialized);
12409 if (loc_result == NULL)
12410 loc_result = tls_mem_loc_descriptor (rtl);
12411 if (loc_result == NULL)
12413 rtx new_rtl = avoid_constant_pool_reference (rtl);
12414 if (new_rtl != rtl)
12415 loc_result = loc_descriptor (new_rtl, mode, initialized);
12420 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
12425 loc_result = concatn_loc_descriptor (rtl, initialized);
12430 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
12432 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
12433 if (GET_CODE (loc) == EXPR_LIST)
12434 loc = XEXP (loc, 0);
12435 loc_result = loc_descriptor (loc, mode, initialized);
12439 rtl = XEXP (rtl, 1);
12444 rtvec par_elems = XVEC (rtl, 0);
12445 int num_elem = GET_NUM_ELEM (par_elems);
12446 enum machine_mode mode;
12449 /* Create the first one, so we have something to add to. */
12450 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
12451 VOIDmode, initialized);
12452 if (loc_result == NULL)
12454 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
12455 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12456 for (i = 1; i < num_elem; i++)
12458 dw_loc_descr_ref temp;
12460 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
12461 VOIDmode, initialized);
12464 add_loc_descr (&loc_result, temp);
12465 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
12466 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12472 if (mode != VOIDmode && mode != BLKmode)
12473 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
12478 if (mode == VOIDmode)
12479 mode = GET_MODE (rtl);
12481 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12483 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12485 /* Note that a CONST_DOUBLE rtx could represent either an integer
12486 or a floating-point constant. A CONST_DOUBLE is used whenever
12487 the constant requires more than one word in order to be
12488 adequately represented. We output CONST_DOUBLEs as blocks. */
12489 loc_result = new_loc_descr (DW_OP_implicit_value,
12490 GET_MODE_SIZE (mode), 0);
12491 if (SCALAR_FLOAT_MODE_P (mode))
12493 unsigned int length = GET_MODE_SIZE (mode);
12494 unsigned char *array
12495 = (unsigned char*) ggc_alloc_atomic (length);
12497 insert_float (rtl, array);
12498 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12499 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12500 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12501 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12505 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
12506 loc_result->dw_loc_oprnd2.v.val_double
12507 = rtx_to_double_int (rtl);
12513 if (mode == VOIDmode)
12514 mode = GET_MODE (rtl);
12516 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12518 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
12519 unsigned int length = CONST_VECTOR_NUNITS (rtl);
12520 unsigned char *array = (unsigned char *)
12521 ggc_alloc_atomic (length * elt_size);
12525 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12526 switch (GET_MODE_CLASS (mode))
12528 case MODE_VECTOR_INT:
12529 for (i = 0, p = array; i < length; i++, p += elt_size)
12531 rtx elt = CONST_VECTOR_ELT (rtl, i);
12532 double_int val = rtx_to_double_int (elt);
12534 if (elt_size <= sizeof (HOST_WIDE_INT))
12535 insert_int (double_int_to_shwi (val), elt_size, p);
12538 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
12539 insert_double (val, p);
12544 case MODE_VECTOR_FLOAT:
12545 for (i = 0, p = array; i < length; i++, p += elt_size)
12547 rtx elt = CONST_VECTOR_ELT (rtl, i);
12548 insert_float (elt, p);
12553 gcc_unreachable ();
12556 loc_result = new_loc_descr (DW_OP_implicit_value,
12557 length * elt_size, 0);
12558 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12559 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
12560 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
12561 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12566 if (mode == VOIDmode
12567 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
12568 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
12569 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
12571 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
12576 if (!const_ok_for_output (rtl))
12579 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
12580 && (dwarf_version >= 4 || !dwarf_strict))
12582 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
12583 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
12584 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
12585 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
12586 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12590 case DEBUG_IMPLICIT_PTR:
12591 loc_result = implicit_ptr_descriptor (rtl, 0);
12595 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
12596 && CONST_INT_P (XEXP (rtl, 1)))
12599 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
12605 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
12606 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
12607 && dwarf_version >= 4)
12608 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
12610 /* Value expression. */
12611 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
12613 add_loc_descr (&loc_result,
12614 new_loc_descr (DW_OP_stack_value, 0, 0));
12622 /* We need to figure out what section we should use as the base for the
12623 address ranges where a given location is valid.
12624 1. If this particular DECL has a section associated with it, use that.
12625 2. If this function has a section associated with it, use that.
12626 3. Otherwise, use the text section.
12627 XXX: If you split a variable across multiple sections, we won't notice. */
12629 static const char *
12630 secname_for_decl (const_tree decl)
12632 const char *secname;
12634 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
12636 tree sectree = DECL_SECTION_NAME (decl);
12637 secname = TREE_STRING_POINTER (sectree);
12639 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
12641 tree sectree = DECL_SECTION_NAME (current_function_decl);
12642 secname = TREE_STRING_POINTER (sectree);
12644 else if (cfun && in_cold_section_p)
12645 secname = crtl->subsections.cold_section_label;
12647 secname = text_section_label;
12652 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12655 decl_by_reference_p (tree decl)
12657 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
12658 || TREE_CODE (decl) == VAR_DECL)
12659 && DECL_BY_REFERENCE (decl));
12662 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12665 static dw_loc_descr_ref
12666 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
12667 enum var_init_status initialized)
12669 int have_address = 0;
12670 dw_loc_descr_ref descr;
12671 enum machine_mode mode;
12673 if (want_address != 2)
12675 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12677 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
12679 varloc = PAT_VAR_LOCATION_LOC (varloc);
12680 if (GET_CODE (varloc) == EXPR_LIST)
12681 varloc = XEXP (varloc, 0);
12682 mode = GET_MODE (varloc);
12683 if (MEM_P (varloc))
12685 rtx addr = XEXP (varloc, 0);
12686 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
12687 mode, initialized);
12692 rtx x = avoid_constant_pool_reference (varloc);
12694 descr = mem_loc_descriptor (x, mode, VOIDmode,
12699 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
12706 if (GET_CODE (varloc) == VAR_LOCATION)
12707 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
12709 mode = DECL_MODE (loc);
12710 descr = loc_descriptor (varloc, mode, initialized);
12717 if (want_address == 2 && !have_address
12718 && (dwarf_version >= 4 || !dwarf_strict))
12720 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
12722 expansion_failed (loc, NULL_RTX,
12723 "DWARF address size mismatch");
12726 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
12729 /* Show if we can't fill the request for an address. */
12730 if (want_address && !have_address)
12732 expansion_failed (loc, NULL_RTX,
12733 "Want address and only have value");
12737 /* If we've got an address and don't want one, dereference. */
12738 if (!want_address && have_address)
12740 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
12741 enum dwarf_location_atom op;
12743 if (size > DWARF2_ADDR_SIZE || size == -1)
12745 expansion_failed (loc, NULL_RTX,
12746 "DWARF address size mismatch");
12749 else if (size == DWARF2_ADDR_SIZE)
12752 op = DW_OP_deref_size;
12754 add_loc_descr (&descr, new_loc_descr (op, size, 0));
12760 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
12761 if it is not possible. */
12763 static dw_loc_descr_ref
12764 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
12766 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
12767 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
12768 else if (dwarf_version >= 3 || !dwarf_strict)
12769 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
12774 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12775 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
12777 static dw_loc_descr_ref
12778 dw_sra_loc_expr (tree decl, rtx loc)
12781 unsigned int padsize = 0;
12782 dw_loc_descr_ref descr, *descr_tail;
12783 unsigned HOST_WIDE_INT decl_size;
12785 enum var_init_status initialized;
12787 if (DECL_SIZE (decl) == NULL
12788 || !host_integerp (DECL_SIZE (decl), 1))
12791 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
12793 descr_tail = &descr;
12795 for (p = loc; p; p = XEXP (p, 1))
12797 unsigned int bitsize = decl_piece_bitsize (p);
12798 rtx loc_note = *decl_piece_varloc_ptr (p);
12799 dw_loc_descr_ref cur_descr;
12800 dw_loc_descr_ref *tail, last = NULL;
12801 unsigned int opsize = 0;
12803 if (loc_note == NULL_RTX
12804 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
12806 padsize += bitsize;
12809 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
12810 varloc = NOTE_VAR_LOCATION (loc_note);
12811 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
12812 if (cur_descr == NULL)
12814 padsize += bitsize;
12818 /* Check that cur_descr either doesn't use
12819 DW_OP_*piece operations, or their sum is equal
12820 to bitsize. Otherwise we can't embed it. */
12821 for (tail = &cur_descr; *tail != NULL;
12822 tail = &(*tail)->dw_loc_next)
12823 if ((*tail)->dw_loc_opc == DW_OP_piece)
12825 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
12829 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
12831 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
12835 if (last != NULL && opsize != bitsize)
12837 padsize += bitsize;
12841 /* If there is a hole, add DW_OP_*piece after empty DWARF
12842 expression, which means that those bits are optimized out. */
12845 if (padsize > decl_size)
12847 decl_size -= padsize;
12848 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
12849 if (*descr_tail == NULL)
12851 descr_tail = &(*descr_tail)->dw_loc_next;
12854 *descr_tail = cur_descr;
12856 if (bitsize > decl_size)
12858 decl_size -= bitsize;
12861 HOST_WIDE_INT offset = 0;
12862 if (GET_CODE (varloc) == VAR_LOCATION
12863 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
12865 varloc = PAT_VAR_LOCATION_LOC (varloc);
12866 if (GET_CODE (varloc) == EXPR_LIST)
12867 varloc = XEXP (varloc, 0);
12871 if (GET_CODE (varloc) == CONST
12872 || GET_CODE (varloc) == SIGN_EXTEND
12873 || GET_CODE (varloc) == ZERO_EXTEND)
12874 varloc = XEXP (varloc, 0);
12875 else if (GET_CODE (varloc) == SUBREG)
12876 varloc = SUBREG_REG (varloc);
12881 /* DW_OP_bit_size offset should be zero for register
12882 or implicit location descriptions and empty location
12883 descriptions, but for memory addresses needs big endian
12885 if (MEM_P (varloc))
12887 unsigned HOST_WIDE_INT memsize
12888 = MEM_SIZE (varloc) * BITS_PER_UNIT;
12889 if (memsize != bitsize)
12891 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
12892 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
12894 if (memsize < bitsize)
12896 if (BITS_BIG_ENDIAN)
12897 offset = memsize - bitsize;
12901 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
12902 if (*descr_tail == NULL)
12904 descr_tail = &(*descr_tail)->dw_loc_next;
12908 /* If there were any non-empty expressions, add padding till the end of
12910 if (descr != NULL && decl_size != 0)
12912 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
12913 if (*descr_tail == NULL)
12919 /* Return the dwarf representation of the location list LOC_LIST of
12920 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
12923 static dw_loc_list_ref
12924 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
12926 const char *endname, *secname;
12928 enum var_init_status initialized;
12929 struct var_loc_node *node;
12930 dw_loc_descr_ref descr;
12931 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12932 dw_loc_list_ref list = NULL;
12933 dw_loc_list_ref *listp = &list;
12935 /* Now that we know what section we are using for a base,
12936 actually construct the list of locations.
12937 The first location information is what is passed to the
12938 function that creates the location list, and the remaining
12939 locations just get added on to that list.
12940 Note that we only know the start address for a location
12941 (IE location changes), so to build the range, we use
12942 the range [current location start, next location start].
12943 This means we have to special case the last node, and generate
12944 a range of [last location start, end of function label]. */
12946 secname = secname_for_decl (decl);
12948 for (node = loc_list->first; node; node = node->next)
12949 if (GET_CODE (node->loc) == EXPR_LIST
12950 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
12952 if (GET_CODE (node->loc) == EXPR_LIST)
12954 /* This requires DW_OP_{,bit_}piece, which is not usable
12955 inside DWARF expressions. */
12956 if (want_address != 2)
12958 descr = dw_sra_loc_expr (decl, node->loc);
12964 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
12965 varloc = NOTE_VAR_LOCATION (node->loc);
12966 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
12970 bool range_across_switch = false;
12971 /* If section switch happens in between node->label
12972 and node->next->label (or end of function) and
12973 we can't emit it as a single entry list,
12974 emit two ranges, first one ending at the end
12975 of first partition and second one starting at the
12976 beginning of second partition. */
12977 if (node == loc_list->last_before_switch
12978 && (node != loc_list->first || loc_list->first->next)
12979 && current_function_decl)
12981 endname = cfun->fde->dw_fde_end;
12982 range_across_switch = true;
12984 /* The variable has a location between NODE->LABEL and
12985 NODE->NEXT->LABEL. */
12986 else if (node->next)
12987 endname = node->next->label;
12988 /* If the variable has a location at the last label
12989 it keeps its location until the end of function. */
12990 else if (!current_function_decl)
12991 endname = text_end_label;
12994 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12995 current_function_funcdef_no);
12996 endname = ggc_strdup (label_id);
12999 *listp = new_loc_list (descr, node->label, endname, secname);
13000 if (TREE_CODE (decl) == PARM_DECL
13001 && node == loc_list->first
13002 && GET_CODE (node->loc) == NOTE
13003 && strcmp (node->label, endname) == 0)
13004 (*listp)->force = true;
13005 listp = &(*listp)->dw_loc_next;
13007 if (range_across_switch)
13009 if (GET_CODE (node->loc) == EXPR_LIST)
13010 descr = dw_sra_loc_expr (decl, node->loc);
13013 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
13014 varloc = NOTE_VAR_LOCATION (node->loc);
13015 descr = dw_loc_list_1 (decl, varloc, want_address,
13018 gcc_assert (descr);
13019 /* The variable has a location between NODE->LABEL and
13020 NODE->NEXT->LABEL. */
13022 endname = node->next->label;
13024 endname = cfun->fde->dw_fde_second_end;
13025 *listp = new_loc_list (descr,
13026 cfun->fde->dw_fde_second_begin,
13028 listp = &(*listp)->dw_loc_next;
13033 /* Try to avoid the overhead of a location list emitting a location
13034 expression instead, but only if we didn't have more than one
13035 location entry in the first place. If some entries were not
13036 representable, we don't want to pretend a single entry that was
13037 applies to the entire scope in which the variable is
13039 if (list && loc_list->first->next)
13045 /* Return if the loc_list has only single element and thus can be represented
13046 as location description. */
13049 single_element_loc_list_p (dw_loc_list_ref list)
13051 gcc_assert (!list->dw_loc_next || list->ll_symbol);
13052 return !list->ll_symbol;
13055 /* To each location in list LIST add loc descr REF. */
13058 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
13060 dw_loc_descr_ref copy;
13061 add_loc_descr (&list->expr, ref);
13062 list = list->dw_loc_next;
13065 copy = ggc_alloc_dw_loc_descr_node ();
13066 memcpy (copy, ref, sizeof (dw_loc_descr_node));
13067 add_loc_descr (&list->expr, copy);
13068 while (copy->dw_loc_next)
13070 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
13071 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
13072 copy->dw_loc_next = new_copy;
13075 list = list->dw_loc_next;
13079 /* Given two lists RET and LIST
13080 produce location list that is result of adding expression in LIST
13081 to expression in RET on each possition in program.
13082 Might be destructive on both RET and LIST.
13084 TODO: We handle only simple cases of RET or LIST having at most one
13085 element. General case would inolve sorting the lists in program order
13086 and merging them that will need some additional work.
13087 Adding that will improve quality of debug info especially for SRA-ed
13091 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
13100 if (!list->dw_loc_next)
13102 add_loc_descr_to_each (*ret, list->expr);
13105 if (!(*ret)->dw_loc_next)
13107 add_loc_descr_to_each (list, (*ret)->expr);
13111 expansion_failed (NULL_TREE, NULL_RTX,
13112 "Don't know how to merge two non-trivial"
13113 " location lists.\n");
13118 /* LOC is constant expression. Try a luck, look it up in constant
13119 pool and return its loc_descr of its address. */
13121 static dw_loc_descr_ref
13122 cst_pool_loc_descr (tree loc)
13124 /* Get an RTL for this, if something has been emitted. */
13125 rtx rtl = lookup_constant_def (loc);
13127 if (!rtl || !MEM_P (rtl))
13132 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
13134 /* TODO: We might get more coverage if we was actually delaying expansion
13135 of all expressions till end of compilation when constant pools are fully
13137 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
13139 expansion_failed (loc, NULL_RTX,
13140 "CST value in contant pool but not marked.");
13143 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
13144 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
13147 /* Return dw_loc_list representing address of addr_expr LOC
13148 by looking for innder INDIRECT_REF expression and turing it
13149 into simple arithmetics. */
13151 static dw_loc_list_ref
13152 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
13155 HOST_WIDE_INT bitsize, bitpos, bytepos;
13156 enum machine_mode mode;
13158 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13159 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13161 obj = get_inner_reference (TREE_OPERAND (loc, 0),
13162 &bitsize, &bitpos, &offset, &mode,
13163 &unsignedp, &volatilep, false);
13165 if (bitpos % BITS_PER_UNIT)
13167 expansion_failed (loc, NULL_RTX, "bitfield access");
13170 if (!INDIRECT_REF_P (obj))
13172 expansion_failed (obj,
13173 NULL_RTX, "no indirect ref in inner refrence");
13176 if (!offset && !bitpos)
13177 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
13179 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
13180 && (dwarf_version >= 4 || !dwarf_strict))
13182 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
13187 /* Variable offset. */
13188 list_ret1 = loc_list_from_tree (offset, 0);
13189 if (list_ret1 == 0)
13191 add_loc_list (&list_ret, list_ret1);
13194 add_loc_descr_to_each (list_ret,
13195 new_loc_descr (DW_OP_plus, 0, 0));
13197 bytepos = bitpos / BITS_PER_UNIT;
13199 add_loc_descr_to_each (list_ret,
13200 new_loc_descr (DW_OP_plus_uconst,
13202 else if (bytepos < 0)
13203 loc_list_plus_const (list_ret, bytepos);
13204 add_loc_descr_to_each (list_ret,
13205 new_loc_descr (DW_OP_stack_value, 0, 0));
13211 /* Generate Dwarf location list representing LOC.
13212 If WANT_ADDRESS is false, expression computing LOC will be computed
13213 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13214 if WANT_ADDRESS is 2, expression computing address useable in location
13215 will be returned (i.e. DW_OP_reg can be used
13216 to refer to register values). */
13218 static dw_loc_list_ref
13219 loc_list_from_tree (tree loc, int want_address)
13221 dw_loc_descr_ref ret = NULL, ret1 = NULL;
13222 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13223 int have_address = 0;
13224 enum dwarf_location_atom op;
13226 /* ??? Most of the time we do not take proper care for sign/zero
13227 extending the values properly. Hopefully this won't be a real
13230 switch (TREE_CODE (loc))
13233 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
13236 case PLACEHOLDER_EXPR:
13237 /* This case involves extracting fields from an object to determine the
13238 position of other fields. We don't try to encode this here. The
13239 only user of this is Ada, which encodes the needed information using
13240 the names of types. */
13241 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
13245 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
13246 /* There are no opcodes for these operations. */
13249 case PREINCREMENT_EXPR:
13250 case PREDECREMENT_EXPR:
13251 case POSTINCREMENT_EXPR:
13252 case POSTDECREMENT_EXPR:
13253 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
13254 /* There are no opcodes for these operations. */
13258 /* If we already want an address, see if there is INDIRECT_REF inside
13259 e.g. for &this->field. */
13262 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
13263 (loc, want_address == 2);
13266 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
13267 && (ret = cst_pool_loc_descr (loc)))
13270 /* Otherwise, process the argument and look for the address. */
13271 if (!list_ret && !ret)
13272 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
13276 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
13282 if (DECL_THREAD_LOCAL_P (loc))
13285 enum dwarf_location_atom first_op;
13286 enum dwarf_location_atom second_op;
13287 bool dtprel = false;
13289 if (targetm.have_tls)
13291 /* If this is not defined, we have no way to emit the
13293 if (!targetm.asm_out.output_dwarf_dtprel)
13296 /* The way DW_OP_GNU_push_tls_address is specified, we
13297 can only look up addresses of objects in the current
13298 module. We used DW_OP_addr as first op, but that's
13299 wrong, because DW_OP_addr is relocated by the debug
13300 info consumer, while DW_OP_GNU_push_tls_address
13301 operand shouldn't be. */
13302 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
13304 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
13306 second_op = DW_OP_GNU_push_tls_address;
13310 if (!targetm.emutls.debug_form_tls_address
13311 || !(dwarf_version >= 3 || !dwarf_strict))
13313 /* We stuffed the control variable into the DECL_VALUE_EXPR
13314 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13315 no longer appear in gimple code. We used the control
13316 variable in specific so that we could pick it up here. */
13317 loc = DECL_VALUE_EXPR (loc);
13318 first_op = DW_OP_addr;
13319 second_op = DW_OP_form_tls_address;
13322 rtl = rtl_for_decl_location (loc);
13323 if (rtl == NULL_RTX)
13328 rtl = XEXP (rtl, 0);
13329 if (! CONSTANT_P (rtl))
13332 ret = new_loc_descr (first_op, 0, 0);
13333 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13334 ret->dw_loc_oprnd1.v.val_addr = rtl;
13335 ret->dtprel = dtprel;
13337 ret1 = new_loc_descr (second_op, 0, 0);
13338 add_loc_descr (&ret, ret1);
13347 if (DECL_HAS_VALUE_EXPR_P (loc))
13348 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
13352 case FUNCTION_DECL:
13355 var_loc_list *loc_list = lookup_decl_loc (loc);
13357 if (loc_list && loc_list->first)
13359 list_ret = dw_loc_list (loc_list, loc, want_address);
13360 have_address = want_address != 0;
13363 rtl = rtl_for_decl_location (loc);
13364 if (rtl == NULL_RTX)
13366 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
13369 else if (CONST_INT_P (rtl))
13371 HOST_WIDE_INT val = INTVAL (rtl);
13372 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13373 val &= GET_MODE_MASK (DECL_MODE (loc));
13374 ret = int_loc_descriptor (val);
13376 else if (GET_CODE (rtl) == CONST_STRING)
13378 expansion_failed (loc, NULL_RTX, "CONST_STRING");
13381 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
13383 ret = new_loc_descr (DW_OP_addr, 0, 0);
13384 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13385 ret->dw_loc_oprnd1.v.val_addr = rtl;
13389 enum machine_mode mode, mem_mode;
13391 /* Certain constructs can only be represented at top-level. */
13392 if (want_address == 2)
13394 ret = loc_descriptor (rtl, VOIDmode,
13395 VAR_INIT_STATUS_INITIALIZED);
13400 mode = GET_MODE (rtl);
13401 mem_mode = VOIDmode;
13405 mode = get_address_mode (rtl);
13406 rtl = XEXP (rtl, 0);
13409 ret = mem_loc_descriptor (rtl, mode, mem_mode,
13410 VAR_INIT_STATUS_INITIALIZED);
13413 expansion_failed (loc, rtl,
13414 "failed to produce loc descriptor for rtl");
13421 if (!integer_zerop (TREE_OPERAND (loc, 1)))
13425 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13429 case COMPOUND_EXPR:
13430 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
13433 case VIEW_CONVERT_EXPR:
13436 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
13438 case COMPONENT_REF:
13439 case BIT_FIELD_REF:
13441 case ARRAY_RANGE_REF:
13442 case REALPART_EXPR:
13443 case IMAGPART_EXPR:
13446 HOST_WIDE_INT bitsize, bitpos, bytepos;
13447 enum machine_mode mode;
13449 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13451 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
13452 &unsignedp, &volatilep, false);
13454 gcc_assert (obj != loc);
13456 list_ret = loc_list_from_tree (obj,
13458 && !bitpos && !offset ? 2 : 1);
13459 /* TODO: We can extract value of the small expression via shifting even
13460 for nonzero bitpos. */
13463 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
13465 expansion_failed (loc, NULL_RTX,
13466 "bitfield access");
13470 if (offset != NULL_TREE)
13472 /* Variable offset. */
13473 list_ret1 = loc_list_from_tree (offset, 0);
13474 if (list_ret1 == 0)
13476 add_loc_list (&list_ret, list_ret1);
13479 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
13482 bytepos = bitpos / BITS_PER_UNIT;
13484 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
13485 else if (bytepos < 0)
13486 loc_list_plus_const (list_ret, bytepos);
13493 if ((want_address || !host_integerp (loc, 0))
13494 && (ret = cst_pool_loc_descr (loc)))
13496 else if (want_address == 2
13497 && host_integerp (loc, 0)
13498 && (ret = address_of_int_loc_descriptor
13499 (int_size_in_bytes (TREE_TYPE (loc)),
13500 tree_low_cst (loc, 0))))
13502 else if (host_integerp (loc, 0))
13503 ret = int_loc_descriptor (tree_low_cst (loc, 0));
13506 expansion_failed (loc, NULL_RTX,
13507 "Integer operand is not host integer");
13516 if ((ret = cst_pool_loc_descr (loc)))
13519 /* We can construct small constants here using int_loc_descriptor. */
13520 expansion_failed (loc, NULL_RTX,
13521 "constructor or constant not in constant pool");
13524 case TRUTH_AND_EXPR:
13525 case TRUTH_ANDIF_EXPR:
13530 case TRUTH_XOR_EXPR:
13535 case TRUTH_OR_EXPR:
13536 case TRUTH_ORIF_EXPR:
13541 case FLOOR_DIV_EXPR:
13542 case CEIL_DIV_EXPR:
13543 case ROUND_DIV_EXPR:
13544 case TRUNC_DIV_EXPR:
13545 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13554 case FLOOR_MOD_EXPR:
13555 case CEIL_MOD_EXPR:
13556 case ROUND_MOD_EXPR:
13557 case TRUNC_MOD_EXPR:
13558 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13563 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13564 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
13565 if (list_ret == 0 || list_ret1 == 0)
13568 add_loc_list (&list_ret, list_ret1);
13571 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
13572 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
13573 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
13574 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
13575 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
13587 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
13590 case POINTER_PLUS_EXPR:
13592 if (host_integerp (TREE_OPERAND (loc, 1), 0))
13594 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13598 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
13606 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13613 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13620 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13627 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13642 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13643 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
13644 if (list_ret == 0 || list_ret1 == 0)
13647 add_loc_list (&list_ret, list_ret1);
13650 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
13653 case TRUTH_NOT_EXPR:
13667 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13671 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
13677 const enum tree_code code =
13678 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
13680 loc = build3 (COND_EXPR, TREE_TYPE (loc),
13681 build2 (code, integer_type_node,
13682 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
13683 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
13686 /* ... fall through ... */
13690 dw_loc_descr_ref lhs
13691 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
13692 dw_loc_list_ref rhs
13693 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
13694 dw_loc_descr_ref bra_node, jump_node, tmp;
13696 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13697 if (list_ret == 0 || lhs == 0 || rhs == 0)
13700 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
13701 add_loc_descr_to_each (list_ret, bra_node);
13703 add_loc_list (&list_ret, rhs);
13704 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
13705 add_loc_descr_to_each (list_ret, jump_node);
13707 add_loc_descr_to_each (list_ret, lhs);
13708 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13709 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
13711 /* ??? Need a node to point the skip at. Use a nop. */
13712 tmp = new_loc_descr (DW_OP_nop, 0, 0);
13713 add_loc_descr_to_each (list_ret, tmp);
13714 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13715 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
13719 case FIX_TRUNC_EXPR:
13723 /* Leave front-end specific codes as simply unknown. This comes
13724 up, for instance, with the C STMT_EXPR. */
13725 if ((unsigned int) TREE_CODE (loc)
13726 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
13728 expansion_failed (loc, NULL_RTX,
13729 "language specific tree node");
13733 #ifdef ENABLE_CHECKING
13734 /* Otherwise this is a generic code; we should just lists all of
13735 these explicitly. We forgot one. */
13736 gcc_unreachable ();
13738 /* In a release build, we want to degrade gracefully: better to
13739 generate incomplete debugging information than to crash. */
13744 if (!ret && !list_ret)
13747 if (want_address == 2 && !have_address
13748 && (dwarf_version >= 4 || !dwarf_strict))
13750 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
13752 expansion_failed (loc, NULL_RTX,
13753 "DWARF address size mismatch");
13757 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
13759 add_loc_descr_to_each (list_ret,
13760 new_loc_descr (DW_OP_stack_value, 0, 0));
13763 /* Show if we can't fill the request for an address. */
13764 if (want_address && !have_address)
13766 expansion_failed (loc, NULL_RTX,
13767 "Want address and only have value");
13771 gcc_assert (!ret || !list_ret);
13773 /* If we've got an address and don't want one, dereference. */
13774 if (!want_address && have_address)
13776 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
13778 if (size > DWARF2_ADDR_SIZE || size == -1)
13780 expansion_failed (loc, NULL_RTX,
13781 "DWARF address size mismatch");
13784 else if (size == DWARF2_ADDR_SIZE)
13787 op = DW_OP_deref_size;
13790 add_loc_descr (&ret, new_loc_descr (op, size, 0));
13792 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
13795 list_ret = new_loc_list (ret, NULL, NULL, NULL);
13800 /* Same as above but return only single location expression. */
13801 static dw_loc_descr_ref
13802 loc_descriptor_from_tree (tree loc, int want_address)
13804 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
13807 if (ret->dw_loc_next)
13809 expansion_failed (loc, NULL_RTX,
13810 "Location list where only loc descriptor needed");
13816 /* Given a value, round it up to the lowest multiple of `boundary'
13817 which is not less than the value itself. */
13819 static inline HOST_WIDE_INT
13820 ceiling (HOST_WIDE_INT value, unsigned int boundary)
13822 return (((value + boundary - 1) / boundary) * boundary);
13825 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
13826 pointer to the declared type for the relevant field variable, or return
13827 `integer_type_node' if the given node turns out to be an
13828 ERROR_MARK node. */
13831 field_type (const_tree decl)
13835 if (TREE_CODE (decl) == ERROR_MARK)
13836 return integer_type_node;
13838 type = DECL_BIT_FIELD_TYPE (decl);
13839 if (type == NULL_TREE)
13840 type = TREE_TYPE (decl);
13845 /* Given a pointer to a tree node, return the alignment in bits for
13846 it, or else return BITS_PER_WORD if the node actually turns out to
13847 be an ERROR_MARK node. */
13849 static inline unsigned
13850 simple_type_align_in_bits (const_tree type)
13852 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
13855 static inline unsigned
13856 simple_decl_align_in_bits (const_tree decl)
13858 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
13861 /* Return the result of rounding T up to ALIGN. */
13863 static inline double_int
13864 round_up_to_align (double_int t, unsigned int align)
13866 double_int alignd = uhwi_to_double_int (align);
13867 t = double_int_add (t, alignd);
13868 t = double_int_add (t, double_int_minus_one);
13869 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
13870 t = double_int_mul (t, alignd);
13874 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
13875 lowest addressed byte of the "containing object" for the given FIELD_DECL,
13876 or return 0 if we are unable to determine what that offset is, either
13877 because the argument turns out to be a pointer to an ERROR_MARK node, or
13878 because the offset is actually variable. (We can't handle the latter case
13881 static HOST_WIDE_INT
13882 field_byte_offset (const_tree decl)
13884 double_int object_offset_in_bits;
13885 double_int object_offset_in_bytes;
13886 double_int bitpos_int;
13888 if (TREE_CODE (decl) == ERROR_MARK)
13891 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
13893 /* We cannot yet cope with fields whose positions are variable, so
13894 for now, when we see such things, we simply return 0. Someday, we may
13895 be able to handle such cases, but it will be damn difficult. */
13896 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
13899 bitpos_int = tree_to_double_int (bit_position (decl));
13901 #ifdef PCC_BITFIELD_TYPE_MATTERS
13902 if (PCC_BITFIELD_TYPE_MATTERS)
13905 tree field_size_tree;
13906 double_int deepest_bitpos;
13907 double_int field_size_in_bits;
13908 unsigned int type_align_in_bits;
13909 unsigned int decl_align_in_bits;
13910 double_int type_size_in_bits;
13912 type = field_type (decl);
13913 type_size_in_bits = double_int_type_size_in_bits (type);
13914 type_align_in_bits = simple_type_align_in_bits (type);
13916 field_size_tree = DECL_SIZE (decl);
13918 /* The size could be unspecified if there was an error, or for
13919 a flexible array member. */
13920 if (!field_size_tree)
13921 field_size_tree = bitsize_zero_node;
13923 /* If the size of the field is not constant, use the type size. */
13924 if (TREE_CODE (field_size_tree) == INTEGER_CST)
13925 field_size_in_bits = tree_to_double_int (field_size_tree);
13927 field_size_in_bits = type_size_in_bits;
13929 decl_align_in_bits = simple_decl_align_in_bits (decl);
13931 /* The GCC front-end doesn't make any attempt to keep track of the
13932 starting bit offset (relative to the start of the containing
13933 structure type) of the hypothetical "containing object" for a
13934 bit-field. Thus, when computing the byte offset value for the
13935 start of the "containing object" of a bit-field, we must deduce
13936 this information on our own. This can be rather tricky to do in
13937 some cases. For example, handling the following structure type
13938 definition when compiling for an i386/i486 target (which only
13939 aligns long long's to 32-bit boundaries) can be very tricky:
13941 struct S { int field1; long long field2:31; };
13943 Fortunately, there is a simple rule-of-thumb which can be used
13944 in such cases. When compiling for an i386/i486, GCC will
13945 allocate 8 bytes for the structure shown above. It decides to
13946 do this based upon one simple rule for bit-field allocation.
13947 GCC allocates each "containing object" for each bit-field at
13948 the first (i.e. lowest addressed) legitimate alignment boundary
13949 (based upon the required minimum alignment for the declared
13950 type of the field) which it can possibly use, subject to the
13951 condition that there is still enough available space remaining
13952 in the containing object (when allocated at the selected point)
13953 to fully accommodate all of the bits of the bit-field itself.
13955 This simple rule makes it obvious why GCC allocates 8 bytes for
13956 each object of the structure type shown above. When looking
13957 for a place to allocate the "containing object" for `field2',
13958 the compiler simply tries to allocate a 64-bit "containing
13959 object" at each successive 32-bit boundary (starting at zero)
13960 until it finds a place to allocate that 64- bit field such that
13961 at least 31 contiguous (and previously unallocated) bits remain
13962 within that selected 64 bit field. (As it turns out, for the
13963 example above, the compiler finds it is OK to allocate the
13964 "containing object" 64-bit field at bit-offset zero within the
13967 Here we attempt to work backwards from the limited set of facts
13968 we're given, and we try to deduce from those facts, where GCC
13969 must have believed that the containing object started (within
13970 the structure type). The value we deduce is then used (by the
13971 callers of this routine) to generate DW_AT_location and
13972 DW_AT_bit_offset attributes for fields (both bit-fields and, in
13973 the case of DW_AT_location, regular fields as well). */
13975 /* Figure out the bit-distance from the start of the structure to
13976 the "deepest" bit of the bit-field. */
13977 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
13979 /* This is the tricky part. Use some fancy footwork to deduce
13980 where the lowest addressed bit of the containing object must
13982 object_offset_in_bits
13983 = double_int_sub (deepest_bitpos, type_size_in_bits);
13985 /* Round up to type_align by default. This works best for
13987 object_offset_in_bits
13988 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
13990 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
13992 object_offset_in_bits
13993 = double_int_sub (deepest_bitpos, type_size_in_bits);
13995 /* Round up to decl_align instead. */
13996 object_offset_in_bits
13997 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
14001 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14002 object_offset_in_bits = bitpos_int;
14004 object_offset_in_bytes
14005 = double_int_div (object_offset_in_bits,
14006 uhwi_to_double_int (BITS_PER_UNIT), true,
14008 return double_int_to_shwi (object_offset_in_bytes);
14011 /* The following routines define various Dwarf attributes and any data
14012 associated with them. */
14014 /* Add a location description attribute value to a DIE.
14016 This emits location attributes suitable for whole variables and
14017 whole parameters. Note that the location attributes for struct fields are
14018 generated by the routine `data_member_location_attribute' below. */
14021 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
14022 dw_loc_list_ref descr)
14026 if (single_element_loc_list_p (descr))
14027 add_AT_loc (die, attr_kind, descr->expr);
14029 add_AT_loc_list (die, attr_kind, descr);
14032 /* Add DW_AT_accessibility attribute to DIE if needed. */
14035 add_accessibility_attribute (dw_die_ref die, tree decl)
14037 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14038 children, otherwise the default is DW_ACCESS_public. In DWARF2
14039 the default has always been DW_ACCESS_public. */
14040 if (TREE_PROTECTED (decl))
14041 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14042 else if (TREE_PRIVATE (decl))
14044 if (dwarf_version == 2
14045 || die->die_parent == NULL
14046 || die->die_parent->die_tag != DW_TAG_class_type)
14047 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
14049 else if (dwarf_version > 2
14051 && die->die_parent->die_tag == DW_TAG_class_type)
14052 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14055 /* Attach the specialized form of location attribute used for data members of
14056 struct and union types. In the special case of a FIELD_DECL node which
14057 represents a bit-field, the "offset" part of this special location
14058 descriptor must indicate the distance in bytes from the lowest-addressed
14059 byte of the containing struct or union type to the lowest-addressed byte of
14060 the "containing object" for the bit-field. (See the `field_byte_offset'
14063 For any given bit-field, the "containing object" is a hypothetical object
14064 (of some integral or enum type) within which the given bit-field lives. The
14065 type of this hypothetical "containing object" is always the same as the
14066 declared type of the individual bit-field itself (for GCC anyway... the
14067 DWARF spec doesn't actually mandate this). Note that it is the size (in
14068 bytes) of the hypothetical "containing object" which will be given in the
14069 DW_AT_byte_size attribute for this bit-field. (See the
14070 `byte_size_attribute' function below.) It is also used when calculating the
14071 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14072 function below.) */
14075 add_data_member_location_attribute (dw_die_ref die, tree decl)
14077 HOST_WIDE_INT offset;
14078 dw_loc_descr_ref loc_descr = 0;
14080 if (TREE_CODE (decl) == TREE_BINFO)
14082 /* We're working on the TAG_inheritance for a base class. */
14083 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
14085 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14086 aren't at a fixed offset from all (sub)objects of the same
14087 type. We need to extract the appropriate offset from our
14088 vtable. The following dwarf expression means
14090 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14092 This is specific to the V3 ABI, of course. */
14094 dw_loc_descr_ref tmp;
14096 /* Make a copy of the object address. */
14097 tmp = new_loc_descr (DW_OP_dup, 0, 0);
14098 add_loc_descr (&loc_descr, tmp);
14100 /* Extract the vtable address. */
14101 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14102 add_loc_descr (&loc_descr, tmp);
14104 /* Calculate the address of the offset. */
14105 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
14106 gcc_assert (offset < 0);
14108 tmp = int_loc_descriptor (-offset);
14109 add_loc_descr (&loc_descr, tmp);
14110 tmp = new_loc_descr (DW_OP_minus, 0, 0);
14111 add_loc_descr (&loc_descr, tmp);
14113 /* Extract the offset. */
14114 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14115 add_loc_descr (&loc_descr, tmp);
14117 /* Add it to the object address. */
14118 tmp = new_loc_descr (DW_OP_plus, 0, 0);
14119 add_loc_descr (&loc_descr, tmp);
14122 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
14125 offset = field_byte_offset (decl);
14129 if (dwarf_version > 2)
14131 /* Don't need to output a location expression, just the constant. */
14133 add_AT_int (die, DW_AT_data_member_location, offset);
14135 add_AT_unsigned (die, DW_AT_data_member_location, offset);
14140 enum dwarf_location_atom op;
14142 /* The DWARF2 standard says that we should assume that the structure
14143 address is already on the stack, so we can specify a structure
14144 field address by using DW_OP_plus_uconst. */
14146 #ifdef MIPS_DEBUGGING_INFO
14147 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
14148 operator correctly. It works only if we leave the offset on the
14152 op = DW_OP_plus_uconst;
14155 loc_descr = new_loc_descr (op, offset, 0);
14159 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
14162 /* Writes integer values to dw_vec_const array. */
14165 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
14169 *dest++ = val & 0xff;
14175 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14177 static HOST_WIDE_INT
14178 extract_int (const unsigned char *src, unsigned int size)
14180 HOST_WIDE_INT val = 0;
14186 val |= *--src & 0xff;
14192 /* Writes double_int values to dw_vec_const array. */
14195 insert_double (double_int val, unsigned char *dest)
14197 unsigned char *p0 = dest;
14198 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
14200 if (WORDS_BIG_ENDIAN)
14206 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
14207 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
14210 /* Writes floating point values to dw_vec_const array. */
14213 insert_float (const_rtx rtl, unsigned char *array)
14215 REAL_VALUE_TYPE rv;
14219 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
14220 real_to_target (val, &rv, GET_MODE (rtl));
14222 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14223 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
14225 insert_int (val[i], 4, array);
14230 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14231 does not have a "location" either in memory or in a register. These
14232 things can arise in GNU C when a constant is passed as an actual parameter
14233 to an inlined function. They can also arise in C++ where declared
14234 constants do not necessarily get memory "homes". */
14237 add_const_value_attribute (dw_die_ref die, rtx rtl)
14239 switch (GET_CODE (rtl))
14243 HOST_WIDE_INT val = INTVAL (rtl);
14246 add_AT_int (die, DW_AT_const_value, val);
14248 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
14253 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14254 floating-point constant. A CONST_DOUBLE is used whenever the
14255 constant requires more than one word in order to be adequately
14258 enum machine_mode mode = GET_MODE (rtl);
14260 if (SCALAR_FLOAT_MODE_P (mode))
14262 unsigned int length = GET_MODE_SIZE (mode);
14263 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
14265 insert_float (rtl, array);
14266 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
14269 add_AT_double (die, DW_AT_const_value,
14270 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
14276 enum machine_mode mode = GET_MODE (rtl);
14277 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
14278 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14279 unsigned char *array = (unsigned char *) ggc_alloc_atomic
14280 (length * elt_size);
14284 switch (GET_MODE_CLASS (mode))
14286 case MODE_VECTOR_INT:
14287 for (i = 0, p = array; i < length; i++, p += elt_size)
14289 rtx elt = CONST_VECTOR_ELT (rtl, i);
14290 double_int val = rtx_to_double_int (elt);
14292 if (elt_size <= sizeof (HOST_WIDE_INT))
14293 insert_int (double_int_to_shwi (val), elt_size, p);
14296 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14297 insert_double (val, p);
14302 case MODE_VECTOR_FLOAT:
14303 for (i = 0, p = array; i < length; i++, p += elt_size)
14305 rtx elt = CONST_VECTOR_ELT (rtl, i);
14306 insert_float (elt, p);
14311 gcc_unreachable ();
14314 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
14319 if (dwarf_version >= 4 || !dwarf_strict)
14321 dw_loc_descr_ref loc_result;
14322 resolve_one_addr (&rtl, NULL);
14324 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14325 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14326 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14327 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14328 add_AT_loc (die, DW_AT_location, loc_result);
14329 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14335 if (CONSTANT_P (XEXP (rtl, 0)))
14336 return add_const_value_attribute (die, XEXP (rtl, 0));
14339 if (!const_ok_for_output (rtl))
14342 if (dwarf_version >= 4 || !dwarf_strict)
14347 /* In cases where an inlined instance of an inline function is passed
14348 the address of an `auto' variable (which is local to the caller) we
14349 can get a situation where the DECL_RTL of the artificial local
14350 variable (for the inlining) which acts as a stand-in for the
14351 corresponding formal parameter (of the inline function) will look
14352 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14353 exactly a compile-time constant expression, but it isn't the address
14354 of the (artificial) local variable either. Rather, it represents the
14355 *value* which the artificial local variable always has during its
14356 lifetime. We currently have no way to represent such quasi-constant
14357 values in Dwarf, so for now we just punt and generate nothing. */
14365 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
14366 && MEM_READONLY_P (rtl)
14367 && GET_MODE (rtl) == BLKmode)
14369 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
14375 /* No other kinds of rtx should be possible here. */
14376 gcc_unreachable ();
14381 /* Determine whether the evaluation of EXPR references any variables
14382 or functions which aren't otherwise used (and therefore may not be
14385 reference_to_unused (tree * tp, int * walk_subtrees,
14386 void * data ATTRIBUTE_UNUSED)
14388 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
14389 *walk_subtrees = 0;
14391 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
14392 && ! TREE_ASM_WRITTEN (*tp))
14394 /* ??? The C++ FE emits debug information for using decls, so
14395 putting gcc_unreachable here falls over. See PR31899. For now
14396 be conservative. */
14397 else if (!cgraph_global_info_ready
14398 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
14400 else if (TREE_CODE (*tp) == VAR_DECL)
14402 struct varpool_node *node = varpool_get_node (*tp);
14403 if (!node || !node->needed)
14406 else if (TREE_CODE (*tp) == FUNCTION_DECL
14407 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
14409 /* The call graph machinery must have finished analyzing,
14410 optimizing and gimplifying the CU by now.
14411 So if *TP has no call graph node associated
14412 to it, it means *TP will not be emitted. */
14413 if (!cgraph_get_node (*tp))
14416 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
14422 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14423 for use in a later add_const_value_attribute call. */
14426 rtl_for_decl_init (tree init, tree type)
14428 rtx rtl = NULL_RTX;
14432 /* If a variable is initialized with a string constant without embedded
14433 zeros, build CONST_STRING. */
14434 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
14436 tree enttype = TREE_TYPE (type);
14437 tree domain = TYPE_DOMAIN (type);
14438 enum machine_mode mode = TYPE_MODE (enttype);
14440 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
14442 && integer_zerop (TYPE_MIN_VALUE (domain))
14443 && compare_tree_int (TYPE_MAX_VALUE (domain),
14444 TREE_STRING_LENGTH (init) - 1) == 0
14445 && ((size_t) TREE_STRING_LENGTH (init)
14446 == strlen (TREE_STRING_POINTER (init)) + 1))
14448 rtl = gen_rtx_CONST_STRING (VOIDmode,
14449 ggc_strdup (TREE_STRING_POINTER (init)));
14450 rtl = gen_rtx_MEM (BLKmode, rtl);
14451 MEM_READONLY_P (rtl) = 1;
14454 /* Other aggregates, and complex values, could be represented using
14456 else if (AGGREGATE_TYPE_P (type)
14457 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
14458 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
14459 || TREE_CODE (type) == COMPLEX_TYPE)
14461 /* Vectors only work if their mode is supported by the target.
14462 FIXME: generic vectors ought to work too. */
14463 else if (TREE_CODE (type) == VECTOR_TYPE
14464 && !VECTOR_MODE_P (TYPE_MODE (type)))
14466 /* If the initializer is something that we know will expand into an
14467 immediate RTL constant, expand it now. We must be careful not to
14468 reference variables which won't be output. */
14469 else if (initializer_constant_valid_p (init, type)
14470 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
14472 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14474 if (TREE_CODE (type) == VECTOR_TYPE)
14475 switch (TREE_CODE (init))
14480 if (TREE_CONSTANT (init))
14482 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
14483 bool constant_p = true;
14485 unsigned HOST_WIDE_INT ix;
14487 /* Even when ctor is constant, it might contain non-*_CST
14488 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14489 belong into VECTOR_CST nodes. */
14490 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
14491 if (!CONSTANT_CLASS_P (value))
14493 constant_p = false;
14499 init = build_vector_from_ctor (type, elts);
14509 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
14511 /* If expand_expr returns a MEM, it wasn't immediate. */
14512 gcc_assert (!rtl || !MEM_P (rtl));
14518 /* Generate RTL for the variable DECL to represent its location. */
14521 rtl_for_decl_location (tree decl)
14525 /* Here we have to decide where we are going to say the parameter "lives"
14526 (as far as the debugger is concerned). We only have a couple of
14527 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14529 DECL_RTL normally indicates where the parameter lives during most of the
14530 activation of the function. If optimization is enabled however, this
14531 could be either NULL or else a pseudo-reg. Both of those cases indicate
14532 that the parameter doesn't really live anywhere (as far as the code
14533 generation parts of GCC are concerned) during most of the function's
14534 activation. That will happen (for example) if the parameter is never
14535 referenced within the function.
14537 We could just generate a location descriptor here for all non-NULL
14538 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14539 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14540 where DECL_RTL is NULL or is a pseudo-reg.
14542 Note however that we can only get away with using DECL_INCOMING_RTL as
14543 a backup substitute for DECL_RTL in certain limited cases. In cases
14544 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14545 we can be sure that the parameter was passed using the same type as it is
14546 declared to have within the function, and that its DECL_INCOMING_RTL
14547 points us to a place where a value of that type is passed.
14549 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14550 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14551 because in these cases DECL_INCOMING_RTL points us to a value of some
14552 type which is *different* from the type of the parameter itself. Thus,
14553 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14554 such cases, the debugger would end up (for example) trying to fetch a
14555 `float' from a place which actually contains the first part of a
14556 `double'. That would lead to really incorrect and confusing
14557 output at debug-time.
14559 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14560 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14561 are a couple of exceptions however. On little-endian machines we can
14562 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14563 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14564 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14565 when (on a little-endian machine) a non-prototyped function has a
14566 parameter declared to be of type `short' or `char'. In such cases,
14567 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14568 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14569 passed `int' value. If the debugger then uses that address to fetch
14570 a `short' or a `char' (on a little-endian machine) the result will be
14571 the correct data, so we allow for such exceptional cases below.
14573 Note that our goal here is to describe the place where the given formal
14574 parameter lives during most of the function's activation (i.e. between the
14575 end of the prologue and the start of the epilogue). We'll do that as best
14576 as we can. Note however that if the given formal parameter is modified
14577 sometime during the execution of the function, then a stack backtrace (at
14578 debug-time) will show the function as having been called with the *new*
14579 value rather than the value which was originally passed in. This happens
14580 rarely enough that it is not a major problem, but it *is* a problem, and
14581 I'd like to fix it.
14583 A future version of dwarf2out.c may generate two additional attributes for
14584 any given DW_TAG_formal_parameter DIE which will describe the "passed
14585 type" and the "passed location" for the given formal parameter in addition
14586 to the attributes we now generate to indicate the "declared type" and the
14587 "active location" for each parameter. This additional set of attributes
14588 could be used by debuggers for stack backtraces. Separately, note that
14589 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
14590 This happens (for example) for inlined-instances of inline function formal
14591 parameters which are never referenced. This really shouldn't be
14592 happening. All PARM_DECL nodes should get valid non-NULL
14593 DECL_INCOMING_RTL values. FIXME. */
14595 /* Use DECL_RTL as the "location" unless we find something better. */
14596 rtl = DECL_RTL_IF_SET (decl);
14598 /* When generating abstract instances, ignore everything except
14599 constants, symbols living in memory, and symbols living in
14600 fixed registers. */
14601 if (! reload_completed)
14604 && (CONSTANT_P (rtl)
14606 && CONSTANT_P (XEXP (rtl, 0)))
14608 && TREE_CODE (decl) == VAR_DECL
14609 && TREE_STATIC (decl))))
14611 rtl = targetm.delegitimize_address (rtl);
14616 else if (TREE_CODE (decl) == PARM_DECL)
14618 if (rtl == NULL_RTX
14619 || is_pseudo_reg (rtl)
14621 && is_pseudo_reg (XEXP (rtl, 0))
14622 && DECL_INCOMING_RTL (decl)
14623 && MEM_P (DECL_INCOMING_RTL (decl))
14624 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
14626 tree declared_type = TREE_TYPE (decl);
14627 tree passed_type = DECL_ARG_TYPE (decl);
14628 enum machine_mode dmode = TYPE_MODE (declared_type);
14629 enum machine_mode pmode = TYPE_MODE (passed_type);
14631 /* This decl represents a formal parameter which was optimized out.
14632 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
14633 all cases where (rtl == NULL_RTX) just below. */
14634 if (dmode == pmode)
14635 rtl = DECL_INCOMING_RTL (decl);
14636 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
14637 && SCALAR_INT_MODE_P (dmode)
14638 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
14639 && DECL_INCOMING_RTL (decl))
14641 rtx inc = DECL_INCOMING_RTL (decl);
14644 else if (MEM_P (inc))
14646 if (BYTES_BIG_ENDIAN)
14647 rtl = adjust_address_nv (inc, dmode,
14648 GET_MODE_SIZE (pmode)
14649 - GET_MODE_SIZE (dmode));
14656 /* If the parm was passed in registers, but lives on the stack, then
14657 make a big endian correction if the mode of the type of the
14658 parameter is not the same as the mode of the rtl. */
14659 /* ??? This is the same series of checks that are made in dbxout.c before
14660 we reach the big endian correction code there. It isn't clear if all
14661 of these checks are necessary here, but keeping them all is the safe
14663 else if (MEM_P (rtl)
14664 && XEXP (rtl, 0) != const0_rtx
14665 && ! CONSTANT_P (XEXP (rtl, 0))
14666 /* Not passed in memory. */
14667 && !MEM_P (DECL_INCOMING_RTL (decl))
14668 /* Not passed by invisible reference. */
14669 && (!REG_P (XEXP (rtl, 0))
14670 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
14671 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
14672 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
14673 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
14676 /* Big endian correction check. */
14677 && BYTES_BIG_ENDIAN
14678 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
14679 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
14682 int offset = (UNITS_PER_WORD
14683 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
14685 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
14686 plus_constant (XEXP (rtl, 0), offset));
14689 else if (TREE_CODE (decl) == VAR_DECL
14692 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
14693 && BYTES_BIG_ENDIAN)
14695 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
14696 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
14698 /* If a variable is declared "register" yet is smaller than
14699 a register, then if we store the variable to memory, it
14700 looks like we're storing a register-sized value, when in
14701 fact we are not. We need to adjust the offset of the
14702 storage location to reflect the actual value's bytes,
14703 else gdb will not be able to display it. */
14705 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
14706 plus_constant (XEXP (rtl, 0), rsize-dsize));
14709 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
14710 and will have been substituted directly into all expressions that use it.
14711 C does not have such a concept, but C++ and other languages do. */
14712 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
14713 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
14716 rtl = targetm.delegitimize_address (rtl);
14718 /* If we don't look past the constant pool, we risk emitting a
14719 reference to a constant pool entry that isn't referenced from
14720 code, and thus is not emitted. */
14722 rtl = avoid_constant_pool_reference (rtl);
14724 /* Try harder to get a rtl. If this symbol ends up not being emitted
14725 in the current CU, resolve_addr will remove the expression referencing
14727 if (rtl == NULL_RTX
14728 && TREE_CODE (decl) == VAR_DECL
14729 && !DECL_EXTERNAL (decl)
14730 && TREE_STATIC (decl)
14731 && DECL_NAME (decl)
14732 && !DECL_HARD_REGISTER (decl)
14733 && DECL_MODE (decl) != VOIDmode)
14735 rtl = make_decl_rtl_for_debug (decl);
14737 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
14738 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
14745 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
14746 returned. If so, the decl for the COMMON block is returned, and the
14747 value is the offset into the common block for the symbol. */
14750 fortran_common (tree decl, HOST_WIDE_INT *value)
14752 tree val_expr, cvar;
14753 enum machine_mode mode;
14754 HOST_WIDE_INT bitsize, bitpos;
14756 int volatilep = 0, unsignedp = 0;
14758 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
14759 it does not have a value (the offset into the common area), or if it
14760 is thread local (as opposed to global) then it isn't common, and shouldn't
14761 be handled as such. */
14762 if (TREE_CODE (decl) != VAR_DECL
14763 || !TREE_STATIC (decl)
14764 || !DECL_HAS_VALUE_EXPR_P (decl)
14768 val_expr = DECL_VALUE_EXPR (decl);
14769 if (TREE_CODE (val_expr) != COMPONENT_REF)
14772 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
14773 &mode, &unsignedp, &volatilep, true);
14775 if (cvar == NULL_TREE
14776 || TREE_CODE (cvar) != VAR_DECL
14777 || DECL_ARTIFICIAL (cvar)
14778 || !TREE_PUBLIC (cvar))
14782 if (offset != NULL)
14784 if (!host_integerp (offset, 0))
14786 *value = tree_low_cst (offset, 0);
14789 *value += bitpos / BITS_PER_UNIT;
14794 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
14795 data attribute for a variable or a parameter. We generate the
14796 DW_AT_const_value attribute only in those cases where the given variable
14797 or parameter does not have a true "location" either in memory or in a
14798 register. This can happen (for example) when a constant is passed as an
14799 actual argument in a call to an inline function. (It's possible that
14800 these things can crop up in other ways also.) Note that one type of
14801 constant value which can be passed into an inlined function is a constant
14802 pointer. This can happen for example if an actual argument in an inlined
14803 function call evaluates to a compile-time constant address.
14805 CACHE_P is true if it is worth caching the location list for DECL,
14806 so that future calls can reuse it rather than regenerate it from scratch.
14807 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
14808 since we will need to refer to them each time the function is inlined. */
14811 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
14812 enum dwarf_attribute attr)
14815 dw_loc_list_ref list;
14816 var_loc_list *loc_list;
14817 cached_dw_loc_list *cache;
14820 if (TREE_CODE (decl) == ERROR_MARK)
14823 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
14824 || TREE_CODE (decl) == RESULT_DECL);
14826 /* Try to get some constant RTL for this decl, and use that as the value of
14829 rtl = rtl_for_decl_location (decl);
14830 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
14831 && add_const_value_attribute (die, rtl))
14834 /* See if we have single element location list that is equivalent to
14835 a constant value. That way we are better to use add_const_value_attribute
14836 rather than expanding constant value equivalent. */
14837 loc_list = lookup_decl_loc (decl);
14840 && loc_list->first->next == NULL
14841 && NOTE_P (loc_list->first->loc)
14842 && NOTE_VAR_LOCATION (loc_list->first->loc)
14843 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
14845 struct var_loc_node *node;
14847 node = loc_list->first;
14848 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
14849 if (GET_CODE (rtl) == EXPR_LIST)
14850 rtl = XEXP (rtl, 0);
14851 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
14852 && add_const_value_attribute (die, rtl))
14855 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
14856 list several times. See if we've already cached the contents. */
14858 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
14862 cache = (cached_dw_loc_list *)
14863 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
14865 list = cache->loc_list;
14869 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
14870 /* It is usually worth caching this result if the decl is from
14871 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
14872 if (cache_p && list && list->dw_loc_next)
14874 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
14875 DECL_UID (decl), INSERT);
14876 cache = ggc_alloc_cleared_cached_dw_loc_list ();
14877 cache->decl_id = DECL_UID (decl);
14878 cache->loc_list = list;
14884 add_AT_location_description (die, attr, list);
14887 /* None of that worked, so it must not really have a location;
14888 try adding a constant value attribute from the DECL_INITIAL. */
14889 return tree_add_const_value_attribute_for_decl (die, decl);
14892 /* Add VARIABLE and DIE into deferred locations list. */
14895 defer_location (tree variable, dw_die_ref die)
14897 deferred_locations entry;
14898 entry.variable = variable;
14900 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
14903 /* Helper function for tree_add_const_value_attribute. Natively encode
14904 initializer INIT into an array. Return true if successful. */
14907 native_encode_initializer (tree init, unsigned char *array, int size)
14911 if (init == NULL_TREE)
14915 switch (TREE_CODE (init))
14918 type = TREE_TYPE (init);
14919 if (TREE_CODE (type) == ARRAY_TYPE)
14921 tree enttype = TREE_TYPE (type);
14922 enum machine_mode mode = TYPE_MODE (enttype);
14924 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
14926 if (int_size_in_bytes (type) != size)
14928 if (size > TREE_STRING_LENGTH (init))
14930 memcpy (array, TREE_STRING_POINTER (init),
14931 TREE_STRING_LENGTH (init));
14932 memset (array + TREE_STRING_LENGTH (init),
14933 '\0', size - TREE_STRING_LENGTH (init));
14936 memcpy (array, TREE_STRING_POINTER (init), size);
14941 type = TREE_TYPE (init);
14942 if (int_size_in_bytes (type) != size)
14944 if (TREE_CODE (type) == ARRAY_TYPE)
14946 HOST_WIDE_INT min_index;
14947 unsigned HOST_WIDE_INT cnt;
14948 int curpos = 0, fieldsize;
14949 constructor_elt *ce;
14951 if (TYPE_DOMAIN (type) == NULL_TREE
14952 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
14955 fieldsize = int_size_in_bytes (TREE_TYPE (type));
14956 if (fieldsize <= 0)
14959 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
14960 memset (array, '\0', size);
14961 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
14963 tree val = ce->value;
14964 tree index = ce->index;
14966 if (index && TREE_CODE (index) == RANGE_EXPR)
14967 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
14970 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
14975 if (!native_encode_initializer (val, array + pos, fieldsize))
14978 curpos = pos + fieldsize;
14979 if (index && TREE_CODE (index) == RANGE_EXPR)
14981 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
14982 - tree_low_cst (TREE_OPERAND (index, 0), 0);
14983 while (count-- > 0)
14986 memcpy (array + curpos, array + pos, fieldsize);
14987 curpos += fieldsize;
14990 gcc_assert (curpos <= size);
14994 else if (TREE_CODE (type) == RECORD_TYPE
14995 || TREE_CODE (type) == UNION_TYPE)
14997 tree field = NULL_TREE;
14998 unsigned HOST_WIDE_INT cnt;
14999 constructor_elt *ce;
15001 if (int_size_in_bytes (type) != size)
15004 if (TREE_CODE (type) == RECORD_TYPE)
15005 field = TYPE_FIELDS (type);
15007 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
15009 tree val = ce->value;
15010 int pos, fieldsize;
15012 if (ce->index != 0)
15018 if (field == NULL_TREE || DECL_BIT_FIELD (field))
15021 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
15022 && TYPE_DOMAIN (TREE_TYPE (field))
15023 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
15025 else if (DECL_SIZE_UNIT (field) == NULL_TREE
15026 || !host_integerp (DECL_SIZE_UNIT (field), 0))
15028 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
15029 pos = int_byte_position (field);
15030 gcc_assert (pos + fieldsize <= size);
15032 && !native_encode_initializer (val, array + pos, fieldsize))
15038 case VIEW_CONVERT_EXPR:
15039 case NON_LVALUE_EXPR:
15040 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
15042 return native_encode_expr (init, array, size) == size;
15046 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15047 attribute is the const value T. */
15050 tree_add_const_value_attribute (dw_die_ref die, tree t)
15053 tree type = TREE_TYPE (t);
15056 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
15060 gcc_assert (!DECL_P (init));
15062 rtl = rtl_for_decl_init (init, type);
15064 return add_const_value_attribute (die, rtl);
15065 /* If the host and target are sane, try harder. */
15066 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
15067 && initializer_constant_valid_p (init, type))
15069 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
15070 if (size > 0 && (int) size == size)
15072 unsigned char *array = (unsigned char *)
15073 ggc_alloc_cleared_atomic (size);
15075 if (native_encode_initializer (init, array, size))
15077 add_AT_vec (die, DW_AT_const_value, size, 1, array);
15085 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15086 attribute is the const value of T, where T is an integral constant
15087 variable with static storage duration
15088 (so it can't be a PARM_DECL or a RESULT_DECL). */
15091 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
15095 || (TREE_CODE (decl) != VAR_DECL
15096 && TREE_CODE (decl) != CONST_DECL)
15097 || (TREE_CODE (decl) == VAR_DECL
15098 && !TREE_STATIC (decl)))
15101 if (TREE_READONLY (decl)
15102 && ! TREE_THIS_VOLATILE (decl)
15103 && DECL_INITIAL (decl))
15108 /* Don't add DW_AT_const_value if abstract origin already has one. */
15109 if (get_AT (var_die, DW_AT_const_value))
15112 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
15115 /* Convert the CFI instructions for the current function into a
15116 location list. This is used for DW_AT_frame_base when we targeting
15117 a dwarf2 consumer that does not support the dwarf3
15118 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15121 static dw_loc_list_ref
15122 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
15126 dw_loc_list_ref list, *list_tail;
15128 dw_cfa_location last_cfa, next_cfa;
15129 const char *start_label, *last_label, *section;
15130 dw_cfa_location remember;
15133 gcc_assert (fde != NULL);
15135 section = secname_for_decl (current_function_decl);
15139 memset (&next_cfa, 0, sizeof (next_cfa));
15140 next_cfa.reg = INVALID_REGNUM;
15141 remember = next_cfa;
15143 start_label = fde->dw_fde_begin;
15145 /* ??? Bald assumption that the CIE opcode list does not contain
15146 advance opcodes. */
15147 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
15148 lookup_cfa_1 (cfi, &next_cfa, &remember);
15150 last_cfa = next_cfa;
15151 last_label = start_label;
15153 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
15155 /* If the first partition contained no CFI adjustments, the
15156 CIE opcodes apply to the whole first partition. */
15157 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15158 fde->dw_fde_begin, fde->dw_fde_end, section);
15159 list_tail =&(*list_tail)->dw_loc_next;
15160 start_label = last_label = fde->dw_fde_second_begin;
15163 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
15165 switch (cfi->dw_cfi_opc)
15167 case DW_CFA_set_loc:
15168 case DW_CFA_advance_loc1:
15169 case DW_CFA_advance_loc2:
15170 case DW_CFA_advance_loc4:
15171 if (!cfa_equal_p (&last_cfa, &next_cfa))
15173 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15174 start_label, last_label, section);
15176 list_tail = &(*list_tail)->dw_loc_next;
15177 last_cfa = next_cfa;
15178 start_label = last_label;
15180 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
15183 case DW_CFA_advance_loc:
15184 /* The encoding is complex enough that we should never emit this. */
15185 gcc_unreachable ();
15188 lookup_cfa_1 (cfi, &next_cfa, &remember);
15191 if (ix + 1 == fde->dw_fde_switch_cfi_index)
15193 if (!cfa_equal_p (&last_cfa, &next_cfa))
15195 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15196 start_label, last_label, section);
15198 list_tail = &(*list_tail)->dw_loc_next;
15199 last_cfa = next_cfa;
15200 start_label = last_label;
15202 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15203 start_label, fde->dw_fde_end, section);
15204 list_tail = &(*list_tail)->dw_loc_next;
15205 start_label = last_label = fde->dw_fde_second_begin;
15209 if (!cfa_equal_p (&last_cfa, &next_cfa))
15211 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15212 start_label, last_label, section);
15213 list_tail = &(*list_tail)->dw_loc_next;
15214 start_label = last_label;
15217 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
15219 fde->dw_fde_second_begin
15220 ? fde->dw_fde_second_end : fde->dw_fde_end,
15223 if (list && list->dw_loc_next)
15229 /* Compute a displacement from the "steady-state frame pointer" to the
15230 frame base (often the same as the CFA), and store it in
15231 frame_pointer_fb_offset. OFFSET is added to the displacement
15232 before the latter is negated. */
15235 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
15239 #ifdef FRAME_POINTER_CFA_OFFSET
15240 reg = frame_pointer_rtx;
15241 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
15243 reg = arg_pointer_rtx;
15244 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
15247 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
15248 if (GET_CODE (elim) == PLUS)
15250 offset += INTVAL (XEXP (elim, 1));
15251 elim = XEXP (elim, 0);
15254 frame_pointer_fb_offset = -offset;
15256 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15257 in which to eliminate. This is because it's stack pointer isn't
15258 directly accessible as a register within the ISA. To work around
15259 this, assume that while we cannot provide a proper value for
15260 frame_pointer_fb_offset, we won't need one either. */
15261 frame_pointer_fb_offset_valid
15262 = ((SUPPORTS_STACK_ALIGNMENT
15263 && (elim == hard_frame_pointer_rtx
15264 || elim == stack_pointer_rtx))
15265 || elim == (frame_pointer_needed
15266 ? hard_frame_pointer_rtx
15267 : stack_pointer_rtx));
15270 /* Generate a DW_AT_name attribute given some string value to be included as
15271 the value of the attribute. */
15274 add_name_attribute (dw_die_ref die, const char *name_string)
15276 if (name_string != NULL && *name_string != 0)
15278 if (demangle_name_func)
15279 name_string = (*demangle_name_func) (name_string);
15281 add_AT_string (die, DW_AT_name, name_string);
15285 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15286 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15287 of TYPE accordingly.
15289 ??? This is a temporary measure until after we're able to generate
15290 regular DWARF for the complex Ada type system. */
15293 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
15294 dw_die_ref context_die)
15297 dw_die_ref dtype_die;
15299 if (!lang_hooks.types.descriptive_type)
15302 dtype = lang_hooks.types.descriptive_type (type);
15306 dtype_die = lookup_type_die (dtype);
15309 gen_type_die (dtype, context_die);
15310 dtype_die = lookup_type_die (dtype);
15311 gcc_assert (dtype_die);
15314 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
15317 /* Generate a DW_AT_comp_dir attribute for DIE. */
15320 add_comp_dir_attribute (dw_die_ref die)
15322 const char *wd = get_src_pwd ();
15328 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
15332 wdlen = strlen (wd);
15333 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
15335 wd1 [wdlen] = DIR_SEPARATOR;
15336 wd1 [wdlen + 1] = 0;
15340 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
15343 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15347 lower_bound_default (void)
15349 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
15354 case DW_LANG_C_plus_plus:
15356 case DW_LANG_ObjC_plus_plus:
15359 case DW_LANG_Fortran77:
15360 case DW_LANG_Fortran90:
15361 case DW_LANG_Fortran95:
15365 case DW_LANG_Python:
15366 return dwarf_version >= 4 ? 0 : -1;
15367 case DW_LANG_Ada95:
15368 case DW_LANG_Ada83:
15369 case DW_LANG_Cobol74:
15370 case DW_LANG_Cobol85:
15371 case DW_LANG_Pascal83:
15372 case DW_LANG_Modula2:
15374 return dwarf_version >= 4 ? 1 : -1;
15380 /* Given a tree node describing an array bound (either lower or upper) output
15381 a representation for that bound. */
15384 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
15386 switch (TREE_CODE (bound))
15391 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15394 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
15397 /* Use the default if possible. */
15398 if (bound_attr == DW_AT_lower_bound
15399 && host_integerp (bound, 0)
15400 && (dflt = lower_bound_default ()) != -1
15401 && tree_low_cst (bound, 0) == dflt)
15404 /* Otherwise represent the bound as an unsigned value with the
15405 precision of its type. The precision and signedness of the
15406 type will be necessary to re-interpret it unambiguously. */
15407 else if (prec < HOST_BITS_PER_WIDE_INT)
15409 unsigned HOST_WIDE_INT mask
15410 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
15411 add_AT_unsigned (subrange_die, bound_attr,
15412 TREE_INT_CST_LOW (bound) & mask);
15414 else if (prec == HOST_BITS_PER_WIDE_INT
15415 || TREE_INT_CST_HIGH (bound) == 0)
15416 add_AT_unsigned (subrange_die, bound_attr,
15417 TREE_INT_CST_LOW (bound));
15419 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
15420 TREE_INT_CST_LOW (bound));
15425 case VIEW_CONVERT_EXPR:
15426 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
15436 dw_die_ref decl_die = lookup_decl_die (bound);
15438 /* ??? Can this happen, or should the variable have been bound
15439 first? Probably it can, since I imagine that we try to create
15440 the types of parameters in the order in which they exist in
15441 the list, and won't have created a forward reference to a
15442 later parameter. */
15443 if (decl_die != NULL)
15445 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15453 /* Otherwise try to create a stack operation procedure to
15454 evaluate the value of the array bound. */
15456 dw_die_ref ctx, decl_die;
15457 dw_loc_list_ref list;
15459 list = loc_list_from_tree (bound, 2);
15460 if (list == NULL || single_element_loc_list_p (list))
15462 /* If DW_AT_*bound is not a reference nor constant, it is
15463 a DWARF expression rather than location description.
15464 For that loc_list_from_tree (bound, 0) is needed.
15465 If that fails to give a single element list,
15466 fall back to outputting this as a reference anyway. */
15467 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
15468 if (list2 && single_element_loc_list_p (list2))
15470 add_AT_loc (subrange_die, bound_attr, list2->expr);
15477 if (current_function_decl == 0)
15478 ctx = comp_unit_die ();
15480 ctx = lookup_decl_die (current_function_decl);
15482 decl_die = new_die (DW_TAG_variable, ctx, bound);
15483 add_AT_flag (decl_die, DW_AT_artificial, 1);
15484 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
15485 add_AT_location_description (decl_die, DW_AT_location, list);
15486 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15492 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15493 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15494 Note that the block of subscript information for an array type also
15495 includes information about the element type of the given array type. */
15498 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
15500 unsigned dimension_number;
15502 dw_die_ref subrange_die;
15504 for (dimension_number = 0;
15505 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
15506 type = TREE_TYPE (type), dimension_number++)
15508 tree domain = TYPE_DOMAIN (type);
15510 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
15513 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15514 and (in GNU C only) variable bounds. Handle all three forms
15516 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
15519 /* We have an array type with specified bounds. */
15520 lower = TYPE_MIN_VALUE (domain);
15521 upper = TYPE_MAX_VALUE (domain);
15523 /* Define the index type. */
15524 if (TREE_TYPE (domain))
15526 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15527 TREE_TYPE field. We can't emit debug info for this
15528 because it is an unnamed integral type. */
15529 if (TREE_CODE (domain) == INTEGER_TYPE
15530 && TYPE_NAME (domain) == NULL_TREE
15531 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
15532 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
15535 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
15539 /* ??? If upper is NULL, the array has unspecified length,
15540 but it does have a lower bound. This happens with Fortran
15542 Since the debugger is definitely going to need to know N
15543 to produce useful results, go ahead and output the lower
15544 bound solo, and hope the debugger can cope. */
15546 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
15548 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
15551 /* Otherwise we have an array type with an unspecified length. The
15552 DWARF-2 spec does not say how to handle this; let's just leave out the
15558 add_byte_size_attribute (dw_die_ref die, tree tree_node)
15562 switch (TREE_CODE (tree_node))
15567 case ENUMERAL_TYPE:
15570 case QUAL_UNION_TYPE:
15571 size = int_size_in_bytes (tree_node);
15574 /* For a data member of a struct or union, the DW_AT_byte_size is
15575 generally given as the number of bytes normally allocated for an
15576 object of the *declared* type of the member itself. This is true
15577 even for bit-fields. */
15578 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
15581 gcc_unreachable ();
15584 /* Note that `size' might be -1 when we get to this point. If it is, that
15585 indicates that the byte size of the entity in question is variable. We
15586 have no good way of expressing this fact in Dwarf at the present time,
15587 so just let the -1 pass on through. */
15588 add_AT_unsigned (die, DW_AT_byte_size, size);
15591 /* For a FIELD_DECL node which represents a bit-field, output an attribute
15592 which specifies the distance in bits from the highest order bit of the
15593 "containing object" for the bit-field to the highest order bit of the
15596 For any given bit-field, the "containing object" is a hypothetical object
15597 (of some integral or enum type) within which the given bit-field lives. The
15598 type of this hypothetical "containing object" is always the same as the
15599 declared type of the individual bit-field itself. The determination of the
15600 exact location of the "containing object" for a bit-field is rather
15601 complicated. It's handled by the `field_byte_offset' function (above).
15603 Note that it is the size (in bytes) of the hypothetical "containing object"
15604 which will be given in the DW_AT_byte_size attribute for this bit-field.
15605 (See `byte_size_attribute' above). */
15608 add_bit_offset_attribute (dw_die_ref die, tree decl)
15610 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
15611 tree type = DECL_BIT_FIELD_TYPE (decl);
15612 HOST_WIDE_INT bitpos_int;
15613 HOST_WIDE_INT highest_order_object_bit_offset;
15614 HOST_WIDE_INT highest_order_field_bit_offset;
15615 HOST_WIDE_INT bit_offset;
15617 /* Must be a field and a bit field. */
15618 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
15620 /* We can't yet handle bit-fields whose offsets are variable, so if we
15621 encounter such things, just return without generating any attribute
15622 whatsoever. Likewise for variable or too large size. */
15623 if (! host_integerp (bit_position (decl), 0)
15624 || ! host_integerp (DECL_SIZE (decl), 1))
15627 bitpos_int = int_bit_position (decl);
15629 /* Note that the bit offset is always the distance (in bits) from the
15630 highest-order bit of the "containing object" to the highest-order bit of
15631 the bit-field itself. Since the "high-order end" of any object or field
15632 is different on big-endian and little-endian machines, the computation
15633 below must take account of these differences. */
15634 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
15635 highest_order_field_bit_offset = bitpos_int;
15637 if (! BYTES_BIG_ENDIAN)
15639 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
15640 highest_order_object_bit_offset += simple_type_size_in_bits (type);
15644 = (! BYTES_BIG_ENDIAN
15645 ? highest_order_object_bit_offset - highest_order_field_bit_offset
15646 : highest_order_field_bit_offset - highest_order_object_bit_offset);
15648 if (bit_offset < 0)
15649 add_AT_int (die, DW_AT_bit_offset, bit_offset);
15651 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
15654 /* For a FIELD_DECL node which represents a bit field, output an attribute
15655 which specifies the length in bits of the given field. */
15658 add_bit_size_attribute (dw_die_ref die, tree decl)
15660 /* Must be a field and a bit field. */
15661 gcc_assert (TREE_CODE (decl) == FIELD_DECL
15662 && DECL_BIT_FIELD_TYPE (decl));
15664 if (host_integerp (DECL_SIZE (decl), 1))
15665 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
15668 /* If the compiled language is ANSI C, then add a 'prototyped'
15669 attribute, if arg types are given for the parameters of a function. */
15672 add_prototyped_attribute (dw_die_ref die, tree func_type)
15674 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
15675 && prototype_p (func_type))
15676 add_AT_flag (die, DW_AT_prototyped, 1);
15679 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
15680 by looking in either the type declaration or object declaration
15683 static inline dw_die_ref
15684 add_abstract_origin_attribute (dw_die_ref die, tree origin)
15686 dw_die_ref origin_die = NULL;
15688 if (TREE_CODE (origin) != FUNCTION_DECL)
15690 /* We may have gotten separated from the block for the inlined
15691 function, if we're in an exception handler or some such; make
15692 sure that the abstract function has been written out.
15694 Doing this for nested functions is wrong, however; functions are
15695 distinct units, and our context might not even be inline. */
15699 fn = TYPE_STUB_DECL (fn);
15701 fn = decl_function_context (fn);
15703 dwarf2out_abstract_function (fn);
15706 if (DECL_P (origin))
15707 origin_die = lookup_decl_die (origin);
15708 else if (TYPE_P (origin))
15709 origin_die = lookup_type_die (origin);
15711 /* XXX: Functions that are never lowered don't always have correct block
15712 trees (in the case of java, they simply have no block tree, in some other
15713 languages). For these functions, there is nothing we can really do to
15714 output correct debug info for inlined functions in all cases. Rather
15715 than die, we'll just produce deficient debug info now, in that we will
15716 have variables without a proper abstract origin. In the future, when all
15717 functions are lowered, we should re-add a gcc_assert (origin_die)
15721 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
15725 /* We do not currently support the pure_virtual attribute. */
15728 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
15730 if (DECL_VINDEX (func_decl))
15732 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
15734 if (host_integerp (DECL_VINDEX (func_decl), 0))
15735 add_AT_loc (die, DW_AT_vtable_elem_location,
15736 new_loc_descr (DW_OP_constu,
15737 tree_low_cst (DECL_VINDEX (func_decl), 0),
15740 /* GNU extension: Record what type this method came from originally. */
15741 if (debug_info_level > DINFO_LEVEL_TERSE
15742 && DECL_CONTEXT (func_decl))
15743 add_AT_die_ref (die, DW_AT_containing_type,
15744 lookup_type_die (DECL_CONTEXT (func_decl)));
15748 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
15749 given decl. This used to be a vendor extension until after DWARF 4
15750 standardized it. */
15753 add_linkage_attr (dw_die_ref die, tree decl)
15755 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15757 /* Mimic what assemble_name_raw does with a leading '*'. */
15758 if (name[0] == '*')
15761 if (dwarf_version >= 4)
15762 add_AT_string (die, DW_AT_linkage_name, name);
15764 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
15767 /* Add source coordinate attributes for the given decl. */
15770 add_src_coords_attributes (dw_die_ref die, tree decl)
15772 expanded_location s;
15774 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
15776 s = expand_location (DECL_SOURCE_LOCATION (decl));
15777 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
15778 add_AT_unsigned (die, DW_AT_decl_line, s.line);
15781 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
15784 add_linkage_name (dw_die_ref die, tree decl)
15786 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
15787 && TREE_PUBLIC (decl)
15788 && !DECL_ABSTRACT (decl)
15789 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
15790 && die->die_tag != DW_TAG_member)
15792 /* Defer until we have an assembler name set. */
15793 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
15795 limbo_die_node *asm_name;
15797 asm_name = ggc_alloc_cleared_limbo_die_node ();
15798 asm_name->die = die;
15799 asm_name->created_for = decl;
15800 asm_name->next = deferred_asm_name;
15801 deferred_asm_name = asm_name;
15803 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
15804 add_linkage_attr (die, decl);
15808 /* Add a DW_AT_name attribute and source coordinate attribute for the
15809 given decl, but only if it actually has a name. */
15812 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
15816 decl_name = DECL_NAME (decl);
15817 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
15819 const char *name = dwarf2_name (decl, 0);
15821 add_name_attribute (die, name);
15822 if (! DECL_ARTIFICIAL (decl))
15823 add_src_coords_attributes (die, decl);
15825 add_linkage_name (die, decl);
15828 #ifdef VMS_DEBUGGING_INFO
15829 /* Get the function's name, as described by its RTL. This may be different
15830 from the DECL_NAME name used in the source file. */
15831 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
15833 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
15834 XEXP (DECL_RTL (decl), 0));
15835 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
15837 #endif /* VMS_DEBUGGING_INFO */
15840 #ifdef VMS_DEBUGGING_INFO
15841 /* Output the debug main pointer die for VMS */
15844 dwarf2out_vms_debug_main_pointer (void)
15846 char label[MAX_ARTIFICIAL_LABEL_BYTES];
15849 /* Allocate the VMS debug main subprogram die. */
15850 die = ggc_alloc_cleared_die_node ();
15851 die->die_tag = DW_TAG_subprogram;
15852 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
15853 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
15854 current_function_funcdef_no);
15855 add_AT_lbl_id (die, DW_AT_entry_pc, label);
15857 /* Make it the first child of comp_unit_die (). */
15858 die->die_parent = comp_unit_die ();
15859 if (comp_unit_die ()->die_child)
15861 die->die_sib = comp_unit_die ()->die_child->die_sib;
15862 comp_unit_die ()->die_child->die_sib = die;
15866 die->die_sib = die;
15867 comp_unit_die ()->die_child = die;
15870 #endif /* VMS_DEBUGGING_INFO */
15872 /* Push a new declaration scope. */
15875 push_decl_scope (tree scope)
15877 VEC_safe_push (tree, gc, decl_scope_table, scope);
15880 /* Pop a declaration scope. */
15883 pop_decl_scope (void)
15885 VEC_pop (tree, decl_scope_table);
15888 /* Return the DIE for the scope that immediately contains this type.
15889 Non-named types get global scope. Named types nested in other
15890 types get their containing scope if it's open, or global scope
15891 otherwise. All other types (i.e. function-local named types) get
15892 the current active scope. */
15895 scope_die_for (tree t, dw_die_ref context_die)
15897 dw_die_ref scope_die = NULL;
15898 tree containing_scope;
15901 /* Non-types always go in the current scope. */
15902 gcc_assert (TYPE_P (t));
15904 containing_scope = TYPE_CONTEXT (t);
15906 /* Use the containing namespace if it was passed in (for a declaration). */
15907 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
15909 if (context_die == lookup_decl_die (containing_scope))
15912 containing_scope = NULL_TREE;
15915 /* Ignore function type "scopes" from the C frontend. They mean that
15916 a tagged type is local to a parmlist of a function declarator, but
15917 that isn't useful to DWARF. */
15918 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
15919 containing_scope = NULL_TREE;
15921 if (SCOPE_FILE_SCOPE_P (containing_scope))
15922 scope_die = comp_unit_die ();
15923 else if (TYPE_P (containing_scope))
15925 /* For types, we can just look up the appropriate DIE. But
15926 first we check to see if we're in the middle of emitting it
15927 so we know where the new DIE should go. */
15928 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
15929 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
15934 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
15935 || TREE_ASM_WRITTEN (containing_scope));
15936 /*We are not in the middle of emitting the type
15937 CONTAINING_SCOPE. Let's see if it's emitted already. */
15938 scope_die = lookup_type_die (containing_scope);
15940 /* If none of the current dies are suitable, we get file scope. */
15941 if (scope_die == NULL)
15942 scope_die = comp_unit_die ();
15945 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
15948 scope_die = context_die;
15953 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
15956 local_scope_p (dw_die_ref context_die)
15958 for (; context_die; context_die = context_die->die_parent)
15959 if (context_die->die_tag == DW_TAG_inlined_subroutine
15960 || context_die->die_tag == DW_TAG_subprogram)
15966 /* Returns nonzero if CONTEXT_DIE is a class. */
15969 class_scope_p (dw_die_ref context_die)
15971 return (context_die
15972 && (context_die->die_tag == DW_TAG_structure_type
15973 || context_die->die_tag == DW_TAG_class_type
15974 || context_die->die_tag == DW_TAG_interface_type
15975 || context_die->die_tag == DW_TAG_union_type));
15978 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
15979 whether or not to treat a DIE in this context as a declaration. */
15982 class_or_namespace_scope_p (dw_die_ref context_die)
15984 return (class_scope_p (context_die)
15985 || (context_die && context_die->die_tag == DW_TAG_namespace));
15988 /* Many forms of DIEs require a "type description" attribute. This
15989 routine locates the proper "type descriptor" die for the type given
15990 by 'type', and adds a DW_AT_type attribute below the given die. */
15993 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
15994 int decl_volatile, dw_die_ref context_die)
15996 enum tree_code code = TREE_CODE (type);
15997 dw_die_ref type_die = NULL;
15999 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16000 or fixed-point type, use the inner type. This is because we have no
16001 support for unnamed types in base_type_die. This can happen if this is
16002 an Ada subrange type. Correct solution is emit a subrange type die. */
16003 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
16004 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
16005 type = TREE_TYPE (type), code = TREE_CODE (type);
16007 if (code == ERROR_MARK
16008 /* Handle a special case. For functions whose return type is void, we
16009 generate *no* type attribute. (Note that no object may have type
16010 `void', so this only applies to function return types). */
16011 || code == VOID_TYPE)
16014 type_die = modified_type_die (type,
16015 decl_const || TYPE_READONLY (type),
16016 decl_volatile || TYPE_VOLATILE (type),
16019 if (type_die != NULL)
16020 add_AT_die_ref (object_die, DW_AT_type, type_die);
16023 /* Given an object die, add the calling convention attribute for the
16024 function call type. */
16026 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
16028 enum dwarf_calling_convention value = DW_CC_normal;
16030 value = ((enum dwarf_calling_convention)
16031 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
16034 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
16036 /* DWARF 2 doesn't provide a way to identify a program's source-level
16037 entry point. DW_AT_calling_convention attributes are only meant
16038 to describe functions' calling conventions. However, lacking a
16039 better way to signal the Fortran main program, we used this for
16040 a long time, following existing custom. Now, DWARF 4 has
16041 DW_AT_main_subprogram, which we add below, but some tools still
16042 rely on the old way, which we thus keep. */
16043 value = DW_CC_program;
16045 if (dwarf_version >= 4 || !dwarf_strict)
16046 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
16049 /* Only add the attribute if the backend requests it, and
16050 is not DW_CC_normal. */
16051 if (value && (value != DW_CC_normal))
16052 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
16055 /* Given a tree pointer to a struct, class, union, or enum type node, return
16056 a pointer to the (string) tag name for the given type, or zero if the type
16057 was declared without a tag. */
16059 static const char *
16060 type_tag (const_tree type)
16062 const char *name = 0;
16064 if (TYPE_NAME (type) != 0)
16068 /* Find the IDENTIFIER_NODE for the type name. */
16069 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
16070 && !TYPE_NAMELESS (type))
16071 t = TYPE_NAME (type);
16073 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16074 a TYPE_DECL node, regardless of whether or not a `typedef' was
16076 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16077 && ! DECL_IGNORED_P (TYPE_NAME (type)))
16079 /* We want to be extra verbose. Don't call dwarf_name if
16080 DECL_NAME isn't set. The default hook for decl_printable_name
16081 doesn't like that, and in this context it's correct to return
16082 0, instead of "<anonymous>" or the like. */
16083 if (DECL_NAME (TYPE_NAME (type))
16084 && !DECL_NAMELESS (TYPE_NAME (type)))
16085 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
16088 /* Now get the name as a string, or invent one. */
16089 if (!name && t != 0)
16090 name = IDENTIFIER_POINTER (t);
16093 return (name == 0 || *name == '\0') ? 0 : name;
16096 /* Return the type associated with a data member, make a special check
16097 for bit field types. */
16100 member_declared_type (const_tree member)
16102 return (DECL_BIT_FIELD_TYPE (member)
16103 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
16106 /* Get the decl's label, as described by its RTL. This may be different
16107 from the DECL_NAME name used in the source file. */
16110 static const char *
16111 decl_start_label (tree decl)
16114 const char *fnname;
16116 x = DECL_RTL (decl);
16117 gcc_assert (MEM_P (x));
16120 gcc_assert (GET_CODE (x) == SYMBOL_REF);
16122 fnname = XSTR (x, 0);
16127 /* These routines generate the internal representation of the DIE's for
16128 the compilation unit. Debugging information is collected by walking
16129 the declaration trees passed in from dwarf2out_decl(). */
16132 gen_array_type_die (tree type, dw_die_ref context_die)
16134 dw_die_ref scope_die = scope_die_for (type, context_die);
16135 dw_die_ref array_die;
16137 /* GNU compilers represent multidimensional array types as sequences of one
16138 dimensional array types whose element types are themselves array types.
16139 We sometimes squish that down to a single array_type DIE with multiple
16140 subscripts in the Dwarf debugging info. The draft Dwarf specification
16141 say that we are allowed to do this kind of compression in C, because
16142 there is no difference between an array of arrays and a multidimensional
16143 array. We don't do this for Ada to remain as close as possible to the
16144 actual representation, which is especially important against the language
16145 flexibilty wrt arrays of variable size. */
16147 bool collapse_nested_arrays = !is_ada ();
16150 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16151 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16152 if (TYPE_STRING_FLAG (type)
16153 && TREE_CODE (type) == ARRAY_TYPE
16155 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
16157 HOST_WIDE_INT size;
16159 array_die = new_die (DW_TAG_string_type, scope_die, type);
16160 add_name_attribute (array_die, type_tag (type));
16161 equate_type_number_to_die (type, array_die);
16162 size = int_size_in_bytes (type);
16164 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16165 else if (TYPE_DOMAIN (type) != NULL_TREE
16166 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
16167 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
16169 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
16170 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
16172 size = int_size_in_bytes (TREE_TYPE (szdecl));
16173 if (loc && size > 0)
16175 add_AT_location_description (array_die, DW_AT_string_length, loc);
16176 if (size != DWARF2_ADDR_SIZE)
16177 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16183 /* ??? The SGI dwarf reader fails for array of array of enum types
16184 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
16185 array type comes before the outer array type. We thus call gen_type_die
16186 before we new_die and must prevent nested array types collapsing for this
16189 #ifdef MIPS_DEBUGGING_INFO
16190 gen_type_die (TREE_TYPE (type), context_die);
16191 collapse_nested_arrays = false;
16194 array_die = new_die (DW_TAG_array_type, scope_die, type);
16195 add_name_attribute (array_die, type_tag (type));
16196 add_gnat_descriptive_type_attribute (array_die, type, context_die);
16197 if (TYPE_ARTIFICIAL (type))
16198 add_AT_flag (array_die, DW_AT_artificial, 1);
16199 equate_type_number_to_die (type, array_die);
16201 if (TREE_CODE (type) == VECTOR_TYPE)
16202 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
16204 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16206 && TREE_CODE (type) == ARRAY_TYPE
16207 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
16208 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
16209 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16212 /* We default the array ordering. SDB will probably do
16213 the right things even if DW_AT_ordering is not present. It's not even
16214 an issue until we start to get into multidimensional arrays anyway. If
16215 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16216 then we'll have to put the DW_AT_ordering attribute back in. (But if
16217 and when we find out that we need to put these in, we will only do so
16218 for multidimensional arrays. */
16219 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
16222 #ifdef MIPS_DEBUGGING_INFO
16223 /* The SGI compilers handle arrays of unknown bound by setting
16224 AT_declaration and not emitting any subrange DIEs. */
16225 if (TREE_CODE (type) == ARRAY_TYPE
16226 && ! TYPE_DOMAIN (type))
16227 add_AT_flag (array_die, DW_AT_declaration, 1);
16230 if (TREE_CODE (type) == VECTOR_TYPE)
16232 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16233 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
16234 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
16235 add_bound_info (subrange_die, DW_AT_upper_bound,
16236 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
16239 add_subscript_info (array_die, type, collapse_nested_arrays);
16241 /* Add representation of the type of the elements of this array type and
16242 emit the corresponding DIE if we haven't done it already. */
16243 element_type = TREE_TYPE (type);
16244 if (collapse_nested_arrays)
16245 while (TREE_CODE (element_type) == ARRAY_TYPE)
16247 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
16249 element_type = TREE_TYPE (element_type);
16252 #ifndef MIPS_DEBUGGING_INFO
16253 gen_type_die (element_type, context_die);
16256 add_type_attribute (array_die, element_type, 0, 0, context_die);
16258 if (get_AT (array_die, DW_AT_name))
16259 add_pubtype (type, array_die);
16262 static dw_loc_descr_ref
16263 descr_info_loc (tree val, tree base_decl)
16265 HOST_WIDE_INT size;
16266 dw_loc_descr_ref loc, loc2;
16267 enum dwarf_location_atom op;
16269 if (val == base_decl)
16270 return new_loc_descr (DW_OP_push_object_address, 0, 0);
16272 switch (TREE_CODE (val))
16275 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16277 return loc_descriptor_from_tree (val, 0);
16279 if (host_integerp (val, 0))
16280 return int_loc_descriptor (tree_low_cst (val, 0));
16283 size = int_size_in_bytes (TREE_TYPE (val));
16286 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16289 if (size == DWARF2_ADDR_SIZE)
16290 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
16292 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
16294 case POINTER_PLUS_EXPR:
16296 if (host_integerp (TREE_OPERAND (val, 1), 1)
16297 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
16300 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16303 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
16309 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16312 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
16315 add_loc_descr (&loc, loc2);
16316 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
16338 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
16339 tree val, tree base_decl)
16341 dw_loc_descr_ref loc;
16343 if (host_integerp (val, 0))
16345 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
16349 loc = descr_info_loc (val, base_decl);
16353 add_AT_loc (die, attr, loc);
16356 /* This routine generates DIE for array with hidden descriptor, details
16357 are filled into *info by a langhook. */
16360 gen_descr_array_type_die (tree type, struct array_descr_info *info,
16361 dw_die_ref context_die)
16363 dw_die_ref scope_die = scope_die_for (type, context_die);
16364 dw_die_ref array_die;
16367 array_die = new_die (DW_TAG_array_type, scope_die, type);
16368 add_name_attribute (array_die, type_tag (type));
16369 equate_type_number_to_die (type, array_die);
16371 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16373 && info->ndimensions >= 2)
16374 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16376 if (info->data_location)
16377 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
16379 if (info->associated)
16380 add_descr_info_field (array_die, DW_AT_associated, info->associated,
16382 if (info->allocated)
16383 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
16386 for (dim = 0; dim < info->ndimensions; dim++)
16388 dw_die_ref subrange_die
16389 = new_die (DW_TAG_subrange_type, array_die, NULL);
16391 if (info->dimen[dim].lower_bound)
16393 /* If it is the default value, omit it. */
16396 if (host_integerp (info->dimen[dim].lower_bound, 0)
16397 && (dflt = lower_bound_default ()) != -1
16398 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
16401 add_descr_info_field (subrange_die, DW_AT_lower_bound,
16402 info->dimen[dim].lower_bound,
16405 if (info->dimen[dim].upper_bound)
16406 add_descr_info_field (subrange_die, DW_AT_upper_bound,
16407 info->dimen[dim].upper_bound,
16409 if (info->dimen[dim].stride)
16410 add_descr_info_field (subrange_die, DW_AT_byte_stride,
16411 info->dimen[dim].stride,
16415 gen_type_die (info->element_type, context_die);
16416 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
16418 if (get_AT (array_die, DW_AT_name))
16419 add_pubtype (type, array_die);
16424 gen_entry_point_die (tree decl, dw_die_ref context_die)
16426 tree origin = decl_ultimate_origin (decl);
16427 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
16429 if (origin != NULL)
16430 add_abstract_origin_attribute (decl_die, origin);
16433 add_name_and_src_coords_attributes (decl_die, decl);
16434 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
16435 0, 0, context_die);
16438 if (DECL_ABSTRACT (decl))
16439 equate_decl_number_to_die (decl, decl_die);
16441 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
16445 /* Walk through the list of incomplete types again, trying once more to
16446 emit full debugging info for them. */
16449 retry_incomplete_types (void)
16453 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
16454 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
16455 DINFO_USAGE_DIR_USE))
16456 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
16459 /* Determine what tag to use for a record type. */
16461 static enum dwarf_tag
16462 record_type_tag (tree type)
16464 if (! lang_hooks.types.classify_record)
16465 return DW_TAG_structure_type;
16467 switch (lang_hooks.types.classify_record (type))
16469 case RECORD_IS_STRUCT:
16470 return DW_TAG_structure_type;
16472 case RECORD_IS_CLASS:
16473 return DW_TAG_class_type;
16475 case RECORD_IS_INTERFACE:
16476 if (dwarf_version >= 3 || !dwarf_strict)
16477 return DW_TAG_interface_type;
16478 return DW_TAG_structure_type;
16481 gcc_unreachable ();
16485 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16486 include all of the information about the enumeration values also. Each
16487 enumerated type name/value is listed as a child of the enumerated type
16491 gen_enumeration_type_die (tree type, dw_die_ref context_die)
16493 dw_die_ref type_die = lookup_type_die (type);
16495 if (type_die == NULL)
16497 type_die = new_die (DW_TAG_enumeration_type,
16498 scope_die_for (type, context_die), type);
16499 equate_type_number_to_die (type, type_die);
16500 add_name_attribute (type_die, type_tag (type));
16501 add_gnat_descriptive_type_attribute (type_die, type, context_die);
16502 if (TYPE_ARTIFICIAL (type))
16503 add_AT_flag (type_die, DW_AT_artificial, 1);
16504 if (dwarf_version >= 4 || !dwarf_strict)
16506 if (ENUM_IS_SCOPED (type))
16507 add_AT_flag (type_die, DW_AT_enum_class, 1);
16508 if (ENUM_IS_OPAQUE (type))
16509 add_AT_flag (type_die, DW_AT_declaration, 1);
16512 else if (! TYPE_SIZE (type))
16515 remove_AT (type_die, DW_AT_declaration);
16517 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16518 given enum type is incomplete, do not generate the DW_AT_byte_size
16519 attribute or the DW_AT_element_list attribute. */
16520 if (TYPE_SIZE (type))
16524 TREE_ASM_WRITTEN (type) = 1;
16525 add_byte_size_attribute (type_die, type);
16526 if (TYPE_STUB_DECL (type) != NULL_TREE)
16528 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
16529 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
16532 /* If the first reference to this type was as the return type of an
16533 inline function, then it may not have a parent. Fix this now. */
16534 if (type_die->die_parent == NULL)
16535 add_child_die (scope_die_for (type, context_die), type_die);
16537 for (link = TYPE_VALUES (type);
16538 link != NULL; link = TREE_CHAIN (link))
16540 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
16541 tree value = TREE_VALUE (link);
16543 add_name_attribute (enum_die,
16544 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
16546 if (TREE_CODE (value) == CONST_DECL)
16547 value = DECL_INITIAL (value);
16549 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
16550 /* DWARF2 does not provide a way of indicating whether or
16551 not enumeration constants are signed or unsigned. GDB
16552 always assumes the values are signed, so we output all
16553 values as if they were signed. That means that
16554 enumeration constants with very large unsigned values
16555 will appear to have negative values in the debugger. */
16556 add_AT_int (enum_die, DW_AT_const_value,
16557 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
16561 add_AT_flag (type_die, DW_AT_declaration, 1);
16563 if (get_AT (type_die, DW_AT_name))
16564 add_pubtype (type, type_die);
16569 /* Generate a DIE to represent either a real live formal parameter decl or to
16570 represent just the type of some formal parameter position in some function
16573 Note that this routine is a bit unusual because its argument may be a
16574 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
16575 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
16576 node. If it's the former then this function is being called to output a
16577 DIE to represent a formal parameter object (or some inlining thereof). If
16578 it's the latter, then this function is only being called to output a
16579 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
16580 argument type of some subprogram type.
16581 If EMIT_NAME_P is true, name and source coordinate attributes
16585 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
16586 dw_die_ref context_die)
16588 tree node_or_origin = node ? node : origin;
16589 tree ultimate_origin;
16590 dw_die_ref parm_die
16591 = new_die (DW_TAG_formal_parameter, context_die, node);
16593 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
16595 case tcc_declaration:
16596 ultimate_origin = decl_ultimate_origin (node_or_origin);
16597 if (node || ultimate_origin)
16598 origin = ultimate_origin;
16599 if (origin != NULL)
16600 add_abstract_origin_attribute (parm_die, origin);
16601 else if (emit_name_p)
16602 add_name_and_src_coords_attributes (parm_die, node);
16604 || (! DECL_ABSTRACT (node_or_origin)
16605 && variably_modified_type_p (TREE_TYPE (node_or_origin),
16606 decl_function_context
16607 (node_or_origin))))
16609 tree type = TREE_TYPE (node_or_origin);
16610 if (decl_by_reference_p (node_or_origin))
16611 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
16614 add_type_attribute (parm_die, type,
16615 TREE_READONLY (node_or_origin),
16616 TREE_THIS_VOLATILE (node_or_origin),
16619 if (origin == NULL && DECL_ARTIFICIAL (node))
16620 add_AT_flag (parm_die, DW_AT_artificial, 1);
16622 if (node && node != origin)
16623 equate_decl_number_to_die (node, parm_die);
16624 if (! DECL_ABSTRACT (node_or_origin))
16625 add_location_or_const_value_attribute (parm_die, node_or_origin,
16626 node == NULL, DW_AT_location);
16631 /* We were called with some kind of a ..._TYPE node. */
16632 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
16636 gcc_unreachable ();
16642 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
16643 children DW_TAG_formal_parameter DIEs representing the arguments of the
16646 PARM_PACK must be a function parameter pack.
16647 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
16648 must point to the subsequent arguments of the function PACK_ARG belongs to.
16649 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
16650 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
16651 following the last one for which a DIE was generated. */
16654 gen_formal_parameter_pack_die (tree parm_pack,
16656 dw_die_ref subr_die,
16660 dw_die_ref parm_pack_die;
16662 gcc_assert (parm_pack
16663 && lang_hooks.function_parameter_pack_p (parm_pack)
16666 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
16667 add_src_coords_attributes (parm_pack_die, parm_pack);
16669 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
16671 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
16674 gen_formal_parameter_die (arg, NULL,
16675 false /* Don't emit name attribute. */,
16680 return parm_pack_die;
16683 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
16684 at the end of an (ANSI prototyped) formal parameters list. */
16687 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
16689 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
16692 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
16693 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
16694 parameters as specified in some function type specification (except for
16695 those which appear as part of a function *definition*). */
16698 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
16701 tree formal_type = NULL;
16702 tree first_parm_type;
16705 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
16707 arg = DECL_ARGUMENTS (function_or_method_type);
16708 function_or_method_type = TREE_TYPE (function_or_method_type);
16713 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
16715 /* Make our first pass over the list of formal parameter types and output a
16716 DW_TAG_formal_parameter DIE for each one. */
16717 for (link = first_parm_type; link; )
16719 dw_die_ref parm_die;
16721 formal_type = TREE_VALUE (link);
16722 if (formal_type == void_type_node)
16725 /* Output a (nameless) DIE to represent the formal parameter itself. */
16726 parm_die = gen_formal_parameter_die (formal_type, NULL,
16727 true /* Emit name attribute. */,
16729 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
16730 && link == first_parm_type)
16732 add_AT_flag (parm_die, DW_AT_artificial, 1);
16733 if (dwarf_version >= 3 || !dwarf_strict)
16734 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
16736 else if (arg && DECL_ARTIFICIAL (arg))
16737 add_AT_flag (parm_die, DW_AT_artificial, 1);
16739 link = TREE_CHAIN (link);
16741 arg = DECL_CHAIN (arg);
16744 /* If this function type has an ellipsis, add a
16745 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
16746 if (formal_type != void_type_node)
16747 gen_unspecified_parameters_die (function_or_method_type, context_die);
16749 /* Make our second (and final) pass over the list of formal parameter types
16750 and output DIEs to represent those types (as necessary). */
16751 for (link = TYPE_ARG_TYPES (function_or_method_type);
16752 link && TREE_VALUE (link);
16753 link = TREE_CHAIN (link))
16754 gen_type_die (TREE_VALUE (link), context_die);
16757 /* We want to generate the DIE for TYPE so that we can generate the
16758 die for MEMBER, which has been defined; we will need to refer back
16759 to the member declaration nested within TYPE. If we're trying to
16760 generate minimal debug info for TYPE, processing TYPE won't do the
16761 trick; we need to attach the member declaration by hand. */
16764 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
16766 gen_type_die (type, context_die);
16768 /* If we're trying to avoid duplicate debug info, we may not have
16769 emitted the member decl for this function. Emit it now. */
16770 if (TYPE_STUB_DECL (type)
16771 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
16772 && ! lookup_decl_die (member))
16774 dw_die_ref type_die;
16775 gcc_assert (!decl_ultimate_origin (member));
16777 push_decl_scope (type);
16778 type_die = lookup_type_die_strip_naming_typedef (type);
16779 if (TREE_CODE (member) == FUNCTION_DECL)
16780 gen_subprogram_die (member, type_die);
16781 else if (TREE_CODE (member) == FIELD_DECL)
16783 /* Ignore the nameless fields that are used to skip bits but handle
16784 C++ anonymous unions and structs. */
16785 if (DECL_NAME (member) != NULL_TREE
16786 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
16787 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
16789 gen_type_die (member_declared_type (member), type_die);
16790 gen_field_die (member, type_die);
16794 gen_variable_die (member, NULL_TREE, type_die);
16800 /* Generate the DWARF2 info for the "abstract" instance of a function which we
16801 may later generate inlined and/or out-of-line instances of. */
16804 dwarf2out_abstract_function (tree decl)
16806 dw_die_ref old_die;
16810 htab_t old_decl_loc_table;
16811 htab_t old_cached_dw_loc_list_table;
16812 int old_call_site_count, old_tail_call_site_count;
16813 struct call_arg_loc_node *old_call_arg_locations;
16815 /* Make sure we have the actual abstract inline, not a clone. */
16816 decl = DECL_ORIGIN (decl);
16818 old_die = lookup_decl_die (decl);
16819 if (old_die && get_AT (old_die, DW_AT_inline))
16820 /* We've already generated the abstract instance. */
16823 /* We can be called while recursively when seeing block defining inlined subroutine
16824 DIE. Be sure to not clobber the outer location table nor use it or we would
16825 get locations in abstract instantces. */
16826 old_decl_loc_table = decl_loc_table;
16827 decl_loc_table = NULL;
16828 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
16829 cached_dw_loc_list_table = NULL;
16830 old_call_arg_locations = call_arg_locations;
16831 call_arg_locations = NULL;
16832 old_call_site_count = call_site_count;
16833 call_site_count = -1;
16834 old_tail_call_site_count = tail_call_site_count;
16835 tail_call_site_count = -1;
16837 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
16838 we don't get confused by DECL_ABSTRACT. */
16839 if (debug_info_level > DINFO_LEVEL_TERSE)
16841 context = decl_class_context (decl);
16843 gen_type_die_for_member
16844 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
16847 /* Pretend we've just finished compiling this function. */
16848 save_fn = current_function_decl;
16849 current_function_decl = decl;
16850 push_cfun (DECL_STRUCT_FUNCTION (decl));
16852 was_abstract = DECL_ABSTRACT (decl);
16853 set_decl_abstract_flags (decl, 1);
16854 dwarf2out_decl (decl);
16855 if (! was_abstract)
16856 set_decl_abstract_flags (decl, 0);
16858 current_function_decl = save_fn;
16859 decl_loc_table = old_decl_loc_table;
16860 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
16861 call_arg_locations = old_call_arg_locations;
16862 call_site_count = old_call_site_count;
16863 tail_call_site_count = old_tail_call_site_count;
16867 /* Helper function of premark_used_types() which gets called through
16870 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16871 marked as unused by prune_unused_types. */
16874 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
16879 type = (tree) *slot;
16880 die = lookup_type_die (type);
16882 die->die_perennial_p = 1;
16886 /* Helper function of premark_types_used_by_global_vars which gets called
16887 through htab_traverse.
16889 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16890 marked as unused by prune_unused_types. The DIE of the type is marked
16891 only if the global variable using the type will actually be emitted. */
16894 premark_types_used_by_global_vars_helper (void **slot,
16895 void *data ATTRIBUTE_UNUSED)
16897 struct types_used_by_vars_entry *entry;
16900 entry = (struct types_used_by_vars_entry *) *slot;
16901 gcc_assert (entry->type != NULL
16902 && entry->var_decl != NULL);
16903 die = lookup_type_die (entry->type);
16906 /* Ask cgraph if the global variable really is to be emitted.
16907 If yes, then we'll keep the DIE of ENTRY->TYPE. */
16908 struct varpool_node *node = varpool_get_node (entry->var_decl);
16909 if (node && node->needed)
16911 die->die_perennial_p = 1;
16912 /* Keep the parent DIEs as well. */
16913 while ((die = die->die_parent) && die->die_perennial_p == 0)
16914 die->die_perennial_p = 1;
16920 /* Mark all members of used_types_hash as perennial. */
16923 premark_used_types (void)
16925 if (cfun && cfun->used_types_hash)
16926 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
16929 /* Mark all members of types_used_by_vars_entry as perennial. */
16932 premark_types_used_by_global_vars (void)
16934 if (types_used_by_vars_hash)
16935 htab_traverse (types_used_by_vars_hash,
16936 premark_types_used_by_global_vars_helper, NULL);
16939 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
16940 for CA_LOC call arg loc node. */
16943 gen_call_site_die (tree decl, dw_die_ref subr_die,
16944 struct call_arg_loc_node *ca_loc)
16946 dw_die_ref stmt_die = NULL, die;
16947 tree block = ca_loc->block;
16950 && block != DECL_INITIAL (decl)
16951 && TREE_CODE (block) == BLOCK)
16953 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
16954 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
16957 block = BLOCK_SUPERCONTEXT (block);
16959 if (stmt_die == NULL)
16960 stmt_die = subr_die;
16961 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
16962 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
16963 if (ca_loc->tail_call_p)
16964 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
16965 if (ca_loc->symbol_ref)
16967 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
16969 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
16971 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
16976 /* Generate a DIE to represent a declared function (either file-scope or
16980 gen_subprogram_die (tree decl, dw_die_ref context_die)
16982 tree origin = decl_ultimate_origin (decl);
16983 dw_die_ref subr_die;
16985 dw_die_ref old_die = lookup_decl_die (decl);
16986 int declaration = (current_function_decl != decl
16987 || class_or_namespace_scope_p (context_die));
16989 premark_used_types ();
16991 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
16992 started to generate the abstract instance of an inline, decided to output
16993 its containing class, and proceeded to emit the declaration of the inline
16994 from the member list for the class. If so, DECLARATION takes priority;
16995 we'll get back to the abstract instance when done with the class. */
16997 /* The class-scope declaration DIE must be the primary DIE. */
16998 if (origin && declaration && class_or_namespace_scope_p (context_die))
17001 gcc_assert (!old_die);
17004 /* Now that the C++ front end lazily declares artificial member fns, we
17005 might need to retrofit the declaration into its class. */
17006 if (!declaration && !origin && !old_die
17007 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
17008 && !class_or_namespace_scope_p (context_die)
17009 && debug_info_level > DINFO_LEVEL_TERSE)
17010 old_die = force_decl_die (decl);
17012 if (origin != NULL)
17014 gcc_assert (!declaration || local_scope_p (context_die));
17016 /* Fixup die_parent for the abstract instance of a nested
17017 inline function. */
17018 if (old_die && old_die->die_parent == NULL)
17019 add_child_die (context_die, old_die);
17021 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17022 add_abstract_origin_attribute (subr_die, origin);
17023 /* This is where the actual code for a cloned function is.
17024 Let's emit linkage name attribute for it. This helps
17025 debuggers to e.g, set breakpoints into
17026 constructors/destructors when the user asks "break
17028 add_linkage_name (subr_die, decl);
17032 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17033 struct dwarf_file_data * file_index = lookup_filename (s.file);
17035 if (!get_AT_flag (old_die, DW_AT_declaration)
17036 /* We can have a normal definition following an inline one in the
17037 case of redefinition of GNU C extern inlines.
17038 It seems reasonable to use AT_specification in this case. */
17039 && !get_AT (old_die, DW_AT_inline))
17041 /* Detect and ignore this case, where we are trying to output
17042 something we have already output. */
17046 /* If the definition comes from the same place as the declaration,
17047 maybe use the old DIE. We always want the DIE for this function
17048 that has the *_pc attributes to be under comp_unit_die so the
17049 debugger can find it. We also need to do this for abstract
17050 instances of inlines, since the spec requires the out-of-line copy
17051 to have the same parent. For local class methods, this doesn't
17052 apply; we just use the old DIE. */
17053 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
17054 && (DECL_ARTIFICIAL (decl)
17055 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
17056 && (get_AT_unsigned (old_die, DW_AT_decl_line)
17057 == (unsigned) s.line))))
17059 subr_die = old_die;
17061 /* Clear out the declaration attribute and the formal parameters.
17062 Do not remove all children, because it is possible that this
17063 declaration die was forced using force_decl_die(). In such
17064 cases die that forced declaration die (e.g. TAG_imported_module)
17065 is one of the children that we do not want to remove. */
17066 remove_AT (subr_die, DW_AT_declaration);
17067 remove_AT (subr_die, DW_AT_object_pointer);
17068 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
17072 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17073 add_AT_specification (subr_die, old_die);
17074 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
17075 add_AT_file (subr_die, DW_AT_decl_file, file_index);
17076 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
17077 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
17082 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17084 if (TREE_PUBLIC (decl))
17085 add_AT_flag (subr_die, DW_AT_external, 1);
17087 add_name_and_src_coords_attributes (subr_die, decl);
17088 if (debug_info_level > DINFO_LEVEL_TERSE)
17090 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
17091 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
17092 0, 0, context_die);
17095 add_pure_or_virtual_attribute (subr_die, decl);
17096 if (DECL_ARTIFICIAL (decl))
17097 add_AT_flag (subr_die, DW_AT_artificial, 1);
17099 add_accessibility_attribute (subr_die, decl);
17104 if (!old_die || !get_AT (old_die, DW_AT_inline))
17106 add_AT_flag (subr_die, DW_AT_declaration, 1);
17108 /* If this is an explicit function declaration then generate
17109 a DW_AT_explicit attribute. */
17110 if (lang_hooks.decls.function_decl_explicit_p (decl)
17111 && (dwarf_version >= 3 || !dwarf_strict))
17112 add_AT_flag (subr_die, DW_AT_explicit, 1);
17114 /* The first time we see a member function, it is in the context of
17115 the class to which it belongs. We make sure of this by emitting
17116 the class first. The next time is the definition, which is
17117 handled above. The two may come from the same source text.
17119 Note that force_decl_die() forces function declaration die. It is
17120 later reused to represent definition. */
17121 equate_decl_number_to_die (decl, subr_die);
17124 else if (DECL_ABSTRACT (decl))
17126 if (DECL_DECLARED_INLINE_P (decl))
17128 if (cgraph_function_possibly_inlined_p (decl))
17129 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
17131 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
17135 if (cgraph_function_possibly_inlined_p (decl))
17136 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
17138 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
17141 if (DECL_DECLARED_INLINE_P (decl)
17142 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
17143 add_AT_flag (subr_die, DW_AT_artificial, 1);
17145 equate_decl_number_to_die (decl, subr_die);
17147 else if (!DECL_EXTERNAL (decl))
17149 HOST_WIDE_INT cfa_fb_offset;
17151 if (!old_die || !get_AT (old_die, DW_AT_inline))
17152 equate_decl_number_to_die (decl, subr_die);
17154 if (!flag_reorder_blocks_and_partition)
17156 dw_fde_ref fde = cfun->fde;
17157 if (fde->dw_fde_begin)
17159 /* We have already generated the labels. */
17160 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17161 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17165 /* Create start/end labels and add the range. */
17166 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
17167 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
17168 current_function_funcdef_no);
17169 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
17170 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
17171 current_function_funcdef_no);
17172 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
17175 #if VMS_DEBUGGING_INFO
17176 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17177 Section 2.3 Prologue and Epilogue Attributes:
17178 When a breakpoint is set on entry to a function, it is generally
17179 desirable for execution to be suspended, not on the very first
17180 instruction of the function, but rather at a point after the
17181 function's frame has been set up, after any language defined local
17182 declaration processing has been completed, and before execution of
17183 the first statement of the function begins. Debuggers generally
17184 cannot properly determine where this point is. Similarly for a
17185 breakpoint set on exit from a function. The prologue and epilogue
17186 attributes allow a compiler to communicate the location(s) to use. */
17189 if (fde->dw_fde_vms_end_prologue)
17190 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
17191 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
17193 if (fde->dw_fde_vms_begin_epilogue)
17194 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
17195 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
17199 add_pubname (decl, subr_die);
17203 /* Generate pubnames entries for the split function code ranges. */
17204 dw_fde_ref fde = cfun->fde;
17206 if (fde->dw_fde_second_begin)
17208 if (dwarf_version >= 3 || !dwarf_strict)
17210 /* We should use ranges for non-contiguous code section
17211 addresses. Use the actual code range for the initial
17212 section, since the HOT/COLD labels might precede an
17213 alignment offset. */
17214 bool range_list_added = false;
17215 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
17216 fde->dw_fde_end, &range_list_added);
17217 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
17218 fde->dw_fde_second_end,
17219 &range_list_added);
17220 add_pubname (decl, subr_die);
17221 if (range_list_added)
17226 /* There is no real support in DW2 for this .. so we make
17227 a work-around. First, emit the pub name for the segment
17228 containing the function label. Then make and emit a
17229 simplified subprogram DIE for the second segment with the
17230 name pre-fixed by __hot/cold_sect_of_. We use the same
17231 linkage name for the second die so that gdb will find both
17232 sections when given "b foo". */
17233 const char *name = NULL;
17234 tree decl_name = DECL_NAME (decl);
17235 dw_die_ref seg_die;
17237 /* Do the 'primary' section. */
17238 add_AT_lbl_id (subr_die, DW_AT_low_pc,
17239 fde->dw_fde_begin);
17240 add_AT_lbl_id (subr_die, DW_AT_high_pc,
17243 add_pubname (decl, subr_die);
17245 /* Build a minimal DIE for the secondary section. */
17246 seg_die = new_die (DW_TAG_subprogram,
17247 subr_die->die_parent, decl);
17249 if (TREE_PUBLIC (decl))
17250 add_AT_flag (seg_die, DW_AT_external, 1);
17252 if (decl_name != NULL
17253 && IDENTIFIER_POINTER (decl_name) != NULL)
17255 name = dwarf2_name (decl, 1);
17256 if (! DECL_ARTIFICIAL (decl))
17257 add_src_coords_attributes (seg_die, decl);
17259 add_linkage_name (seg_die, decl);
17261 gcc_assert (name != NULL);
17262 add_pure_or_virtual_attribute (seg_die, decl);
17263 if (DECL_ARTIFICIAL (decl))
17264 add_AT_flag (seg_die, DW_AT_artificial, 1);
17266 name = concat ("__second_sect_of_", name, NULL);
17267 add_AT_lbl_id (seg_die, DW_AT_low_pc,
17268 fde->dw_fde_second_begin);
17269 add_AT_lbl_id (seg_die, DW_AT_high_pc,
17270 fde->dw_fde_second_end);
17271 add_name_attribute (seg_die, name);
17272 add_pubname_string (name, seg_die);
17277 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17278 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17279 add_pubname (decl, subr_die);
17283 #ifdef MIPS_DEBUGGING_INFO
17284 /* Add a reference to the FDE for this routine. */
17285 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, cfun->fde->fde_index);
17288 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
17290 /* We define the "frame base" as the function's CFA. This is more
17291 convenient for several reasons: (1) It's stable across the prologue
17292 and epilogue, which makes it better than just a frame pointer,
17293 (2) With dwarf3, there exists a one-byte encoding that allows us
17294 to reference the .debug_frame data by proxy, but failing that,
17295 (3) We can at least reuse the code inspection and interpretation
17296 code that determines the CFA position at various points in the
17298 if (dwarf_version >= 3)
17300 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
17301 add_AT_loc (subr_die, DW_AT_frame_base, op);
17305 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
17306 if (list->dw_loc_next)
17307 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
17309 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
17312 /* Compute a displacement from the "steady-state frame pointer" to
17313 the CFA. The former is what all stack slots and argument slots
17314 will reference in the rtl; the later is what we've told the
17315 debugger about. We'll need to adjust all frame_base references
17316 by this displacement. */
17317 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
17319 if (cfun->static_chain_decl)
17320 add_AT_location_description (subr_die, DW_AT_static_link,
17321 loc_list_from_tree (cfun->static_chain_decl, 2));
17324 /* Generate child dies for template paramaters. */
17325 if (debug_info_level > DINFO_LEVEL_TERSE)
17326 gen_generic_params_dies (decl);
17328 /* Now output descriptions of the arguments for this function. This gets
17329 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17330 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17331 `...' at the end of the formal parameter list. In order to find out if
17332 there was a trailing ellipsis or not, we must instead look at the type
17333 associated with the FUNCTION_DECL. This will be a node of type
17334 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17335 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17336 an ellipsis at the end. */
17338 /* In the case where we are describing a mere function declaration, all we
17339 need to do here (and all we *can* do here) is to describe the *types* of
17340 its formal parameters. */
17341 if (debug_info_level <= DINFO_LEVEL_TERSE)
17343 else if (declaration)
17344 gen_formal_types_die (decl, subr_die);
17347 /* Generate DIEs to represent all known formal parameters. */
17348 tree parm = DECL_ARGUMENTS (decl);
17349 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
17350 tree generic_decl_parm = generic_decl
17351 ? DECL_ARGUMENTS (generic_decl)
17354 /* Now we want to walk the list of parameters of the function and
17355 emit their relevant DIEs.
17357 We consider the case of DECL being an instance of a generic function
17358 as well as it being a normal function.
17360 If DECL is an instance of a generic function we walk the
17361 parameters of the generic function declaration _and_ the parameters of
17362 DECL itself. This is useful because we want to emit specific DIEs for
17363 function parameter packs and those are declared as part of the
17364 generic function declaration. In that particular case,
17365 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17366 That DIE has children DIEs representing the set of arguments
17367 of the pack. Note that the set of pack arguments can be empty.
17368 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17371 Otherwise, we just consider the parameters of DECL. */
17372 while (generic_decl_parm || parm)
17374 if (generic_decl_parm
17375 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
17376 gen_formal_parameter_pack_die (generic_decl_parm,
17381 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
17383 if (parm == DECL_ARGUMENTS (decl)
17384 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
17386 && (dwarf_version >= 3 || !dwarf_strict))
17387 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
17389 parm = DECL_CHAIN (parm);
17392 if (generic_decl_parm)
17393 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
17396 /* Decide whether we need an unspecified_parameters DIE at the end.
17397 There are 2 more cases to do this for: 1) the ansi ... declaration -
17398 this is detectable when the end of the arg list is not a
17399 void_type_node 2) an unprototyped function declaration (not a
17400 definition). This just means that we have no info about the
17401 parameters at all. */
17402 if (prototype_p (TREE_TYPE (decl)))
17404 /* This is the prototyped case, check for.... */
17405 if (stdarg_p (TREE_TYPE (decl)))
17406 gen_unspecified_parameters_die (decl, subr_die);
17408 else if (DECL_INITIAL (decl) == NULL_TREE)
17409 gen_unspecified_parameters_die (decl, subr_die);
17412 /* Output Dwarf info for all of the stuff within the body of the function
17413 (if it has one - it may be just a declaration). */
17414 outer_scope = DECL_INITIAL (decl);
17416 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17417 a function. This BLOCK actually represents the outermost binding contour
17418 for the function, i.e. the contour in which the function's formal
17419 parameters and labels get declared. Curiously, it appears that the front
17420 end doesn't actually put the PARM_DECL nodes for the current function onto
17421 the BLOCK_VARS list for this outer scope, but are strung off of the
17422 DECL_ARGUMENTS list for the function instead.
17424 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17425 the LABEL_DECL nodes for the function however, and we output DWARF info
17426 for those in decls_for_scope. Just within the `outer_scope' there will be
17427 a BLOCK node representing the function's outermost pair of curly braces,
17428 and any blocks used for the base and member initializers of a C++
17429 constructor function. */
17430 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
17432 int call_site_note_count = 0;
17433 int tail_call_site_note_count = 0;
17435 /* Emit a DW_TAG_variable DIE for a named return value. */
17436 if (DECL_NAME (DECL_RESULT (decl)))
17437 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
17439 current_function_has_inlines = 0;
17440 decls_for_scope (outer_scope, subr_die, 0);
17442 if (call_arg_locations && !dwarf_strict)
17444 struct call_arg_loc_node *ca_loc;
17445 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
17447 dw_die_ref die = NULL;
17448 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
17451 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
17452 arg; arg = next_arg)
17454 dw_loc_descr_ref reg, val;
17455 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
17456 dw_die_ref cdie, tdie = NULL;
17458 next_arg = XEXP (arg, 1);
17459 if (REG_P (XEXP (XEXP (arg, 0), 0))
17461 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
17462 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
17463 && REGNO (XEXP (XEXP (arg, 0), 0))
17464 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
17465 next_arg = XEXP (next_arg, 1);
17466 if (mode == VOIDmode)
17468 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
17469 if (mode == VOIDmode)
17470 mode = GET_MODE (XEXP (arg, 0));
17472 if (mode == VOIDmode || mode == BLKmode)
17474 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
17476 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17477 tloc = XEXP (XEXP (arg, 0), 1);
17480 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
17481 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
17483 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17484 tlocc = XEXP (XEXP (arg, 0), 1);
17488 if (REG_P (XEXP (XEXP (arg, 0), 0)))
17489 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
17490 VAR_INIT_STATUS_INITIALIZED);
17491 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
17493 rtx mem = XEXP (XEXP (arg, 0), 0);
17494 reg = mem_loc_descriptor (XEXP (mem, 0),
17495 get_address_mode (mem),
17497 VAR_INIT_STATUS_INITIALIZED);
17499 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
17500 == DEBUG_PARAMETER_REF)
17503 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
17504 tdie = lookup_decl_die (tdecl);
17511 && GET_CODE (XEXP (XEXP (arg, 0), 0))
17512 != DEBUG_PARAMETER_REF)
17514 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
17516 VAR_INIT_STATUS_INITIALIZED);
17520 die = gen_call_site_die (decl, subr_die, ca_loc);
17521 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
17524 add_AT_loc (cdie, DW_AT_location, reg);
17525 else if (tdie != NULL)
17526 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
17527 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
17528 if (next_arg != XEXP (arg, 1))
17530 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
17531 if (mode == VOIDmode)
17532 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
17533 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
17536 VAR_INIT_STATUS_INITIALIZED);
17538 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
17542 && (ca_loc->symbol_ref || tloc))
17543 die = gen_call_site_die (decl, subr_die, ca_loc);
17544 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
17546 dw_loc_descr_ref tval = NULL;
17548 if (tloc != NULL_RTX)
17549 tval = mem_loc_descriptor (tloc,
17550 GET_MODE (tloc) == VOIDmode
17551 ? Pmode : GET_MODE (tloc),
17553 VAR_INIT_STATUS_INITIALIZED);
17555 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
17556 else if (tlocc != NULL_RTX)
17558 tval = mem_loc_descriptor (tlocc,
17559 GET_MODE (tlocc) == VOIDmode
17560 ? Pmode : GET_MODE (tlocc),
17562 VAR_INIT_STATUS_INITIALIZED);
17564 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
17570 call_site_note_count++;
17571 if (ca_loc->tail_call_p)
17572 tail_call_site_note_count++;
17576 call_arg_locations = NULL;
17577 call_arg_loc_last = NULL;
17578 if (tail_call_site_count >= 0
17579 && tail_call_site_count == tail_call_site_note_count
17582 if (call_site_count >= 0
17583 && call_site_count == call_site_note_count)
17584 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
17586 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
17588 call_site_count = -1;
17589 tail_call_site_count = -1;
17591 /* Add the calling convention attribute if requested. */
17592 add_calling_convention_attribute (subr_die, decl);
17596 /* Returns a hash value for X (which really is a die_struct). */
17599 common_block_die_table_hash (const void *x)
17601 const_dw_die_ref d = (const_dw_die_ref) x;
17602 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
17605 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17606 as decl_id and die_parent of die_struct Y. */
17609 common_block_die_table_eq (const void *x, const void *y)
17611 const_dw_die_ref d = (const_dw_die_ref) x;
17612 const_dw_die_ref e = (const_dw_die_ref) y;
17613 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
17616 /* Generate a DIE to represent a declared data object.
17617 Either DECL or ORIGIN must be non-null. */
17620 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
17624 tree decl_or_origin = decl ? decl : origin;
17625 tree ultimate_origin;
17626 dw_die_ref var_die;
17627 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
17628 dw_die_ref origin_die;
17629 bool declaration = (DECL_EXTERNAL (decl_or_origin)
17630 || class_or_namespace_scope_p (context_die));
17631 bool specialization_p = false;
17633 ultimate_origin = decl_ultimate_origin (decl_or_origin);
17634 if (decl || ultimate_origin)
17635 origin = ultimate_origin;
17636 com_decl = fortran_common (decl_or_origin, &off);
17638 /* Symbol in common gets emitted as a child of the common block, in the form
17639 of a data member. */
17642 dw_die_ref com_die;
17643 dw_loc_list_ref loc;
17644 die_node com_die_arg;
17646 var_die = lookup_decl_die (decl_or_origin);
17649 if (get_AT (var_die, DW_AT_location) == NULL)
17651 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
17656 /* Optimize the common case. */
17657 if (single_element_loc_list_p (loc)
17658 && loc->expr->dw_loc_opc == DW_OP_addr
17659 && loc->expr->dw_loc_next == NULL
17660 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
17662 loc->expr->dw_loc_oprnd1.v.val_addr
17663 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
17665 loc_list_plus_const (loc, off);
17667 add_AT_location_description (var_die, DW_AT_location, loc);
17668 remove_AT (var_die, DW_AT_declaration);
17674 if (common_block_die_table == NULL)
17675 common_block_die_table
17676 = htab_create_ggc (10, common_block_die_table_hash,
17677 common_block_die_table_eq, NULL);
17679 com_die_arg.decl_id = DECL_UID (com_decl);
17680 com_die_arg.die_parent = context_die;
17681 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
17682 loc = loc_list_from_tree (com_decl, 2);
17683 if (com_die == NULL)
17686 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
17689 com_die = new_die (DW_TAG_common_block, context_die, decl);
17690 add_name_and_src_coords_attributes (com_die, com_decl);
17693 add_AT_location_description (com_die, DW_AT_location, loc);
17694 /* Avoid sharing the same loc descriptor between
17695 DW_TAG_common_block and DW_TAG_variable. */
17696 loc = loc_list_from_tree (com_decl, 2);
17698 else if (DECL_EXTERNAL (decl))
17699 add_AT_flag (com_die, DW_AT_declaration, 1);
17700 add_pubname_string (cnam, com_die); /* ??? needed? */
17701 com_die->decl_id = DECL_UID (com_decl);
17702 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
17703 *slot = (void *) com_die;
17705 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
17707 add_AT_location_description (com_die, DW_AT_location, loc);
17708 loc = loc_list_from_tree (com_decl, 2);
17709 remove_AT (com_die, DW_AT_declaration);
17711 var_die = new_die (DW_TAG_variable, com_die, decl);
17712 add_name_and_src_coords_attributes (var_die, decl);
17713 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
17714 TREE_THIS_VOLATILE (decl), context_die);
17715 add_AT_flag (var_die, DW_AT_external, 1);
17720 /* Optimize the common case. */
17721 if (single_element_loc_list_p (loc)
17722 && loc->expr->dw_loc_opc == DW_OP_addr
17723 && loc->expr->dw_loc_next == NULL
17724 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
17725 loc->expr->dw_loc_oprnd1.v.val_addr
17726 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
17728 loc_list_plus_const (loc, off);
17730 add_AT_location_description (var_die, DW_AT_location, loc);
17732 else if (DECL_EXTERNAL (decl))
17733 add_AT_flag (var_die, DW_AT_declaration, 1);
17734 equate_decl_number_to_die (decl, var_die);
17738 /* If the compiler emitted a definition for the DECL declaration
17739 and if we already emitted a DIE for it, don't emit a second
17740 DIE for it again. Allow re-declarations of DECLs that are
17741 inside functions, though. */
17742 if (old_die && declaration && !local_scope_p (context_die))
17745 /* For static data members, the declaration in the class is supposed
17746 to have DW_TAG_member tag; the specification should still be
17747 DW_TAG_variable referencing the DW_TAG_member DIE. */
17748 if (declaration && class_scope_p (context_die))
17749 var_die = new_die (DW_TAG_member, context_die, decl);
17751 var_die = new_die (DW_TAG_variable, context_die, decl);
17754 if (origin != NULL)
17755 origin_die = add_abstract_origin_attribute (var_die, origin);
17757 /* Loop unrolling can create multiple blocks that refer to the same
17758 static variable, so we must test for the DW_AT_declaration flag.
17760 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17761 copy decls and set the DECL_ABSTRACT flag on them instead of
17764 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17766 ??? The declare_in_namespace support causes us to get two DIEs for one
17767 variable, both of which are declarations. We want to avoid considering
17768 one to be a specification, so we must test that this DIE is not a
17770 else if (old_die && TREE_STATIC (decl) && ! declaration
17771 && get_AT_flag (old_die, DW_AT_declaration) == 1)
17773 /* This is a definition of a C++ class level static. */
17774 add_AT_specification (var_die, old_die);
17775 specialization_p = true;
17776 if (DECL_NAME (decl))
17778 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17779 struct dwarf_file_data * file_index = lookup_filename (s.file);
17781 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
17782 add_AT_file (var_die, DW_AT_decl_file, file_index);
17784 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
17785 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
17787 if (old_die->die_tag == DW_TAG_member)
17788 add_linkage_name (var_die, decl);
17792 add_name_and_src_coords_attributes (var_die, decl);
17794 if ((origin == NULL && !specialization_p)
17796 && !DECL_ABSTRACT (decl_or_origin)
17797 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
17798 decl_function_context
17799 (decl_or_origin))))
17801 tree type = TREE_TYPE (decl_or_origin);
17803 if (decl_by_reference_p (decl_or_origin))
17804 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
17806 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
17807 TREE_THIS_VOLATILE (decl_or_origin), context_die);
17810 if (origin == NULL && !specialization_p)
17812 if (TREE_PUBLIC (decl))
17813 add_AT_flag (var_die, DW_AT_external, 1);
17815 if (DECL_ARTIFICIAL (decl))
17816 add_AT_flag (var_die, DW_AT_artificial, 1);
17818 add_accessibility_attribute (var_die, decl);
17822 add_AT_flag (var_die, DW_AT_declaration, 1);
17824 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
17825 equate_decl_number_to_die (decl, var_die);
17828 && (! DECL_ABSTRACT (decl_or_origin)
17829 /* Local static vars are shared between all clones/inlines,
17830 so emit DW_AT_location on the abstract DIE if DECL_RTL is
17832 || (TREE_CODE (decl_or_origin) == VAR_DECL
17833 && TREE_STATIC (decl_or_origin)
17834 && DECL_RTL_SET_P (decl_or_origin)))
17835 /* When abstract origin already has DW_AT_location attribute, no need
17836 to add it again. */
17837 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
17839 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
17840 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
17841 defer_location (decl_or_origin, var_die);
17843 add_location_or_const_value_attribute (var_die, decl_or_origin,
17844 decl == NULL, DW_AT_location);
17845 add_pubname (decl_or_origin, var_die);
17848 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
17851 /* Generate a DIE to represent a named constant. */
17854 gen_const_die (tree decl, dw_die_ref context_die)
17856 dw_die_ref const_die;
17857 tree type = TREE_TYPE (decl);
17859 const_die = new_die (DW_TAG_constant, context_die, decl);
17860 add_name_and_src_coords_attributes (const_die, decl);
17861 add_type_attribute (const_die, type, 1, 0, context_die);
17862 if (TREE_PUBLIC (decl))
17863 add_AT_flag (const_die, DW_AT_external, 1);
17864 if (DECL_ARTIFICIAL (decl))
17865 add_AT_flag (const_die, DW_AT_artificial, 1);
17866 tree_add_const_value_attribute_for_decl (const_die, decl);
17869 /* Generate a DIE to represent a label identifier. */
17872 gen_label_die (tree decl, dw_die_ref context_die)
17874 tree origin = decl_ultimate_origin (decl);
17875 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
17877 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17879 if (origin != NULL)
17880 add_abstract_origin_attribute (lbl_die, origin);
17882 add_name_and_src_coords_attributes (lbl_die, decl);
17884 if (DECL_ABSTRACT (decl))
17885 equate_decl_number_to_die (decl, lbl_die);
17888 insn = DECL_RTL_IF_SET (decl);
17890 /* Deleted labels are programmer specified labels which have been
17891 eliminated because of various optimizations. We still emit them
17892 here so that it is possible to put breakpoints on them. */
17896 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
17898 /* When optimization is enabled (via -O) some parts of the compiler
17899 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
17900 represent source-level labels which were explicitly declared by
17901 the user. This really shouldn't be happening though, so catch
17902 it if it ever does happen. */
17903 gcc_assert (!INSN_DELETED_P (insn));
17905 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
17906 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
17911 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
17912 attributes to the DIE for a block STMT, to describe where the inlined
17913 function was called from. This is similar to add_src_coords_attributes. */
17916 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
17918 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
17920 if (dwarf_version >= 3 || !dwarf_strict)
17922 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
17923 add_AT_unsigned (die, DW_AT_call_line, s.line);
17928 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
17929 Add low_pc and high_pc attributes to the DIE for a block STMT. */
17932 add_high_low_attributes (tree stmt, dw_die_ref die)
17934 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17936 if (BLOCK_FRAGMENT_CHAIN (stmt)
17937 && (dwarf_version >= 3 || !dwarf_strict))
17941 if (inlined_function_outer_scope_p (stmt))
17943 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
17944 BLOCK_NUMBER (stmt));
17945 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17948 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
17950 chain = BLOCK_FRAGMENT_CHAIN (stmt);
17953 add_ranges (chain);
17954 chain = BLOCK_FRAGMENT_CHAIN (chain);
17961 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
17962 BLOCK_NUMBER (stmt));
17963 add_AT_lbl_id (die, DW_AT_low_pc, label);
17964 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
17965 BLOCK_NUMBER (stmt));
17966 add_AT_lbl_id (die, DW_AT_high_pc, label);
17970 /* Generate a DIE for a lexical block. */
17973 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
17975 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
17977 if (call_arg_locations)
17979 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
17980 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
17981 BLOCK_NUMBER (stmt) + 1);
17982 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
17985 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
17986 add_high_low_attributes (stmt, stmt_die);
17988 decls_for_scope (stmt, stmt_die, depth);
17991 /* Generate a DIE for an inlined subprogram. */
17994 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
17998 /* The instance of function that is effectively being inlined shall not
18000 gcc_assert (! BLOCK_ABSTRACT (stmt));
18002 decl = block_ultimate_origin (stmt);
18004 /* Emit info for the abstract instance first, if we haven't yet. We
18005 must emit this even if the block is abstract, otherwise when we
18006 emit the block below (or elsewhere), we may end up trying to emit
18007 a die whose origin die hasn't been emitted, and crashing. */
18008 dwarf2out_abstract_function (decl);
18010 if (! BLOCK_ABSTRACT (stmt))
18012 dw_die_ref subr_die
18013 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
18015 if (call_arg_locations)
18017 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
18018 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
18019 BLOCK_NUMBER (stmt) + 1);
18020 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
18022 add_abstract_origin_attribute (subr_die, decl);
18023 if (TREE_ASM_WRITTEN (stmt))
18024 add_high_low_attributes (stmt, subr_die);
18025 add_call_src_coords_attributes (stmt, subr_die);
18027 decls_for_scope (stmt, subr_die, depth);
18028 current_function_has_inlines = 1;
18032 /* Generate a DIE for a field in a record, or structure. */
18035 gen_field_die (tree decl, dw_die_ref context_die)
18037 dw_die_ref decl_die;
18039 if (TREE_TYPE (decl) == error_mark_node)
18042 decl_die = new_die (DW_TAG_member, context_die, decl);
18043 add_name_and_src_coords_attributes (decl_die, decl);
18044 add_type_attribute (decl_die, member_declared_type (decl),
18045 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
18048 if (DECL_BIT_FIELD_TYPE (decl))
18050 add_byte_size_attribute (decl_die, decl);
18051 add_bit_size_attribute (decl_die, decl);
18052 add_bit_offset_attribute (decl_die, decl);
18055 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
18056 add_data_member_location_attribute (decl_die, decl);
18058 if (DECL_ARTIFICIAL (decl))
18059 add_AT_flag (decl_die, DW_AT_artificial, 1);
18061 add_accessibility_attribute (decl_die, decl);
18063 /* Equate decl number to die, so that we can look up this decl later on. */
18064 equate_decl_number_to_die (decl, decl_die);
18068 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18069 Use modified_type_die instead.
18070 We keep this code here just in case these types of DIEs may be needed to
18071 represent certain things in other languages (e.g. Pascal) someday. */
18074 gen_pointer_type_die (tree type, dw_die_ref context_die)
18077 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
18079 equate_type_number_to_die (type, ptr_die);
18080 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18081 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18084 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18085 Use modified_type_die instead.
18086 We keep this code here just in case these types of DIEs may be needed to
18087 represent certain things in other languages (e.g. Pascal) someday. */
18090 gen_reference_type_die (tree type, dw_die_ref context_die)
18092 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
18094 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
18095 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
18097 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
18099 equate_type_number_to_die (type, ref_die);
18100 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
18101 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18105 /* Generate a DIE for a pointer to a member type. */
18108 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
18111 = new_die (DW_TAG_ptr_to_member_type,
18112 scope_die_for (type, context_die), type);
18114 equate_type_number_to_die (type, ptr_die);
18115 add_AT_die_ref (ptr_die, DW_AT_containing_type,
18116 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
18117 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18120 typedef const char *dchar_p; /* For DEF_VEC_P. */
18121 DEF_VEC_P(dchar_p);
18122 DEF_VEC_ALLOC_P(dchar_p,heap);
18124 static char *producer_string;
18126 /* Return a heap allocated producer string including command line options
18127 if -grecord-gcc-switches. */
18130 gen_producer_string (void)
18133 VEC(dchar_p, heap) *switches = NULL;
18134 const char *language_string = lang_hooks.name;
18135 char *producer, *tail;
18137 size_t len = dwarf_record_gcc_switches ? 0 : 3;
18138 size_t plen = strlen (language_string) + 1 + strlen (version_string);
18140 for (j = 1; dwarf_record_gcc_switches && j < save_decoded_options_count; j++)
18141 switch (save_decoded_options[j].opt_index)
18148 case OPT_auxbase_strip:
18157 case OPT_SPECIAL_unknown:
18158 case OPT_SPECIAL_ignore:
18159 case OPT_SPECIAL_program_name:
18160 case OPT_SPECIAL_input_file:
18161 case OPT_grecord_gcc_switches:
18162 case OPT_gno_record_gcc_switches:
18163 case OPT__output_pch_:
18164 case OPT_fdiagnostics_show_location_:
18165 case OPT_fdiagnostics_show_option:
18167 case OPT__sysroot_:
18169 case OPT_nostdinc__:
18170 /* Ignore these. */
18173 gcc_checking_assert (save_decoded_options[j].canonical_option[0][0]
18175 switch (save_decoded_options[j].canonical_option[0][1])
18182 if (strncmp (save_decoded_options[j].canonical_option[0] + 2,
18189 VEC_safe_push (dchar_p, heap, switches,
18190 save_decoded_options[j].orig_option_with_args_text);
18191 len += strlen (save_decoded_options[j].orig_option_with_args_text) + 1;
18195 producer = XNEWVEC (char, plen + 1 + len + 1);
18197 sprintf (tail, "%s %s", language_string, version_string);
18200 if (!dwarf_record_gcc_switches)
18202 #ifdef MIPS_DEBUGGING_INFO
18203 /* The MIPS/SGI compilers place the 'cc' command line options in the
18204 producer string. The SGI debugger looks for -g, -g1, -g2, or -g3;
18205 if they do not appear in the producer string, the debugger reaches
18206 the conclusion that the object file is stripped and has no debugging
18207 information. To get the MIPS/SGI debugger to believe that there is
18208 debugging information in the object file, we add a -g to the producer
18210 if (debug_info_level > DINFO_LEVEL_TERSE)
18212 memcpy (tail, " -g", 3);
18218 FOR_EACH_VEC_ELT (dchar_p, switches, j, p)
18222 memcpy (tail + 1, p, len);
18227 VEC_free (dchar_p, heap, switches);
18231 /* Generate the DIE for the compilation unit. */
18234 gen_compile_unit_die (const char *filename)
18237 const char *language_string = lang_hooks.name;
18240 die = new_die (DW_TAG_compile_unit, NULL, NULL);
18244 add_name_attribute (die, filename);
18245 /* Don't add cwd for <built-in>. */
18246 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
18247 add_comp_dir_attribute (die);
18250 if (producer_string == NULL)
18251 producer_string = gen_producer_string ();
18252 add_AT_string (die, DW_AT_producer, producer_string);
18254 /* If our producer is LTO try to figure out a common language to use
18255 from the global list of translation units. */
18256 if (strcmp (language_string, "GNU GIMPLE") == 0)
18260 const char *common_lang = NULL;
18262 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
18264 if (!TRANSLATION_UNIT_LANGUAGE (t))
18267 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
18268 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
18270 else if (strncmp (common_lang, "GNU C", 5) == 0
18271 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
18272 /* Mixing C and C++ is ok, use C++ in that case. */
18273 common_lang = "GNU C++";
18276 /* Fall back to C. */
18277 common_lang = NULL;
18283 language_string = common_lang;
18286 language = DW_LANG_C89;
18287 if (strcmp (language_string, "GNU C++") == 0)
18288 language = DW_LANG_C_plus_plus;
18289 else if (strcmp (language_string, "GNU F77") == 0)
18290 language = DW_LANG_Fortran77;
18291 else if (strcmp (language_string, "GNU Pascal") == 0)
18292 language = DW_LANG_Pascal83;
18293 else if (dwarf_version >= 3 || !dwarf_strict)
18295 if (strcmp (language_string, "GNU Ada") == 0)
18296 language = DW_LANG_Ada95;
18297 else if (strcmp (language_string, "GNU Fortran") == 0)
18298 language = DW_LANG_Fortran95;
18299 else if (strcmp (language_string, "GNU Java") == 0)
18300 language = DW_LANG_Java;
18301 else if (strcmp (language_string, "GNU Objective-C") == 0)
18302 language = DW_LANG_ObjC;
18303 else if (strcmp (language_string, "GNU Objective-C++") == 0)
18304 language = DW_LANG_ObjC_plus_plus;
18307 add_AT_unsigned (die, DW_AT_language, language);
18311 case DW_LANG_Fortran77:
18312 case DW_LANG_Fortran90:
18313 case DW_LANG_Fortran95:
18314 /* Fortran has case insensitive identifiers and the front-end
18315 lowercases everything. */
18316 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
18319 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18325 /* Generate the DIE for a base class. */
18328 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
18330 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
18332 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
18333 add_data_member_location_attribute (die, binfo);
18335 if (BINFO_VIRTUAL_P (binfo))
18336 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18338 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18339 children, otherwise the default is DW_ACCESS_public. In DWARF2
18340 the default has always been DW_ACCESS_private. */
18341 if (access == access_public_node)
18343 if (dwarf_version == 2
18344 || context_die->die_tag == DW_TAG_class_type)
18345 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
18347 else if (access == access_protected_node)
18348 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
18349 else if (dwarf_version > 2
18350 && context_die->die_tag != DW_TAG_class_type)
18351 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
18354 /* Generate a DIE for a class member. */
18357 gen_member_die (tree type, dw_die_ref context_die)
18360 tree binfo = TYPE_BINFO (type);
18363 /* If this is not an incomplete type, output descriptions of each of its
18364 members. Note that as we output the DIEs necessary to represent the
18365 members of this record or union type, we will also be trying to output
18366 DIEs to represent the *types* of those members. However the `type'
18367 function (above) will specifically avoid generating type DIEs for member
18368 types *within* the list of member DIEs for this (containing) type except
18369 for those types (of members) which are explicitly marked as also being
18370 members of this (containing) type themselves. The g++ front- end can
18371 force any given type to be treated as a member of some other (containing)
18372 type by setting the TYPE_CONTEXT of the given (member) type to point to
18373 the TREE node representing the appropriate (containing) type. */
18375 /* First output info about the base classes. */
18378 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
18382 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
18383 gen_inheritance_die (base,
18384 (accesses ? VEC_index (tree, accesses, i)
18385 : access_public_node), context_die);
18388 /* Now output info about the data members and type members. */
18389 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
18391 /* If we thought we were generating minimal debug info for TYPE
18392 and then changed our minds, some of the member declarations
18393 may have already been defined. Don't define them again, but
18394 do put them in the right order. */
18396 child = lookup_decl_die (member);
18398 splice_child_die (context_die, child);
18400 gen_decl_die (member, NULL, context_die);
18403 /* Now output info about the function members (if any). */
18404 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
18406 /* Don't include clones in the member list. */
18407 if (DECL_ABSTRACT_ORIGIN (member))
18410 child = lookup_decl_die (member);
18412 splice_child_die (context_die, child);
18414 gen_decl_die (member, NULL, context_die);
18418 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18419 is set, we pretend that the type was never defined, so we only get the
18420 member DIEs needed by later specification DIEs. */
18423 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
18424 enum debug_info_usage usage)
18426 dw_die_ref type_die = lookup_type_die (type);
18427 dw_die_ref scope_die = 0;
18429 int complete = (TYPE_SIZE (type)
18430 && (! TYPE_STUB_DECL (type)
18431 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
18432 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
18433 complete = complete && should_emit_struct_debug (type, usage);
18435 if (type_die && ! complete)
18438 if (TYPE_CONTEXT (type) != NULL_TREE
18439 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18440 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
18443 scope_die = scope_die_for (type, context_die);
18445 if (! type_die || (nested && is_cu_die (scope_die)))
18446 /* First occurrence of type or toplevel definition of nested class. */
18448 dw_die_ref old_die = type_die;
18450 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
18451 ? record_type_tag (type) : DW_TAG_union_type,
18453 equate_type_number_to_die (type, type_die);
18455 add_AT_specification (type_die, old_die);
18458 add_name_attribute (type_die, type_tag (type));
18459 add_gnat_descriptive_type_attribute (type_die, type, context_die);
18460 if (TYPE_ARTIFICIAL (type))
18461 add_AT_flag (type_die, DW_AT_artificial, 1);
18465 remove_AT (type_die, DW_AT_declaration);
18467 /* Generate child dies for template paramaters. */
18468 if (debug_info_level > DINFO_LEVEL_TERSE
18469 && COMPLETE_TYPE_P (type))
18470 schedule_generic_params_dies_gen (type);
18472 /* If this type has been completed, then give it a byte_size attribute and
18473 then give a list of members. */
18474 if (complete && !ns_decl)
18476 /* Prevent infinite recursion in cases where the type of some member of
18477 this type is expressed in terms of this type itself. */
18478 TREE_ASM_WRITTEN (type) = 1;
18479 add_byte_size_attribute (type_die, type);
18480 if (TYPE_STUB_DECL (type) != NULL_TREE)
18482 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18483 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18486 /* If the first reference to this type was as the return type of an
18487 inline function, then it may not have a parent. Fix this now. */
18488 if (type_die->die_parent == NULL)
18489 add_child_die (scope_die, type_die);
18491 push_decl_scope (type);
18492 gen_member_die (type, type_die);
18495 /* GNU extension: Record what type our vtable lives in. */
18496 if (TYPE_VFIELD (type))
18498 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
18500 gen_type_die (vtype, context_die);
18501 add_AT_die_ref (type_die, DW_AT_containing_type,
18502 lookup_type_die (vtype));
18507 add_AT_flag (type_die, DW_AT_declaration, 1);
18509 /* We don't need to do this for function-local types. */
18510 if (TYPE_STUB_DECL (type)
18511 && ! decl_function_context (TYPE_STUB_DECL (type)))
18512 VEC_safe_push (tree, gc, incomplete_types, type);
18515 if (get_AT (type_die, DW_AT_name))
18516 add_pubtype (type, type_die);
18519 /* Generate a DIE for a subroutine _type_. */
18522 gen_subroutine_type_die (tree type, dw_die_ref context_die)
18524 tree return_type = TREE_TYPE (type);
18525 dw_die_ref subr_die
18526 = new_die (DW_TAG_subroutine_type,
18527 scope_die_for (type, context_die), type);
18529 equate_type_number_to_die (type, subr_die);
18530 add_prototyped_attribute (subr_die, type);
18531 add_type_attribute (subr_die, return_type, 0, 0, context_die);
18532 gen_formal_types_die (type, subr_die);
18534 if (get_AT (subr_die, DW_AT_name))
18535 add_pubtype (type, subr_die);
18538 /* Generate a DIE for a type definition. */
18541 gen_typedef_die (tree decl, dw_die_ref context_die)
18543 dw_die_ref type_die;
18546 if (TREE_ASM_WRITTEN (decl))
18549 TREE_ASM_WRITTEN (decl) = 1;
18550 type_die = new_die (DW_TAG_typedef, context_die, decl);
18551 origin = decl_ultimate_origin (decl);
18552 if (origin != NULL)
18553 add_abstract_origin_attribute (type_die, origin);
18558 add_name_and_src_coords_attributes (type_die, decl);
18559 if (DECL_ORIGINAL_TYPE (decl))
18561 type = DECL_ORIGINAL_TYPE (decl);
18563 gcc_assert (type != TREE_TYPE (decl));
18564 equate_type_number_to_die (TREE_TYPE (decl), type_die);
18568 type = TREE_TYPE (decl);
18570 if (is_naming_typedef_decl (TYPE_NAME (type)))
18572 /* Here, we are in the case of decl being a typedef naming
18573 an anonymous type, e.g:
18574 typedef struct {...} foo;
18575 In that case TREE_TYPE (decl) is not a typedef variant
18576 type and TYPE_NAME of the anonymous type is set to the
18577 TYPE_DECL of the typedef. This construct is emitted by
18580 TYPE is the anonymous struct named by the typedef
18581 DECL. As we need the DW_AT_type attribute of the
18582 DW_TAG_typedef to point to the DIE of TYPE, let's
18583 generate that DIE right away. add_type_attribute
18584 called below will then pick (via lookup_type_die) that
18585 anonymous struct DIE. */
18586 if (!TREE_ASM_WRITTEN (type))
18587 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
18589 /* This is a GNU Extension. We are adding a
18590 DW_AT_linkage_name attribute to the DIE of the
18591 anonymous struct TYPE. The value of that attribute
18592 is the name of the typedef decl naming the anonymous
18593 struct. This greatly eases the work of consumers of
18594 this debug info. */
18595 add_linkage_attr (lookup_type_die (type), decl);
18599 add_type_attribute (type_die, type, TREE_READONLY (decl),
18600 TREE_THIS_VOLATILE (decl), context_die);
18602 if (is_naming_typedef_decl (decl))
18603 /* We want that all subsequent calls to lookup_type_die with
18604 TYPE in argument yield the DW_TAG_typedef we have just
18606 equate_type_number_to_die (type, type_die);
18608 add_accessibility_attribute (type_die, decl);
18611 if (DECL_ABSTRACT (decl))
18612 equate_decl_number_to_die (decl, type_die);
18614 if (get_AT (type_die, DW_AT_name))
18615 add_pubtype (decl, type_die);
18618 /* Generate a DIE for a struct, class, enum or union type. */
18621 gen_tagged_type_die (tree type,
18622 dw_die_ref context_die,
18623 enum debug_info_usage usage)
18627 if (type == NULL_TREE
18628 || !is_tagged_type (type))
18631 /* If this is a nested type whose containing class hasn't been written
18632 out yet, writing it out will cover this one, too. This does not apply
18633 to instantiations of member class templates; they need to be added to
18634 the containing class as they are generated. FIXME: This hurts the
18635 idea of combining type decls from multiple TUs, since we can't predict
18636 what set of template instantiations we'll get. */
18637 if (TYPE_CONTEXT (type)
18638 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18639 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
18641 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
18643 if (TREE_ASM_WRITTEN (type))
18646 /* If that failed, attach ourselves to the stub. */
18647 push_decl_scope (TYPE_CONTEXT (type));
18648 context_die = lookup_type_die (TYPE_CONTEXT (type));
18651 else if (TYPE_CONTEXT (type) != NULL_TREE
18652 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
18654 /* If this type is local to a function that hasn't been written
18655 out yet, use a NULL context for now; it will be fixed up in
18656 decls_for_scope. */
18657 context_die = lookup_decl_die (TYPE_CONTEXT (type));
18658 /* A declaration DIE doesn't count; nested types need to go in the
18660 if (context_die && is_declaration_die (context_die))
18661 context_die = NULL;
18666 context_die = declare_in_namespace (type, context_die);
18670 if (TREE_CODE (type) == ENUMERAL_TYPE)
18672 /* This might have been written out by the call to
18673 declare_in_namespace. */
18674 if (!TREE_ASM_WRITTEN (type))
18675 gen_enumeration_type_die (type, context_die);
18678 gen_struct_or_union_type_die (type, context_die, usage);
18683 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18684 it up if it is ever completed. gen_*_type_die will set it for us
18685 when appropriate. */
18688 /* Generate a type description DIE. */
18691 gen_type_die_with_usage (tree type, dw_die_ref context_die,
18692 enum debug_info_usage usage)
18694 struct array_descr_info info;
18696 if (type == NULL_TREE || type == error_mark_node)
18699 if (TYPE_NAME (type) != NULL_TREE
18700 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18701 && is_redundant_typedef (TYPE_NAME (type))
18702 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
18703 /* The DECL of this type is a typedef we don't want to emit debug
18704 info for but we want debug info for its underlying typedef.
18705 This can happen for e.g, the injected-class-name of a C++
18707 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
18709 /* If TYPE is a typedef type variant, let's generate debug info
18710 for the parent typedef which TYPE is a type of. */
18711 if (typedef_variant_p (type))
18713 if (TREE_ASM_WRITTEN (type))
18716 /* Prevent broken recursion; we can't hand off to the same type. */
18717 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
18719 /* Use the DIE of the containing namespace as the parent DIE of
18720 the type description DIE we want to generate. */
18721 if (DECL_CONTEXT (TYPE_NAME (type))
18722 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
18723 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
18725 TREE_ASM_WRITTEN (type) = 1;
18727 gen_decl_die (TYPE_NAME (type), NULL, context_die);
18731 /* If type is an anonymous tagged type named by a typedef, let's
18732 generate debug info for the typedef. */
18733 if (is_naming_typedef_decl (TYPE_NAME (type)))
18735 /* Use the DIE of the containing namespace as the parent DIE of
18736 the type description DIE we want to generate. */
18737 if (DECL_CONTEXT (TYPE_NAME (type))
18738 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
18739 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
18741 gen_decl_die (TYPE_NAME (type), NULL, context_die);
18745 /* If this is an array type with hidden descriptor, handle it first. */
18746 if (!TREE_ASM_WRITTEN (type)
18747 && lang_hooks.types.get_array_descr_info
18748 && lang_hooks.types.get_array_descr_info (type, &info)
18749 && (dwarf_version >= 3 || !dwarf_strict))
18751 gen_descr_array_type_die (type, &info, context_die);
18752 TREE_ASM_WRITTEN (type) = 1;
18756 /* We are going to output a DIE to represent the unqualified version
18757 of this type (i.e. without any const or volatile qualifiers) so
18758 get the main variant (i.e. the unqualified version) of this type
18759 now. (Vectors are special because the debugging info is in the
18760 cloned type itself). */
18761 if (TREE_CODE (type) != VECTOR_TYPE)
18762 type = type_main_variant (type);
18764 if (TREE_ASM_WRITTEN (type))
18767 switch (TREE_CODE (type))
18773 case REFERENCE_TYPE:
18774 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
18775 ensures that the gen_type_die recursion will terminate even if the
18776 type is recursive. Recursive types are possible in Ada. */
18777 /* ??? We could perhaps do this for all types before the switch
18779 TREE_ASM_WRITTEN (type) = 1;
18781 /* For these types, all that is required is that we output a DIE (or a
18782 set of DIEs) to represent the "basis" type. */
18783 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18784 DINFO_USAGE_IND_USE);
18788 /* This code is used for C++ pointer-to-data-member types.
18789 Output a description of the relevant class type. */
18790 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
18791 DINFO_USAGE_IND_USE);
18793 /* Output a description of the type of the object pointed to. */
18794 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18795 DINFO_USAGE_IND_USE);
18797 /* Now output a DIE to represent this pointer-to-data-member type
18799 gen_ptr_to_mbr_type_die (type, context_die);
18802 case FUNCTION_TYPE:
18803 /* Force out return type (in case it wasn't forced out already). */
18804 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18805 DINFO_USAGE_DIR_USE);
18806 gen_subroutine_type_die (type, context_die);
18810 /* Force out return type (in case it wasn't forced out already). */
18811 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18812 DINFO_USAGE_DIR_USE);
18813 gen_subroutine_type_die (type, context_die);
18817 gen_array_type_die (type, context_die);
18821 gen_array_type_die (type, context_die);
18824 case ENUMERAL_TYPE:
18827 case QUAL_UNION_TYPE:
18828 gen_tagged_type_die (type, context_die, usage);
18834 case FIXED_POINT_TYPE:
18837 /* No DIEs needed for fundamental types. */
18842 /* Just use DW_TAG_unspecified_type. */
18844 dw_die_ref type_die = lookup_type_die (type);
18845 if (type_die == NULL)
18847 tree name = TYPE_NAME (type);
18848 if (TREE_CODE (name) == TYPE_DECL)
18849 name = DECL_NAME (name);
18850 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
18851 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
18852 equate_type_number_to_die (type, type_die);
18858 gcc_unreachable ();
18861 TREE_ASM_WRITTEN (type) = 1;
18865 gen_type_die (tree type, dw_die_ref context_die)
18867 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
18870 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
18871 things which are local to the given block. */
18874 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
18876 int must_output_die = 0;
18879 /* Ignore blocks that are NULL. */
18880 if (stmt == NULL_TREE)
18883 inlined_func = inlined_function_outer_scope_p (stmt);
18885 /* If the block is one fragment of a non-contiguous block, do not
18886 process the variables, since they will have been done by the
18887 origin block. Do process subblocks. */
18888 if (BLOCK_FRAGMENT_ORIGIN (stmt))
18892 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
18893 gen_block_die (sub, context_die, depth + 1);
18898 /* Determine if we need to output any Dwarf DIEs at all to represent this
18901 /* The outer scopes for inlinings *must* always be represented. We
18902 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
18903 must_output_die = 1;
18906 /* Determine if this block directly contains any "significant"
18907 local declarations which we will need to output DIEs for. */
18908 if (debug_info_level > DINFO_LEVEL_TERSE)
18909 /* We are not in terse mode so *any* local declaration counts
18910 as being a "significant" one. */
18911 must_output_die = ((BLOCK_VARS (stmt) != NULL
18912 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
18913 && (TREE_USED (stmt)
18914 || TREE_ASM_WRITTEN (stmt)
18915 || BLOCK_ABSTRACT (stmt)));
18916 else if ((TREE_USED (stmt)
18917 || TREE_ASM_WRITTEN (stmt)
18918 || BLOCK_ABSTRACT (stmt))
18919 && !dwarf2out_ignore_block (stmt))
18920 must_output_die = 1;
18923 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
18924 DIE for any block which contains no significant local declarations at
18925 all. Rather, in such cases we just call `decls_for_scope' so that any
18926 needed Dwarf info for any sub-blocks will get properly generated. Note
18927 that in terse mode, our definition of what constitutes a "significant"
18928 local declaration gets restricted to include only inlined function
18929 instances and local (nested) function definitions. */
18930 if (must_output_die)
18934 /* If STMT block is abstract, that means we have been called
18935 indirectly from dwarf2out_abstract_function.
18936 That function rightfully marks the descendent blocks (of
18937 the abstract function it is dealing with) as being abstract,
18938 precisely to prevent us from emitting any
18939 DW_TAG_inlined_subroutine DIE as a descendent
18940 of an abstract function instance. So in that case, we should
18941 not call gen_inlined_subroutine_die.
18943 Later though, when cgraph asks dwarf2out to emit info
18944 for the concrete instance of the function decl into which
18945 the concrete instance of STMT got inlined, the later will lead
18946 to the generation of a DW_TAG_inlined_subroutine DIE. */
18947 if (! BLOCK_ABSTRACT (stmt))
18948 gen_inlined_subroutine_die (stmt, context_die, depth);
18951 gen_lexical_block_die (stmt, context_die, depth);
18954 decls_for_scope (stmt, context_die, depth);
18957 /* Process variable DECL (or variable with origin ORIGIN) within
18958 block STMT and add it to CONTEXT_DIE. */
18960 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
18963 tree decl_or_origin = decl ? decl : origin;
18965 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
18966 die = lookup_decl_die (decl_or_origin);
18967 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
18968 && TYPE_DECL_IS_STUB (decl_or_origin))
18969 die = lookup_type_die (TREE_TYPE (decl_or_origin));
18973 if (die != NULL && die->die_parent == NULL)
18974 add_child_die (context_die, die);
18975 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
18976 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
18977 stmt, context_die);
18979 gen_decl_die (decl, origin, context_die);
18982 /* Generate all of the decls declared within a given scope and (recursively)
18983 all of its sub-blocks. */
18986 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
18992 /* Ignore NULL blocks. */
18993 if (stmt == NULL_TREE)
18996 /* Output the DIEs to represent all of the data objects and typedefs
18997 declared directly within this block but not within any nested
18998 sub-blocks. Also, nested function and tag DIEs have been
18999 generated with a parent of NULL; fix that up now. */
19000 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
19001 process_scope_var (stmt, decl, NULL_TREE, context_die);
19002 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
19003 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
19006 /* If we're at -g1, we're not interested in subblocks. */
19007 if (debug_info_level <= DINFO_LEVEL_TERSE)
19010 /* Output the DIEs to represent all sub-blocks (and the items declared
19011 therein) of this block. */
19012 for (subblocks = BLOCK_SUBBLOCKS (stmt);
19014 subblocks = BLOCK_CHAIN (subblocks))
19015 gen_block_die (subblocks, context_die, depth + 1);
19018 /* Is this a typedef we can avoid emitting? */
19021 is_redundant_typedef (const_tree decl)
19023 if (TYPE_DECL_IS_STUB (decl))
19026 if (DECL_ARTIFICIAL (decl)
19027 && DECL_CONTEXT (decl)
19028 && is_tagged_type (DECL_CONTEXT (decl))
19029 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
19030 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
19031 /* Also ignore the artificial member typedef for the class name. */
19037 /* Return TRUE if TYPE is a typedef that names a type for linkage
19038 purposes. This kind of typedefs is produced by the C++ FE for
19041 typedef struct {...} foo;
19043 In that case, there is no typedef variant type produced for foo.
19044 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19048 is_naming_typedef_decl (const_tree decl)
19050 if (decl == NULL_TREE
19051 || TREE_CODE (decl) != TYPE_DECL
19052 || !is_tagged_type (TREE_TYPE (decl))
19053 || DECL_IS_BUILTIN (decl)
19054 || is_redundant_typedef (decl)
19055 /* It looks like Ada produces TYPE_DECLs that are very similar
19056 to C++ naming typedefs but that have different
19057 semantics. Let's be specific to c++ for now. */
19061 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
19062 && TYPE_NAME (TREE_TYPE (decl)) == decl
19063 && (TYPE_STUB_DECL (TREE_TYPE (decl))
19064 != TYPE_NAME (TREE_TYPE (decl))));
19067 /* Returns the DIE for a context. */
19069 static inline dw_die_ref
19070 get_context_die (tree context)
19074 /* Find die that represents this context. */
19075 if (TYPE_P (context))
19077 context = TYPE_MAIN_VARIANT (context);
19078 return strip_naming_typedef (context, force_type_die (context));
19081 return force_decl_die (context);
19083 return comp_unit_die ();
19086 /* Returns the DIE for decl. A DIE will always be returned. */
19089 force_decl_die (tree decl)
19091 dw_die_ref decl_die;
19092 unsigned saved_external_flag;
19093 tree save_fn = NULL_TREE;
19094 decl_die = lookup_decl_die (decl);
19097 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
19099 decl_die = lookup_decl_die (decl);
19103 switch (TREE_CODE (decl))
19105 case FUNCTION_DECL:
19106 /* Clear current_function_decl, so that gen_subprogram_die thinks
19107 that this is a declaration. At this point, we just want to force
19108 declaration die. */
19109 save_fn = current_function_decl;
19110 current_function_decl = NULL_TREE;
19111 gen_subprogram_die (decl, context_die);
19112 current_function_decl = save_fn;
19116 /* Set external flag to force declaration die. Restore it after
19117 gen_decl_die() call. */
19118 saved_external_flag = DECL_EXTERNAL (decl);
19119 DECL_EXTERNAL (decl) = 1;
19120 gen_decl_die (decl, NULL, context_die);
19121 DECL_EXTERNAL (decl) = saved_external_flag;
19124 case NAMESPACE_DECL:
19125 if (dwarf_version >= 3 || !dwarf_strict)
19126 dwarf2out_decl (decl);
19128 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19129 decl_die = comp_unit_die ();
19132 case TRANSLATION_UNIT_DECL:
19133 decl_die = comp_unit_die ();
19137 gcc_unreachable ();
19140 /* We should be able to find the DIE now. */
19142 decl_die = lookup_decl_die (decl);
19143 gcc_assert (decl_die);
19149 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19150 always returned. */
19153 force_type_die (tree type)
19155 dw_die_ref type_die;
19157 type_die = lookup_type_die (type);
19160 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
19162 type_die = modified_type_die (type, TYPE_READONLY (type),
19163 TYPE_VOLATILE (type), context_die);
19164 gcc_assert (type_die);
19169 /* Force out any required namespaces to be able to output DECL,
19170 and return the new context_die for it, if it's changed. */
19173 setup_namespace_context (tree thing, dw_die_ref context_die)
19175 tree context = (DECL_P (thing)
19176 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
19177 if (context && TREE_CODE (context) == NAMESPACE_DECL)
19178 /* Force out the namespace. */
19179 context_die = force_decl_die (context);
19181 return context_die;
19184 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19185 type) within its namespace, if appropriate.
19187 For compatibility with older debuggers, namespace DIEs only contain
19188 declarations; all definitions are emitted at CU scope. */
19191 declare_in_namespace (tree thing, dw_die_ref context_die)
19193 dw_die_ref ns_context;
19195 if (debug_info_level <= DINFO_LEVEL_TERSE)
19196 return context_die;
19198 /* If this decl is from an inlined function, then don't try to emit it in its
19199 namespace, as we will get confused. It would have already been emitted
19200 when the abstract instance of the inline function was emitted anyways. */
19201 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
19202 return context_die;
19204 ns_context = setup_namespace_context (thing, context_die);
19206 if (ns_context != context_die)
19210 if (DECL_P (thing))
19211 gen_decl_die (thing, NULL, ns_context);
19213 gen_type_die (thing, ns_context);
19215 return context_die;
19218 /* Generate a DIE for a namespace or namespace alias. */
19221 gen_namespace_die (tree decl, dw_die_ref context_die)
19223 dw_die_ref namespace_die;
19225 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19226 they are an alias of. */
19227 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
19229 /* Output a real namespace or module. */
19230 context_die = setup_namespace_context (decl, comp_unit_die ());
19231 namespace_die = new_die (is_fortran ()
19232 ? DW_TAG_module : DW_TAG_namespace,
19233 context_die, decl);
19234 /* For Fortran modules defined in different CU don't add src coords. */
19235 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
19237 const char *name = dwarf2_name (decl, 0);
19239 add_name_attribute (namespace_die, name);
19242 add_name_and_src_coords_attributes (namespace_die, decl);
19243 if (DECL_EXTERNAL (decl))
19244 add_AT_flag (namespace_die, DW_AT_declaration, 1);
19245 equate_decl_number_to_die (decl, namespace_die);
19249 /* Output a namespace alias. */
19251 /* Force out the namespace we are an alias of, if necessary. */
19252 dw_die_ref origin_die
19253 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
19255 if (DECL_FILE_SCOPE_P (decl)
19256 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
19257 context_die = setup_namespace_context (decl, comp_unit_die ());
19258 /* Now create the namespace alias DIE. */
19259 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
19260 add_name_and_src_coords_attributes (namespace_die, decl);
19261 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
19262 equate_decl_number_to_die (decl, namespace_die);
19266 /* Generate Dwarf debug information for a decl described by DECL.
19267 The return value is currently only meaningful for PARM_DECLs,
19268 for all other decls it returns NULL. */
19271 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
19273 tree decl_or_origin = decl ? decl : origin;
19274 tree class_origin = NULL, ultimate_origin;
19276 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
19279 switch (TREE_CODE (decl_or_origin))
19285 if (!is_fortran () && !is_ada ())
19287 /* The individual enumerators of an enum type get output when we output
19288 the Dwarf representation of the relevant enum type itself. */
19292 /* Emit its type. */
19293 gen_type_die (TREE_TYPE (decl), context_die);
19295 /* And its containing namespace. */
19296 context_die = declare_in_namespace (decl, context_die);
19298 gen_const_die (decl, context_die);
19301 case FUNCTION_DECL:
19302 /* Don't output any DIEs to represent mere function declarations,
19303 unless they are class members or explicit block externs. */
19304 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
19305 && DECL_FILE_SCOPE_P (decl_or_origin)
19306 && (current_function_decl == NULL_TREE
19307 || DECL_ARTIFICIAL (decl_or_origin)))
19312 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19313 on local redeclarations of global functions. That seems broken. */
19314 if (current_function_decl != decl)
19315 /* This is only a declaration. */;
19318 /* If we're emitting a clone, emit info for the abstract instance. */
19319 if (origin || DECL_ORIGIN (decl) != decl)
19320 dwarf2out_abstract_function (origin
19321 ? DECL_ORIGIN (origin)
19322 : DECL_ABSTRACT_ORIGIN (decl));
19324 /* If we're emitting an out-of-line copy of an inline function,
19325 emit info for the abstract instance and set up to refer to it. */
19326 else if (cgraph_function_possibly_inlined_p (decl)
19327 && ! DECL_ABSTRACT (decl)
19328 && ! class_or_namespace_scope_p (context_die)
19329 /* dwarf2out_abstract_function won't emit a die if this is just
19330 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19331 that case, because that works only if we have a die. */
19332 && DECL_INITIAL (decl) != NULL_TREE)
19334 dwarf2out_abstract_function (decl);
19335 set_decl_origin_self (decl);
19338 /* Otherwise we're emitting the primary DIE for this decl. */
19339 else if (debug_info_level > DINFO_LEVEL_TERSE)
19341 /* Before we describe the FUNCTION_DECL itself, make sure that we
19342 have its containing type. */
19344 origin = decl_class_context (decl);
19345 if (origin != NULL_TREE)
19346 gen_type_die (origin, context_die);
19348 /* And its return type. */
19349 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
19351 /* And its virtual context. */
19352 if (DECL_VINDEX (decl) != NULL_TREE)
19353 gen_type_die (DECL_CONTEXT (decl), context_die);
19355 /* Make sure we have a member DIE for decl. */
19356 if (origin != NULL_TREE)
19357 gen_type_die_for_member (origin, decl, context_die);
19359 /* And its containing namespace. */
19360 context_die = declare_in_namespace (decl, context_die);
19363 /* Now output a DIE to represent the function itself. */
19365 gen_subprogram_die (decl, context_die);
19369 /* If we are in terse mode, don't generate any DIEs to represent any
19370 actual typedefs. */
19371 if (debug_info_level <= DINFO_LEVEL_TERSE)
19374 /* In the special case of a TYPE_DECL node representing the declaration
19375 of some type tag, if the given TYPE_DECL is marked as having been
19376 instantiated from some other (original) TYPE_DECL node (e.g. one which
19377 was generated within the original definition of an inline function) we
19378 used to generate a special (abbreviated) DW_TAG_structure_type,
19379 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19380 should be actually referencing those DIEs, as variable DIEs with that
19381 type would be emitted already in the abstract origin, so it was always
19382 removed during unused type prunning. Don't add anything in this
19384 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
19387 if (is_redundant_typedef (decl))
19388 gen_type_die (TREE_TYPE (decl), context_die);
19390 /* Output a DIE to represent the typedef itself. */
19391 gen_typedef_die (decl, context_die);
19395 if (debug_info_level >= DINFO_LEVEL_NORMAL)
19396 gen_label_die (decl, context_die);
19401 /* If we are in terse mode, don't generate any DIEs to represent any
19402 variable declarations or definitions. */
19403 if (debug_info_level <= DINFO_LEVEL_TERSE)
19406 /* Output any DIEs that are needed to specify the type of this data
19408 if (decl_by_reference_p (decl_or_origin))
19409 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19411 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19413 /* And its containing type. */
19414 class_origin = decl_class_context (decl_or_origin);
19415 if (class_origin != NULL_TREE)
19416 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
19418 /* And its containing namespace. */
19419 context_die = declare_in_namespace (decl_or_origin, context_die);
19421 /* Now output the DIE to represent the data object itself. This gets
19422 complicated because of the possibility that the VAR_DECL really
19423 represents an inlined instance of a formal parameter for an inline
19425 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19426 if (ultimate_origin != NULL_TREE
19427 && TREE_CODE (ultimate_origin) == PARM_DECL)
19428 gen_formal_parameter_die (decl, origin,
19429 true /* Emit name attribute. */,
19432 gen_variable_die (decl, origin, context_die);
19436 /* Ignore the nameless fields that are used to skip bits but handle C++
19437 anonymous unions and structs. */
19438 if (DECL_NAME (decl) != NULL_TREE
19439 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
19440 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
19442 gen_type_die (member_declared_type (decl), context_die);
19443 gen_field_die (decl, context_die);
19448 if (DECL_BY_REFERENCE (decl_or_origin))
19449 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19451 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19452 return gen_formal_parameter_die (decl, origin,
19453 true /* Emit name attribute. */,
19456 case NAMESPACE_DECL:
19457 case IMPORTED_DECL:
19458 if (dwarf_version >= 3 || !dwarf_strict)
19459 gen_namespace_die (decl, context_die);
19463 /* Probably some frontend-internal decl. Assume we don't care. */
19464 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
19471 /* Output debug information for global decl DECL. Called from toplev.c after
19472 compilation proper has finished. */
19475 dwarf2out_global_decl (tree decl)
19477 /* Output DWARF2 information for file-scope tentative data object
19478 declarations, file-scope (extern) function declarations (which
19479 had no corresponding body) and file-scope tagged type declarations
19480 and definitions which have not yet been forced out. */
19481 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
19482 dwarf2out_decl (decl);
19485 /* Output debug information for type decl DECL. Called from toplev.c
19486 and from language front ends (to record built-in types). */
19488 dwarf2out_type_decl (tree decl, int local)
19491 dwarf2out_decl (decl);
19494 /* Output debug information for imported module or decl DECL.
19495 NAME is non-NULL name in the lexical block if the decl has been renamed.
19496 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19497 that DECL belongs to.
19498 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19500 dwarf2out_imported_module_or_decl_1 (tree decl,
19502 tree lexical_block,
19503 dw_die_ref lexical_block_die)
19505 expanded_location xloc;
19506 dw_die_ref imported_die = NULL;
19507 dw_die_ref at_import_die;
19509 if (TREE_CODE (decl) == IMPORTED_DECL)
19511 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
19512 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
19516 xloc = expand_location (input_location);
19518 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
19520 at_import_die = force_type_die (TREE_TYPE (decl));
19521 /* For namespace N { typedef void T; } using N::T; base_type_die
19522 returns NULL, but DW_TAG_imported_declaration requires
19523 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19524 if (!at_import_die)
19526 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
19527 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
19528 at_import_die = lookup_type_die (TREE_TYPE (decl));
19529 gcc_assert (at_import_die);
19534 at_import_die = lookup_decl_die (decl);
19535 if (!at_import_die)
19537 /* If we're trying to avoid duplicate debug info, we may not have
19538 emitted the member decl for this field. Emit it now. */
19539 if (TREE_CODE (decl) == FIELD_DECL)
19541 tree type = DECL_CONTEXT (decl);
19543 if (TYPE_CONTEXT (type)
19544 && TYPE_P (TYPE_CONTEXT (type))
19545 && !should_emit_struct_debug (TYPE_CONTEXT (type),
19546 DINFO_USAGE_DIR_USE))
19548 gen_type_die_for_member (type, decl,
19549 get_context_die (TYPE_CONTEXT (type)));
19551 at_import_die = force_decl_die (decl);
19555 if (TREE_CODE (decl) == NAMESPACE_DECL)
19557 if (dwarf_version >= 3 || !dwarf_strict)
19558 imported_die = new_die (DW_TAG_imported_module,
19565 imported_die = new_die (DW_TAG_imported_declaration,
19569 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
19570 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
19572 add_AT_string (imported_die, DW_AT_name,
19573 IDENTIFIER_POINTER (name));
19574 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
19577 /* Output debug information for imported module or decl DECL.
19578 NAME is non-NULL name in context if the decl has been renamed.
19579 CHILD is true if decl is one of the renamed decls as part of
19580 importing whole module. */
19583 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
19586 /* dw_die_ref at_import_die; */
19587 dw_die_ref scope_die;
19589 if (debug_info_level <= DINFO_LEVEL_TERSE)
19594 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19595 We need decl DIE for reference and scope die. First, get DIE for the decl
19598 /* Get the scope die for decl context. Use comp_unit_die for global module
19599 or decl. If die is not found for non globals, force new die. */
19601 && TYPE_P (context)
19602 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
19605 if (!(dwarf_version >= 3 || !dwarf_strict))
19608 scope_die = get_context_die (context);
19612 gcc_assert (scope_die->die_child);
19613 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
19614 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
19615 scope_die = scope_die->die_child;
19618 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19619 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
19623 /* Write the debugging output for DECL. */
19626 dwarf2out_decl (tree decl)
19628 dw_die_ref context_die = comp_unit_die ();
19630 switch (TREE_CODE (decl))
19635 case FUNCTION_DECL:
19636 /* What we would really like to do here is to filter out all mere
19637 file-scope declarations of file-scope functions which are never
19638 referenced later within this translation unit (and keep all of ones
19639 that *are* referenced later on) but we aren't clairvoyant, so we have
19640 no idea which functions will be referenced in the future (i.e. later
19641 on within the current translation unit). So here we just ignore all
19642 file-scope function declarations which are not also definitions. If
19643 and when the debugger needs to know something about these functions,
19644 it will have to hunt around and find the DWARF information associated
19645 with the definition of the function.
19647 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19648 nodes represent definitions and which ones represent mere
19649 declarations. We have to check DECL_INITIAL instead. That's because
19650 the C front-end supports some weird semantics for "extern inline"
19651 function definitions. These can get inlined within the current
19652 translation unit (and thus, we need to generate Dwarf info for their
19653 abstract instances so that the Dwarf info for the concrete inlined
19654 instances can have something to refer to) but the compiler never
19655 generates any out-of-lines instances of such things (despite the fact
19656 that they *are* definitions).
19658 The important point is that the C front-end marks these "extern
19659 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19660 them anyway. Note that the C++ front-end also plays some similar games
19661 for inline function definitions appearing within include files which
19662 also contain `#pragma interface' pragmas. */
19663 if (DECL_INITIAL (decl) == NULL_TREE)
19666 /* If we're a nested function, initially use a parent of NULL; if we're
19667 a plain function, this will be fixed up in decls_for_scope. If
19668 we're a method, it will be ignored, since we already have a DIE. */
19669 if (decl_function_context (decl)
19670 /* But if we're in terse mode, we don't care about scope. */
19671 && debug_info_level > DINFO_LEVEL_TERSE)
19672 context_die = NULL;
19676 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19677 declaration and if the declaration was never even referenced from
19678 within this entire compilation unit. We suppress these DIEs in
19679 order to save space in the .debug section (by eliminating entries
19680 which are probably useless). Note that we must not suppress
19681 block-local extern declarations (whether used or not) because that
19682 would screw-up the debugger's name lookup mechanism and cause it to
19683 miss things which really ought to be in scope at a given point. */
19684 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
19687 /* For local statics lookup proper context die. */
19688 if (TREE_STATIC (decl) && decl_function_context (decl))
19689 context_die = lookup_decl_die (DECL_CONTEXT (decl));
19691 /* If we are in terse mode, don't generate any DIEs to represent any
19692 variable declarations or definitions. */
19693 if (debug_info_level <= DINFO_LEVEL_TERSE)
19698 if (debug_info_level <= DINFO_LEVEL_TERSE)
19700 if (!is_fortran () && !is_ada ())
19702 if (TREE_STATIC (decl) && decl_function_context (decl))
19703 context_die = lookup_decl_die (DECL_CONTEXT (decl));
19706 case NAMESPACE_DECL:
19707 case IMPORTED_DECL:
19708 if (debug_info_level <= DINFO_LEVEL_TERSE)
19710 if (lookup_decl_die (decl) != NULL)
19715 /* Don't emit stubs for types unless they are needed by other DIEs. */
19716 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
19719 /* Don't bother trying to generate any DIEs to represent any of the
19720 normal built-in types for the language we are compiling. */
19721 if (DECL_IS_BUILTIN (decl))
19724 /* If we are in terse mode, don't generate any DIEs for types. */
19725 if (debug_info_level <= DINFO_LEVEL_TERSE)
19728 /* If we're a function-scope tag, initially use a parent of NULL;
19729 this will be fixed up in decls_for_scope. */
19730 if (decl_function_context (decl))
19731 context_die = NULL;
19739 gen_decl_die (decl, NULL, context_die);
19742 /* Write the debugging output for DECL. */
19745 dwarf2out_function_decl (tree decl)
19747 dwarf2out_decl (decl);
19748 call_arg_locations = NULL;
19749 call_arg_loc_last = NULL;
19750 call_site_count = -1;
19751 tail_call_site_count = -1;
19752 VEC_free (dw_die_ref, heap, block_map);
19753 htab_empty (decl_loc_table);
19754 htab_empty (cached_dw_loc_list_table);
19757 /* Output a marker (i.e. a label) for the beginning of the generated code for
19758 a lexical block. */
19761 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
19762 unsigned int blocknum)
19764 switch_to_section (current_function_section ());
19765 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
19768 /* Output a marker (i.e. a label) for the end of the generated code for a
19772 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
19774 switch_to_section (current_function_section ());
19775 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
19778 /* Returns nonzero if it is appropriate not to emit any debugging
19779 information for BLOCK, because it doesn't contain any instructions.
19781 Don't allow this for blocks with nested functions or local classes
19782 as we would end up with orphans, and in the presence of scheduling
19783 we may end up calling them anyway. */
19786 dwarf2out_ignore_block (const_tree block)
19791 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
19792 if (TREE_CODE (decl) == FUNCTION_DECL
19793 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
19795 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
19797 decl = BLOCK_NONLOCALIZED_VAR (block, i);
19798 if (TREE_CODE (decl) == FUNCTION_DECL
19799 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
19806 /* Hash table routines for file_hash. */
19809 file_table_eq (const void *p1_p, const void *p2_p)
19811 const struct dwarf_file_data *const p1 =
19812 (const struct dwarf_file_data *) p1_p;
19813 const char *const p2 = (const char *) p2_p;
19814 return filename_cmp (p1->filename, p2) == 0;
19818 file_table_hash (const void *p_p)
19820 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
19821 return htab_hash_string (p->filename);
19824 /* Lookup FILE_NAME (in the list of filenames that we know about here in
19825 dwarf2out.c) and return its "index". The index of each (known) filename is
19826 just a unique number which is associated with only that one filename. We
19827 need such numbers for the sake of generating labels (in the .debug_sfnames
19828 section) and references to those files numbers (in the .debug_srcinfo
19829 and.debug_macinfo sections). If the filename given as an argument is not
19830 found in our current list, add it to the list and assign it the next
19831 available unique index number. In order to speed up searches, we remember
19832 the index of the filename was looked up last. This handles the majority of
19835 static struct dwarf_file_data *
19836 lookup_filename (const char *file_name)
19839 struct dwarf_file_data * created;
19841 /* Check to see if the file name that was searched on the previous
19842 call matches this file name. If so, return the index. */
19843 if (file_table_last_lookup
19844 && (file_name == file_table_last_lookup->filename
19845 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
19846 return file_table_last_lookup;
19848 /* Didn't match the previous lookup, search the table. */
19849 slot = htab_find_slot_with_hash (file_table, file_name,
19850 htab_hash_string (file_name), INSERT);
19852 return (struct dwarf_file_data *) *slot;
19854 created = ggc_alloc_dwarf_file_data ();
19855 created->filename = file_name;
19856 created->emitted_number = 0;
19861 /* If the assembler will construct the file table, then translate the compiler
19862 internal file table number into the assembler file table number, and emit
19863 a .file directive if we haven't already emitted one yet. The file table
19864 numbers are different because we prune debug info for unused variables and
19865 types, which may include filenames. */
19868 maybe_emit_file (struct dwarf_file_data * fd)
19870 if (! fd->emitted_number)
19872 if (last_emitted_file)
19873 fd->emitted_number = last_emitted_file->emitted_number + 1;
19875 fd->emitted_number = 1;
19876 last_emitted_file = fd;
19878 if (DWARF2_ASM_LINE_DEBUG_INFO)
19880 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
19881 output_quoted_string (asm_out_file,
19882 remap_debug_filename (fd->filename));
19883 fputc ('\n', asm_out_file);
19887 return fd->emitted_number;
19890 /* Schedule generation of a DW_AT_const_value attribute to DIE.
19891 That generation should happen after function debug info has been
19892 generated. The value of the attribute is the constant value of ARG. */
19895 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
19897 die_arg_entry entry;
19902 if (!tmpl_value_parm_die_table)
19903 tmpl_value_parm_die_table
19904 = VEC_alloc (die_arg_entry, gc, 32);
19908 VEC_safe_push (die_arg_entry, gc,
19909 tmpl_value_parm_die_table,
19913 /* Return TRUE if T is an instance of generic type, FALSE
19917 generic_type_p (tree t)
19919 if (t == NULL_TREE || !TYPE_P (t))
19921 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
19924 /* Schedule the generation of the generic parameter dies for the
19925 instance of generic type T. The proper generation itself is later
19926 done by gen_scheduled_generic_parms_dies. */
19929 schedule_generic_params_dies_gen (tree t)
19931 if (!generic_type_p (t))
19934 if (generic_type_instances == NULL)
19935 generic_type_instances = VEC_alloc (tree, gc, 256);
19937 VEC_safe_push (tree, gc, generic_type_instances, t);
19940 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
19941 by append_entry_to_tmpl_value_parm_die_table. This function must
19942 be called after function DIEs have been generated. */
19945 gen_remaining_tmpl_value_param_die_attribute (void)
19947 if (tmpl_value_parm_die_table)
19952 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
19953 tree_add_const_value_attribute (e->die, e->arg);
19957 /* Generate generic parameters DIEs for instances of generic types
19958 that have been previously scheduled by
19959 schedule_generic_params_dies_gen. This function must be called
19960 after all the types of the CU have been laid out. */
19963 gen_scheduled_generic_parms_dies (void)
19968 if (generic_type_instances == NULL)
19971 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
19972 gen_generic_params_dies (t);
19976 /* Replace DW_AT_name for the decl with name. */
19979 dwarf2out_set_name (tree decl, tree name)
19985 die = TYPE_SYMTAB_DIE (decl);
19989 dname = dwarf2_name (name, 0);
19993 attr = get_AT (die, DW_AT_name);
19996 struct indirect_string_node *node;
19998 node = find_AT_string (dname);
19999 /* replace the string. */
20000 attr->dw_attr_val.v.val_str = node;
20004 add_name_attribute (die, dname);
20007 /* Called by the final INSN scan whenever we see a var location. We
20008 use it to drop labels in the right places, and throw the location in
20009 our lookup table. */
20012 dwarf2out_var_location (rtx loc_note)
20014 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
20015 struct var_loc_node *newloc;
20017 static const char *last_label;
20018 static const char *last_postcall_label;
20019 static bool last_in_cold_section_p;
20023 if (!NOTE_P (loc_note))
20025 if (CALL_P (loc_note))
20028 if (SIBLING_CALL_P (loc_note))
20029 tail_call_site_count++;
20034 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
20035 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
20038 next_real = next_real_insn (loc_note);
20040 /* If there are no instructions which would be affected by this note,
20041 don't do anything. */
20043 && next_real == NULL_RTX
20044 && !NOTE_DURING_CALL_P (loc_note))
20047 if (next_real == NULL_RTX)
20048 next_real = get_last_insn ();
20050 /* If there were any real insns between note we processed last time
20051 and this note (or if it is the first note), clear
20052 last_{,postcall_}label so that they are not reused this time. */
20053 if (last_var_location_insn == NULL_RTX
20054 || last_var_location_insn != next_real
20055 || last_in_cold_section_p != in_cold_section_p)
20058 last_postcall_label = NULL;
20063 decl = NOTE_VAR_LOCATION_DECL (loc_note);
20064 newloc = add_var_loc_to_decl (decl, loc_note,
20065 NOTE_DURING_CALL_P (loc_note)
20066 ? last_postcall_label : last_label);
20067 if (newloc == NULL)
20076 /* If there were no real insns between note we processed last time
20077 and this note, use the label we emitted last time. Otherwise
20078 create a new label and emit it. */
20079 if (last_label == NULL)
20081 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
20082 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
20084 last_label = ggc_strdup (loclabel);
20089 struct call_arg_loc_node *ca_loc
20090 = ggc_alloc_cleared_call_arg_loc_node ();
20091 rtx prev = prev_real_insn (loc_note), x;
20092 ca_loc->call_arg_loc_note = loc_note;
20093 ca_loc->next = NULL;
20094 ca_loc->label = last_label;
20097 || (NONJUMP_INSN_P (prev)
20098 && GET_CODE (PATTERN (prev)) == SEQUENCE
20099 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
20100 if (!CALL_P (prev))
20101 prev = XVECEXP (PATTERN (prev), 0, 0);
20102 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
20103 x = PATTERN (prev);
20104 if (GET_CODE (x) == PARALLEL)
20105 x = XVECEXP (x, 0, 0);
20106 if (GET_CODE (x) == SET)
20108 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
20110 x = XEXP (XEXP (x, 0), 0);
20111 if (GET_CODE (x) == SYMBOL_REF
20112 && SYMBOL_REF_DECL (x)
20113 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
20114 ca_loc->symbol_ref = x;
20116 ca_loc->block = insn_scope (prev);
20117 if (call_arg_locations)
20118 call_arg_loc_last->next = ca_loc;
20120 call_arg_locations = ca_loc;
20121 call_arg_loc_last = ca_loc;
20123 else if (!NOTE_DURING_CALL_P (loc_note))
20124 newloc->label = last_label;
20127 if (!last_postcall_label)
20129 sprintf (loclabel, "%s-1", last_label);
20130 last_postcall_label = ggc_strdup (loclabel);
20132 newloc->label = last_postcall_label;
20135 last_var_location_insn = next_real;
20136 last_in_cold_section_p = in_cold_section_p;
20139 /* Note in one location list that text section has changed. */
20142 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
20144 var_loc_list *list = (var_loc_list *) *slot;
20146 list->last_before_switch
20147 = list->last->next ? list->last->next : list->last;
20151 /* Note in all location lists that text section has changed. */
20154 var_location_switch_text_section (void)
20156 if (decl_loc_table == NULL)
20159 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
20162 /* Create a new line number table. */
20164 static dw_line_info_table *
20165 new_line_info_table (void)
20167 dw_line_info_table *table;
20169 table = ggc_alloc_cleared_dw_line_info_table_struct ();
20170 table->file_num = 1;
20171 table->line_num = 1;
20172 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
20177 /* Lookup the "current" table into which we emit line info, so
20178 that we don't have to do it for every source line. */
20181 set_cur_line_info_table (section *sec)
20183 dw_line_info_table *table;
20185 if (sec == text_section)
20186 table = text_section_line_info;
20187 else if (sec == cold_text_section)
20189 table = cold_text_section_line_info;
20192 cold_text_section_line_info = table = new_line_info_table ();
20193 table->end_label = cold_end_label;
20198 const char *end_label;
20200 if (flag_reorder_blocks_and_partition)
20202 if (in_cold_section_p)
20203 end_label = crtl->subsections.cold_section_end_label;
20205 end_label = crtl->subsections.hot_section_end_label;
20209 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20210 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
20211 current_function_funcdef_no);
20212 end_label = ggc_strdup (label);
20215 table = new_line_info_table ();
20216 table->end_label = end_label;
20218 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
20221 cur_line_info_table = table;
20225 /* We need to reset the locations at the beginning of each
20226 function. We can't do this in the end_function hook, because the
20227 declarations that use the locations won't have been output when
20228 that hook is called. Also compute have_multiple_function_sections here. */
20231 dwarf2out_begin_function (tree fun)
20233 section *sec = function_section (fun);
20235 if (sec != text_section)
20236 have_multiple_function_sections = true;
20238 if (flag_reorder_blocks_and_partition && !cold_text_section)
20240 gcc_assert (current_function_decl == fun);
20241 cold_text_section = unlikely_text_section ();
20242 switch_to_section (cold_text_section);
20243 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
20244 switch_to_section (sec);
20247 dwarf2out_note_section_used ();
20248 call_site_count = 0;
20249 tail_call_site_count = 0;
20251 set_cur_line_info_table (sec);
20254 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20257 push_dw_line_info_entry (dw_line_info_table *table,
20258 enum dw_line_info_opcode opcode, unsigned int val)
20260 dw_line_info_entry e;
20263 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
20266 /* Output a label to mark the beginning of a source code line entry
20267 and record information relating to this source line, in
20268 'line_info_table' for later output of the .debug_line section. */
20269 /* ??? The discriminator parameter ought to be unsigned. */
20272 dwarf2out_source_line (unsigned int line, const char *filename,
20273 int discriminator, bool is_stmt)
20275 unsigned int file_num;
20276 dw_line_info_table *table;
20278 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
20281 /* The discriminator column was added in dwarf4. Simplify the below
20282 by simply removing it if we're not supposed to output it. */
20283 if (dwarf_version < 4 && dwarf_strict)
20286 table = cur_line_info_table;
20287 file_num = maybe_emit_file (lookup_filename (filename));
20289 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20290 the debugger has used the second (possibly duplicate) line number
20291 at the beginning of the function to mark the end of the prologue.
20292 We could eliminate any other duplicates within the function. For
20293 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20294 that second line number entry. */
20295 /* Recall that this end-of-prologue indication is *not* the same thing
20296 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20297 to which the hook corresponds, follows the last insn that was
20298 emitted by gen_prologue. What we need is to preceed the first insn
20299 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20300 insn that corresponds to something the user wrote. These may be
20301 very different locations once scheduling is enabled. */
20303 if (0 && file_num == table->file_num
20304 && line == table->line_num
20305 && discriminator == table->discrim_num
20306 && is_stmt == table->is_stmt)
20309 switch_to_section (current_function_section ());
20311 /* If requested, emit something human-readable. */
20312 if (flag_debug_asm)
20313 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
20315 if (DWARF2_ASM_LINE_DEBUG_INFO)
20317 /* Emit the .loc directive understood by GNU as. */
20318 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
20319 if (is_stmt != table->is_stmt)
20320 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
20321 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
20322 fprintf (asm_out_file, " discriminator %d", discriminator);
20323 fputc ('\n', asm_out_file);
20327 unsigned int label_num = ++line_info_label_num;
20329 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
20331 push_dw_line_info_entry (table, LI_set_address, label_num);
20332 if (file_num != table->file_num)
20333 push_dw_line_info_entry (table, LI_set_file, file_num);
20334 if (discriminator != table->discrim_num)
20335 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
20336 if (is_stmt != table->is_stmt)
20337 push_dw_line_info_entry (table, LI_negate_stmt, 0);
20338 push_dw_line_info_entry (table, LI_set_line, line);
20341 table->file_num = file_num;
20342 table->line_num = line;
20343 table->discrim_num = discriminator;
20344 table->is_stmt = is_stmt;
20345 table->in_use = true;
20348 /* Record the beginning of a new source file. */
20351 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
20353 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20355 /* Record the beginning of the file for break_out_includes. */
20356 dw_die_ref bincl_die;
20358 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
20359 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
20362 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20365 e.code = DW_MACINFO_start_file;
20367 e.info = xstrdup (filename);
20368 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20372 /* Record the end of a source file. */
20375 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
20377 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20378 /* Record the end of the file for break_out_includes. */
20379 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
20381 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20384 e.code = DW_MACINFO_end_file;
20387 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20391 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20392 the tail part of the directive line, i.e. the part which is past the
20393 initial whitespace, #, whitespace, directive-name, whitespace part. */
20396 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
20397 const char *buffer ATTRIBUTE_UNUSED)
20399 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20402 /* Insert a dummy first entry to be able to optimize the whole
20403 predefined macro block using DW_MACRO_GNU_transparent_include. */
20404 if (VEC_empty (macinfo_entry, macinfo_table) && lineno == 0)
20409 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20411 e.code = DW_MACINFO_define;
20413 e.info = xstrdup (buffer);;
20414 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20418 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20419 the tail part of the directive line, i.e. the part which is past the
20420 initial whitespace, #, whitespace, directive-name, whitespace part. */
20423 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
20424 const char *buffer ATTRIBUTE_UNUSED)
20426 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20429 /* Insert a dummy first entry to be able to optimize the whole
20430 predefined macro block using DW_MACRO_GNU_transparent_include. */
20431 if (VEC_empty (macinfo_entry, macinfo_table) && lineno == 0)
20436 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20438 e.code = DW_MACINFO_undef;
20440 e.info = xstrdup (buffer);
20441 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20445 /* Routines to manipulate hash table of CUs. */
20448 htab_macinfo_hash (const void *of)
20450 const macinfo_entry *const entry =
20451 (const macinfo_entry *) of;
20453 return htab_hash_string (entry->info);
20457 htab_macinfo_eq (const void *of1, const void *of2)
20459 const macinfo_entry *const entry1 = (const macinfo_entry *) of1;
20460 const macinfo_entry *const entry2 = (const macinfo_entry *) of2;
20462 return !strcmp (entry1->info, entry2->info);
20465 /* Output a single .debug_macinfo entry. */
20468 output_macinfo_op (macinfo_entry *ref)
20472 struct indirect_string_node *node;
20473 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20477 case DW_MACINFO_start_file:
20478 file_num = maybe_emit_file (lookup_filename (ref->info));
20479 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
20480 dw2_asm_output_data_uleb128 (ref->lineno,
20481 "Included from line number %lu",
20482 (unsigned long) ref->lineno);
20483 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
20485 case DW_MACINFO_end_file:
20486 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
20488 case DW_MACINFO_define:
20489 case DW_MACINFO_undef:
20490 len = strlen (ref->info) + 1;
20492 && len > DWARF_OFFSET_SIZE
20493 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
20494 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
20496 ref->code = ref->code == DW_MACINFO_define
20497 ? DW_MACRO_GNU_define_indirect
20498 : DW_MACRO_GNU_undef_indirect;
20499 output_macinfo_op (ref);
20502 dw2_asm_output_data (1, ref->code,
20503 ref->code == DW_MACINFO_define
20504 ? "Define macro" : "Undefine macro");
20505 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20506 (unsigned long) ref->lineno);
20507 dw2_asm_output_nstring (ref->info, -1, "The macro");
20509 case DW_MACRO_GNU_define_indirect:
20510 case DW_MACRO_GNU_undef_indirect:
20511 node = find_AT_string (ref->info);
20512 if (node->form != DW_FORM_strp)
20515 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
20516 ++dw2_string_counter;
20517 node->label = xstrdup (label);
20518 node->form = DW_FORM_strp;
20520 dw2_asm_output_data (1, ref->code,
20521 ref->code == DW_MACRO_GNU_define_indirect
20522 ? "Define macro indirect"
20523 : "Undefine macro indirect");
20524 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20525 (unsigned long) ref->lineno);
20526 dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
20527 debug_str_section, "The macro: \"%s\"",
20530 case DW_MACRO_GNU_transparent_include:
20531 dw2_asm_output_data (1, ref->code, "Transparent include");
20532 ASM_GENERATE_INTERNAL_LABEL (label,
20533 DEBUG_MACRO_SECTION_LABEL, ref->lineno);
20534 dw2_asm_output_offset (DWARF_OFFSET_SIZE, label, NULL, NULL);
20537 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
20538 ASM_COMMENT_START, (unsigned long) ref->code);
20543 /* Attempt to make a sequence of define/undef macinfo ops shareable with
20544 other compilation unit .debug_macinfo sections. IDX is the first
20545 index of a define/undef, return the number of ops that should be
20546 emitted in a comdat .debug_macinfo section and emit
20547 a DW_MACRO_GNU_transparent_include entry referencing it.
20548 If the define/undef entry should be emitted normally, return 0. */
20551 optimize_macinfo_range (unsigned int idx, VEC (macinfo_entry, gc) *files,
20552 htab_t *macinfo_htab)
20554 macinfo_entry *first, *second, *cur, *inc;
20555 char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
20556 unsigned char checksum[16];
20557 struct md5_ctx ctx;
20558 char *grp_name, *tail;
20560 unsigned int i, count, encoded_filename_len, linebuf_len;
20563 first = VEC_index (macinfo_entry, macinfo_table, idx);
20564 second = VEC_index (macinfo_entry, macinfo_table, idx + 1);
20566 /* Optimize only if there are at least two consecutive define/undef ops,
20567 and either all of them are before first DW_MACINFO_start_file
20568 with lineno 0 (i.e. predefined macro block), or all of them are
20569 in some included header file. */
20570 if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
20572 if (VEC_empty (macinfo_entry, files))
20574 if (first->lineno != 0 || second->lineno != 0)
20577 else if (first->lineno == 0)
20580 /* Find the last define/undef entry that can be grouped together
20581 with first and at the same time compute md5 checksum of their
20582 codes, linenumbers and strings. */
20583 md5_init_ctx (&ctx);
20584 for (i = idx; VEC_iterate (macinfo_entry, macinfo_table, i, cur); i++)
20585 if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
20587 else if (first->lineno == 0 && cur->lineno != 0)
20591 unsigned char code = cur->code;
20592 md5_process_bytes (&code, 1, &ctx);
20593 checksum_uleb128 (cur->lineno, &ctx);
20594 md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
20596 md5_finish_ctx (&ctx, checksum);
20599 /* From the containing include filename (if any) pick up just
20600 usable characters from its basename. */
20601 if (first->lineno == 0)
20604 base = lbasename (VEC_last (macinfo_entry, files)->info);
20605 for (encoded_filename_len = 0, i = 0; base[i]; i++)
20606 if (ISIDNUM (base[i]) || base[i] == '.')
20607 encoded_filename_len++;
20608 /* Count . at the end. */
20609 if (encoded_filename_len)
20610 encoded_filename_len++;
20612 sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
20613 linebuf_len = strlen (linebuf);
20615 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
20616 grp_name = XNEWVEC (char, 4 + encoded_filename_len + linebuf_len + 1
20618 memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4);
20619 tail = grp_name + 4;
20620 if (encoded_filename_len)
20622 for (i = 0; base[i]; i++)
20623 if (ISIDNUM (base[i]) || base[i] == '.')
20627 memcpy (tail, linebuf, linebuf_len);
20628 tail += linebuf_len;
20630 for (i = 0; i < 16; i++)
20631 sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
20633 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
20634 in the empty vector entry before the first define/undef. */
20635 inc = VEC_index (macinfo_entry, macinfo_table, idx - 1);
20636 inc->code = DW_MACRO_GNU_transparent_include;
20638 inc->info = grp_name;
20639 if (*macinfo_htab == NULL)
20640 *macinfo_htab = htab_create (10, htab_macinfo_hash, htab_macinfo_eq, NULL);
20641 /* Avoid emitting duplicates. */
20642 slot = htab_find_slot (*macinfo_htab, inc, INSERT);
20645 free (CONST_CAST (char *, inc->info));
20648 /* If such an entry has been used before, just emit
20649 a DW_MACRO_GNU_transparent_include op. */
20650 inc = (macinfo_entry *) *slot;
20651 output_macinfo_op (inc);
20652 /* And clear all macinfo_entry in the range to avoid emitting them
20653 in the second pass. */
20655 VEC_iterate (macinfo_entry, macinfo_table, i, cur)
20656 && i < idx + count;
20660 free (CONST_CAST (char *, cur->info));
20667 inc->lineno = htab_elements (*macinfo_htab);
20668 output_macinfo_op (inc);
20673 /* Output macinfo section(s). */
20676 output_macinfo (void)
20679 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
20680 macinfo_entry *ref;
20681 VEC (macinfo_entry, gc) *files = NULL;
20682 htab_t macinfo_htab = NULL;
20687 /* output_macinfo* uses these interchangeably. */
20688 gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_GNU_define
20689 && (int) DW_MACINFO_undef == (int) DW_MACRO_GNU_undef
20690 && (int) DW_MACINFO_start_file == (int) DW_MACRO_GNU_start_file
20691 && (int) DW_MACINFO_end_file == (int) DW_MACRO_GNU_end_file);
20693 /* For .debug_macro emit the section header. */
20696 dw2_asm_output_data (2, 4, "DWARF macro version number");
20697 if (DWARF_OFFSET_SIZE == 8)
20698 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
20700 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
20701 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_line_section_label,
20702 debug_line_section, NULL);
20705 /* In the first loop, it emits the primary .debug_macinfo section
20706 and after each emitted op the macinfo_entry is cleared.
20707 If a longer range of define/undef ops can be optimized using
20708 DW_MACRO_GNU_transparent_include, the
20709 DW_MACRO_GNU_transparent_include op is emitted and kept in
20710 the vector before the first define/undef in the range and the
20711 whole range of define/undef ops is not emitted and kept. */
20712 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
20716 case DW_MACINFO_start_file:
20717 VEC_safe_push (macinfo_entry, gc, files, ref);
20719 case DW_MACINFO_end_file:
20720 if (!VEC_empty (macinfo_entry, files))
20722 macinfo_entry *file = VEC_last (macinfo_entry, files);
20723 free (CONST_CAST (char *, file->info));
20724 VEC_pop (macinfo_entry, files);
20727 case DW_MACINFO_define:
20728 case DW_MACINFO_undef:
20730 && HAVE_COMDAT_GROUP
20731 && VEC_length (macinfo_entry, files) != 1
20734 && VEC_index (macinfo_entry, macinfo_table, i - 1)->code == 0)
20736 unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
20745 /* A dummy entry may be inserted at the beginning to be able
20746 to optimize the whole block of predefined macros. */
20752 output_macinfo_op (ref);
20753 /* For DW_MACINFO_start_file ref->info has been copied into files
20755 if (ref->code != DW_MACINFO_start_file)
20756 free (CONST_CAST (char *, ref->info));
20761 if (macinfo_htab == NULL)
20764 htab_delete (macinfo_htab);
20766 /* If any DW_MACRO_GNU_transparent_include were used, on those
20767 DW_MACRO_GNU_transparent_include entries terminate the
20768 current chain and switch to a new comdat .debug_macinfo
20769 section and emit the define/undef entries within it. */
20770 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
20775 case DW_MACRO_GNU_transparent_include:
20777 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20778 tree comdat_key = get_identifier (ref->info);
20779 /* Terminate the previous .debug_macinfo section. */
20780 dw2_asm_output_data (1, 0, "End compilation unit");
20781 targetm.asm_out.named_section (DEBUG_MACRO_SECTION,
20783 | SECTION_LINKONCE,
20785 ASM_GENERATE_INTERNAL_LABEL (label,
20786 DEBUG_MACRO_SECTION_LABEL,
20788 ASM_OUTPUT_LABEL (asm_out_file, label);
20790 free (CONST_CAST (char *, ref->info));
20792 dw2_asm_output_data (2, 4, "DWARF macro version number");
20793 if (DWARF_OFFSET_SIZE == 8)
20794 dw2_asm_output_data (1, 1, "Flags: 64-bit");
20796 dw2_asm_output_data (1, 0, "Flags: 32-bit");
20799 case DW_MACINFO_define:
20800 case DW_MACINFO_undef:
20801 output_macinfo_op (ref);
20803 free (CONST_CAST (char *, ref->info));
20807 gcc_unreachable ();
20811 /* Set up for Dwarf output at the start of compilation. */
20814 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
20816 /* Allocate the file_table. */
20817 file_table = htab_create_ggc (50, file_table_hash,
20818 file_table_eq, NULL);
20820 /* Allocate the decl_die_table. */
20821 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
20822 decl_die_table_eq, NULL);
20824 /* Allocate the decl_loc_table. */
20825 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
20826 decl_loc_table_eq, NULL);
20828 /* Allocate the cached_dw_loc_list_table. */
20829 cached_dw_loc_list_table
20830 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
20831 cached_dw_loc_list_table_eq, NULL);
20833 /* Allocate the initial hunk of the decl_scope_table. */
20834 decl_scope_table = VEC_alloc (tree, gc, 256);
20836 /* Allocate the initial hunk of the abbrev_die_table. */
20837 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
20838 (ABBREV_DIE_TABLE_INCREMENT);
20839 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
20840 /* Zero-th entry is allocated, but unused. */
20841 abbrev_die_table_in_use = 1;
20843 /* Allocate the pubtypes and pubnames vectors. */
20844 pubname_table = VEC_alloc (pubname_entry, gc, 32);
20845 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
20847 incomplete_types = VEC_alloc (tree, gc, 64);
20849 used_rtx_array = VEC_alloc (rtx, gc, 32);
20851 debug_info_section = get_section (DEBUG_INFO_SECTION,
20852 SECTION_DEBUG, NULL);
20853 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
20854 SECTION_DEBUG, NULL);
20855 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
20856 SECTION_DEBUG, NULL);
20857 debug_macinfo_section = get_section (dwarf_strict
20858 ? DEBUG_MACINFO_SECTION
20859 : DEBUG_MACRO_SECTION,
20860 SECTION_DEBUG, NULL);
20861 debug_line_section = get_section (DEBUG_LINE_SECTION,
20862 SECTION_DEBUG, NULL);
20863 debug_loc_section = get_section (DEBUG_LOC_SECTION,
20864 SECTION_DEBUG, NULL);
20865 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
20866 SECTION_DEBUG, NULL);
20867 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
20868 SECTION_DEBUG, NULL);
20869 debug_str_section = get_section (DEBUG_STR_SECTION,
20870 DEBUG_STR_SECTION_FLAGS, NULL);
20871 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
20872 SECTION_DEBUG, NULL);
20873 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
20874 SECTION_DEBUG, NULL);
20876 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
20877 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
20878 DEBUG_ABBREV_SECTION_LABEL, 0);
20879 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
20880 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
20881 COLD_TEXT_SECTION_LABEL, 0);
20882 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
20884 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
20885 DEBUG_INFO_SECTION_LABEL, 0);
20886 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
20887 DEBUG_LINE_SECTION_LABEL, 0);
20888 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
20889 DEBUG_RANGES_SECTION_LABEL, 0);
20890 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
20892 ? DEBUG_MACINFO_SECTION_LABEL
20893 : DEBUG_MACRO_SECTION_LABEL, 0);
20895 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20896 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
20898 switch_to_section (text_section);
20899 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
20901 /* Make sure the line number table for .text always exists. */
20902 text_section_line_info = new_line_info_table ();
20903 text_section_line_info->end_label = text_end_label;
20906 /* Called before cgraph_optimize starts outputtting functions, variables
20907 and toplevel asms into assembly. */
20910 dwarf2out_assembly_start (void)
20912 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
20913 && dwarf2out_do_cfi_asm ()
20914 && (!(flag_unwind_tables || flag_exceptions)
20915 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
20916 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
20919 /* A helper function for dwarf2out_finish called through
20920 htab_traverse. Emit one queued .debug_str string. */
20923 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
20925 struct indirect_string_node *node = (struct indirect_string_node *) *h;
20927 if (node->form == DW_FORM_strp)
20929 switch_to_section (debug_str_section);
20930 ASM_OUTPUT_LABEL (asm_out_file, node->label);
20931 assemble_string (node->str, strlen (node->str) + 1);
20937 #if ENABLE_ASSERT_CHECKING
20938 /* Verify that all marks are clear. */
20941 verify_marks_clear (dw_die_ref die)
20945 gcc_assert (! die->die_mark);
20946 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
20948 #endif /* ENABLE_ASSERT_CHECKING */
20950 /* Clear the marks for a die and its children.
20951 Be cool if the mark isn't set. */
20954 prune_unmark_dies (dw_die_ref die)
20960 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
20963 /* Given DIE that we're marking as used, find any other dies
20964 it references as attributes and mark them as used. */
20967 prune_unused_types_walk_attribs (dw_die_ref die)
20972 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
20974 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
20976 /* A reference to another DIE.
20977 Make sure that it will get emitted.
20978 If it was broken out into a comdat group, don't follow it. */
20979 if (! use_debug_types
20980 || a->dw_attr == DW_AT_specification
20981 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
20982 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
20984 /* Set the string's refcount to 0 so that prune_unused_types_mark
20985 accounts properly for it. */
20986 if (AT_class (a) == dw_val_class_str)
20987 a->dw_attr_val.v.val_str->refcount = 0;
20991 /* Mark the generic parameters and arguments children DIEs of DIE. */
20994 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
20998 if (die == NULL || die->die_child == NULL)
21000 c = die->die_child;
21003 switch (c->die_tag)
21005 case DW_TAG_template_type_param:
21006 case DW_TAG_template_value_param:
21007 case DW_TAG_GNU_template_template_param:
21008 case DW_TAG_GNU_template_parameter_pack:
21009 prune_unused_types_mark (c, 1);
21015 } while (c && c != die->die_child);
21018 /* Mark DIE as being used. If DOKIDS is true, then walk down
21019 to DIE's children. */
21022 prune_unused_types_mark (dw_die_ref die, int dokids)
21026 if (die->die_mark == 0)
21028 /* We haven't done this node yet. Mark it as used. */
21030 /* If this is the DIE of a generic type instantiation,
21031 mark the children DIEs that describe its generic parms and
21033 prune_unused_types_mark_generic_parms_dies (die);
21035 /* We also have to mark its parents as used.
21036 (But we don't want to mark our parents' kids due to this.) */
21037 if (die->die_parent)
21038 prune_unused_types_mark (die->die_parent, 0);
21040 /* Mark any referenced nodes. */
21041 prune_unused_types_walk_attribs (die);
21043 /* If this node is a specification,
21044 also mark the definition, if it exists. */
21045 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
21046 prune_unused_types_mark (die->die_definition, 1);
21049 if (dokids && die->die_mark != 2)
21051 /* We need to walk the children, but haven't done so yet.
21052 Remember that we've walked the kids. */
21055 /* If this is an array type, we need to make sure our
21056 kids get marked, even if they're types. If we're
21057 breaking out types into comdat sections, do this
21058 for all type definitions. */
21059 if (die->die_tag == DW_TAG_array_type
21060 || (use_debug_types
21061 && is_type_die (die) && ! is_declaration_die (die)))
21062 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
21064 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21068 /* For local classes, look if any static member functions were emitted
21069 and if so, mark them. */
21072 prune_unused_types_walk_local_classes (dw_die_ref die)
21076 if (die->die_mark == 2)
21079 switch (die->die_tag)
21081 case DW_TAG_structure_type:
21082 case DW_TAG_union_type:
21083 case DW_TAG_class_type:
21086 case DW_TAG_subprogram:
21087 if (!get_AT_flag (die, DW_AT_declaration)
21088 || die->die_definition != NULL)
21089 prune_unused_types_mark (die, 1);
21096 /* Mark children. */
21097 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
21100 /* Walk the tree DIE and mark types that we actually use. */
21103 prune_unused_types_walk (dw_die_ref die)
21107 /* Don't do anything if this node is already marked and
21108 children have been marked as well. */
21109 if (die->die_mark == 2)
21112 switch (die->die_tag)
21114 case DW_TAG_structure_type:
21115 case DW_TAG_union_type:
21116 case DW_TAG_class_type:
21117 if (die->die_perennial_p)
21120 for (c = die->die_parent; c; c = c->die_parent)
21121 if (c->die_tag == DW_TAG_subprogram)
21124 /* Finding used static member functions inside of classes
21125 is needed just for local classes, because for other classes
21126 static member function DIEs with DW_AT_specification
21127 are emitted outside of the DW_TAG_*_type. If we ever change
21128 it, we'd need to call this even for non-local classes. */
21130 prune_unused_types_walk_local_classes (die);
21132 /* It's a type node --- don't mark it. */
21135 case DW_TAG_const_type:
21136 case DW_TAG_packed_type:
21137 case DW_TAG_pointer_type:
21138 case DW_TAG_reference_type:
21139 case DW_TAG_rvalue_reference_type:
21140 case DW_TAG_volatile_type:
21141 case DW_TAG_typedef:
21142 case DW_TAG_array_type:
21143 case DW_TAG_interface_type:
21144 case DW_TAG_friend:
21145 case DW_TAG_variant_part:
21146 case DW_TAG_enumeration_type:
21147 case DW_TAG_subroutine_type:
21148 case DW_TAG_string_type:
21149 case DW_TAG_set_type:
21150 case DW_TAG_subrange_type:
21151 case DW_TAG_ptr_to_member_type:
21152 case DW_TAG_file_type:
21153 if (die->die_perennial_p)
21156 /* It's a type node --- don't mark it. */
21160 /* Mark everything else. */
21164 if (die->die_mark == 0)
21168 /* Now, mark any dies referenced from here. */
21169 prune_unused_types_walk_attribs (die);
21174 /* Mark children. */
21175 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21178 /* Increment the string counts on strings referred to from DIE's
21182 prune_unused_types_update_strings (dw_die_ref die)
21187 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21188 if (AT_class (a) == dw_val_class_str)
21190 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
21192 /* Avoid unnecessarily putting strings that are used less than
21193 twice in the hash table. */
21195 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
21198 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
21199 htab_hash_string (s->str),
21201 gcc_assert (*slot == NULL);
21207 /* Remove from the tree DIE any dies that aren't marked. */
21210 prune_unused_types_prune (dw_die_ref die)
21214 gcc_assert (die->die_mark);
21215 prune_unused_types_update_strings (die);
21217 if (! die->die_child)
21220 c = die->die_child;
21222 dw_die_ref prev = c;
21223 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
21224 if (c == die->die_child)
21226 /* No marked children between 'prev' and the end of the list. */
21228 /* No marked children at all. */
21229 die->die_child = NULL;
21232 prev->die_sib = c->die_sib;
21233 die->die_child = prev;
21238 if (c != prev->die_sib)
21240 prune_unused_types_prune (c);
21241 } while (c != die->die_child);
21244 /* Remove dies representing declarations that we never use. */
21247 prune_unused_types (void)
21250 limbo_die_node *node;
21251 comdat_type_node *ctnode;
21253 dw_die_ref base_type;
21255 #if ENABLE_ASSERT_CHECKING
21256 /* All the marks should already be clear. */
21257 verify_marks_clear (comp_unit_die ());
21258 for (node = limbo_die_list; node; node = node->next)
21259 verify_marks_clear (node->die);
21260 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21261 verify_marks_clear (ctnode->root_die);
21262 #endif /* ENABLE_ASSERT_CHECKING */
21264 /* Mark types that are used in global variables. */
21265 premark_types_used_by_global_vars ();
21267 /* Set the mark on nodes that are actually used. */
21268 prune_unused_types_walk (comp_unit_die ());
21269 for (node = limbo_die_list; node; node = node->next)
21270 prune_unused_types_walk (node->die);
21271 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21273 prune_unused_types_walk (ctnode->root_die);
21274 prune_unused_types_mark (ctnode->type_die, 1);
21277 /* Also set the mark on nodes referenced from the
21279 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
21280 prune_unused_types_mark (pub->die, 1);
21281 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21282 prune_unused_types_mark (base_type, 1);
21284 if (debug_str_hash)
21285 htab_empty (debug_str_hash);
21286 prune_unused_types_prune (comp_unit_die ());
21287 for (node = limbo_die_list; node; node = node->next)
21288 prune_unused_types_prune (node->die);
21289 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21290 prune_unused_types_prune (ctnode->root_die);
21292 /* Leave the marks clear. */
21293 prune_unmark_dies (comp_unit_die ());
21294 for (node = limbo_die_list; node; node = node->next)
21295 prune_unmark_dies (node->die);
21296 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21297 prune_unmark_dies (ctnode->root_die);
21300 /* Set the parameter to true if there are any relative pathnames in
21303 file_table_relative_p (void ** slot, void *param)
21305 bool *p = (bool *) param;
21306 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
21307 if (!IS_ABSOLUTE_PATH (d->filename))
21315 /* Routines to manipulate hash table of comdat type units. */
21318 htab_ct_hash (const void *of)
21321 const comdat_type_node *const type_node = (const comdat_type_node *) of;
21323 memcpy (&h, type_node->signature, sizeof (h));
21328 htab_ct_eq (const void *of1, const void *of2)
21330 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
21331 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
21333 return (! memcmp (type_node_1->signature, type_node_2->signature,
21334 DWARF_TYPE_SIGNATURE_SIZE));
21337 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21338 to the location it would have been added, should we know its
21339 DECL_ASSEMBLER_NAME when we added other attributes. This will
21340 probably improve compactness of debug info, removing equivalent
21341 abbrevs, and hide any differences caused by deferring the
21342 computation of the assembler name, triggered by e.g. PCH. */
21345 move_linkage_attr (dw_die_ref die)
21347 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
21348 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
21350 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
21351 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
21355 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
21357 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
21361 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
21363 VEC_pop (dw_attr_node, die->die_attr);
21364 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
21368 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21369 referenced from typed stack ops and count how often they are used. */
21372 mark_base_types (dw_loc_descr_ref loc)
21374 dw_die_ref base_type = NULL;
21376 for (; loc; loc = loc->dw_loc_next)
21378 switch (loc->dw_loc_opc)
21380 case DW_OP_GNU_regval_type:
21381 case DW_OP_GNU_deref_type:
21382 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
21384 case DW_OP_GNU_convert:
21385 case DW_OP_GNU_reinterpret:
21386 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
21389 case DW_OP_GNU_const_type:
21390 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
21392 case DW_OP_GNU_entry_value:
21393 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
21398 gcc_assert (base_type->die_parent == comp_unit_die ());
21399 if (base_type->die_mark)
21400 base_type->die_mark++;
21403 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
21404 base_type->die_mark = 1;
21409 /* Comparison function for sorting marked base types. */
21412 base_type_cmp (const void *x, const void *y)
21414 dw_die_ref dx = *(const dw_die_ref *) x;
21415 dw_die_ref dy = *(const dw_die_ref *) y;
21416 unsigned int byte_size1, byte_size2;
21417 unsigned int encoding1, encoding2;
21418 if (dx->die_mark > dy->die_mark)
21420 if (dx->die_mark < dy->die_mark)
21422 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
21423 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
21424 if (byte_size1 < byte_size2)
21426 if (byte_size1 > byte_size2)
21428 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
21429 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
21430 if (encoding1 < encoding2)
21432 if (encoding1 > encoding2)
21437 /* Move base types marked by mark_base_types as early as possible
21438 in the CU, sorted by decreasing usage count both to make the
21439 uleb128 references as small as possible and to make sure they
21440 will have die_offset already computed by calc_die_sizes when
21441 sizes of typed stack loc ops is computed. */
21444 move_marked_base_types (void)
21447 dw_die_ref base_type, die, c;
21449 if (VEC_empty (dw_die_ref, base_types))
21452 /* Sort by decreasing usage count, they will be added again in that
21454 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
21455 die = comp_unit_die ();
21456 c = die->die_child;
21459 dw_die_ref prev = c;
21461 while (c->die_mark)
21463 remove_child_with_prev (c, prev);
21464 /* As base types got marked, there must be at least
21465 one node other than DW_TAG_base_type. */
21466 gcc_assert (c != c->die_sib);
21470 while (c != die->die_child);
21471 gcc_assert (die->die_child);
21472 c = die->die_child;
21473 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21475 base_type->die_mark = 0;
21476 base_type->die_sib = c->die_sib;
21477 c->die_sib = base_type;
21482 /* Helper function for resolve_addr, attempt to resolve
21483 one CONST_STRING, return non-zero if not successful. Similarly verify that
21484 SYMBOL_REFs refer to variables emitted in the current CU. */
21487 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
21491 if (GET_CODE (rtl) == CONST_STRING)
21493 size_t len = strlen (XSTR (rtl, 0)) + 1;
21494 tree t = build_string (len, XSTR (rtl, 0));
21495 tree tlen = size_int (len - 1);
21497 = build_array_type (char_type_node, build_index_type (tlen));
21498 rtl = lookup_constant_def (t);
21499 if (!rtl || !MEM_P (rtl))
21501 rtl = XEXP (rtl, 0);
21502 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
21507 if (GET_CODE (rtl) == SYMBOL_REF
21508 && SYMBOL_REF_DECL (rtl))
21510 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
21512 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
21515 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
21519 if (GET_CODE (rtl) == CONST
21520 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
21526 /* Helper function for resolve_addr, handle one location
21527 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21528 the location list couldn't be resolved. */
21531 resolve_addr_in_expr (dw_loc_descr_ref loc)
21533 dw_loc_descr_ref keep = NULL;
21534 for (; loc; loc = loc->dw_loc_next)
21535 switch (loc->dw_loc_opc)
21538 if (resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21541 case DW_OP_const4u:
21542 case DW_OP_const8u:
21544 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21547 case DW_OP_plus_uconst:
21548 if (size_of_loc_descr (loc)
21549 > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
21551 && loc->dw_loc_oprnd1.v.val_unsigned > 0)
21553 dw_loc_descr_ref repl
21554 = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
21555 add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
21556 add_loc_descr (&repl, loc->dw_loc_next);
21560 case DW_OP_implicit_value:
21561 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
21562 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL))
21565 case DW_OP_GNU_implicit_pointer:
21566 case DW_OP_GNU_parameter_ref:
21567 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
21570 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
21573 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
21574 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
21575 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
21578 case DW_OP_GNU_const_type:
21579 case DW_OP_GNU_regval_type:
21580 case DW_OP_GNU_deref_type:
21581 case DW_OP_GNU_convert:
21582 case DW_OP_GNU_reinterpret:
21583 while (loc->dw_loc_next
21584 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
21586 dw_die_ref base1, base2;
21587 unsigned enc1, enc2, size1, size2;
21588 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21589 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21590 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
21591 else if (loc->dw_loc_oprnd1.val_class
21592 == dw_val_class_unsigned_const)
21595 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
21596 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
21597 == dw_val_class_unsigned_const)
21599 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
21600 gcc_assert (base1->die_tag == DW_TAG_base_type
21601 && base2->die_tag == DW_TAG_base_type);
21602 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
21603 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
21604 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
21605 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
21607 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
21608 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
21612 /* Optimize away next DW_OP_GNU_convert after
21613 adjusting LOC's base type die reference. */
21614 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21615 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21616 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
21618 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
21619 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
21622 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21623 point typed stack entry. */
21624 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
21625 keep = loc->dw_loc_next;
21635 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21636 an address in .rodata section if the string literal is emitted there,
21637 or remove the containing location list or replace DW_AT_const_value
21638 with DW_AT_location and empty location expression, if it isn't found
21639 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21640 to something that has been emitted in the current CU. */
21643 resolve_addr (dw_die_ref die)
21647 dw_loc_list_ref *curr, *start, loc;
21650 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21651 switch (AT_class (a))
21653 case dw_val_class_loc_list:
21654 start = curr = AT_loc_list_ptr (a);
21657 /* The same list can be referenced more than once. See if we have
21658 already recorded the result from a previous pass. */
21660 *curr = loc->dw_loc_next;
21661 else if (!loc->resolved_addr)
21663 /* As things stand, we do not expect or allow one die to
21664 reference a suffix of another die's location list chain.
21665 References must be identical or completely separate.
21666 There is therefore no need to cache the result of this
21667 pass on any list other than the first; doing so
21668 would lead to unnecessary writes. */
21671 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
21672 if (!resolve_addr_in_expr ((*curr)->expr))
21674 dw_loc_list_ref next = (*curr)->dw_loc_next;
21675 if (next && (*curr)->ll_symbol)
21677 gcc_assert (!next->ll_symbol);
21678 next->ll_symbol = (*curr)->ll_symbol;
21684 mark_base_types ((*curr)->expr);
21685 curr = &(*curr)->dw_loc_next;
21689 loc->resolved_addr = 1;
21693 loc->dw_loc_next = *start;
21698 remove_AT (die, a->dw_attr);
21702 case dw_val_class_loc:
21703 if (!resolve_addr_in_expr (AT_loc (a)))
21705 remove_AT (die, a->dw_attr);
21709 mark_base_types (AT_loc (a));
21711 case dw_val_class_addr:
21712 if (a->dw_attr == DW_AT_const_value
21713 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
21715 remove_AT (die, a->dw_attr);
21718 if (die->die_tag == DW_TAG_GNU_call_site
21719 && a->dw_attr == DW_AT_abstract_origin)
21721 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
21722 dw_die_ref tdie = lookup_decl_die (tdecl);
21724 && DECL_EXTERNAL (tdecl)
21725 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
21727 force_decl_die (tdecl);
21728 tdie = lookup_decl_die (tdecl);
21732 a->dw_attr_val.val_class = dw_val_class_die_ref;
21733 a->dw_attr_val.v.val_die_ref.die = tdie;
21734 a->dw_attr_val.v.val_die_ref.external = 0;
21738 remove_AT (die, a->dw_attr);
21747 FOR_EACH_CHILD (die, c, resolve_addr (c));
21750 /* Helper routines for optimize_location_lists.
21751 This pass tries to share identical local lists in .debug_loc
21754 /* Iteratively hash operands of LOC opcode. */
21756 static inline hashval_t
21757 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
21759 dw_val_ref val1 = &loc->dw_loc_oprnd1;
21760 dw_val_ref val2 = &loc->dw_loc_oprnd2;
21762 switch (loc->dw_loc_opc)
21764 case DW_OP_const4u:
21765 case DW_OP_const8u:
21769 case DW_OP_const1u:
21770 case DW_OP_const1s:
21771 case DW_OP_const2u:
21772 case DW_OP_const2s:
21773 case DW_OP_const4s:
21774 case DW_OP_const8s:
21778 case DW_OP_plus_uconst:
21814 case DW_OP_deref_size:
21815 case DW_OP_xderef_size:
21816 hash = iterative_hash_object (val1->v.val_int, hash);
21823 gcc_assert (val1->val_class == dw_val_class_loc);
21824 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
21825 hash = iterative_hash_object (offset, hash);
21828 case DW_OP_implicit_value:
21829 hash = iterative_hash_object (val1->v.val_unsigned, hash);
21830 switch (val2->val_class)
21832 case dw_val_class_const:
21833 hash = iterative_hash_object (val2->v.val_int, hash);
21835 case dw_val_class_vec:
21837 unsigned int elt_size = val2->v.val_vec.elt_size;
21838 unsigned int len = val2->v.val_vec.length;
21840 hash = iterative_hash_object (elt_size, hash);
21841 hash = iterative_hash_object (len, hash);
21842 hash = iterative_hash (val2->v.val_vec.array,
21843 len * elt_size, hash);
21846 case dw_val_class_const_double:
21847 hash = iterative_hash_object (val2->v.val_double.low, hash);
21848 hash = iterative_hash_object (val2->v.val_double.high, hash);
21850 case dw_val_class_addr:
21851 hash = iterative_hash_rtx (val2->v.val_addr, hash);
21854 gcc_unreachable ();
21858 case DW_OP_bit_piece:
21859 hash = iterative_hash_object (val1->v.val_int, hash);
21860 hash = iterative_hash_object (val2->v.val_int, hash);
21866 unsigned char dtprel = 0xd1;
21867 hash = iterative_hash_object (dtprel, hash);
21869 hash = iterative_hash_rtx (val1->v.val_addr, hash);
21871 case DW_OP_GNU_implicit_pointer:
21872 hash = iterative_hash_object (val2->v.val_int, hash);
21874 case DW_OP_GNU_entry_value:
21875 hash = hash_loc_operands (val1->v.val_loc, hash);
21877 case DW_OP_GNU_regval_type:
21878 case DW_OP_GNU_deref_type:
21880 unsigned int byte_size
21881 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
21882 unsigned int encoding
21883 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
21884 hash = iterative_hash_object (val1->v.val_int, hash);
21885 hash = iterative_hash_object (byte_size, hash);
21886 hash = iterative_hash_object (encoding, hash);
21889 case DW_OP_GNU_convert:
21890 case DW_OP_GNU_reinterpret:
21891 if (val1->val_class == dw_val_class_unsigned_const)
21893 hash = iterative_hash_object (val1->v.val_unsigned, hash);
21897 case DW_OP_GNU_const_type:
21899 unsigned int byte_size
21900 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
21901 unsigned int encoding
21902 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
21903 hash = iterative_hash_object (byte_size, hash);
21904 hash = iterative_hash_object (encoding, hash);
21905 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
21907 hash = iterative_hash_object (val2->val_class, hash);
21908 switch (val2->val_class)
21910 case dw_val_class_const:
21911 hash = iterative_hash_object (val2->v.val_int, hash);
21913 case dw_val_class_vec:
21915 unsigned int elt_size = val2->v.val_vec.elt_size;
21916 unsigned int len = val2->v.val_vec.length;
21918 hash = iterative_hash_object (elt_size, hash);
21919 hash = iterative_hash_object (len, hash);
21920 hash = iterative_hash (val2->v.val_vec.array,
21921 len * elt_size, hash);
21924 case dw_val_class_const_double:
21925 hash = iterative_hash_object (val2->v.val_double.low, hash);
21926 hash = iterative_hash_object (val2->v.val_double.high, hash);
21929 gcc_unreachable ();
21935 /* Other codes have no operands. */
21941 /* Iteratively hash the whole DWARF location expression LOC. */
21943 static inline hashval_t
21944 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
21946 dw_loc_descr_ref l;
21947 bool sizes_computed = false;
21948 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
21949 size_of_locs (loc);
21951 for (l = loc; l != NULL; l = l->dw_loc_next)
21953 enum dwarf_location_atom opc = l->dw_loc_opc;
21954 hash = iterative_hash_object (opc, hash);
21955 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
21957 size_of_locs (loc);
21958 sizes_computed = true;
21960 hash = hash_loc_operands (l, hash);
21965 /* Compute hash of the whole location list LIST_HEAD. */
21968 hash_loc_list (dw_loc_list_ref list_head)
21970 dw_loc_list_ref curr = list_head;
21971 hashval_t hash = 0;
21973 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
21975 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
21976 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
21978 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
21980 hash = hash_locs (curr->expr, hash);
21982 list_head->hash = hash;
21985 /* Return true if X and Y opcodes have the same operands. */
21988 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
21990 dw_val_ref valx1 = &x->dw_loc_oprnd1;
21991 dw_val_ref valx2 = &x->dw_loc_oprnd2;
21992 dw_val_ref valy1 = &y->dw_loc_oprnd1;
21993 dw_val_ref valy2 = &y->dw_loc_oprnd2;
21995 switch (x->dw_loc_opc)
21997 case DW_OP_const4u:
21998 case DW_OP_const8u:
22002 case DW_OP_const1u:
22003 case DW_OP_const1s:
22004 case DW_OP_const2u:
22005 case DW_OP_const2s:
22006 case DW_OP_const4s:
22007 case DW_OP_const8s:
22011 case DW_OP_plus_uconst:
22047 case DW_OP_deref_size:
22048 case DW_OP_xderef_size:
22049 return valx1->v.val_int == valy1->v.val_int;
22052 gcc_assert (valx1->val_class == dw_val_class_loc
22053 && valy1->val_class == dw_val_class_loc
22054 && x->dw_loc_addr == y->dw_loc_addr);
22055 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
22056 case DW_OP_implicit_value:
22057 if (valx1->v.val_unsigned != valy1->v.val_unsigned
22058 || valx2->val_class != valy2->val_class)
22060 switch (valx2->val_class)
22062 case dw_val_class_const:
22063 return valx2->v.val_int == valy2->v.val_int;
22064 case dw_val_class_vec:
22065 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22066 && valx2->v.val_vec.length == valy2->v.val_vec.length
22067 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22068 valx2->v.val_vec.elt_size
22069 * valx2->v.val_vec.length) == 0;
22070 case dw_val_class_const_double:
22071 return valx2->v.val_double.low == valy2->v.val_double.low
22072 && valx2->v.val_double.high == valy2->v.val_double.high;
22073 case dw_val_class_addr:
22074 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
22076 gcc_unreachable ();
22079 case DW_OP_bit_piece:
22080 return valx1->v.val_int == valy1->v.val_int
22081 && valx2->v.val_int == valy2->v.val_int;
22084 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
22085 case DW_OP_GNU_implicit_pointer:
22086 return valx1->val_class == dw_val_class_die_ref
22087 && valx1->val_class == valy1->val_class
22088 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
22089 && valx2->v.val_int == valy2->v.val_int;
22090 case DW_OP_GNU_entry_value:
22091 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
22092 case DW_OP_GNU_const_type:
22093 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
22094 || valx2->val_class != valy2->val_class)
22096 switch (valx2->val_class)
22098 case dw_val_class_const:
22099 return valx2->v.val_int == valy2->v.val_int;
22100 case dw_val_class_vec:
22101 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22102 && valx2->v.val_vec.length == valy2->v.val_vec.length
22103 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22104 valx2->v.val_vec.elt_size
22105 * valx2->v.val_vec.length) == 0;
22106 case dw_val_class_const_double:
22107 return valx2->v.val_double.low == valy2->v.val_double.low
22108 && valx2->v.val_double.high == valy2->v.val_double.high;
22110 gcc_unreachable ();
22112 case DW_OP_GNU_regval_type:
22113 case DW_OP_GNU_deref_type:
22114 return valx1->v.val_int == valy1->v.val_int
22115 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
22116 case DW_OP_GNU_convert:
22117 case DW_OP_GNU_reinterpret:
22118 if (valx1->val_class != valy1->val_class)
22120 if (valx1->val_class == dw_val_class_unsigned_const)
22121 return valx1->v.val_unsigned == valy1->v.val_unsigned;
22122 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
22123 case DW_OP_GNU_parameter_ref:
22124 return valx1->val_class == dw_val_class_die_ref
22125 && valx1->val_class == valy1->val_class
22126 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
22128 /* Other codes have no operands. */
22133 /* Return true if DWARF location expressions X and Y are the same. */
22136 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
22138 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
22139 if (x->dw_loc_opc != y->dw_loc_opc
22140 || x->dtprel != y->dtprel
22141 || !compare_loc_operands (x, y))
22143 return x == NULL && y == NULL;
22146 /* Return precomputed hash of location list X. */
22149 loc_list_hash (const void *x)
22151 return ((const struct dw_loc_list_struct *) x)->hash;
22154 /* Return 1 if location lists X and Y are the same. */
22157 loc_list_eq (const void *x, const void *y)
22159 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
22160 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
22163 if (a->hash != b->hash)
22165 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
22166 if (strcmp (a->begin, b->begin) != 0
22167 || strcmp (a->end, b->end) != 0
22168 || (a->section == NULL) != (b->section == NULL)
22169 || (a->section && strcmp (a->section, b->section) != 0)
22170 || !compare_locs (a->expr, b->expr))
22172 return a == NULL && b == NULL;
22175 /* Recursively optimize location lists referenced from DIE
22176 children and share them whenever possible. */
22179 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
22186 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22187 if (AT_class (a) == dw_val_class_loc_list)
22189 dw_loc_list_ref list = AT_loc_list (a);
22190 /* TODO: perform some optimizations here, before hashing
22191 it and storing into the hash table. */
22192 hash_loc_list (list);
22193 slot = htab_find_slot_with_hash (htab, list, list->hash,
22196 *slot = (void *) list;
22198 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
22201 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
22204 /* Optimize location lists referenced from DIE
22205 children and share them whenever possible. */
22208 optimize_location_lists (dw_die_ref die)
22210 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
22211 optimize_location_lists_1 (die, htab);
22212 htab_delete (htab);
22215 /* Output stuff that dwarf requires at the end of every file,
22216 and generate the DWARF-2 debugging info. */
22219 dwarf2out_finish (const char *filename)
22221 limbo_die_node *node, *next_node;
22222 comdat_type_node *ctnode;
22223 htab_t comdat_type_table;
22226 /* PCH might result in DW_AT_producer string being restored from the
22227 header compilation, fix it up if needed. */
22228 dw_attr_ref producer = get_AT (comp_unit_die (), DW_AT_producer);
22229 if (strcmp (AT_string (producer), producer_string) != 0)
22231 struct indirect_string_node *node = find_AT_string (producer_string);
22232 producer->dw_attr_val.v.val_str = node;
22235 gen_scheduled_generic_parms_dies ();
22236 gen_remaining_tmpl_value_param_die_attribute ();
22238 /* Add the name for the main input file now. We delayed this from
22239 dwarf2out_init to avoid complications with PCH. */
22240 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
22241 if (!IS_ABSOLUTE_PATH (filename))
22242 add_comp_dir_attribute (comp_unit_die ());
22243 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
22246 htab_traverse (file_table, file_table_relative_p, &p);
22248 add_comp_dir_attribute (comp_unit_die ());
22251 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
22253 add_location_or_const_value_attribute (
22254 VEC_index (deferred_locations, deferred_locations_list, i)->die,
22255 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
22260 /* Traverse the limbo die list, and add parent/child links. The only
22261 dies without parents that should be here are concrete instances of
22262 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22263 For concrete instances, we can get the parent die from the abstract
22265 for (node = limbo_die_list; node; node = next_node)
22267 dw_die_ref die = node->die;
22268 next_node = node->next;
22270 if (die->die_parent == NULL)
22272 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
22274 if (origin && origin->die_parent)
22275 add_child_die (origin->die_parent, die);
22276 else if (is_cu_die (die))
22278 else if (seen_error ())
22279 /* It's OK to be confused by errors in the input. */
22280 add_child_die (comp_unit_die (), die);
22283 /* In certain situations, the lexical block containing a
22284 nested function can be optimized away, which results
22285 in the nested function die being orphaned. Likewise
22286 with the return type of that nested function. Force
22287 this to be a child of the containing function.
22289 It may happen that even the containing function got fully
22290 inlined and optimized out. In that case we are lost and
22291 assign the empty child. This should not be big issue as
22292 the function is likely unreachable too. */
22293 tree context = NULL_TREE;
22295 gcc_assert (node->created_for);
22297 if (DECL_P (node->created_for))
22298 context = DECL_CONTEXT (node->created_for);
22299 else if (TYPE_P (node->created_for))
22300 context = TYPE_CONTEXT (node->created_for);
22302 gcc_assert (context
22303 && (TREE_CODE (context) == FUNCTION_DECL
22304 || TREE_CODE (context) == NAMESPACE_DECL));
22306 origin = lookup_decl_die (context);
22308 add_child_die (origin, die);
22310 add_child_die (comp_unit_die (), die);
22315 limbo_die_list = NULL;
22317 #if ENABLE_ASSERT_CHECKING
22319 dw_die_ref die = comp_unit_die (), c;
22320 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
22323 resolve_addr (comp_unit_die ());
22324 move_marked_base_types ();
22326 for (node = deferred_asm_name; node; node = node->next)
22328 tree decl = node->created_for;
22329 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22331 add_linkage_attr (node->die, decl);
22332 move_linkage_attr (node->die);
22336 deferred_asm_name = NULL;
22338 /* Walk through the list of incomplete types again, trying once more to
22339 emit full debugging info for them. */
22340 retry_incomplete_types ();
22342 if (flag_eliminate_unused_debug_types)
22343 prune_unused_types ();
22345 /* Generate separate CUs for each of the include files we've seen.
22346 They will go into limbo_die_list. */
22347 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22348 break_out_includes (comp_unit_die ());
22350 /* Generate separate COMDAT sections for type DIEs. */
22351 if (use_debug_types)
22353 break_out_comdat_types (comp_unit_die ());
22355 /* Each new type_unit DIE was added to the limbo die list when created.
22356 Since these have all been added to comdat_type_list, clear the
22358 limbo_die_list = NULL;
22360 /* For each new comdat type unit, copy declarations for incomplete
22361 types to make the new unit self-contained (i.e., no direct
22362 references to the main compile unit). */
22363 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22364 copy_decls_for_unworthy_types (ctnode->root_die);
22365 copy_decls_for_unworthy_types (comp_unit_die ());
22367 /* In the process of copying declarations from one unit to another,
22368 we may have left some declarations behind that are no longer
22369 referenced. Prune them. */
22370 prune_unused_types ();
22373 /* Traverse the DIE's and add add sibling attributes to those DIE's
22374 that have children. */
22375 add_sibling_attributes (comp_unit_die ());
22376 for (node = limbo_die_list; node; node = node->next)
22377 add_sibling_attributes (node->die);
22378 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22379 add_sibling_attributes (ctnode->root_die);
22381 /* Output a terminator label for the .text section. */
22382 switch_to_section (text_section);
22383 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
22384 if (cold_text_section)
22386 switch_to_section (cold_text_section);
22387 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
22390 /* We can only use the low/high_pc attributes if all of the code was
22392 if (!have_multiple_function_sections
22393 || (dwarf_version < 3 && dwarf_strict))
22395 /* Don't add if the CU has no associated code. */
22396 if (text_section_used)
22398 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
22399 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
22406 bool range_list_added = false;
22408 if (text_section_used)
22409 add_ranges_by_labels (comp_unit_die (), text_section_label,
22410 text_end_label, &range_list_added);
22411 if (cold_text_section_used)
22412 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
22413 cold_end_label, &range_list_added);
22415 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
22417 if (!fde->in_std_section)
22418 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
22419 fde->dw_fde_end, &range_list_added);
22420 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
22421 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
22422 fde->dw_fde_second_end, &range_list_added);
22425 if (range_list_added)
22427 /* We need to give .debug_loc and .debug_ranges an appropriate
22428 "base address". Use zero so that these addresses become
22429 absolute. Historically, we've emitted the unexpected
22430 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22431 Emit both to give time for other tools to adapt. */
22432 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
22433 if (! dwarf_strict && dwarf_version < 4)
22434 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
22440 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22441 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
22442 debug_line_section_label);
22444 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22445 add_AT_macptr (comp_unit_die (),
22446 dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros,
22447 macinfo_section_label);
22449 if (have_location_lists)
22450 optimize_location_lists (comp_unit_die ());
22452 /* Output all of the compilation units. We put the main one last so that
22453 the offsets are available to output_pubnames. */
22454 for (node = limbo_die_list; node; node = node->next)
22455 output_comp_unit (node->die, 0);
22457 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
22458 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22460 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
22462 /* Don't output duplicate types. */
22463 if (*slot != HTAB_EMPTY_ENTRY)
22466 /* Add a pointer to the line table for the main compilation unit
22467 so that the debugger can make sense of DW_AT_decl_file
22469 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22470 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
22471 debug_line_section_label);
22473 output_comdat_type_unit (ctnode);
22476 htab_delete (comdat_type_table);
22478 /* Output the main compilation unit if non-empty or if .debug_macinfo
22479 will be emitted. */
22480 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
22482 /* Output the abbreviation table. */
22483 if (abbrev_die_table_in_use != 1)
22485 switch_to_section (debug_abbrev_section);
22486 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
22487 output_abbrev_section ();
22490 /* Output location list section if necessary. */
22491 if (have_location_lists)
22493 /* Output the location lists info. */
22494 switch_to_section (debug_loc_section);
22495 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
22496 DEBUG_LOC_SECTION_LABEL, 0);
22497 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
22498 output_location_lists (comp_unit_die ());
22501 /* Output public names table if necessary. */
22502 if (!VEC_empty (pubname_entry, pubname_table))
22504 gcc_assert (info_section_emitted);
22505 switch_to_section (debug_pubnames_section);
22506 output_pubnames (pubname_table);
22509 /* Output public types table if necessary. */
22510 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22511 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22512 simply won't look for the section. */
22513 if (!VEC_empty (pubname_entry, pubtype_table))
22515 bool empty = false;
22517 if (flag_eliminate_unused_debug_types)
22519 /* The pubtypes table might be emptied by pruning unused items. */
22523 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
22524 if (p->die->die_offset != 0)
22532 gcc_assert (info_section_emitted);
22533 switch_to_section (debug_pubtypes_section);
22534 output_pubnames (pubtype_table);
22538 /* Output the address range information if a CU (.debug_info section)
22539 was emitted. We output an empty table even if we had no functions
22540 to put in it. This because the consumer has no way to tell the
22541 difference between an empty table that we omitted and failure to
22542 generate a table that would have contained data. */
22543 if (info_section_emitted)
22545 unsigned long aranges_length = size_of_aranges ();
22547 switch_to_section (debug_aranges_section);
22548 output_aranges (aranges_length);
22551 /* Output ranges section if necessary. */
22552 if (ranges_table_in_use)
22554 switch_to_section (debug_ranges_section);
22555 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
22559 /* Output the source line correspondence table. We must do this
22560 even if there is no line information. Otherwise, on an empty
22561 translation unit, we will generate a present, but empty,
22562 .debug_info section. IRIX 6.5 `nm' will then complain when
22563 examining the file. This is done late so that any filenames
22564 used by the debug_info section are marked as 'used'. */
22565 switch_to_section (debug_line_section);
22566 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
22567 if (! DWARF2_ASM_LINE_DEBUG_INFO)
22568 output_line_info ();
22570 /* Have to end the macro section. */
22571 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22573 switch_to_section (debug_macinfo_section);
22574 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
22575 if (!VEC_empty (macinfo_entry, macinfo_table))
22577 dw2_asm_output_data (1, 0, "End compilation unit");
22580 /* If we emitted any DW_FORM_strp form attribute, output the string
22582 if (debug_str_hash)
22583 htab_traverse (debug_str_hash, output_indirect_string, NULL);
22586 #include "gt-dwarf2out.h"