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 {
2774 unsigned HOST_WIDE_INT code;
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_LINE_SECTION
3422 #define DEBUG_LINE_SECTION ".debug_line"
3424 #ifndef DEBUG_LOC_SECTION
3425 #define DEBUG_LOC_SECTION ".debug_loc"
3427 #ifndef DEBUG_PUBNAMES_SECTION
3428 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3430 #ifndef DEBUG_PUBTYPES_SECTION
3431 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3433 #ifndef DEBUG_STR_SECTION
3434 #define DEBUG_STR_SECTION ".debug_str"
3436 #ifndef DEBUG_RANGES_SECTION
3437 #define DEBUG_RANGES_SECTION ".debug_ranges"
3440 /* Standard ELF section names for compiled code and data. */
3441 #ifndef TEXT_SECTION_NAME
3442 #define TEXT_SECTION_NAME ".text"
3445 /* Section flags for .debug_str section. */
3446 #define DEBUG_STR_SECTION_FLAGS \
3447 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3448 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3451 /* Labels we insert at beginning sections we can reference instead of
3452 the section names themselves. */
3454 #ifndef TEXT_SECTION_LABEL
3455 #define TEXT_SECTION_LABEL "Ltext"
3457 #ifndef COLD_TEXT_SECTION_LABEL
3458 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3460 #ifndef DEBUG_LINE_SECTION_LABEL
3461 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3463 #ifndef DEBUG_INFO_SECTION_LABEL
3464 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3466 #ifndef DEBUG_ABBREV_SECTION_LABEL
3467 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3469 #ifndef DEBUG_LOC_SECTION_LABEL
3470 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3472 #ifndef DEBUG_RANGES_SECTION_LABEL
3473 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3475 #ifndef DEBUG_MACINFO_SECTION_LABEL
3476 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3480 /* Definitions of defaults for formats and names of various special
3481 (artificial) labels which may be generated within this file (when the -g
3482 options is used and DWARF2_DEBUGGING_INFO is in effect.
3483 If necessary, these may be overridden from within the tm.h file, but
3484 typically, overriding these defaults is unnecessary. */
3486 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3487 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3488 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3489 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3490 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3491 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3492 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3493 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3494 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3495 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3497 #ifndef TEXT_END_LABEL
3498 #define TEXT_END_LABEL "Letext"
3500 #ifndef COLD_END_LABEL
3501 #define COLD_END_LABEL "Letext_cold"
3503 #ifndef BLOCK_BEGIN_LABEL
3504 #define BLOCK_BEGIN_LABEL "LBB"
3506 #ifndef BLOCK_END_LABEL
3507 #define BLOCK_END_LABEL "LBE"
3509 #ifndef LINE_CODE_LABEL
3510 #define LINE_CODE_LABEL "LM"
3514 /* Return the root of the DIE's built for the current compilation unit. */
3516 comp_unit_die (void)
3518 if (!single_comp_unit_die)
3519 single_comp_unit_die = gen_compile_unit_die (NULL);
3520 return single_comp_unit_die;
3523 /* We allow a language front-end to designate a function that is to be
3524 called to "demangle" any name before it is put into a DIE. */
3526 static const char *(*demangle_name_func) (const char *);
3529 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3531 demangle_name_func = func;
3534 /* Test if rtl node points to a pseudo register. */
3537 is_pseudo_reg (const_rtx rtl)
3539 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3540 || (GET_CODE (rtl) == SUBREG
3541 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3544 /* Return a reference to a type, with its const and volatile qualifiers
3548 type_main_variant (tree type)
3550 type = TYPE_MAIN_VARIANT (type);
3552 /* ??? There really should be only one main variant among any group of
3553 variants of a given type (and all of the MAIN_VARIANT values for all
3554 members of the group should point to that one type) but sometimes the C
3555 front-end messes this up for array types, so we work around that bug
3557 if (TREE_CODE (type) == ARRAY_TYPE)
3558 while (type != TYPE_MAIN_VARIANT (type))
3559 type = TYPE_MAIN_VARIANT (type);
3564 /* Return nonzero if the given type node represents a tagged type. */
3567 is_tagged_type (const_tree type)
3569 enum tree_code code = TREE_CODE (type);
3571 return (code == RECORD_TYPE || code == UNION_TYPE
3572 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3575 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3578 get_ref_die_offset_label (char *label, dw_die_ref ref)
3580 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
3583 /* Return die_offset of a DIE reference to a base type. */
3585 static unsigned long int
3586 get_base_type_offset (dw_die_ref ref)
3588 if (ref->die_offset)
3589 return ref->die_offset;
3590 if (comp_unit_die ()->die_abbrev)
3592 calc_base_type_die_sizes ();
3593 gcc_assert (ref->die_offset);
3595 return ref->die_offset;
3598 /* Return die_offset of a DIE reference other than base type. */
3600 static unsigned long int
3601 get_ref_die_offset (dw_die_ref ref)
3603 gcc_assert (ref->die_offset);
3604 return ref->die_offset;
3607 /* Convert a DIE tag into its string name. */
3610 dwarf_tag_name (unsigned int tag)
3614 case DW_TAG_padding:
3615 return "DW_TAG_padding";
3616 case DW_TAG_array_type:
3617 return "DW_TAG_array_type";
3618 case DW_TAG_class_type:
3619 return "DW_TAG_class_type";
3620 case DW_TAG_entry_point:
3621 return "DW_TAG_entry_point";
3622 case DW_TAG_enumeration_type:
3623 return "DW_TAG_enumeration_type";
3624 case DW_TAG_formal_parameter:
3625 return "DW_TAG_formal_parameter";
3626 case DW_TAG_imported_declaration:
3627 return "DW_TAG_imported_declaration";
3629 return "DW_TAG_label";
3630 case DW_TAG_lexical_block:
3631 return "DW_TAG_lexical_block";
3633 return "DW_TAG_member";
3634 case DW_TAG_pointer_type:
3635 return "DW_TAG_pointer_type";
3636 case DW_TAG_reference_type:
3637 return "DW_TAG_reference_type";
3638 case DW_TAG_compile_unit:
3639 return "DW_TAG_compile_unit";
3640 case DW_TAG_string_type:
3641 return "DW_TAG_string_type";
3642 case DW_TAG_structure_type:
3643 return "DW_TAG_structure_type";
3644 case DW_TAG_subroutine_type:
3645 return "DW_TAG_subroutine_type";
3646 case DW_TAG_typedef:
3647 return "DW_TAG_typedef";
3648 case DW_TAG_union_type:
3649 return "DW_TAG_union_type";
3650 case DW_TAG_unspecified_parameters:
3651 return "DW_TAG_unspecified_parameters";
3652 case DW_TAG_variant:
3653 return "DW_TAG_variant";
3654 case DW_TAG_common_block:
3655 return "DW_TAG_common_block";
3656 case DW_TAG_common_inclusion:
3657 return "DW_TAG_common_inclusion";
3658 case DW_TAG_inheritance:
3659 return "DW_TAG_inheritance";
3660 case DW_TAG_inlined_subroutine:
3661 return "DW_TAG_inlined_subroutine";
3663 return "DW_TAG_module";
3664 case DW_TAG_ptr_to_member_type:
3665 return "DW_TAG_ptr_to_member_type";
3666 case DW_TAG_set_type:
3667 return "DW_TAG_set_type";
3668 case DW_TAG_subrange_type:
3669 return "DW_TAG_subrange_type";
3670 case DW_TAG_with_stmt:
3671 return "DW_TAG_with_stmt";
3672 case DW_TAG_access_declaration:
3673 return "DW_TAG_access_declaration";
3674 case DW_TAG_base_type:
3675 return "DW_TAG_base_type";
3676 case DW_TAG_catch_block:
3677 return "DW_TAG_catch_block";
3678 case DW_TAG_const_type:
3679 return "DW_TAG_const_type";
3680 case DW_TAG_constant:
3681 return "DW_TAG_constant";
3682 case DW_TAG_enumerator:
3683 return "DW_TAG_enumerator";
3684 case DW_TAG_file_type:
3685 return "DW_TAG_file_type";
3687 return "DW_TAG_friend";
3688 case DW_TAG_namelist:
3689 return "DW_TAG_namelist";
3690 case DW_TAG_namelist_item:
3691 return "DW_TAG_namelist_item";
3692 case DW_TAG_packed_type:
3693 return "DW_TAG_packed_type";
3694 case DW_TAG_subprogram:
3695 return "DW_TAG_subprogram";
3696 case DW_TAG_template_type_param:
3697 return "DW_TAG_template_type_param";
3698 case DW_TAG_template_value_param:
3699 return "DW_TAG_template_value_param";
3700 case DW_TAG_thrown_type:
3701 return "DW_TAG_thrown_type";
3702 case DW_TAG_try_block:
3703 return "DW_TAG_try_block";
3704 case DW_TAG_variant_part:
3705 return "DW_TAG_variant_part";
3706 case DW_TAG_variable:
3707 return "DW_TAG_variable";
3708 case DW_TAG_volatile_type:
3709 return "DW_TAG_volatile_type";
3710 case DW_TAG_dwarf_procedure:
3711 return "DW_TAG_dwarf_procedure";
3712 case DW_TAG_restrict_type:
3713 return "DW_TAG_restrict_type";
3714 case DW_TAG_interface_type:
3715 return "DW_TAG_interface_type";
3716 case DW_TAG_namespace:
3717 return "DW_TAG_namespace";
3718 case DW_TAG_imported_module:
3719 return "DW_TAG_imported_module";
3720 case DW_TAG_unspecified_type:
3721 return "DW_TAG_unspecified_type";
3722 case DW_TAG_partial_unit:
3723 return "DW_TAG_partial_unit";
3724 case DW_TAG_imported_unit:
3725 return "DW_TAG_imported_unit";
3726 case DW_TAG_condition:
3727 return "DW_TAG_condition";
3728 case DW_TAG_shared_type:
3729 return "DW_TAG_shared_type";
3730 case DW_TAG_type_unit:
3731 return "DW_TAG_type_unit";
3732 case DW_TAG_rvalue_reference_type:
3733 return "DW_TAG_rvalue_reference_type";
3734 case DW_TAG_template_alias:
3735 return "DW_TAG_template_alias";
3736 case DW_TAG_GNU_template_parameter_pack:
3737 return "DW_TAG_GNU_template_parameter_pack";
3738 case DW_TAG_GNU_formal_parameter_pack:
3739 return "DW_TAG_GNU_formal_parameter_pack";
3740 case DW_TAG_MIPS_loop:
3741 return "DW_TAG_MIPS_loop";
3742 case DW_TAG_format_label:
3743 return "DW_TAG_format_label";
3744 case DW_TAG_function_template:
3745 return "DW_TAG_function_template";
3746 case DW_TAG_class_template:
3747 return "DW_TAG_class_template";
3748 case DW_TAG_GNU_BINCL:
3749 return "DW_TAG_GNU_BINCL";
3750 case DW_TAG_GNU_EINCL:
3751 return "DW_TAG_GNU_EINCL";
3752 case DW_TAG_GNU_template_template_param:
3753 return "DW_TAG_GNU_template_template_param";
3754 case DW_TAG_GNU_call_site:
3755 return "DW_TAG_GNU_call_site";
3756 case DW_TAG_GNU_call_site_parameter:
3757 return "DW_TAG_GNU_call_site_parameter";
3759 return "DW_TAG_<unknown>";
3763 /* Convert a DWARF attribute code into its string name. */
3766 dwarf_attr_name (unsigned int attr)
3771 return "DW_AT_sibling";
3772 case DW_AT_location:
3773 return "DW_AT_location";
3775 return "DW_AT_name";
3776 case DW_AT_ordering:
3777 return "DW_AT_ordering";
3778 case DW_AT_subscr_data:
3779 return "DW_AT_subscr_data";
3780 case DW_AT_byte_size:
3781 return "DW_AT_byte_size";
3782 case DW_AT_bit_offset:
3783 return "DW_AT_bit_offset";
3784 case DW_AT_bit_size:
3785 return "DW_AT_bit_size";
3786 case DW_AT_element_list:
3787 return "DW_AT_element_list";
3788 case DW_AT_stmt_list:
3789 return "DW_AT_stmt_list";
3791 return "DW_AT_low_pc";
3793 return "DW_AT_high_pc";
3794 case DW_AT_language:
3795 return "DW_AT_language";
3797 return "DW_AT_member";
3799 return "DW_AT_discr";
3800 case DW_AT_discr_value:
3801 return "DW_AT_discr_value";
3802 case DW_AT_visibility:
3803 return "DW_AT_visibility";
3805 return "DW_AT_import";
3806 case DW_AT_string_length:
3807 return "DW_AT_string_length";
3808 case DW_AT_common_reference:
3809 return "DW_AT_common_reference";
3810 case DW_AT_comp_dir:
3811 return "DW_AT_comp_dir";
3812 case DW_AT_const_value:
3813 return "DW_AT_const_value";
3814 case DW_AT_containing_type:
3815 return "DW_AT_containing_type";
3816 case DW_AT_default_value:
3817 return "DW_AT_default_value";
3819 return "DW_AT_inline";
3820 case DW_AT_is_optional:
3821 return "DW_AT_is_optional";
3822 case DW_AT_lower_bound:
3823 return "DW_AT_lower_bound";
3824 case DW_AT_producer:
3825 return "DW_AT_producer";
3826 case DW_AT_prototyped:
3827 return "DW_AT_prototyped";
3828 case DW_AT_return_addr:
3829 return "DW_AT_return_addr";
3830 case DW_AT_start_scope:
3831 return "DW_AT_start_scope";
3832 case DW_AT_bit_stride:
3833 return "DW_AT_bit_stride";
3834 case DW_AT_upper_bound:
3835 return "DW_AT_upper_bound";
3836 case DW_AT_abstract_origin:
3837 return "DW_AT_abstract_origin";
3838 case DW_AT_accessibility:
3839 return "DW_AT_accessibility";
3840 case DW_AT_address_class:
3841 return "DW_AT_address_class";
3842 case DW_AT_artificial:
3843 return "DW_AT_artificial";
3844 case DW_AT_base_types:
3845 return "DW_AT_base_types";
3846 case DW_AT_calling_convention:
3847 return "DW_AT_calling_convention";
3849 return "DW_AT_count";
3850 case DW_AT_data_member_location:
3851 return "DW_AT_data_member_location";
3852 case DW_AT_decl_column:
3853 return "DW_AT_decl_column";
3854 case DW_AT_decl_file:
3855 return "DW_AT_decl_file";
3856 case DW_AT_decl_line:
3857 return "DW_AT_decl_line";
3858 case DW_AT_declaration:
3859 return "DW_AT_declaration";
3860 case DW_AT_discr_list:
3861 return "DW_AT_discr_list";
3862 case DW_AT_encoding:
3863 return "DW_AT_encoding";
3864 case DW_AT_external:
3865 return "DW_AT_external";
3866 case DW_AT_explicit:
3867 return "DW_AT_explicit";
3868 case DW_AT_frame_base:
3869 return "DW_AT_frame_base";
3871 return "DW_AT_friend";
3872 case DW_AT_identifier_case:
3873 return "DW_AT_identifier_case";
3874 case DW_AT_macro_info:
3875 return "DW_AT_macro_info";
3876 case DW_AT_namelist_items:
3877 return "DW_AT_namelist_items";
3878 case DW_AT_priority:
3879 return "DW_AT_priority";
3881 return "DW_AT_segment";
3882 case DW_AT_specification:
3883 return "DW_AT_specification";
3884 case DW_AT_static_link:
3885 return "DW_AT_static_link";
3887 return "DW_AT_type";
3888 case DW_AT_use_location:
3889 return "DW_AT_use_location";
3890 case DW_AT_variable_parameter:
3891 return "DW_AT_variable_parameter";
3892 case DW_AT_virtuality:
3893 return "DW_AT_virtuality";
3894 case DW_AT_vtable_elem_location:
3895 return "DW_AT_vtable_elem_location";
3897 case DW_AT_allocated:
3898 return "DW_AT_allocated";
3899 case DW_AT_associated:
3900 return "DW_AT_associated";
3901 case DW_AT_data_location:
3902 return "DW_AT_data_location";
3903 case DW_AT_byte_stride:
3904 return "DW_AT_byte_stride";
3905 case DW_AT_entry_pc:
3906 return "DW_AT_entry_pc";
3907 case DW_AT_use_UTF8:
3908 return "DW_AT_use_UTF8";
3909 case DW_AT_extension:
3910 return "DW_AT_extension";
3912 return "DW_AT_ranges";
3913 case DW_AT_trampoline:
3914 return "DW_AT_trampoline";
3915 case DW_AT_call_column:
3916 return "DW_AT_call_column";
3917 case DW_AT_call_file:
3918 return "DW_AT_call_file";
3919 case DW_AT_call_line:
3920 return "DW_AT_call_line";
3921 case DW_AT_object_pointer:
3922 return "DW_AT_object_pointer";
3924 case DW_AT_signature:
3925 return "DW_AT_signature";
3926 case DW_AT_main_subprogram:
3927 return "DW_AT_main_subprogram";
3928 case DW_AT_data_bit_offset:
3929 return "DW_AT_data_bit_offset";
3930 case DW_AT_const_expr:
3931 return "DW_AT_const_expr";
3932 case DW_AT_enum_class:
3933 return "DW_AT_enum_class";
3934 case DW_AT_linkage_name:
3935 return "DW_AT_linkage_name";
3937 case DW_AT_MIPS_fde:
3938 return "DW_AT_MIPS_fde";
3939 case DW_AT_MIPS_loop_begin:
3940 return "DW_AT_MIPS_loop_begin";
3941 case DW_AT_MIPS_tail_loop_begin:
3942 return "DW_AT_MIPS_tail_loop_begin";
3943 case DW_AT_MIPS_epilog_begin:
3944 return "DW_AT_MIPS_epilog_begin";
3945 #if VMS_DEBUGGING_INFO
3946 case DW_AT_HP_prologue:
3947 return "DW_AT_HP_prologue";
3949 case DW_AT_MIPS_loop_unroll_factor:
3950 return "DW_AT_MIPS_loop_unroll_factor";
3952 case DW_AT_MIPS_software_pipeline_depth:
3953 return "DW_AT_MIPS_software_pipeline_depth";
3954 case DW_AT_MIPS_linkage_name:
3955 return "DW_AT_MIPS_linkage_name";
3956 #if VMS_DEBUGGING_INFO
3957 case DW_AT_HP_epilogue:
3958 return "DW_AT_HP_epilogue";
3960 case DW_AT_MIPS_stride:
3961 return "DW_AT_MIPS_stride";
3963 case DW_AT_MIPS_abstract_name:
3964 return "DW_AT_MIPS_abstract_name";
3965 case DW_AT_MIPS_clone_origin:
3966 return "DW_AT_MIPS_clone_origin";
3967 case DW_AT_MIPS_has_inlines:
3968 return "DW_AT_MIPS_has_inlines";
3970 case DW_AT_sf_names:
3971 return "DW_AT_sf_names";
3972 case DW_AT_src_info:
3973 return "DW_AT_src_info";
3974 case DW_AT_mac_info:
3975 return "DW_AT_mac_info";
3976 case DW_AT_src_coords:
3977 return "DW_AT_src_coords";
3978 case DW_AT_body_begin:
3979 return "DW_AT_body_begin";
3980 case DW_AT_body_end:
3981 return "DW_AT_body_end";
3983 case DW_AT_GNU_vector:
3984 return "DW_AT_GNU_vector";
3985 case DW_AT_GNU_guarded_by:
3986 return "DW_AT_GNU_guarded_by";
3987 case DW_AT_GNU_pt_guarded_by:
3988 return "DW_AT_GNU_pt_guarded_by";
3989 case DW_AT_GNU_guarded:
3990 return "DW_AT_GNU_guarded";
3991 case DW_AT_GNU_pt_guarded:
3992 return "DW_AT_GNU_pt_guarded";
3993 case DW_AT_GNU_locks_excluded:
3994 return "DW_AT_GNU_locks_excluded";
3995 case DW_AT_GNU_exclusive_locks_required:
3996 return "DW_AT_GNU_exclusive_locks_required";
3997 case DW_AT_GNU_shared_locks_required:
3998 return "DW_AT_GNU_shared_locks_required";
3999 case DW_AT_GNU_odr_signature:
4000 return "DW_AT_GNU_odr_signature";
4001 case DW_AT_GNU_template_name:
4002 return "DW_AT_GNU_template_name";
4003 case DW_AT_GNU_call_site_value:
4004 return "DW_AT_GNU_call_site_value";
4005 case DW_AT_GNU_call_site_data_value:
4006 return "DW_AT_GNU_call_site_data_value";
4007 case DW_AT_GNU_call_site_target:
4008 return "DW_AT_GNU_call_site_target";
4009 case DW_AT_GNU_call_site_target_clobbered:
4010 return "DW_AT_GNU_call_site_target_clobbered";
4011 case DW_AT_GNU_tail_call:
4012 return "DW_AT_GNU_tail_call";
4013 case DW_AT_GNU_all_tail_call_sites:
4014 return "DW_AT_GNU_all_tail_call_sites";
4015 case DW_AT_GNU_all_call_sites:
4016 return "DW_AT_GNU_all_call_sites";
4017 case DW_AT_GNU_all_source_call_sites:
4018 return "DW_AT_GNU_all_source_call_sites";
4020 case DW_AT_GNAT_descriptive_type:
4021 return "DW_AT_GNAT_descriptive_type";
4023 case DW_AT_VMS_rtnbeg_pd_address:
4024 return "DW_AT_VMS_rtnbeg_pd_address";
4027 return "DW_AT_<unknown>";
4031 /* Convert a DWARF value form code into its string name. */
4034 dwarf_form_name (unsigned int form)
4039 return "DW_FORM_addr";
4040 case DW_FORM_block2:
4041 return "DW_FORM_block2";
4042 case DW_FORM_block4:
4043 return "DW_FORM_block4";
4045 return "DW_FORM_data2";
4047 return "DW_FORM_data4";
4049 return "DW_FORM_data8";
4050 case DW_FORM_string:
4051 return "DW_FORM_string";
4053 return "DW_FORM_block";
4054 case DW_FORM_block1:
4055 return "DW_FORM_block1";
4057 return "DW_FORM_data1";
4059 return "DW_FORM_flag";
4061 return "DW_FORM_sdata";
4063 return "DW_FORM_strp";
4065 return "DW_FORM_udata";
4066 case DW_FORM_ref_addr:
4067 return "DW_FORM_ref_addr";
4069 return "DW_FORM_ref1";
4071 return "DW_FORM_ref2";
4073 return "DW_FORM_ref4";
4075 return "DW_FORM_ref8";
4076 case DW_FORM_ref_udata:
4077 return "DW_FORM_ref_udata";
4078 case DW_FORM_indirect:
4079 return "DW_FORM_indirect";
4080 case DW_FORM_sec_offset:
4081 return "DW_FORM_sec_offset";
4082 case DW_FORM_exprloc:
4083 return "DW_FORM_exprloc";
4084 case DW_FORM_flag_present:
4085 return "DW_FORM_flag_present";
4086 case DW_FORM_ref_sig8:
4087 return "DW_FORM_ref_sig8";
4089 return "DW_FORM_<unknown>";
4093 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4094 instance of an inlined instance of a decl which is local to an inline
4095 function, so we have to trace all of the way back through the origin chain
4096 to find out what sort of node actually served as the original seed for the
4100 decl_ultimate_origin (const_tree decl)
4102 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4105 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4106 nodes in the function to point to themselves; ignore that if
4107 we're trying to output the abstract instance of this function. */
4108 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4111 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4112 most distant ancestor, this should never happen. */
4113 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4115 return DECL_ABSTRACT_ORIGIN (decl);
4118 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4119 of a virtual function may refer to a base class, so we check the 'this'
4123 decl_class_context (tree decl)
4125 tree context = NULL_TREE;
4127 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4128 context = DECL_CONTEXT (decl);
4130 context = TYPE_MAIN_VARIANT
4131 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4133 if (context && !TYPE_P (context))
4134 context = NULL_TREE;
4139 /* Add an attribute/value pair to a DIE. */
4142 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4144 /* Maybe this should be an assert? */
4148 if (die->die_attr == NULL)
4149 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4150 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4153 static inline enum dw_val_class
4154 AT_class (dw_attr_ref a)
4156 return a->dw_attr_val.val_class;
4159 /* Add a flag value attribute to a DIE. */
4162 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4166 attr.dw_attr = attr_kind;
4167 attr.dw_attr_val.val_class = dw_val_class_flag;
4168 attr.dw_attr_val.v.val_flag = flag;
4169 add_dwarf_attr (die, &attr);
4172 static inline unsigned
4173 AT_flag (dw_attr_ref a)
4175 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4176 return a->dw_attr_val.v.val_flag;
4179 /* Add a signed integer attribute value to a DIE. */
4182 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4186 attr.dw_attr = attr_kind;
4187 attr.dw_attr_val.val_class = dw_val_class_const;
4188 attr.dw_attr_val.v.val_int = int_val;
4189 add_dwarf_attr (die, &attr);
4192 static inline HOST_WIDE_INT
4193 AT_int (dw_attr_ref a)
4195 gcc_assert (a && AT_class (a) == dw_val_class_const);
4196 return a->dw_attr_val.v.val_int;
4199 /* Add an unsigned integer attribute value to a DIE. */
4202 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4203 unsigned HOST_WIDE_INT unsigned_val)
4207 attr.dw_attr = attr_kind;
4208 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4209 attr.dw_attr_val.v.val_unsigned = unsigned_val;
4210 add_dwarf_attr (die, &attr);
4213 static inline unsigned HOST_WIDE_INT
4214 AT_unsigned (dw_attr_ref a)
4216 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4217 return a->dw_attr_val.v.val_unsigned;
4220 /* Add an unsigned double integer attribute value to a DIE. */
4223 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
4224 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
4228 attr.dw_attr = attr_kind;
4229 attr.dw_attr_val.val_class = dw_val_class_const_double;
4230 attr.dw_attr_val.v.val_double.high = high;
4231 attr.dw_attr_val.v.val_double.low = low;
4232 add_dwarf_attr (die, &attr);
4235 /* Add a floating point attribute value to a DIE and return it. */
4238 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4239 unsigned int length, unsigned int elt_size, unsigned char *array)
4243 attr.dw_attr = attr_kind;
4244 attr.dw_attr_val.val_class = dw_val_class_vec;
4245 attr.dw_attr_val.v.val_vec.length = length;
4246 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4247 attr.dw_attr_val.v.val_vec.array = array;
4248 add_dwarf_attr (die, &attr);
4251 /* Add an 8-byte data attribute value to a DIE. */
4254 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
4255 unsigned char data8[8])
4259 attr.dw_attr = attr_kind;
4260 attr.dw_attr_val.val_class = dw_val_class_data8;
4261 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
4262 add_dwarf_attr (die, &attr);
4265 /* Hash and equality functions for debug_str_hash. */
4268 debug_str_do_hash (const void *x)
4270 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4274 debug_str_eq (const void *x1, const void *x2)
4276 return strcmp ((((const struct indirect_string_node *)x1)->str),
4277 (const char *)x2) == 0;
4280 /* Add STR to the indirect string hash table. */
4282 static struct indirect_string_node *
4283 find_AT_string (const char *str)
4285 struct indirect_string_node *node;
4288 if (! debug_str_hash)
4289 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4290 debug_str_eq, NULL);
4292 slot = htab_find_slot_with_hash (debug_str_hash, str,
4293 htab_hash_string (str), INSERT);
4296 node = ggc_alloc_cleared_indirect_string_node ();
4297 node->str = ggc_strdup (str);
4301 node = (struct indirect_string_node *) *slot;
4307 /* Add a string attribute value to a DIE. */
4310 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4313 struct indirect_string_node *node;
4315 node = find_AT_string (str);
4317 attr.dw_attr = attr_kind;
4318 attr.dw_attr_val.val_class = dw_val_class_str;
4319 attr.dw_attr_val.v.val_str = node;
4320 add_dwarf_attr (die, &attr);
4323 static inline const char *
4324 AT_string (dw_attr_ref a)
4326 gcc_assert (a && AT_class (a) == dw_val_class_str);
4327 return a->dw_attr_val.v.val_str->str;
4330 /* Find out whether a string should be output inline in DIE
4331 or out-of-line in .debug_str section. */
4333 static enum dwarf_form
4334 AT_string_form (dw_attr_ref a)
4336 struct indirect_string_node *node;
4340 gcc_assert (a && AT_class (a) == dw_val_class_str);
4342 node = a->dw_attr_val.v.val_str;
4346 len = strlen (node->str) + 1;
4348 /* If the string is shorter or equal to the size of the reference, it is
4349 always better to put it inline. */
4350 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4351 return node->form = DW_FORM_string;
4353 /* If we cannot expect the linker to merge strings in .debug_str
4354 section, only put it into .debug_str if it is worth even in this
4356 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4357 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
4358 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
4359 return node->form = DW_FORM_string;
4361 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4362 ++dw2_string_counter;
4363 node->label = xstrdup (label);
4365 return node->form = DW_FORM_strp;
4368 /* Add a DIE reference attribute value to a DIE. */
4371 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4375 #ifdef ENABLE_CHECKING
4376 gcc_assert (targ_die != NULL);
4378 /* With LTO we can end up trying to reference something we didn't create
4379 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4380 if (targ_die == NULL)
4384 attr.dw_attr = attr_kind;
4385 attr.dw_attr_val.val_class = dw_val_class_die_ref;
4386 attr.dw_attr_val.v.val_die_ref.die = targ_die;
4387 attr.dw_attr_val.v.val_die_ref.external = 0;
4388 add_dwarf_attr (die, &attr);
4391 /* Add an AT_specification attribute to a DIE, and also make the back
4392 pointer from the specification to the definition. */
4395 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4397 add_AT_die_ref (die, DW_AT_specification, targ_die);
4398 gcc_assert (!targ_die->die_definition);
4399 targ_die->die_definition = die;
4402 static inline dw_die_ref
4403 AT_ref (dw_attr_ref a)
4405 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4406 return a->dw_attr_val.v.val_die_ref.die;
4410 AT_ref_external (dw_attr_ref a)
4412 if (a && AT_class (a) == dw_val_class_die_ref)
4413 return a->dw_attr_val.v.val_die_ref.external;
4419 set_AT_ref_external (dw_attr_ref a, int i)
4421 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4422 a->dw_attr_val.v.val_die_ref.external = i;
4425 /* Add an FDE reference attribute value to a DIE. */
4428 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4432 attr.dw_attr = attr_kind;
4433 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
4434 attr.dw_attr_val.v.val_fde_index = targ_fde;
4435 add_dwarf_attr (die, &attr);
4438 /* Add a location description attribute value to a DIE. */
4441 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4445 attr.dw_attr = attr_kind;
4446 attr.dw_attr_val.val_class = dw_val_class_loc;
4447 attr.dw_attr_val.v.val_loc = loc;
4448 add_dwarf_attr (die, &attr);
4451 static inline dw_loc_descr_ref
4452 AT_loc (dw_attr_ref a)
4454 gcc_assert (a && AT_class (a) == dw_val_class_loc);
4455 return a->dw_attr_val.v.val_loc;
4459 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4463 attr.dw_attr = attr_kind;
4464 attr.dw_attr_val.val_class = dw_val_class_loc_list;
4465 attr.dw_attr_val.v.val_loc_list = loc_list;
4466 add_dwarf_attr (die, &attr);
4467 have_location_lists = true;
4470 static inline dw_loc_list_ref
4471 AT_loc_list (dw_attr_ref a)
4473 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4474 return a->dw_attr_val.v.val_loc_list;
4477 static inline dw_loc_list_ref *
4478 AT_loc_list_ptr (dw_attr_ref a)
4480 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4481 return &a->dw_attr_val.v.val_loc_list;
4484 /* Add an address constant attribute value to a DIE. */
4487 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
4491 attr.dw_attr = attr_kind;
4492 attr.dw_attr_val.val_class = dw_val_class_addr;
4493 attr.dw_attr_val.v.val_addr = addr;
4494 add_dwarf_attr (die, &attr);
4497 /* Get the RTX from to an address DIE attribute. */
4500 AT_addr (dw_attr_ref a)
4502 gcc_assert (a && AT_class (a) == dw_val_class_addr);
4503 return a->dw_attr_val.v.val_addr;
4506 /* Add a file attribute value to a DIE. */
4509 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
4510 struct dwarf_file_data *fd)
4514 attr.dw_attr = attr_kind;
4515 attr.dw_attr_val.val_class = dw_val_class_file;
4516 attr.dw_attr_val.v.val_file = fd;
4517 add_dwarf_attr (die, &attr);
4520 /* Get the dwarf_file_data from a file DIE attribute. */
4522 static inline struct dwarf_file_data *
4523 AT_file (dw_attr_ref a)
4525 gcc_assert (a && AT_class (a) == dw_val_class_file);
4526 return a->dw_attr_val.v.val_file;
4529 /* Add a vms delta attribute value to a DIE. */
4532 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
4533 const char *lbl1, const char *lbl2)
4537 attr.dw_attr = attr_kind;
4538 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
4539 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
4540 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
4541 add_dwarf_attr (die, &attr);
4544 /* Add a label identifier attribute value to a DIE. */
4547 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
4551 attr.dw_attr = attr_kind;
4552 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4553 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4554 add_dwarf_attr (die, &attr);
4557 /* Add a section offset attribute value to a DIE, an offset into the
4558 debug_line section. */
4561 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4566 attr.dw_attr = attr_kind;
4567 attr.dw_attr_val.val_class = dw_val_class_lineptr;
4568 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4569 add_dwarf_attr (die, &attr);
4572 /* Add a section offset attribute value to a DIE, an offset into the
4573 debug_macinfo section. */
4576 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
4581 attr.dw_attr = attr_kind;
4582 attr.dw_attr_val.val_class = dw_val_class_macptr;
4583 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
4584 add_dwarf_attr (die, &attr);
4587 /* Add an offset attribute value to a DIE. */
4590 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
4591 unsigned HOST_WIDE_INT offset)
4595 attr.dw_attr = attr_kind;
4596 attr.dw_attr_val.val_class = dw_val_class_offset;
4597 attr.dw_attr_val.v.val_offset = offset;
4598 add_dwarf_attr (die, &attr);
4601 /* Add an range_list attribute value to a DIE. */
4604 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4605 long unsigned int offset)
4609 attr.dw_attr = attr_kind;
4610 attr.dw_attr_val.val_class = dw_val_class_range_list;
4611 attr.dw_attr_val.v.val_offset = offset;
4612 add_dwarf_attr (die, &attr);
4615 /* Return the start label of a delta attribute. */
4617 static inline const char *
4618 AT_vms_delta1 (dw_attr_ref a)
4620 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4621 return a->dw_attr_val.v.val_vms_delta.lbl1;
4624 /* Return the end label of a delta attribute. */
4626 static inline const char *
4627 AT_vms_delta2 (dw_attr_ref a)
4629 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
4630 return a->dw_attr_val.v.val_vms_delta.lbl2;
4633 static inline const char *
4634 AT_lbl (dw_attr_ref a)
4636 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
4637 || AT_class (a) == dw_val_class_lineptr
4638 || AT_class (a) == dw_val_class_macptr));
4639 return a->dw_attr_val.v.val_lbl_id;
4642 /* Get the attribute of type attr_kind. */
4645 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4649 dw_die_ref spec = NULL;
4654 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
4655 if (a->dw_attr == attr_kind)
4657 else if (a->dw_attr == DW_AT_specification
4658 || a->dw_attr == DW_AT_abstract_origin)
4662 return get_AT (spec, attr_kind);
4667 /* Return the "low pc" attribute value, typically associated with a subprogram
4668 DIE. Return null if the "low pc" attribute is either not present, or if it
4669 cannot be represented as an assembler label identifier. */
4671 static inline const char *
4672 get_AT_low_pc (dw_die_ref die)
4674 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4676 return a ? AT_lbl (a) : NULL;
4679 /* Return the "high pc" attribute value, typically associated with a subprogram
4680 DIE. Return null if the "high pc" attribute is either not present, or if it
4681 cannot be represented as an assembler label identifier. */
4683 static inline const char *
4684 get_AT_hi_pc (dw_die_ref die)
4686 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4688 return a ? AT_lbl (a) : NULL;
4691 /* Return the value of the string attribute designated by ATTR_KIND, or
4692 NULL if it is not present. */
4694 static inline const char *
4695 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4697 dw_attr_ref a = get_AT (die, attr_kind);
4699 return a ? AT_string (a) : NULL;
4702 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4703 if it is not present. */
4706 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4708 dw_attr_ref a = get_AT (die, attr_kind);
4710 return a ? AT_flag (a) : 0;
4713 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4714 if it is not present. */
4716 static inline unsigned
4717 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4719 dw_attr_ref a = get_AT (die, attr_kind);
4721 return a ? AT_unsigned (a) : 0;
4724 static inline dw_die_ref
4725 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4727 dw_attr_ref a = get_AT (die, attr_kind);
4729 return a ? AT_ref (a) : NULL;
4732 static inline struct dwarf_file_data *
4733 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
4735 dw_attr_ref a = get_AT (die, attr_kind);
4737 return a ? AT_file (a) : NULL;
4740 /* Return TRUE if the language is C++. */
4745 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4747 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
4750 /* Return TRUE if the language is Fortran. */
4755 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4757 return (lang == DW_LANG_Fortran77
4758 || lang == DW_LANG_Fortran90
4759 || lang == DW_LANG_Fortran95);
4762 /* Return TRUE if the language is Ada. */
4767 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
4769 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4772 /* Remove the specified attribute if present. */
4775 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4783 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
4784 if (a->dw_attr == attr_kind)
4786 if (AT_class (a) == dw_val_class_str)
4787 if (a->dw_attr_val.v.val_str->refcount)
4788 a->dw_attr_val.v.val_str->refcount--;
4790 /* VEC_ordered_remove should help reduce the number of abbrevs
4792 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
4797 /* Remove CHILD from its parent. PREV must have the property that
4798 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4801 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
4803 gcc_assert (child->die_parent == prev->die_parent);
4804 gcc_assert (prev->die_sib == child);
4807 gcc_assert (child->die_parent->die_child == child);
4811 prev->die_sib = child->die_sib;
4812 if (child->die_parent->die_child == child)
4813 child->die_parent->die_child = prev;
4816 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4817 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4820 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
4822 dw_die_ref parent = old_child->die_parent;
4824 gcc_assert (parent == prev->die_parent);
4825 gcc_assert (prev->die_sib == old_child);
4827 new_child->die_parent = parent;
4828 if (prev == old_child)
4830 gcc_assert (parent->die_child == old_child);
4831 new_child->die_sib = new_child;
4835 prev->die_sib = new_child;
4836 new_child->die_sib = old_child->die_sib;
4838 if (old_child->die_parent->die_child == old_child)
4839 old_child->die_parent->die_child = new_child;
4842 /* Move all children from OLD_PARENT to NEW_PARENT. */
4845 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
4848 new_parent->die_child = old_parent->die_child;
4849 old_parent->die_child = NULL;
4850 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
4853 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4857 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
4863 dw_die_ref prev = c;
4865 while (c->die_tag == tag)
4867 remove_child_with_prev (c, prev);
4868 /* Might have removed every child. */
4869 if (c == c->die_sib)
4873 } while (c != die->die_child);
4876 /* Add a CHILD_DIE as the last child of DIE. */
4879 add_child_die (dw_die_ref die, dw_die_ref child_die)
4881 /* FIXME this should probably be an assert. */
4882 if (! die || ! child_die)
4884 gcc_assert (die != child_die);
4886 child_die->die_parent = die;
4889 child_die->die_sib = die->die_child->die_sib;
4890 die->die_child->die_sib = child_die;
4893 child_die->die_sib = child_die;
4894 die->die_child = child_die;
4897 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4898 is the specification, to the end of PARENT's list of children.
4899 This is done by removing and re-adding it. */
4902 splice_child_die (dw_die_ref parent, dw_die_ref child)
4906 /* We want the declaration DIE from inside the class, not the
4907 specification DIE at toplevel. */
4908 if (child->die_parent != parent)
4910 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4916 gcc_assert (child->die_parent == parent
4917 || (child->die_parent
4918 == get_AT_ref (parent, DW_AT_specification)));
4920 for (p = child->die_parent->die_child; ; p = p->die_sib)
4921 if (p->die_sib == child)
4923 remove_child_with_prev (child, p);
4927 add_child_die (parent, child);
4930 /* Return a pointer to a newly created DIE node. */
4932 static inline dw_die_ref
4933 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
4935 dw_die_ref die = ggc_alloc_cleared_die_node ();
4937 die->die_tag = tag_value;
4939 if (parent_die != NULL)
4940 add_child_die (parent_die, die);
4943 limbo_die_node *limbo_node;
4945 limbo_node = ggc_alloc_cleared_limbo_die_node ();
4946 limbo_node->die = die;
4947 limbo_node->created_for = t;
4948 limbo_node->next = limbo_die_list;
4949 limbo_die_list = limbo_node;
4955 /* Return the DIE associated with the given type specifier. */
4957 static inline dw_die_ref
4958 lookup_type_die (tree type)
4960 return TYPE_SYMTAB_DIE (type);
4963 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4964 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4965 anonymous type instead the one of the naming typedef. */
4967 static inline dw_die_ref
4968 strip_naming_typedef (tree type, dw_die_ref type_die)
4971 && TREE_CODE (type) == RECORD_TYPE
4973 && type_die->die_tag == DW_TAG_typedef
4974 && is_naming_typedef_decl (TYPE_NAME (type)))
4975 type_die = get_AT_ref (type_die, DW_AT_type);
4979 /* Like lookup_type_die, but if type is an anonymous type named by a
4980 typedef[1], return the DIE of the anonymous type instead the one of
4981 the naming typedef. This is because in gen_typedef_die, we did
4982 equate the anonymous struct named by the typedef with the DIE of
4983 the naming typedef. So by default, lookup_type_die on an anonymous
4984 struct yields the DIE of the naming typedef.
4986 [1]: Read the comment of is_naming_typedef_decl to learn about what
4987 a naming typedef is. */
4989 static inline dw_die_ref
4990 lookup_type_die_strip_naming_typedef (tree type)
4992 dw_die_ref die = lookup_type_die (type);
4993 return strip_naming_typedef (type, die);
4996 /* Equate a DIE to a given type specifier. */
4999 equate_type_number_to_die (tree type, dw_die_ref type_die)
5001 TYPE_SYMTAB_DIE (type) = type_die;
5004 /* Returns a hash value for X (which really is a die_struct). */
5007 decl_die_table_hash (const void *x)
5009 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5012 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5015 decl_die_table_eq (const void *x, const void *y)
5017 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5020 /* Return the DIE associated with a given declaration. */
5022 static inline dw_die_ref
5023 lookup_decl_die (tree decl)
5025 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5028 /* Returns a hash value for X (which really is a var_loc_list). */
5031 decl_loc_table_hash (const void *x)
5033 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5036 /* Return nonzero if decl_id of var_loc_list X is the same as
5040 decl_loc_table_eq (const void *x, const void *y)
5042 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5045 /* Return the var_loc list associated with a given declaration. */
5047 static inline var_loc_list *
5048 lookup_decl_loc (const_tree decl)
5050 if (!decl_loc_table)
5052 return (var_loc_list *)
5053 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5056 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5059 cached_dw_loc_list_table_hash (const void *x)
5061 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
5064 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5068 cached_dw_loc_list_table_eq (const void *x, const void *y)
5070 return (((const cached_dw_loc_list *) x)->decl_id
5071 == DECL_UID ((const_tree) y));
5074 /* Equate a DIE to a particular declaration. */
5077 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5079 unsigned int decl_id = DECL_UID (decl);
5082 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5084 decl_die->decl_id = decl_id;
5087 /* Return how many bits covers PIECE EXPR_LIST. */
5090 decl_piece_bitsize (rtx piece)
5092 int ret = (int) GET_MODE (piece);
5095 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
5096 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
5097 return INTVAL (XEXP (XEXP (piece, 0), 0));
5100 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5103 decl_piece_varloc_ptr (rtx piece)
5105 if ((int) GET_MODE (piece))
5106 return &XEXP (piece, 0);
5108 return &XEXP (XEXP (piece, 0), 1);
5111 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5112 Next is the chain of following piece nodes. */
5115 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
5117 if (bitsize <= (int) MAX_MACHINE_MODE)
5118 return alloc_EXPR_LIST (bitsize, loc_note, next);
5120 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
5125 /* Return rtx that should be stored into loc field for
5126 LOC_NOTE and BITPOS/BITSIZE. */
5129 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
5130 HOST_WIDE_INT bitsize)
5134 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
5136 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
5141 /* This function either modifies location piece list *DEST in
5142 place (if SRC and INNER is NULL), or copies location piece list
5143 *SRC to *DEST while modifying it. Location BITPOS is modified
5144 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5145 not copied and if needed some padding around it is added.
5146 When modifying in place, DEST should point to EXPR_LIST where
5147 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5148 to the start of the whole list and INNER points to the EXPR_LIST
5149 where earlier pieces cover PIECE_BITPOS bits. */
5152 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
5153 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
5154 HOST_WIDE_INT bitsize, rtx loc_note)
5157 bool copy = inner != NULL;
5161 /* First copy all nodes preceeding the current bitpos. */
5162 while (src != inner)
5164 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5165 decl_piece_bitsize (*src), NULL_RTX);
5166 dest = &XEXP (*dest, 1);
5167 src = &XEXP (*src, 1);
5170 /* Add padding if needed. */
5171 if (bitpos != piece_bitpos)
5173 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
5174 copy ? NULL_RTX : *dest);
5175 dest = &XEXP (*dest, 1);
5177 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
5180 /* A piece with correct bitpos and bitsize already exist,
5181 just update the location for it and return. */
5182 *decl_piece_varloc_ptr (*dest) = loc_note;
5185 /* Add the piece that changed. */
5186 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
5187 dest = &XEXP (*dest, 1);
5188 /* Skip over pieces that overlap it. */
5189 diff = bitpos - piece_bitpos + bitsize;
5192 while (diff > 0 && *src)
5195 diff -= decl_piece_bitsize (piece);
5197 src = &XEXP (piece, 1);
5200 *src = XEXP (piece, 1);
5201 free_EXPR_LIST_node (piece);
5204 /* Add padding if needed. */
5205 if (diff < 0 && *src)
5209 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
5210 dest = &XEXP (*dest, 1);
5214 /* Finally copy all nodes following it. */
5217 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5218 decl_piece_bitsize (*src), NULL_RTX);
5219 dest = &XEXP (*dest, 1);
5220 src = &XEXP (*src, 1);
5224 /* Add a variable location node to the linked list for DECL. */
5226 static struct var_loc_node *
5227 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
5229 unsigned int decl_id;
5232 struct var_loc_node *loc = NULL;
5233 HOST_WIDE_INT bitsize = -1, bitpos = -1;
5235 if (DECL_DEBUG_EXPR_IS_FROM (decl))
5237 tree realdecl = DECL_DEBUG_EXPR (decl);
5238 if (realdecl && handled_component_p (realdecl))
5240 HOST_WIDE_INT maxsize;
5243 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
5244 if (!DECL_P (innerdecl)
5245 || DECL_IGNORED_P (innerdecl)
5246 || TREE_STATIC (innerdecl)
5248 || bitpos + bitsize > 256
5249 || bitsize != maxsize)
5255 decl_id = DECL_UID (decl);
5256 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5259 temp = ggc_alloc_cleared_var_loc_list ();
5260 temp->decl_id = decl_id;
5264 temp = (var_loc_list *) *slot;
5266 /* For PARM_DECLs try to keep around the original incoming value,
5267 even if that means we'll emit a zero-range .debug_loc entry. */
5269 && temp->first == temp->last
5270 && TREE_CODE (decl) == PARM_DECL
5271 && GET_CODE (temp->first->loc) == NOTE
5272 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
5273 && DECL_INCOMING_RTL (decl)
5274 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
5275 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
5276 == GET_CODE (DECL_INCOMING_RTL (decl))
5277 && prev_real_insn (temp->first->loc) == NULL_RTX
5279 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
5280 NOTE_VAR_LOCATION_LOC (loc_note))
5281 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
5282 != NOTE_VAR_LOCATION_STATUS (loc_note))))
5284 loc = ggc_alloc_cleared_var_loc_node ();
5285 temp->first->next = loc;
5287 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5289 else if (temp->last)
5291 struct var_loc_node *last = temp->last, *unused = NULL;
5292 rtx *piece_loc = NULL, last_loc_note;
5293 int piece_bitpos = 0;
5297 gcc_assert (last->next == NULL);
5299 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
5301 piece_loc = &last->loc;
5304 int cur_bitsize = decl_piece_bitsize (*piece_loc);
5305 if (piece_bitpos + cur_bitsize > bitpos)
5307 piece_bitpos += cur_bitsize;
5308 piece_loc = &XEXP (*piece_loc, 1);
5312 /* TEMP->LAST here is either pointer to the last but one or
5313 last element in the chained list, LAST is pointer to the
5315 if (label && strcmp (last->label, label) == 0)
5317 /* For SRA optimized variables if there weren't any real
5318 insns since last note, just modify the last node. */
5319 if (piece_loc != NULL)
5321 adjust_piece_list (piece_loc, NULL, NULL,
5322 bitpos, piece_bitpos, bitsize, loc_note);
5325 /* If the last note doesn't cover any instructions, remove it. */
5326 if (temp->last != last)
5328 temp->last->next = NULL;
5331 gcc_assert (strcmp (last->label, label) != 0);
5335 gcc_assert (temp->first == temp->last
5336 || (temp->first->next == temp->last
5337 && TREE_CODE (decl) == PARM_DECL));
5338 memset (temp->last, '\0', sizeof (*temp->last));
5339 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
5343 if (bitsize == -1 && NOTE_P (last->loc))
5344 last_loc_note = last->loc;
5345 else if (piece_loc != NULL
5346 && *piece_loc != NULL_RTX
5347 && piece_bitpos == bitpos
5348 && decl_piece_bitsize (*piece_loc) == bitsize)
5349 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
5351 last_loc_note = NULL_RTX;
5352 /* If the current location is the same as the end of the list,
5353 and either both or neither of the locations is uninitialized,
5354 we have nothing to do. */
5355 if (last_loc_note == NULL_RTX
5356 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
5357 NOTE_VAR_LOCATION_LOC (loc_note)))
5358 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5359 != NOTE_VAR_LOCATION_STATUS (loc_note))
5360 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
5361 == VAR_INIT_STATUS_UNINITIALIZED)
5362 || (NOTE_VAR_LOCATION_STATUS (loc_note)
5363 == VAR_INIT_STATUS_UNINITIALIZED))))
5365 /* Add LOC to the end of list and update LAST. If the last
5366 element of the list has been removed above, reuse its
5367 memory for the new node, otherwise allocate a new one. */
5371 memset (loc, '\0', sizeof (*loc));
5374 loc = ggc_alloc_cleared_var_loc_node ();
5375 if (bitsize == -1 || piece_loc == NULL)
5376 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5378 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
5379 bitpos, piece_bitpos, bitsize, loc_note);
5381 /* Ensure TEMP->LAST will point either to the new last but one
5382 element of the chain, or to the last element in it. */
5383 if (last != temp->last)
5391 loc = ggc_alloc_cleared_var_loc_node ();
5394 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5399 /* Keep track of the number of spaces used to indent the
5400 output of the debugging routines that print the structure of
5401 the DIE internal representation. */
5402 static int print_indent;
5404 /* Indent the line the number of spaces given by print_indent. */
5407 print_spaces (FILE *outfile)
5409 fprintf (outfile, "%*s", print_indent, "");
5412 /* Print a type signature in hex. */
5415 print_signature (FILE *outfile, char *sig)
5419 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
5420 fprintf (outfile, "%02x", sig[i] & 0xff);
5423 /* Print the information associated with a given DIE, and its children.
5424 This routine is a debugging aid only. */
5427 print_die (dw_die_ref die, FILE *outfile)
5433 print_spaces (outfile);
5434 fprintf (outfile, "DIE %4ld: %s (%p)\n",
5435 die->die_offset, dwarf_tag_name (die->die_tag),
5437 print_spaces (outfile);
5438 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5439 fprintf (outfile, " offset: %ld", die->die_offset);
5440 fprintf (outfile, " mark: %d\n", die->die_mark);
5442 if (use_debug_types && die->die_id.die_type_node)
5444 print_spaces (outfile);
5445 fprintf (outfile, " signature: ");
5446 print_signature (outfile, die->die_id.die_type_node->signature);
5447 fprintf (outfile, "\n");
5450 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5452 print_spaces (outfile);
5453 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5455 switch (AT_class (a))
5457 case dw_val_class_addr:
5458 fprintf (outfile, "address");
5460 case dw_val_class_offset:
5461 fprintf (outfile, "offset");
5463 case dw_val_class_loc:
5464 fprintf (outfile, "location descriptor");
5466 case dw_val_class_loc_list:
5467 fprintf (outfile, "location list -> label:%s",
5468 AT_loc_list (a)->ll_symbol);
5470 case dw_val_class_range_list:
5471 fprintf (outfile, "range list");
5473 case dw_val_class_const:
5474 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5476 case dw_val_class_unsigned_const:
5477 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5479 case dw_val_class_const_double:
5480 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
5481 HOST_WIDE_INT_PRINT_UNSIGNED")",
5482 a->dw_attr_val.v.val_double.high,
5483 a->dw_attr_val.v.val_double.low);
5485 case dw_val_class_vec:
5486 fprintf (outfile, "floating-point or vector constant");
5488 case dw_val_class_flag:
5489 fprintf (outfile, "%u", AT_flag (a));
5491 case dw_val_class_die_ref:
5492 if (AT_ref (a) != NULL)
5494 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
5496 fprintf (outfile, "die -> signature: ");
5497 print_signature (outfile,
5498 AT_ref (a)->die_id.die_type_node->signature);
5500 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
5501 fprintf (outfile, "die -> label: %s",
5502 AT_ref (a)->die_id.die_symbol);
5504 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5505 fprintf (outfile, " (%p)", (void *) AT_ref (a));
5508 fprintf (outfile, "die -> <null>");
5510 case dw_val_class_vms_delta:
5511 fprintf (outfile, "delta: @slotcount(%s-%s)",
5512 AT_vms_delta2 (a), AT_vms_delta1 (a));
5514 case dw_val_class_lbl_id:
5515 case dw_val_class_lineptr:
5516 case dw_val_class_macptr:
5517 fprintf (outfile, "label: %s", AT_lbl (a));
5519 case dw_val_class_str:
5520 if (AT_string (a) != NULL)
5521 fprintf (outfile, "\"%s\"", AT_string (a));
5523 fprintf (outfile, "<null>");
5525 case dw_val_class_file:
5526 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
5527 AT_file (a)->emitted_number);
5529 case dw_val_class_data8:
5533 for (i = 0; i < 8; i++)
5534 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
5541 fprintf (outfile, "\n");
5544 if (die->die_child != NULL)
5547 FOR_EACH_CHILD (die, c, print_die (c, outfile));
5550 if (print_indent == 0)
5551 fprintf (outfile, "\n");
5554 /* Print the information collected for a given DIE. */
5557 debug_dwarf_die (dw_die_ref die)
5559 print_die (die, stderr);
5562 /* Print all DWARF information collected for the compilation unit.
5563 This routine is a debugging aid only. */
5569 print_die (comp_unit_die (), stderr);
5572 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5573 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5574 DIE that marks the start of the DIEs for this include file. */
5577 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5579 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5580 dw_die_ref new_unit = gen_compile_unit_die (filename);
5582 new_unit->die_sib = old_unit;
5586 /* Close an include-file CU and reopen the enclosing one. */
5589 pop_compile_unit (dw_die_ref old_unit)
5591 dw_die_ref new_unit = old_unit->die_sib;
5593 old_unit->die_sib = NULL;
5597 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5598 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5600 /* Calculate the checksum of a location expression. */
5603 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5607 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
5609 CHECKSUM (loc->dw_loc_oprnd1);
5610 CHECKSUM (loc->dw_loc_oprnd2);
5613 /* Calculate the checksum of an attribute. */
5616 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5618 dw_loc_descr_ref loc;
5621 CHECKSUM (at->dw_attr);
5623 /* We don't care that this was compiled with a different compiler
5624 snapshot; if the output is the same, that's what matters. */
5625 if (at->dw_attr == DW_AT_producer)
5628 switch (AT_class (at))
5630 case dw_val_class_const:
5631 CHECKSUM (at->dw_attr_val.v.val_int);
5633 case dw_val_class_unsigned_const:
5634 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5636 case dw_val_class_const_double:
5637 CHECKSUM (at->dw_attr_val.v.val_double);
5639 case dw_val_class_vec:
5640 CHECKSUM (at->dw_attr_val.v.val_vec);
5642 case dw_val_class_flag:
5643 CHECKSUM (at->dw_attr_val.v.val_flag);
5645 case dw_val_class_str:
5646 CHECKSUM_STRING (AT_string (at));
5649 case dw_val_class_addr:
5651 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5652 CHECKSUM_STRING (XSTR (r, 0));
5655 case dw_val_class_offset:
5656 CHECKSUM (at->dw_attr_val.v.val_offset);
5659 case dw_val_class_loc:
5660 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5661 loc_checksum (loc, ctx);
5664 case dw_val_class_die_ref:
5665 die_checksum (AT_ref (at), ctx, mark);
5668 case dw_val_class_fde_ref:
5669 case dw_val_class_vms_delta:
5670 case dw_val_class_lbl_id:
5671 case dw_val_class_lineptr:
5672 case dw_val_class_macptr:
5675 case dw_val_class_file:
5676 CHECKSUM_STRING (AT_file (at)->filename);
5679 case dw_val_class_data8:
5680 CHECKSUM (at->dw_attr_val.v.val_data8);
5688 /* Calculate the checksum of a DIE. */
5691 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5697 /* To avoid infinite recursion. */
5700 CHECKSUM (die->die_mark);
5703 die->die_mark = ++(*mark);
5705 CHECKSUM (die->die_tag);
5707 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5708 attr_checksum (a, ctx, mark);
5710 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
5714 #undef CHECKSUM_STRING
5716 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5717 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5718 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5719 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5720 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5721 #define CHECKSUM_ATTR(FOO) \
5722 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5724 /* Calculate the checksum of a number in signed LEB128 format. */
5727 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
5734 byte = (value & 0x7f);
5736 more = !((value == 0 && (byte & 0x40) == 0)
5737 || (value == -1 && (byte & 0x40) != 0));
5746 /* Calculate the checksum of a number in unsigned LEB128 format. */
5749 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
5753 unsigned char byte = (value & 0x7f);
5756 /* More bytes to follow. */
5764 /* Checksum the context of the DIE. This adds the names of any
5765 surrounding namespaces or structures to the checksum. */
5768 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
5772 int tag = die->die_tag;
5774 if (tag != DW_TAG_namespace
5775 && tag != DW_TAG_structure_type
5776 && tag != DW_TAG_class_type)
5779 name = get_AT_string (die, DW_AT_name);
5781 spec = get_AT_ref (die, DW_AT_specification);
5785 if (die->die_parent != NULL)
5786 checksum_die_context (die->die_parent, ctx);
5788 CHECKSUM_ULEB128 ('C');
5789 CHECKSUM_ULEB128 (tag);
5791 CHECKSUM_STRING (name);
5794 /* Calculate the checksum of a location expression. */
5797 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5799 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5800 were emitted as a DW_FORM_sdata instead of a location expression. */
5801 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
5803 CHECKSUM_ULEB128 (DW_FORM_sdata);
5804 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
5808 /* Otherwise, just checksum the raw location expression. */
5811 CHECKSUM_ULEB128 (loc->dw_loc_opc);
5812 CHECKSUM (loc->dw_loc_oprnd1);
5813 CHECKSUM (loc->dw_loc_oprnd2);
5814 loc = loc->dw_loc_next;
5818 /* Calculate the checksum of an attribute. */
5821 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
5822 struct md5_ctx *ctx, int *mark)
5824 dw_loc_descr_ref loc;
5827 if (AT_class (at) == dw_val_class_die_ref)
5829 dw_die_ref target_die = AT_ref (at);
5831 /* For pointer and reference types, we checksum only the (qualified)
5832 name of the target type (if there is a name). For friend entries,
5833 we checksum only the (qualified) name of the target type or function.
5834 This allows the checksum to remain the same whether the target type
5835 is complete or not. */
5836 if ((at->dw_attr == DW_AT_type
5837 && (tag == DW_TAG_pointer_type
5838 || tag == DW_TAG_reference_type
5839 || tag == DW_TAG_rvalue_reference_type
5840 || tag == DW_TAG_ptr_to_member_type))
5841 || (at->dw_attr == DW_AT_friend
5842 && tag == DW_TAG_friend))
5844 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
5846 if (name_attr != NULL)
5848 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
5852 CHECKSUM_ULEB128 ('N');
5853 CHECKSUM_ULEB128 (at->dw_attr);
5854 if (decl->die_parent != NULL)
5855 checksum_die_context (decl->die_parent, ctx);
5856 CHECKSUM_ULEB128 ('E');
5857 CHECKSUM_STRING (AT_string (name_attr));
5862 /* For all other references to another DIE, we check to see if the
5863 target DIE has already been visited. If it has, we emit a
5864 backward reference; if not, we descend recursively. */
5865 if (target_die->die_mark > 0)
5867 CHECKSUM_ULEB128 ('R');
5868 CHECKSUM_ULEB128 (at->dw_attr);
5869 CHECKSUM_ULEB128 (target_die->die_mark);
5873 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
5877 target_die->die_mark = ++(*mark);
5878 CHECKSUM_ULEB128 ('T');
5879 CHECKSUM_ULEB128 (at->dw_attr);
5880 if (decl->die_parent != NULL)
5881 checksum_die_context (decl->die_parent, ctx);
5882 die_checksum_ordered (target_die, ctx, mark);
5887 CHECKSUM_ULEB128 ('A');
5888 CHECKSUM_ULEB128 (at->dw_attr);
5890 switch (AT_class (at))
5892 case dw_val_class_const:
5893 CHECKSUM_ULEB128 (DW_FORM_sdata);
5894 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
5897 case dw_val_class_unsigned_const:
5898 CHECKSUM_ULEB128 (DW_FORM_sdata);
5899 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
5902 case dw_val_class_const_double:
5903 CHECKSUM_ULEB128 (DW_FORM_block);
5904 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
5905 CHECKSUM (at->dw_attr_val.v.val_double);
5908 case dw_val_class_vec:
5909 CHECKSUM_ULEB128 (DW_FORM_block);
5910 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
5911 CHECKSUM (at->dw_attr_val.v.val_vec);
5914 case dw_val_class_flag:
5915 CHECKSUM_ULEB128 (DW_FORM_flag);
5916 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
5919 case dw_val_class_str:
5920 CHECKSUM_ULEB128 (DW_FORM_string);
5921 CHECKSUM_STRING (AT_string (at));
5924 case dw_val_class_addr:
5926 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5927 CHECKSUM_ULEB128 (DW_FORM_string);
5928 CHECKSUM_STRING (XSTR (r, 0));
5931 case dw_val_class_offset:
5932 CHECKSUM_ULEB128 (DW_FORM_sdata);
5933 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
5936 case dw_val_class_loc:
5937 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5938 loc_checksum_ordered (loc, ctx);
5941 case dw_val_class_fde_ref:
5942 case dw_val_class_lbl_id:
5943 case dw_val_class_lineptr:
5944 case dw_val_class_macptr:
5947 case dw_val_class_file:
5948 CHECKSUM_ULEB128 (DW_FORM_string);
5949 CHECKSUM_STRING (AT_file (at)->filename);
5952 case dw_val_class_data8:
5953 CHECKSUM (at->dw_attr_val.v.val_data8);
5961 struct checksum_attributes
5963 dw_attr_ref at_name;
5964 dw_attr_ref at_type;
5965 dw_attr_ref at_friend;
5966 dw_attr_ref at_accessibility;
5967 dw_attr_ref at_address_class;
5968 dw_attr_ref at_allocated;
5969 dw_attr_ref at_artificial;
5970 dw_attr_ref at_associated;
5971 dw_attr_ref at_binary_scale;
5972 dw_attr_ref at_bit_offset;
5973 dw_attr_ref at_bit_size;
5974 dw_attr_ref at_bit_stride;
5975 dw_attr_ref at_byte_size;
5976 dw_attr_ref at_byte_stride;
5977 dw_attr_ref at_const_value;
5978 dw_attr_ref at_containing_type;
5979 dw_attr_ref at_count;
5980 dw_attr_ref at_data_location;
5981 dw_attr_ref at_data_member_location;
5982 dw_attr_ref at_decimal_scale;
5983 dw_attr_ref at_decimal_sign;
5984 dw_attr_ref at_default_value;
5985 dw_attr_ref at_digit_count;
5986 dw_attr_ref at_discr;
5987 dw_attr_ref at_discr_list;
5988 dw_attr_ref at_discr_value;
5989 dw_attr_ref at_encoding;
5990 dw_attr_ref at_endianity;
5991 dw_attr_ref at_explicit;
5992 dw_attr_ref at_is_optional;
5993 dw_attr_ref at_location;
5994 dw_attr_ref at_lower_bound;
5995 dw_attr_ref at_mutable;
5996 dw_attr_ref at_ordering;
5997 dw_attr_ref at_picture_string;
5998 dw_attr_ref at_prototyped;
5999 dw_attr_ref at_small;
6000 dw_attr_ref at_segment;
6001 dw_attr_ref at_string_length;
6002 dw_attr_ref at_threads_scaled;
6003 dw_attr_ref at_upper_bound;
6004 dw_attr_ref at_use_location;
6005 dw_attr_ref at_use_UTF8;
6006 dw_attr_ref at_variable_parameter;
6007 dw_attr_ref at_virtuality;
6008 dw_attr_ref at_visibility;
6009 dw_attr_ref at_vtable_elem_location;
6012 /* Collect the attributes that we will want to use for the checksum. */
6015 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
6020 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6031 attrs->at_friend = a;
6033 case DW_AT_accessibility:
6034 attrs->at_accessibility = a;
6036 case DW_AT_address_class:
6037 attrs->at_address_class = a;
6039 case DW_AT_allocated:
6040 attrs->at_allocated = a;
6042 case DW_AT_artificial:
6043 attrs->at_artificial = a;
6045 case DW_AT_associated:
6046 attrs->at_associated = a;
6048 case DW_AT_binary_scale:
6049 attrs->at_binary_scale = a;
6051 case DW_AT_bit_offset:
6052 attrs->at_bit_offset = a;
6054 case DW_AT_bit_size:
6055 attrs->at_bit_size = a;
6057 case DW_AT_bit_stride:
6058 attrs->at_bit_stride = a;
6060 case DW_AT_byte_size:
6061 attrs->at_byte_size = a;
6063 case DW_AT_byte_stride:
6064 attrs->at_byte_stride = a;
6066 case DW_AT_const_value:
6067 attrs->at_const_value = a;
6069 case DW_AT_containing_type:
6070 attrs->at_containing_type = a;
6073 attrs->at_count = a;
6075 case DW_AT_data_location:
6076 attrs->at_data_location = a;
6078 case DW_AT_data_member_location:
6079 attrs->at_data_member_location = a;
6081 case DW_AT_decimal_scale:
6082 attrs->at_decimal_scale = a;
6084 case DW_AT_decimal_sign:
6085 attrs->at_decimal_sign = a;
6087 case DW_AT_default_value:
6088 attrs->at_default_value = a;
6090 case DW_AT_digit_count:
6091 attrs->at_digit_count = a;
6094 attrs->at_discr = a;
6096 case DW_AT_discr_list:
6097 attrs->at_discr_list = a;
6099 case DW_AT_discr_value:
6100 attrs->at_discr_value = a;
6102 case DW_AT_encoding:
6103 attrs->at_encoding = a;
6105 case DW_AT_endianity:
6106 attrs->at_endianity = a;
6108 case DW_AT_explicit:
6109 attrs->at_explicit = a;
6111 case DW_AT_is_optional:
6112 attrs->at_is_optional = a;
6114 case DW_AT_location:
6115 attrs->at_location = a;
6117 case DW_AT_lower_bound:
6118 attrs->at_lower_bound = a;
6121 attrs->at_mutable = a;
6123 case DW_AT_ordering:
6124 attrs->at_ordering = a;
6126 case DW_AT_picture_string:
6127 attrs->at_picture_string = a;
6129 case DW_AT_prototyped:
6130 attrs->at_prototyped = a;
6133 attrs->at_small = a;
6136 attrs->at_segment = a;
6138 case DW_AT_string_length:
6139 attrs->at_string_length = a;
6141 case DW_AT_threads_scaled:
6142 attrs->at_threads_scaled = a;
6144 case DW_AT_upper_bound:
6145 attrs->at_upper_bound = a;
6147 case DW_AT_use_location:
6148 attrs->at_use_location = a;
6150 case DW_AT_use_UTF8:
6151 attrs->at_use_UTF8 = a;
6153 case DW_AT_variable_parameter:
6154 attrs->at_variable_parameter = a;
6156 case DW_AT_virtuality:
6157 attrs->at_virtuality = a;
6159 case DW_AT_visibility:
6160 attrs->at_visibility = a;
6162 case DW_AT_vtable_elem_location:
6163 attrs->at_vtable_elem_location = a;
6171 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6174 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6178 struct checksum_attributes attrs;
6180 CHECKSUM_ULEB128 ('D');
6181 CHECKSUM_ULEB128 (die->die_tag);
6183 memset (&attrs, 0, sizeof (attrs));
6185 decl = get_AT_ref (die, DW_AT_specification);
6187 collect_checksum_attributes (&attrs, decl);
6188 collect_checksum_attributes (&attrs, die);
6190 CHECKSUM_ATTR (attrs.at_name);
6191 CHECKSUM_ATTR (attrs.at_accessibility);
6192 CHECKSUM_ATTR (attrs.at_address_class);
6193 CHECKSUM_ATTR (attrs.at_allocated);
6194 CHECKSUM_ATTR (attrs.at_artificial);
6195 CHECKSUM_ATTR (attrs.at_associated);
6196 CHECKSUM_ATTR (attrs.at_binary_scale);
6197 CHECKSUM_ATTR (attrs.at_bit_offset);
6198 CHECKSUM_ATTR (attrs.at_bit_size);
6199 CHECKSUM_ATTR (attrs.at_bit_stride);
6200 CHECKSUM_ATTR (attrs.at_byte_size);
6201 CHECKSUM_ATTR (attrs.at_byte_stride);
6202 CHECKSUM_ATTR (attrs.at_const_value);
6203 CHECKSUM_ATTR (attrs.at_containing_type);
6204 CHECKSUM_ATTR (attrs.at_count);
6205 CHECKSUM_ATTR (attrs.at_data_location);
6206 CHECKSUM_ATTR (attrs.at_data_member_location);
6207 CHECKSUM_ATTR (attrs.at_decimal_scale);
6208 CHECKSUM_ATTR (attrs.at_decimal_sign);
6209 CHECKSUM_ATTR (attrs.at_default_value);
6210 CHECKSUM_ATTR (attrs.at_digit_count);
6211 CHECKSUM_ATTR (attrs.at_discr);
6212 CHECKSUM_ATTR (attrs.at_discr_list);
6213 CHECKSUM_ATTR (attrs.at_discr_value);
6214 CHECKSUM_ATTR (attrs.at_encoding);
6215 CHECKSUM_ATTR (attrs.at_endianity);
6216 CHECKSUM_ATTR (attrs.at_explicit);
6217 CHECKSUM_ATTR (attrs.at_is_optional);
6218 CHECKSUM_ATTR (attrs.at_location);
6219 CHECKSUM_ATTR (attrs.at_lower_bound);
6220 CHECKSUM_ATTR (attrs.at_mutable);
6221 CHECKSUM_ATTR (attrs.at_ordering);
6222 CHECKSUM_ATTR (attrs.at_picture_string);
6223 CHECKSUM_ATTR (attrs.at_prototyped);
6224 CHECKSUM_ATTR (attrs.at_small);
6225 CHECKSUM_ATTR (attrs.at_segment);
6226 CHECKSUM_ATTR (attrs.at_string_length);
6227 CHECKSUM_ATTR (attrs.at_threads_scaled);
6228 CHECKSUM_ATTR (attrs.at_upper_bound);
6229 CHECKSUM_ATTR (attrs.at_use_location);
6230 CHECKSUM_ATTR (attrs.at_use_UTF8);
6231 CHECKSUM_ATTR (attrs.at_variable_parameter);
6232 CHECKSUM_ATTR (attrs.at_virtuality);
6233 CHECKSUM_ATTR (attrs.at_visibility);
6234 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
6235 CHECKSUM_ATTR (attrs.at_type);
6236 CHECKSUM_ATTR (attrs.at_friend);
6238 /* Checksum the child DIEs, except for nested types and member functions. */
6241 dw_attr_ref name_attr;
6244 name_attr = get_AT (c, DW_AT_name);
6245 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
6246 && name_attr != NULL)
6248 CHECKSUM_ULEB128 ('S');
6249 CHECKSUM_ULEB128 (c->die_tag);
6250 CHECKSUM_STRING (AT_string (name_attr));
6254 /* Mark this DIE so it gets processed when unmarking. */
6255 if (c->die_mark == 0)
6257 die_checksum_ordered (c, ctx, mark);
6259 } while (c != die->die_child);
6261 CHECKSUM_ULEB128 (0);
6265 #undef CHECKSUM_STRING
6266 #undef CHECKSUM_ATTR
6267 #undef CHECKSUM_LEB128
6268 #undef CHECKSUM_ULEB128
6270 /* Generate the type signature for DIE. This is computed by generating an
6271 MD5 checksum over the DIE's tag, its relevant attributes, and its
6272 children. Attributes that are references to other DIEs are processed
6273 by recursion, using the MARK field to prevent infinite recursion.
6274 If the DIE is nested inside a namespace or another type, we also
6275 need to include that context in the signature. The lower 64 bits
6276 of the resulting MD5 checksum comprise the signature. */
6279 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
6283 unsigned char checksum[16];
6287 name = get_AT_string (die, DW_AT_name);
6288 decl = get_AT_ref (die, DW_AT_specification);
6290 /* First, compute a signature for just the type name (and its surrounding
6291 context, if any. This is stored in the type unit DIE for link-time
6292 ODR (one-definition rule) checking. */
6294 if (is_cxx() && name != NULL)
6296 md5_init_ctx (&ctx);
6298 /* Checksum the names of surrounding namespaces and structures. */
6299 if (decl != NULL && decl->die_parent != NULL)
6300 checksum_die_context (decl->die_parent, &ctx);
6302 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
6303 md5_process_bytes (name, strlen (name) + 1, &ctx);
6304 md5_finish_ctx (&ctx, checksum);
6306 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
6309 /* Next, compute the complete type signature. */
6311 md5_init_ctx (&ctx);
6313 die->die_mark = mark;
6315 /* Checksum the names of surrounding namespaces and structures. */
6316 if (decl != NULL && decl->die_parent != NULL)
6317 checksum_die_context (decl->die_parent, &ctx);
6319 /* Checksum the DIE and its children. */
6320 die_checksum_ordered (die, &ctx, &mark);
6321 unmark_all_dies (die);
6322 md5_finish_ctx (&ctx, checksum);
6324 /* Store the signature in the type node and link the type DIE and the
6325 type node together. */
6326 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
6327 DWARF_TYPE_SIGNATURE_SIZE);
6328 die->die_id.die_type_node = type_node;
6329 type_node->type_die = die;
6331 /* If the DIE is a specification, link its declaration to the type node
6334 decl->die_id.die_type_node = type_node;
6337 /* Do the location expressions look same? */
6339 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6341 return loc1->dw_loc_opc == loc2->dw_loc_opc
6342 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6343 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6346 /* Do the values look the same? */
6348 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6350 dw_loc_descr_ref loc1, loc2;
6353 if (v1->val_class != v2->val_class)
6356 switch (v1->val_class)
6358 case dw_val_class_const:
6359 return v1->v.val_int == v2->v.val_int;
6360 case dw_val_class_unsigned_const:
6361 return v1->v.val_unsigned == v2->v.val_unsigned;
6362 case dw_val_class_const_double:
6363 return v1->v.val_double.high == v2->v.val_double.high
6364 && v1->v.val_double.low == v2->v.val_double.low;
6365 case dw_val_class_vec:
6366 if (v1->v.val_vec.length != v2->v.val_vec.length
6367 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6369 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6370 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6373 case dw_val_class_flag:
6374 return v1->v.val_flag == v2->v.val_flag;
6375 case dw_val_class_str:
6376 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6378 case dw_val_class_addr:
6379 r1 = v1->v.val_addr;
6380 r2 = v2->v.val_addr;
6381 if (GET_CODE (r1) != GET_CODE (r2))
6383 return !rtx_equal_p (r1, r2);
6385 case dw_val_class_offset:
6386 return v1->v.val_offset == v2->v.val_offset;
6388 case dw_val_class_loc:
6389 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6391 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6392 if (!same_loc_p (loc1, loc2, mark))
6394 return !loc1 && !loc2;
6396 case dw_val_class_die_ref:
6397 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6399 case dw_val_class_fde_ref:
6400 case dw_val_class_vms_delta:
6401 case dw_val_class_lbl_id:
6402 case dw_val_class_lineptr:
6403 case dw_val_class_macptr:
6406 case dw_val_class_file:
6407 return v1->v.val_file == v2->v.val_file;
6409 case dw_val_class_data8:
6410 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
6417 /* Do the attributes look the same? */
6420 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6422 if (at1->dw_attr != at2->dw_attr)
6425 /* We don't care that this was compiled with a different compiler
6426 snapshot; if the output is the same, that's what matters. */
6427 if (at1->dw_attr == DW_AT_producer)
6430 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6433 /* Do the dies look the same? */
6436 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6442 /* To avoid infinite recursion. */
6444 return die1->die_mark == die2->die_mark;
6445 die1->die_mark = die2->die_mark = ++(*mark);
6447 if (die1->die_tag != die2->die_tag)
6450 if (VEC_length (dw_attr_node, die1->die_attr)
6451 != VEC_length (dw_attr_node, die2->die_attr))
6454 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
6455 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6458 c1 = die1->die_child;
6459 c2 = die2->die_child;
6468 if (!same_die_p (c1, c2, mark))
6472 if (c1 == die1->die_child)
6474 if (c2 == die2->die_child)
6484 /* Do the dies look the same? Wrapper around same_die_p. */
6487 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6490 int ret = same_die_p (die1, die2, &mark);
6492 unmark_all_dies (die1);
6493 unmark_all_dies (die2);
6498 /* The prefix to attach to symbols on DIEs in the current comdat debug
6500 static char *comdat_symbol_id;
6502 /* The index of the current symbol within the current comdat CU. */
6503 static unsigned int comdat_symbol_number;
6505 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6506 children, and set comdat_symbol_id accordingly. */
6509 compute_section_prefix (dw_die_ref unit_die)
6511 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6512 const char *base = die_name ? lbasename (die_name) : "anonymous";
6513 char *name = XALLOCAVEC (char, strlen (base) + 64);
6516 unsigned char checksum[16];
6519 /* Compute the checksum of the DIE, then append part of it as hex digits to
6520 the name filename of the unit. */
6522 md5_init_ctx (&ctx);
6524 die_checksum (unit_die, &ctx, &mark);
6525 unmark_all_dies (unit_die);
6526 md5_finish_ctx (&ctx, checksum);
6528 sprintf (name, "%s.", base);
6529 clean_symbol_name (name);
6531 p = name + strlen (name);
6532 for (i = 0; i < 4; i++)
6534 sprintf (p, "%.2x", checksum[i]);
6538 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
6539 comdat_symbol_number = 0;
6542 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6545 is_type_die (dw_die_ref die)
6547 switch (die->die_tag)
6549 case DW_TAG_array_type:
6550 case DW_TAG_class_type:
6551 case DW_TAG_interface_type:
6552 case DW_TAG_enumeration_type:
6553 case DW_TAG_pointer_type:
6554 case DW_TAG_reference_type:
6555 case DW_TAG_rvalue_reference_type:
6556 case DW_TAG_string_type:
6557 case DW_TAG_structure_type:
6558 case DW_TAG_subroutine_type:
6559 case DW_TAG_union_type:
6560 case DW_TAG_ptr_to_member_type:
6561 case DW_TAG_set_type:
6562 case DW_TAG_subrange_type:
6563 case DW_TAG_base_type:
6564 case DW_TAG_const_type:
6565 case DW_TAG_file_type:
6566 case DW_TAG_packed_type:
6567 case DW_TAG_volatile_type:
6568 case DW_TAG_typedef:
6575 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6576 Basically, we want to choose the bits that are likely to be shared between
6577 compilations (types) and leave out the bits that are specific to individual
6578 compilations (functions). */
6581 is_comdat_die (dw_die_ref c)
6583 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6584 we do for stabs. The advantage is a greater likelihood of sharing between
6585 objects that don't include headers in the same order (and therefore would
6586 put the base types in a different comdat). jason 8/28/00 */
6588 if (c->die_tag == DW_TAG_base_type)
6591 if (c->die_tag == DW_TAG_pointer_type
6592 || c->die_tag == DW_TAG_reference_type
6593 || c->die_tag == DW_TAG_rvalue_reference_type
6594 || c->die_tag == DW_TAG_const_type
6595 || c->die_tag == DW_TAG_volatile_type)
6597 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6599 return t ? is_comdat_die (t) : 0;
6602 return is_type_die (c);
6605 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6606 compilation unit. */
6609 is_symbol_die (dw_die_ref c)
6611 return (is_type_die (c)
6612 || is_declaration_die (c)
6613 || c->die_tag == DW_TAG_namespace
6614 || c->die_tag == DW_TAG_module);
6617 /* Returns true iff C is a compile-unit DIE. */
6620 is_cu_die (dw_die_ref c)
6622 return c && c->die_tag == DW_TAG_compile_unit;
6626 gen_internal_sym (const char *prefix)
6630 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6631 return xstrdup (buf);
6634 /* Assign symbols to all worthy DIEs under DIE. */
6637 assign_symbol_names (dw_die_ref die)
6641 if (is_symbol_die (die))
6643 if (comdat_symbol_id)
6645 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
6647 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6648 comdat_symbol_id, comdat_symbol_number++);
6649 die->die_id.die_symbol = xstrdup (p);
6652 die->die_id.die_symbol = gen_internal_sym ("LDIE");
6655 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6658 struct cu_hash_table_entry
6661 unsigned min_comdat_num, max_comdat_num;
6662 struct cu_hash_table_entry *next;
6665 /* Routines to manipulate hash table of CUs. */
6667 htab_cu_hash (const void *of)
6669 const struct cu_hash_table_entry *const entry =
6670 (const struct cu_hash_table_entry *) of;
6672 return htab_hash_string (entry->cu->die_id.die_symbol);
6676 htab_cu_eq (const void *of1, const void *of2)
6678 const struct cu_hash_table_entry *const entry1 =
6679 (const struct cu_hash_table_entry *) of1;
6680 const struct die_struct *const entry2 = (const struct die_struct *) of2;
6682 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
6686 htab_cu_del (void *what)
6688 struct cu_hash_table_entry *next,
6689 *entry = (struct cu_hash_table_entry *) what;
6699 /* Check whether we have already seen this CU and set up SYM_NUM
6702 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6704 struct cu_hash_table_entry dummy;
6705 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6707 dummy.max_comdat_num = 0;
6709 slot = (struct cu_hash_table_entry **)
6710 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
6714 for (; entry; last = entry, entry = entry->next)
6716 if (same_die_p_wrap (cu, entry->cu))
6722 *sym_num = entry->min_comdat_num;
6726 entry = XCNEW (struct cu_hash_table_entry);
6728 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6729 entry->next = *slot;
6735 /* Record SYM_NUM to record of CU in HTABLE. */
6737 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6739 struct cu_hash_table_entry **slot, *entry;
6741 slot = (struct cu_hash_table_entry **)
6742 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
6746 entry->max_comdat_num = sym_num;
6749 /* Traverse the DIE (which is always comp_unit_die), and set up
6750 additional compilation units for each of the include files we see
6751 bracketed by BINCL/EINCL. */
6754 break_out_includes (dw_die_ref die)
6757 dw_die_ref unit = NULL;
6758 limbo_die_node *node, **pnode;
6759 htab_t cu_hash_table;
6763 dw_die_ref prev = c;
6765 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6766 || (unit && is_comdat_die (c)))
6768 dw_die_ref next = c->die_sib;
6770 /* This DIE is for a secondary CU; remove it from the main one. */
6771 remove_child_with_prev (c, prev);
6773 if (c->die_tag == DW_TAG_GNU_BINCL)
6774 unit = push_new_compile_unit (unit, c);
6775 else if (c->die_tag == DW_TAG_GNU_EINCL)
6776 unit = pop_compile_unit (unit);
6778 add_child_die (unit, c);
6780 if (c == die->die_child)
6783 } while (c != die->die_child);
6786 /* We can only use this in debugging, since the frontend doesn't check
6787 to make sure that we leave every include file we enter. */
6791 assign_symbol_names (die);
6792 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6793 for (node = limbo_die_list, pnode = &limbo_die_list;
6799 compute_section_prefix (node->die);
6800 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6801 &comdat_symbol_number);
6802 assign_symbol_names (node->die);
6804 *pnode = node->next;
6807 pnode = &node->next;
6808 record_comdat_symbol_number (node->die, cu_hash_table,
6809 comdat_symbol_number);
6812 htab_delete (cu_hash_table);
6815 /* Return non-zero if this DIE is a declaration. */
6818 is_declaration_die (dw_die_ref die)
6823 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6824 if (a->dw_attr == DW_AT_declaration)
6830 /* Return non-zero if this DIE is nested inside a subprogram. */
6833 is_nested_in_subprogram (dw_die_ref die)
6835 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
6839 return local_scope_p (decl);
6842 /* Return non-zero if this DIE contains a defining declaration of a
6846 contains_subprogram_definition (dw_die_ref die)
6850 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
6852 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
6856 /* Return non-zero if this is a type DIE that should be moved to a
6857 COMDAT .debug_types section. */
6860 should_move_die_to_comdat (dw_die_ref die)
6862 switch (die->die_tag)
6864 case DW_TAG_class_type:
6865 case DW_TAG_structure_type:
6866 case DW_TAG_enumeration_type:
6867 case DW_TAG_union_type:
6868 /* Don't move declarations, inlined instances, or types nested in a
6870 if (is_declaration_die (die)
6871 || get_AT (die, DW_AT_abstract_origin)
6872 || is_nested_in_subprogram (die))
6874 /* A type definition should never contain a subprogram definition. */
6875 gcc_assert (!contains_subprogram_definition (die));
6877 case DW_TAG_array_type:
6878 case DW_TAG_interface_type:
6879 case DW_TAG_pointer_type:
6880 case DW_TAG_reference_type:
6881 case DW_TAG_rvalue_reference_type:
6882 case DW_TAG_string_type:
6883 case DW_TAG_subroutine_type:
6884 case DW_TAG_ptr_to_member_type:
6885 case DW_TAG_set_type:
6886 case DW_TAG_subrange_type:
6887 case DW_TAG_base_type:
6888 case DW_TAG_const_type:
6889 case DW_TAG_file_type:
6890 case DW_TAG_packed_type:
6891 case DW_TAG_volatile_type:
6892 case DW_TAG_typedef:
6898 /* Make a clone of DIE. */
6901 clone_die (dw_die_ref die)
6907 clone = ggc_alloc_cleared_die_node ();
6908 clone->die_tag = die->die_tag;
6910 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6911 add_dwarf_attr (clone, a);
6916 /* Make a clone of the tree rooted at DIE. */
6919 clone_tree (dw_die_ref die)
6922 dw_die_ref clone = clone_die (die);
6924 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
6929 /* Make a clone of DIE as a declaration. */
6932 clone_as_declaration (dw_die_ref die)
6939 /* If the DIE is already a declaration, just clone it. */
6940 if (is_declaration_die (die))
6941 return clone_die (die);
6943 /* If the DIE is a specification, just clone its declaration DIE. */
6944 decl = get_AT_ref (die, DW_AT_specification);
6946 return clone_die (decl);
6948 clone = ggc_alloc_cleared_die_node ();
6949 clone->die_tag = die->die_tag;
6951 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6953 /* We don't want to copy over all attributes.
6954 For example we don't want DW_AT_byte_size because otherwise we will no
6955 longer have a declaration and GDB will treat it as a definition. */
6959 case DW_AT_artificial:
6960 case DW_AT_containing_type:
6961 case DW_AT_external:
6964 case DW_AT_virtuality:
6965 case DW_AT_linkage_name:
6966 case DW_AT_MIPS_linkage_name:
6967 add_dwarf_attr (clone, a);
6969 case DW_AT_byte_size:
6975 if (die->die_id.die_type_node)
6976 add_AT_die_ref (clone, DW_AT_signature, die);
6978 add_AT_flag (clone, DW_AT_declaration, 1);
6982 /* Copy the declaration context to the new compile unit DIE. This includes
6983 any surrounding namespace or type declarations. If the DIE has an
6984 AT_specification attribute, it also includes attributes and children
6985 attached to the specification. */
6988 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
6991 dw_die_ref new_decl;
6993 decl = get_AT_ref (die, DW_AT_specification);
7002 /* Copy the type node pointer from the new DIE to the original
7003 declaration DIE so we can forward references later. */
7004 decl->die_id.die_type_node = die->die_id.die_type_node;
7006 remove_AT (die, DW_AT_specification);
7008 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
7010 if (a->dw_attr != DW_AT_name
7011 && a->dw_attr != DW_AT_declaration
7012 && a->dw_attr != DW_AT_external)
7013 add_dwarf_attr (die, a);
7016 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
7019 if (decl->die_parent != NULL
7020 && decl->die_parent->die_tag != DW_TAG_compile_unit
7021 && decl->die_parent->die_tag != DW_TAG_type_unit)
7023 new_decl = copy_ancestor_tree (unit, decl, NULL);
7024 if (new_decl != NULL)
7026 remove_AT (new_decl, DW_AT_signature);
7027 add_AT_specification (die, new_decl);
7032 /* Generate the skeleton ancestor tree for the given NODE, then clone
7033 the DIE and add the clone into the tree. */
7036 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
7038 if (node->new_die != NULL)
7041 node->new_die = clone_as_declaration (node->old_die);
7043 if (node->parent != NULL)
7045 generate_skeleton_ancestor_tree (node->parent);
7046 add_child_die (node->parent->new_die, node->new_die);
7050 /* Generate a skeleton tree of DIEs containing any declarations that are
7051 found in the original tree. We traverse the tree looking for declaration
7052 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7055 generate_skeleton_bottom_up (skeleton_chain_node *parent)
7057 skeleton_chain_node node;
7060 dw_die_ref prev = NULL;
7061 dw_die_ref next = NULL;
7063 node.parent = parent;
7065 first = c = parent->old_die->die_child;
7069 if (prev == NULL || prev->die_sib == c)
7072 next = (c == first ? NULL : c->die_sib);
7074 node.new_die = NULL;
7075 if (is_declaration_die (c))
7077 /* Clone the existing DIE, move the original to the skeleton
7078 tree (which is in the main CU), and put the clone, with
7079 all the original's children, where the original came from. */
7080 dw_die_ref clone = clone_die (c);
7081 move_all_children (c, clone);
7083 replace_child (c, clone, prev);
7084 generate_skeleton_ancestor_tree (parent);
7085 add_child_die (parent->new_die, c);
7089 generate_skeleton_bottom_up (&node);
7090 } while (next != NULL);
7093 /* Wrapper function for generate_skeleton_bottom_up. */
7096 generate_skeleton (dw_die_ref die)
7098 skeleton_chain_node node;
7101 node.new_die = NULL;
7104 /* If this type definition is nested inside another type,
7105 always leave at least a declaration in its place. */
7106 if (die->die_parent != NULL && is_type_die (die->die_parent))
7107 node.new_die = clone_as_declaration (die);
7109 generate_skeleton_bottom_up (&node);
7110 return node.new_die;
7113 /* Remove the DIE from its parent, possibly replacing it with a cloned
7114 declaration. The original DIE will be moved to a new compile unit
7115 so that existing references to it follow it to the new location. If
7116 any of the original DIE's descendants is a declaration, we need to
7117 replace the original DIE with a skeleton tree and move the
7118 declarations back into the skeleton tree. */
7121 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
7123 dw_die_ref skeleton;
7125 skeleton = generate_skeleton (child);
7126 if (skeleton == NULL)
7127 remove_child_with_prev (child, prev);
7130 skeleton->die_id.die_type_node = child->die_id.die_type_node;
7131 replace_child (child, skeleton, prev);
7137 /* Traverse the DIE and set up additional .debug_types sections for each
7138 type worthy of being placed in a COMDAT section. */
7141 break_out_comdat_types (dw_die_ref die)
7145 dw_die_ref prev = NULL;
7146 dw_die_ref next = NULL;
7147 dw_die_ref unit = NULL;
7149 first = c = die->die_child;
7153 if (prev == NULL || prev->die_sib == c)
7156 next = (c == first ? NULL : c->die_sib);
7157 if (should_move_die_to_comdat (c))
7159 dw_die_ref replacement;
7160 comdat_type_node_ref type_node;
7162 /* Create a new type unit DIE as the root for the new tree, and
7163 add it to the list of comdat types. */
7164 unit = new_die (DW_TAG_type_unit, NULL, NULL);
7165 add_AT_unsigned (unit, DW_AT_language,
7166 get_AT_unsigned (comp_unit_die (), DW_AT_language));
7167 type_node = ggc_alloc_cleared_comdat_type_node ();
7168 type_node->root_die = unit;
7169 type_node->next = comdat_type_list;
7170 comdat_type_list = type_node;
7172 /* Generate the type signature. */
7173 generate_type_signature (c, type_node);
7175 /* Copy the declaration context, attributes, and children of the
7176 declaration into the new compile unit DIE. */
7177 copy_declaration_context (unit, c);
7179 /* Remove this DIE from the main CU. */
7180 replacement = remove_child_or_replace_with_skeleton (c, prev);
7182 /* Break out nested types into their own type units. */
7183 break_out_comdat_types (c);
7185 /* Add the DIE to the new compunit. */
7186 add_child_die (unit, c);
7188 if (replacement != NULL)
7191 else if (c->die_tag == DW_TAG_namespace
7192 || c->die_tag == DW_TAG_class_type
7193 || c->die_tag == DW_TAG_structure_type
7194 || c->die_tag == DW_TAG_union_type)
7196 /* Look for nested types that can be broken out. */
7197 break_out_comdat_types (c);
7199 } while (next != NULL);
7202 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7204 struct decl_table_entry
7210 /* Routines to manipulate hash table of copied declarations. */
7213 htab_decl_hash (const void *of)
7215 const struct decl_table_entry *const entry =
7216 (const struct decl_table_entry *) of;
7218 return htab_hash_pointer (entry->orig);
7222 htab_decl_eq (const void *of1, const void *of2)
7224 const struct decl_table_entry *const entry1 =
7225 (const struct decl_table_entry *) of1;
7226 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7228 return entry1->orig == entry2;
7232 htab_decl_del (void *what)
7234 struct decl_table_entry *entry = (struct decl_table_entry *) what;
7239 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7240 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7241 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7242 to check if the ancestor has already been copied into UNIT. */
7245 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7247 dw_die_ref parent = die->die_parent;
7248 dw_die_ref new_parent = unit;
7251 struct decl_table_entry *entry = NULL;
7255 /* Check if the entry has already been copied to UNIT. */
7256 slot = htab_find_slot_with_hash (decl_table, die,
7257 htab_hash_pointer (die), INSERT);
7258 if (*slot != HTAB_EMPTY_ENTRY)
7260 entry = (struct decl_table_entry *) *slot;
7264 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7265 entry = XCNEW (struct decl_table_entry);
7273 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
7276 if (parent->die_tag != DW_TAG_compile_unit
7277 && parent->die_tag != DW_TAG_type_unit)
7278 new_parent = copy_ancestor_tree (unit, parent, decl_table);
7281 copy = clone_as_declaration (die);
7282 add_child_die (new_parent, copy);
7284 if (decl_table != NULL)
7286 /* Record the pointer to the copy. */
7293 /* Walk the DIE and its children, looking for references to incomplete
7294 or trivial types that are unmarked (i.e., that are not in the current
7298 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7304 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7306 if (AT_class (a) == dw_val_class_die_ref)
7308 dw_die_ref targ = AT_ref (a);
7309 comdat_type_node_ref type_node = targ->die_id.die_type_node;
7311 struct decl_table_entry *entry;
7313 if (targ->die_mark != 0 || type_node != NULL)
7316 slot = htab_find_slot_with_hash (decl_table, targ,
7317 htab_hash_pointer (targ), INSERT);
7319 if (*slot != HTAB_EMPTY_ENTRY)
7321 /* TARG has already been copied, so we just need to
7322 modify the reference to point to the copy. */
7323 entry = (struct decl_table_entry *) *slot;
7324 a->dw_attr_val.v.val_die_ref.die = entry->copy;
7328 dw_die_ref parent = unit;
7329 dw_die_ref copy = clone_tree (targ);
7331 /* Make sure the cloned tree is marked as part of the
7335 /* Record in DECL_TABLE that TARG has been copied.
7336 Need to do this now, before the recursive call,
7337 because DECL_TABLE may be expanded and SLOT
7338 would no longer be a valid pointer. */
7339 entry = XCNEW (struct decl_table_entry);
7344 /* If TARG has surrounding context, copy its ancestor tree
7345 into the new type unit. */
7346 if (targ->die_parent != NULL
7347 && targ->die_parent->die_tag != DW_TAG_compile_unit
7348 && targ->die_parent->die_tag != DW_TAG_type_unit)
7349 parent = copy_ancestor_tree (unit, targ->die_parent,
7352 add_child_die (parent, copy);
7353 a->dw_attr_val.v.val_die_ref.die = copy;
7355 /* Make sure the newly-copied DIE is walked. If it was
7356 installed in a previously-added context, it won't
7357 get visited otherwise. */
7360 /* Find the highest point of the newly-added tree,
7361 mark each node along the way, and walk from there. */
7362 parent->die_mark = 1;
7363 while (parent->die_parent
7364 && parent->die_parent->die_mark == 0)
7366 parent = parent->die_parent;
7367 parent->die_mark = 1;
7369 copy_decls_walk (unit, parent, decl_table);
7375 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
7378 /* Copy declarations for "unworthy" types into the new comdat section.
7379 Incomplete types, modified types, and certain other types aren't broken
7380 out into comdat sections of their own, so they don't have a signature,
7381 and we need to copy the declaration into the same section so that we
7382 don't have an external reference. */
7385 copy_decls_for_unworthy_types (dw_die_ref unit)
7390 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
7391 copy_decls_walk (unit, unit, decl_table);
7392 htab_delete (decl_table);
7396 /* Traverse the DIE and add a sibling attribute if it may have the
7397 effect of speeding up access to siblings. To save some space,
7398 avoid generating sibling attributes for DIE's without children. */
7401 add_sibling_attributes (dw_die_ref die)
7405 if (! die->die_child)
7408 if (die->die_parent && die != die->die_parent->die_child)
7409 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7411 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7414 /* Output all location lists for the DIE and its children. */
7417 output_location_lists (dw_die_ref die)
7423 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7424 if (AT_class (a) == dw_val_class_loc_list)
7425 output_loc_list (AT_loc_list (a));
7427 FOR_EACH_CHILD (die, c, output_location_lists (c));
7430 /* The format of each DIE (and its attribute value pairs) is encoded in an
7431 abbreviation table. This routine builds the abbreviation table and assigns
7432 a unique abbreviation id for each abbreviation entry. The children of each
7433 die are visited recursively. */
7436 build_abbrev_table (dw_die_ref die)
7438 unsigned long abbrev_id;
7439 unsigned int n_alloc;
7444 /* Scan the DIE references, and mark as external any that refer to
7445 DIEs from other CUs (i.e. those which are not marked). */
7446 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7447 if (AT_class (a) == dw_val_class_die_ref
7448 && AT_ref (a)->die_mark == 0)
7450 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
7451 set_AT_ref_external (a, 1);
7454 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7456 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7457 dw_attr_ref die_a, abbrev_a;
7461 if (abbrev->die_tag != die->die_tag)
7463 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7466 if (VEC_length (dw_attr_node, abbrev->die_attr)
7467 != VEC_length (dw_attr_node, die->die_attr))
7470 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
7472 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7473 if ((abbrev_a->dw_attr != die_a->dw_attr)
7474 || (value_format (abbrev_a) != value_format (die_a)))
7484 if (abbrev_id >= abbrev_die_table_in_use)
7486 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7488 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7489 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7492 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7493 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7494 abbrev_die_table_allocated = n_alloc;
7497 ++abbrev_die_table_in_use;
7498 abbrev_die_table[abbrev_id] = die;
7501 die->die_abbrev = abbrev_id;
7502 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7505 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7508 constant_size (unsigned HOST_WIDE_INT value)
7515 log = floor_log2 (value);
7518 log = 1 << (floor_log2 (log) + 1);
7523 /* Return the size of a DIE as it is represented in the
7524 .debug_info section. */
7526 static unsigned long
7527 size_of_die (dw_die_ref die)
7529 unsigned long size = 0;
7533 size += size_of_uleb128 (die->die_abbrev);
7534 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7536 switch (AT_class (a))
7538 case dw_val_class_addr:
7539 size += DWARF2_ADDR_SIZE;
7541 case dw_val_class_offset:
7542 size += DWARF_OFFSET_SIZE;
7544 case dw_val_class_loc:
7546 unsigned long lsize = size_of_locs (AT_loc (a));
7549 if (dwarf_version >= 4)
7550 size += size_of_uleb128 (lsize);
7552 size += constant_size (lsize);
7556 case dw_val_class_loc_list:
7557 size += DWARF_OFFSET_SIZE;
7559 case dw_val_class_range_list:
7560 size += DWARF_OFFSET_SIZE;
7562 case dw_val_class_const:
7563 size += size_of_sleb128 (AT_int (a));
7565 case dw_val_class_unsigned_const:
7566 size += constant_size (AT_unsigned (a));
7568 case dw_val_class_const_double:
7569 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
7570 if (HOST_BITS_PER_WIDE_INT >= 64)
7573 case dw_val_class_vec:
7574 size += constant_size (a->dw_attr_val.v.val_vec.length
7575 * a->dw_attr_val.v.val_vec.elt_size)
7576 + a->dw_attr_val.v.val_vec.length
7577 * a->dw_attr_val.v.val_vec.elt_size; /* block */
7579 case dw_val_class_flag:
7580 if (dwarf_version >= 4)
7581 /* Currently all add_AT_flag calls pass in 1 as last argument,
7582 so DW_FORM_flag_present can be used. If that ever changes,
7583 we'll need to use DW_FORM_flag and have some optimization
7584 in build_abbrev_table that will change those to
7585 DW_FORM_flag_present if it is set to 1 in all DIEs using
7586 the same abbrev entry. */
7587 gcc_assert (a->dw_attr_val.v.val_flag == 1);
7591 case dw_val_class_die_ref:
7592 if (AT_ref_external (a))
7594 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7595 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7596 is sized by target address length, whereas in DWARF3
7597 it's always sized as an offset. */
7598 if (use_debug_types)
7599 size += DWARF_TYPE_SIGNATURE_SIZE;
7600 else if (dwarf_version == 2)
7601 size += DWARF2_ADDR_SIZE;
7603 size += DWARF_OFFSET_SIZE;
7606 size += DWARF_OFFSET_SIZE;
7608 case dw_val_class_fde_ref:
7609 size += DWARF_OFFSET_SIZE;
7611 case dw_val_class_lbl_id:
7612 size += DWARF2_ADDR_SIZE;
7614 case dw_val_class_lineptr:
7615 case dw_val_class_macptr:
7616 size += DWARF_OFFSET_SIZE;
7618 case dw_val_class_str:
7619 if (AT_string_form (a) == DW_FORM_strp)
7620 size += DWARF_OFFSET_SIZE;
7622 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7624 case dw_val_class_file:
7625 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7627 case dw_val_class_data8:
7630 case dw_val_class_vms_delta:
7631 size += DWARF_OFFSET_SIZE;
7641 /* Size the debugging information associated with a given DIE. Visits the
7642 DIE's children recursively. Updates the global variable next_die_offset, on
7643 each time through. Uses the current value of next_die_offset to update the
7644 die_offset field in each DIE. */
7647 calc_die_sizes (dw_die_ref die)
7651 gcc_assert (die->die_offset == 0
7652 || (unsigned long int) die->die_offset == next_die_offset);
7653 die->die_offset = next_die_offset;
7654 next_die_offset += size_of_die (die);
7656 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7658 if (die->die_child != NULL)
7659 /* Count the null byte used to terminate sibling lists. */
7660 next_die_offset += 1;
7663 /* Size just the base type children at the start of the CU.
7664 This is needed because build_abbrev needs to size locs
7665 and sizing of type based stack ops needs to know die_offset
7666 values for the base types. */
7669 calc_base_type_die_sizes (void)
7671 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7673 dw_die_ref base_type;
7674 #if ENABLE_ASSERT_CHECKING
7675 dw_die_ref prev = comp_unit_die ()->die_child;
7678 die_offset += size_of_die (comp_unit_die ());
7679 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
7681 #if ENABLE_ASSERT_CHECKING
7682 gcc_assert (base_type->die_offset == 0
7683 && prev->die_sib == base_type
7684 && base_type->die_child == NULL
7685 && base_type->die_abbrev);
7688 base_type->die_offset = die_offset;
7689 die_offset += size_of_die (base_type);
7693 /* Set the marks for a die and its children. We do this so
7694 that we know whether or not a reference needs to use FORM_ref_addr; only
7695 DIEs in the same CU will be marked. We used to clear out the offset
7696 and use that as the flag, but ran into ordering problems. */
7699 mark_dies (dw_die_ref die)
7703 gcc_assert (!die->die_mark);
7706 FOR_EACH_CHILD (die, c, mark_dies (c));
7709 /* Clear the marks for a die and its children. */
7712 unmark_dies (dw_die_ref die)
7716 if (! use_debug_types)
7717 gcc_assert (die->die_mark);
7720 FOR_EACH_CHILD (die, c, unmark_dies (c));
7723 /* Clear the marks for a die, its children and referred dies. */
7726 unmark_all_dies (dw_die_ref die)
7736 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7738 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7739 if (AT_class (a) == dw_val_class_die_ref)
7740 unmark_all_dies (AT_ref (a));
7743 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7744 generated for the compilation unit. */
7746 static unsigned long
7747 size_of_pubnames (VEC (pubname_entry, gc) * names)
7753 size = DWARF_PUBNAMES_HEADER_SIZE;
7754 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
7755 if (names != pubtype_table
7756 || p->die->die_offset != 0
7757 || !flag_eliminate_unused_debug_types)
7758 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7760 size += DWARF_OFFSET_SIZE;
7764 /* Return the size of the information in the .debug_aranges section. */
7766 static unsigned long
7767 size_of_aranges (void)
7771 size = DWARF_ARANGES_HEADER_SIZE;
7773 /* Count the address/length pair for this compilation unit. */
7774 if (text_section_used)
7775 size += 2 * DWARF2_ADDR_SIZE;
7776 if (cold_text_section_used)
7777 size += 2 * DWARF2_ADDR_SIZE;
7778 if (have_multiple_function_sections)
7783 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
7785 if (!fde->in_std_section)
7786 size += 2 * DWARF2_ADDR_SIZE;
7787 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
7788 size += 2 * DWARF2_ADDR_SIZE;
7792 /* Count the two zero words used to terminated the address range table. */
7793 size += 2 * DWARF2_ADDR_SIZE;
7797 /* Select the encoding of an attribute value. */
7799 static enum dwarf_form
7800 value_format (dw_attr_ref a)
7802 switch (a->dw_attr_val.val_class)
7804 case dw_val_class_addr:
7805 /* Only very few attributes allow DW_FORM_addr. */
7810 case DW_AT_entry_pc:
7811 case DW_AT_trampoline:
7812 return DW_FORM_addr;
7816 switch (DWARF2_ADDR_SIZE)
7819 return DW_FORM_data1;
7821 return DW_FORM_data2;
7823 return DW_FORM_data4;
7825 return DW_FORM_data8;
7829 case dw_val_class_range_list:
7830 case dw_val_class_loc_list:
7831 if (dwarf_version >= 4)
7832 return DW_FORM_sec_offset;
7834 case dw_val_class_vms_delta:
7835 case dw_val_class_offset:
7836 switch (DWARF_OFFSET_SIZE)
7839 return DW_FORM_data4;
7841 return DW_FORM_data8;
7845 case dw_val_class_loc:
7846 if (dwarf_version >= 4)
7847 return DW_FORM_exprloc;
7848 switch (constant_size (size_of_locs (AT_loc (a))))
7851 return DW_FORM_block1;
7853 return DW_FORM_block2;
7857 case dw_val_class_const:
7858 return DW_FORM_sdata;
7859 case dw_val_class_unsigned_const:
7860 switch (constant_size (AT_unsigned (a)))
7863 return DW_FORM_data1;
7865 return DW_FORM_data2;
7867 return DW_FORM_data4;
7869 return DW_FORM_data8;
7873 case dw_val_class_const_double:
7874 switch (HOST_BITS_PER_WIDE_INT)
7877 return DW_FORM_data2;
7879 return DW_FORM_data4;
7881 return DW_FORM_data8;
7884 return DW_FORM_block1;
7886 case dw_val_class_vec:
7887 switch (constant_size (a->dw_attr_val.v.val_vec.length
7888 * a->dw_attr_val.v.val_vec.elt_size))
7891 return DW_FORM_block1;
7893 return DW_FORM_block2;
7895 return DW_FORM_block4;
7899 case dw_val_class_flag:
7900 if (dwarf_version >= 4)
7902 /* Currently all add_AT_flag calls pass in 1 as last argument,
7903 so DW_FORM_flag_present can be used. If that ever changes,
7904 we'll need to use DW_FORM_flag and have some optimization
7905 in build_abbrev_table that will change those to
7906 DW_FORM_flag_present if it is set to 1 in all DIEs using
7907 the same abbrev entry. */
7908 gcc_assert (a->dw_attr_val.v.val_flag == 1);
7909 return DW_FORM_flag_present;
7911 return DW_FORM_flag;
7912 case dw_val_class_die_ref:
7913 if (AT_ref_external (a))
7914 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
7917 case dw_val_class_fde_ref:
7918 return DW_FORM_data;
7919 case dw_val_class_lbl_id:
7920 return DW_FORM_addr;
7921 case dw_val_class_lineptr:
7922 case dw_val_class_macptr:
7923 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
7924 case dw_val_class_str:
7925 return AT_string_form (a);
7926 case dw_val_class_file:
7927 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7930 return DW_FORM_data1;
7932 return DW_FORM_data2;
7934 return DW_FORM_data4;
7939 case dw_val_class_data8:
7940 return DW_FORM_data8;
7947 /* Output the encoding of an attribute value. */
7950 output_value_format (dw_attr_ref a)
7952 enum dwarf_form form = value_format (a);
7954 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7957 /* Output the .debug_abbrev section which defines the DIE abbreviation
7961 output_abbrev_section (void)
7963 unsigned long abbrev_id;
7965 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7967 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7971 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7972 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7973 dwarf_tag_name (abbrev->die_tag));
7975 if (abbrev->die_child != NULL)
7976 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7978 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7980 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7983 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7984 dwarf_attr_name (a_attr->dw_attr));
7985 output_value_format (a_attr);
7988 dw2_asm_output_data (1, 0, NULL);
7989 dw2_asm_output_data (1, 0, NULL);
7992 /* Terminate the table. */
7993 dw2_asm_output_data (1, 0, NULL);
7996 /* Output a symbol we can use to refer to this DIE from another CU. */
7999 output_die_symbol (dw_die_ref die)
8001 char *sym = die->die_id.die_symbol;
8006 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8007 /* We make these global, not weak; if the target doesn't support
8008 .linkonce, it doesn't support combining the sections, so debugging
8010 targetm.asm_out.globalize_label (asm_out_file, sym);
8012 ASM_OUTPUT_LABEL (asm_out_file, sym);
8015 /* Return a new location list, given the begin and end range, and the
8018 static inline dw_loc_list_ref
8019 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8020 const char *section)
8022 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
8024 retlist->begin = begin;
8026 retlist->expr = expr;
8027 retlist->section = section;
8032 /* Generate a new internal symbol for this location list node, if it
8033 hasn't got one yet. */
8036 gen_llsym (dw_loc_list_ref list)
8038 gcc_assert (!list->ll_symbol);
8039 list->ll_symbol = gen_internal_sym ("LLST");
8042 /* Output the location list given to us. */
8045 output_loc_list (dw_loc_list_ref list_head)
8047 dw_loc_list_ref curr = list_head;
8049 if (list_head->emitted)
8051 list_head->emitted = true;
8053 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8055 /* Walk the location list, and output each range + expression. */
8056 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8059 /* Don't output an entry that starts and ends at the same address. */
8060 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
8062 if (!have_multiple_function_sections)
8064 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8065 "Location list begin address (%s)",
8066 list_head->ll_symbol);
8067 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8068 "Location list end address (%s)",
8069 list_head->ll_symbol);
8073 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8074 "Location list begin address (%s)",
8075 list_head->ll_symbol);
8076 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8077 "Location list end address (%s)",
8078 list_head->ll_symbol);
8080 size = size_of_locs (curr->expr);
8082 /* Output the block length for this list of location operations. */
8083 gcc_assert (size <= 0xffff);
8084 dw2_asm_output_data (2, size, "%s", "Location expression size");
8086 output_loc_sequence (curr->expr, -1);
8089 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8090 "Location list terminator begin (%s)",
8091 list_head->ll_symbol);
8092 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8093 "Location list terminator end (%s)",
8094 list_head->ll_symbol);
8097 /* Output a type signature. */
8100 output_signature (const char *sig, const char *name)
8104 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8105 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
8108 /* Output the DIE and its attributes. Called recursively to generate
8109 the definitions of each child DIE. */
8112 output_die (dw_die_ref die)
8119 /* If someone in another CU might refer to us, set up a symbol for
8120 them to point to. */
8121 if (! use_debug_types && die->die_id.die_symbol)
8122 output_die_symbol (die);
8124 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
8125 (unsigned long)die->die_offset,
8126 dwarf_tag_name (die->die_tag));
8128 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8130 const char *name = dwarf_attr_name (a->dw_attr);
8132 switch (AT_class (a))
8134 case dw_val_class_addr:
8135 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8138 case dw_val_class_offset:
8139 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8143 case dw_val_class_range_list:
8145 char *p = strchr (ranges_section_label, '\0');
8147 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8148 a->dw_attr_val.v.val_offset);
8149 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8150 debug_ranges_section, "%s", name);
8155 case dw_val_class_loc:
8156 size = size_of_locs (AT_loc (a));
8158 /* Output the block length for this list of location operations. */
8159 if (dwarf_version >= 4)
8160 dw2_asm_output_data_uleb128 (size, "%s", name);
8162 dw2_asm_output_data (constant_size (size), size, "%s", name);
8164 output_loc_sequence (AT_loc (a), -1);
8167 case dw_val_class_const:
8168 /* ??? It would be slightly more efficient to use a scheme like is
8169 used for unsigned constants below, but gdb 4.x does not sign
8170 extend. Gdb 5.x does sign extend. */
8171 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8174 case dw_val_class_unsigned_const:
8175 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8176 AT_unsigned (a), "%s", name);
8179 case dw_val_class_const_double:
8181 unsigned HOST_WIDE_INT first, second;
8183 if (HOST_BITS_PER_WIDE_INT >= 64)
8184 dw2_asm_output_data (1,
8185 2 * HOST_BITS_PER_WIDE_INT
8186 / HOST_BITS_PER_CHAR,
8189 if (WORDS_BIG_ENDIAN)
8191 first = a->dw_attr_val.v.val_double.high;
8192 second = a->dw_attr_val.v.val_double.low;
8196 first = a->dw_attr_val.v.val_double.low;
8197 second = a->dw_attr_val.v.val_double.high;
8200 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8202 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8207 case dw_val_class_vec:
8209 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8210 unsigned int len = a->dw_attr_val.v.val_vec.length;
8214 dw2_asm_output_data (constant_size (len * elt_size),
8215 len * elt_size, "%s", name);
8216 if (elt_size > sizeof (HOST_WIDE_INT))
8221 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8224 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8225 "fp or vector constant word %u", i);
8229 case dw_val_class_flag:
8230 if (dwarf_version >= 4)
8232 /* Currently all add_AT_flag calls pass in 1 as last argument,
8233 so DW_FORM_flag_present can be used. If that ever changes,
8234 we'll need to use DW_FORM_flag and have some optimization
8235 in build_abbrev_table that will change those to
8236 DW_FORM_flag_present if it is set to 1 in all DIEs using
8237 the same abbrev entry. */
8238 gcc_assert (AT_flag (a) == 1);
8240 fprintf (asm_out_file, "\t\t\t%s %s\n",
8241 ASM_COMMENT_START, name);
8244 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8247 case dw_val_class_loc_list:
8249 char *sym = AT_loc_list (a)->ll_symbol;
8252 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8257 case dw_val_class_die_ref:
8258 if (AT_ref_external (a))
8260 if (use_debug_types)
8262 comdat_type_node_ref type_node =
8263 AT_ref (a)->die_id.die_type_node;
8265 gcc_assert (type_node);
8266 output_signature (type_node->signature, name);
8270 char *sym = AT_ref (a)->die_id.die_symbol;
8274 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8275 length, whereas in DWARF3 it's always sized as an
8277 if (dwarf_version == 2)
8278 size = DWARF2_ADDR_SIZE;
8280 size = DWARF_OFFSET_SIZE;
8281 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
8287 gcc_assert (AT_ref (a)->die_offset);
8288 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8293 case dw_val_class_fde_ref:
8297 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8298 a->dw_attr_val.v.val_fde_index * 2);
8299 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8304 case dw_val_class_vms_delta:
8305 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
8306 AT_vms_delta2 (a), AT_vms_delta1 (a),
8310 case dw_val_class_lbl_id:
8311 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8314 case dw_val_class_lineptr:
8315 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8316 debug_line_section, "%s", name);
8319 case dw_val_class_macptr:
8320 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8321 debug_macinfo_section, "%s", name);
8324 case dw_val_class_str:
8325 if (AT_string_form (a) == DW_FORM_strp)
8326 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8327 a->dw_attr_val.v.val_str->label,
8329 "%s: \"%s\"", name, AT_string (a));
8331 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8334 case dw_val_class_file:
8336 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8338 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8339 a->dw_attr_val.v.val_file->filename);
8343 case dw_val_class_data8:
8347 for (i = 0; i < 8; i++)
8348 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
8349 i == 0 ? "%s" : NULL, name);
8358 FOR_EACH_CHILD (die, c, output_die (c));
8360 /* Add null byte to terminate sibling list. */
8361 if (die->die_child != NULL)
8362 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8363 (unsigned long) die->die_offset);
8366 /* Output the compilation unit that appears at the beginning of the
8367 .debug_info section, and precedes the DIE descriptions. */
8370 output_compilation_unit_header (void)
8372 int ver = dwarf_version;
8374 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8375 dw2_asm_output_data (4, 0xffffffff,
8376 "Initial length escape value indicating 64-bit DWARF extension");
8377 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8378 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8379 "Length of Compilation Unit Info");
8380 dw2_asm_output_data (2, ver, "DWARF version number");
8381 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8382 debug_abbrev_section,
8383 "Offset Into Abbrev. Section");
8384 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8387 /* Output the compilation unit DIE and its children. */
8390 output_comp_unit (dw_die_ref die, int output_if_empty)
8392 const char *secname;
8395 /* Unless we are outputting main CU, we may throw away empty ones. */
8396 if (!output_if_empty && die->die_child == NULL)
8399 /* Even if there are no children of this DIE, we must output the information
8400 about the compilation unit. Otherwise, on an empty translation unit, we
8401 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8402 will then complain when examining the file. First mark all the DIEs in
8403 this CU so we know which get local refs. */
8406 build_abbrev_table (die);
8408 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8409 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8410 calc_die_sizes (die);
8412 oldsym = die->die_id.die_symbol;
8415 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8417 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8419 die->die_id.die_symbol = NULL;
8420 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8424 switch_to_section (debug_info_section);
8425 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
8426 info_section_emitted = true;
8429 /* Output debugging information. */
8430 output_compilation_unit_header ();
8433 /* Leave the marks on the main CU, so we can check them in
8438 die->die_id.die_symbol = oldsym;
8442 /* Output a comdat type unit DIE and its children. */
8445 output_comdat_type_unit (comdat_type_node *node)
8447 const char *secname;
8450 #if defined (OBJECT_FORMAT_ELF)
8454 /* First mark all the DIEs in this CU so we know which get local refs. */
8455 mark_dies (node->root_die);
8457 build_abbrev_table (node->root_die);
8459 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8460 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
8461 calc_die_sizes (node->root_die);
8463 #if defined (OBJECT_FORMAT_ELF)
8464 secname = ".debug_types";
8465 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
8466 sprintf (tmp, "wt.");
8467 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8468 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
8469 comdat_key = get_identifier (tmp);
8470 targetm.asm_out.named_section (secname,
8471 SECTION_DEBUG | SECTION_LINKONCE,
8474 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
8475 sprintf (tmp, ".gnu.linkonce.wt.");
8476 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8477 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
8479 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8482 /* Output debugging information. */
8483 output_compilation_unit_header ();
8484 output_signature (node->signature, "Type Signature");
8485 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
8486 "Offset to Type DIE");
8487 output_die (node->root_die);
8489 unmark_dies (node->root_die);
8492 /* Return the DWARF2/3 pubname associated with a decl. */
8495 dwarf2_name (tree decl, int scope)
8497 if (DECL_NAMELESS (decl))
8499 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8502 /* Add a new entry to .debug_pubnames if appropriate. */
8505 add_pubname_string (const char *str, dw_die_ref die)
8507 if (targetm.want_debug_pub_sections)
8512 e.name = xstrdup (str);
8513 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8518 add_pubname (tree decl, dw_die_ref die)
8520 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
8522 const char *name = dwarf2_name (decl, 1);
8524 add_pubname_string (name, die);
8528 /* Add a new entry to .debug_pubtypes if appropriate. */
8531 add_pubtype (tree decl, dw_die_ref die)
8535 if (!targetm.want_debug_pub_sections)
8539 if ((TREE_PUBLIC (decl)
8540 || is_cu_die (die->die_parent))
8541 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8546 if (TYPE_NAME (decl))
8548 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8549 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8550 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8551 && DECL_NAME (TYPE_NAME (decl)))
8552 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8554 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8559 e.name = dwarf2_name (decl, 1);
8561 e.name = xstrdup (e.name);
8564 /* If we don't have a name for the type, there's no point in adding
8566 if (e.name && e.name[0] != '\0')
8567 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8571 /* Output the public names table used to speed up access to externally
8572 visible names; or the public types table used to find type definitions. */
8575 output_pubnames (VEC (pubname_entry, gc) * names)
8578 unsigned long pubnames_length = size_of_pubnames (names);
8581 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8582 dw2_asm_output_data (4, 0xffffffff,
8583 "Initial length escape value indicating 64-bit DWARF extension");
8584 if (names == pubname_table)
8585 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8586 "Length of Public Names Info");
8588 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8589 "Length of Public Type Names Info");
8590 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8591 dw2_asm_output_data (2, 2, "DWARF Version");
8592 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8594 "Offset of Compilation Unit Info");
8595 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8596 "Compilation Unit Length");
8598 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
8600 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8601 if (names == pubname_table)
8602 gcc_assert (pub->die->die_mark);
8604 if (names != pubtype_table
8605 || pub->die->die_offset != 0
8606 || !flag_eliminate_unused_debug_types)
8608 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8611 dw2_asm_output_nstring (pub->name, -1, "external name");
8615 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8618 /* Output the information that goes into the .debug_aranges table.
8619 Namely, define the beginning and ending address range of the
8620 text section generated for this compilation unit. */
8623 output_aranges (unsigned long aranges_length)
8627 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8628 dw2_asm_output_data (4, 0xffffffff,
8629 "Initial length escape value indicating 64-bit DWARF extension");
8630 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8631 "Length of Address Ranges Info");
8632 /* Version number for aranges is still 2, even in DWARF3. */
8633 dw2_asm_output_data (2, 2, "DWARF Version");
8634 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8636 "Offset of Compilation Unit Info");
8637 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8638 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8640 /* We need to align to twice the pointer size here. */
8641 if (DWARF_ARANGES_PAD_SIZE)
8643 /* Pad using a 2 byte words so that padding is correct for any
8645 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8646 2 * DWARF2_ADDR_SIZE);
8647 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8648 dw2_asm_output_data (2, 0, NULL);
8651 /* It is necessary not to output these entries if the sections were
8652 not used; if the sections were not used, the length will be 0 and
8653 the address may end up as 0 if the section is discarded by ld
8654 --gc-sections, leaving an invalid (0, 0) entry that can be
8655 confused with the terminator. */
8656 if (text_section_used)
8658 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8659 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8660 text_section_label, "Length");
8662 if (cold_text_section_used)
8664 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8666 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8667 cold_text_section_label, "Length");
8670 if (have_multiple_function_sections)
8675 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
8677 if (!fde->in_std_section)
8679 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
8681 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
8682 fde->dw_fde_begin, "Length");
8684 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
8686 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
8688 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
8689 fde->dw_fde_second_begin, "Length");
8694 /* Output the terminator words. */
8695 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8696 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8699 /* Add a new entry to .debug_ranges. Return the offset at which it
8703 add_ranges_num (int num)
8705 unsigned int in_use = ranges_table_in_use;
8707 if (in_use == ranges_table_allocated)
8709 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8710 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8711 ranges_table_allocated);
8712 memset (ranges_table + ranges_table_in_use, 0,
8713 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8716 ranges_table[in_use].num = num;
8717 ranges_table_in_use = in_use + 1;
8719 return in_use * 2 * DWARF2_ADDR_SIZE;
8722 /* Add a new entry to .debug_ranges corresponding to a block, or a
8723 range terminator if BLOCK is NULL. */
8726 add_ranges (const_tree block)
8728 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8731 /* Add a new entry to .debug_ranges corresponding to a pair of
8735 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
8738 unsigned int in_use = ranges_by_label_in_use;
8739 unsigned int offset;
8741 if (in_use == ranges_by_label_allocated)
8743 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8744 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8746 ranges_by_label_allocated);
8747 memset (ranges_by_label + ranges_by_label_in_use, 0,
8748 RANGES_TABLE_INCREMENT
8749 * sizeof (struct dw_ranges_by_label_struct));
8752 ranges_by_label[in_use].begin = begin;
8753 ranges_by_label[in_use].end = end;
8754 ranges_by_label_in_use = in_use + 1;
8756 offset = add_ranges_num (-(int)in_use - 1);
8759 add_AT_range_list (die, DW_AT_ranges, offset);
8765 output_ranges (void)
8768 static const char *const start_fmt = "Offset %#x";
8769 const char *fmt = start_fmt;
8771 for (i = 0; i < ranges_table_in_use; i++)
8773 int block_num = ranges_table[i].num;
8777 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8778 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8780 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8781 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8783 /* If all code is in the text section, then the compilation
8784 unit base address defaults to DW_AT_low_pc, which is the
8785 base of the text section. */
8786 if (!have_multiple_function_sections)
8788 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8790 fmt, i * 2 * DWARF2_ADDR_SIZE);
8791 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8792 text_section_label, NULL);
8795 /* Otherwise, the compilation unit base address is zero,
8796 which allows us to use absolute addresses, and not worry
8797 about whether the target supports cross-section
8801 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8802 fmt, i * 2 * DWARF2_ADDR_SIZE);
8803 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8809 /* Negative block_num stands for an index into ranges_by_label. */
8810 else if (block_num < 0)
8812 int lab_idx = - block_num - 1;
8814 if (!have_multiple_function_sections)
8818 /* If we ever use add_ranges_by_labels () for a single
8819 function section, all we have to do is to take out
8821 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8822 ranges_by_label[lab_idx].begin,
8824 fmt, i * 2 * DWARF2_ADDR_SIZE);
8825 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8826 ranges_by_label[lab_idx].end,
8827 text_section_label, NULL);
8832 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8833 ranges_by_label[lab_idx].begin,
8834 fmt, i * 2 * DWARF2_ADDR_SIZE);
8835 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8836 ranges_by_label[lab_idx].end,
8842 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8843 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8849 /* Data structure containing information about input files. */
8852 const char *path; /* Complete file name. */
8853 const char *fname; /* File name part. */
8854 int length; /* Length of entire string. */
8855 struct dwarf_file_data * file_idx; /* Index in input file table. */
8856 int dir_idx; /* Index in directory table. */
8859 /* Data structure containing information about directories with source
8863 const char *path; /* Path including directory name. */
8864 int length; /* Path length. */
8865 int prefix; /* Index of directory entry which is a prefix. */
8866 int count; /* Number of files in this directory. */
8867 int dir_idx; /* Index of directory used as base. */
8870 /* Callback function for file_info comparison. We sort by looking at
8871 the directories in the path. */
8874 file_info_cmp (const void *p1, const void *p2)
8876 const struct file_info *const s1 = (const struct file_info *) p1;
8877 const struct file_info *const s2 = (const struct file_info *) p2;
8878 const unsigned char *cp1;
8879 const unsigned char *cp2;
8881 /* Take care of file names without directories. We need to make sure that
8882 we return consistent values to qsort since some will get confused if
8883 we return the same value when identical operands are passed in opposite
8884 orders. So if neither has a directory, return 0 and otherwise return
8885 1 or -1 depending on which one has the directory. */
8886 if ((s1->path == s1->fname || s2->path == s2->fname))
8887 return (s2->path == s2->fname) - (s1->path == s1->fname);
8889 cp1 = (const unsigned char *) s1->path;
8890 cp2 = (const unsigned char *) s2->path;
8896 /* Reached the end of the first path? If so, handle like above. */
8897 if ((cp1 == (const unsigned char *) s1->fname)
8898 || (cp2 == (const unsigned char *) s2->fname))
8899 return ((cp2 == (const unsigned char *) s2->fname)
8900 - (cp1 == (const unsigned char *) s1->fname));
8902 /* Character of current path component the same? */
8903 else if (*cp1 != *cp2)
8908 struct file_name_acquire_data
8910 struct file_info *files;
8915 /* Traversal function for the hash table. */
8918 file_name_acquire (void ** slot, void *data)
8920 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
8921 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
8922 struct file_info *fi;
8925 gcc_assert (fnad->max_files >= d->emitted_number);
8927 if (! d->emitted_number)
8930 gcc_assert (fnad->max_files != fnad->used_files);
8932 fi = fnad->files + fnad->used_files++;
8934 /* Skip all leading "./". */
8936 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
8939 /* Create a new array entry. */
8941 fi->length = strlen (f);
8944 /* Search for the file name part. */
8945 f = strrchr (f, DIR_SEPARATOR);
8946 #if defined (DIR_SEPARATOR_2)
8948 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
8952 if (f == NULL || f < g)
8958 fi->fname = f == NULL ? fi->path : f + 1;
8962 /* Output the directory table and the file name table. We try to minimize
8963 the total amount of memory needed. A heuristic is used to avoid large
8964 slowdowns with many input files. */
8967 output_file_names (void)
8969 struct file_name_acquire_data fnad;
8971 struct file_info *files;
8972 struct dir_info *dirs;
8980 if (!last_emitted_file)
8982 dw2_asm_output_data (1, 0, "End directory table");
8983 dw2_asm_output_data (1, 0, "End file name table");
8987 numfiles = last_emitted_file->emitted_number;
8989 /* Allocate the various arrays we need. */
8990 files = XALLOCAVEC (struct file_info, numfiles);
8991 dirs = XALLOCAVEC (struct dir_info, numfiles);
8994 fnad.used_files = 0;
8995 fnad.max_files = numfiles;
8996 htab_traverse (file_table, file_name_acquire, &fnad);
8997 gcc_assert (fnad.used_files == fnad.max_files);
8999 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9001 /* Find all the different directories used. */
9002 dirs[0].path = files[0].path;
9003 dirs[0].length = files[0].fname - files[0].path;
9004 dirs[0].prefix = -1;
9006 dirs[0].dir_idx = 0;
9007 files[0].dir_idx = 0;
9010 for (i = 1; i < numfiles; i++)
9011 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9012 && memcmp (dirs[ndirs - 1].path, files[i].path,
9013 dirs[ndirs - 1].length) == 0)
9015 /* Same directory as last entry. */
9016 files[i].dir_idx = ndirs - 1;
9017 ++dirs[ndirs - 1].count;
9023 /* This is a new directory. */
9024 dirs[ndirs].path = files[i].path;
9025 dirs[ndirs].length = files[i].fname - files[i].path;
9026 dirs[ndirs].count = 1;
9027 dirs[ndirs].dir_idx = ndirs;
9028 files[i].dir_idx = ndirs;
9030 /* Search for a prefix. */
9031 dirs[ndirs].prefix = -1;
9032 for (j = 0; j < ndirs; j++)
9033 if (dirs[j].length < dirs[ndirs].length
9034 && dirs[j].length > 1
9035 && (dirs[ndirs].prefix == -1
9036 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9037 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9038 dirs[ndirs].prefix = j;
9043 /* Now to the actual work. We have to find a subset of the directories which
9044 allow expressing the file name using references to the directory table
9045 with the least amount of characters. We do not do an exhaustive search
9046 where we would have to check out every combination of every single
9047 possible prefix. Instead we use a heuristic which provides nearly optimal
9048 results in most cases and never is much off. */
9049 saved = XALLOCAVEC (int, ndirs);
9050 savehere = XALLOCAVEC (int, ndirs);
9052 memset (saved, '\0', ndirs * sizeof (saved[0]));
9053 for (i = 0; i < ndirs; i++)
9058 /* We can always save some space for the current directory. But this
9059 does not mean it will be enough to justify adding the directory. */
9060 savehere[i] = dirs[i].length;
9061 total = (savehere[i] - saved[i]) * dirs[i].count;
9063 for (j = i + 1; j < ndirs; j++)
9066 if (saved[j] < dirs[i].length)
9068 /* Determine whether the dirs[i] path is a prefix of the
9073 while (k != -1 && k != (int) i)
9078 /* Yes it is. We can possibly save some memory by
9079 writing the filenames in dirs[j] relative to
9081 savehere[j] = dirs[i].length;
9082 total += (savehere[j] - saved[j]) * dirs[j].count;
9087 /* Check whether we can save enough to justify adding the dirs[i]
9089 if (total > dirs[i].length + 1)
9091 /* It's worthwhile adding. */
9092 for (j = i; j < ndirs; j++)
9093 if (savehere[j] > 0)
9095 /* Remember how much we saved for this directory so far. */
9096 saved[j] = savehere[j];
9098 /* Remember the prefix directory. */
9099 dirs[j].dir_idx = i;
9104 /* Emit the directory name table. */
9105 idx_offset = dirs[0].length > 0 ? 1 : 0;
9106 for (i = 1 - idx_offset; i < ndirs; i++)
9107 dw2_asm_output_nstring (dirs[i].path,
9109 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9110 "Directory Entry: %#x", i + idx_offset);
9112 dw2_asm_output_data (1, 0, "End directory table");
9114 /* We have to emit them in the order of emitted_number since that's
9115 used in the debug info generation. To do this efficiently we
9116 generate a back-mapping of the indices first. */
9117 backmap = XALLOCAVEC (int, numfiles);
9118 for (i = 0; i < numfiles; i++)
9119 backmap[files[i].file_idx->emitted_number - 1] = i;
9121 /* Now write all the file names. */
9122 for (i = 0; i < numfiles; i++)
9124 int file_idx = backmap[i];
9125 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9127 #ifdef VMS_DEBUGGING_INFO
9128 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9130 /* Setting these fields can lead to debugger miscomparisons,
9131 but VMS Debug requires them to be set correctly. */
9136 int maxfilelen = strlen (files[file_idx].path)
9137 + dirs[dir_idx].length
9138 + MAX_VMS_VERSION_LEN + 1;
9139 char *filebuf = XALLOCAVEC (char, maxfilelen);
9141 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9142 snprintf (filebuf, maxfilelen, "%s;%d",
9143 files[file_idx].path + dirs[dir_idx].length, ver);
9145 dw2_asm_output_nstring
9146 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
9148 /* Include directory index. */
9149 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9151 /* Modification time. */
9152 dw2_asm_output_data_uleb128
9153 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9157 /* File length in bytes. */
9158 dw2_asm_output_data_uleb128
9159 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9163 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9164 "File Entry: %#x", (unsigned) i + 1);
9166 /* Include directory index. */
9167 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9169 /* Modification time. */
9170 dw2_asm_output_data_uleb128 (0, NULL);
9172 /* File length in bytes. */
9173 dw2_asm_output_data_uleb128 (0, NULL);
9174 #endif /* VMS_DEBUGGING_INFO */
9177 dw2_asm_output_data (1, 0, "End file name table");
9181 /* Output one line number table into the .debug_line section. */
9184 output_one_line_info_table (dw_line_info_table *table)
9186 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9187 unsigned int current_line = 1;
9188 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
9189 dw_line_info_entry *ent;
9192 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
9194 switch (ent->opcode)
9196 case LI_set_address:
9197 /* ??? Unfortunately, we have little choice here currently, and
9198 must always use the most general form. GCC does not know the
9199 address delta itself, so we can't use DW_LNS_advance_pc. Many
9200 ports do have length attributes which will give an upper bound
9201 on the address range. We could perhaps use length attributes
9202 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9203 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
9205 /* This can handle any delta. This takes
9206 4+DWARF2_ADDR_SIZE bytes. */
9207 dw2_asm_output_data (1, 0, "set address %s", line_label);
9208 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9209 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9210 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9214 if (ent->val == current_line)
9216 /* We still need to start a new row, so output a copy insn. */
9217 dw2_asm_output_data (1, DW_LNS_copy,
9218 "copy line %u", current_line);
9222 int line_offset = ent->val - current_line;
9223 int line_delta = line_offset - DWARF_LINE_BASE;
9225 current_line = ent->val;
9226 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9228 /* This can handle deltas from -10 to 234, using the current
9229 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9230 This takes 1 byte. */
9231 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9232 "line %u", current_line);
9236 /* This can handle any delta. This takes at least 4 bytes,
9237 depending on the value being encoded. */
9238 dw2_asm_output_data (1, DW_LNS_advance_line,
9239 "advance to line %u", current_line);
9240 dw2_asm_output_data_sleb128 (line_offset, NULL);
9241 dw2_asm_output_data (1, DW_LNS_copy, NULL);
9247 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
9248 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9252 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
9253 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9256 case LI_negate_stmt:
9257 current_is_stmt = !current_is_stmt;
9258 dw2_asm_output_data (1, DW_LNS_negate_stmt,
9259 "is_stmt %d", current_is_stmt);
9262 case LI_set_prologue_end:
9263 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
9264 "set prologue end");
9267 case LI_set_epilogue_begin:
9268 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
9269 "set epilogue begin");
9272 case LI_set_discriminator:
9273 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
9274 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
9275 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
9276 dw2_asm_output_data_uleb128 (ent->val, NULL);
9281 /* Emit debug info for the address of the end of the table. */
9282 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
9283 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9284 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9285 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
9287 dw2_asm_output_data (1, 0, "end sequence");
9288 dw2_asm_output_data_uleb128 (1, NULL);
9289 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9292 /* Output the source line number correspondence information. This
9293 information goes into the .debug_line section. */
9296 output_line_info (void)
9298 char l1[20], l2[20], p1[20], p2[20];
9299 int ver = dwarf_version;
9300 bool saw_one = false;
9303 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9304 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9305 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9306 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9308 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9309 dw2_asm_output_data (4, 0xffffffff,
9310 "Initial length escape value indicating 64-bit DWARF extension");
9311 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9312 "Length of Source Line Info");
9313 ASM_OUTPUT_LABEL (asm_out_file, l1);
9315 dw2_asm_output_data (2, ver, "DWARF Version");
9316 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9317 ASM_OUTPUT_LABEL (asm_out_file, p1);
9319 /* Define the architecture-dependent minimum instruction length (in bytes).
9320 In this implementation of DWARF, this field is used for information
9321 purposes only. Since GCC generates assembly language, we have no
9322 a priori knowledge of how many instruction bytes are generated for each
9323 source line, and therefore can use only the DW_LNE_set_address and
9324 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9325 this as '1', which is "correct enough" for all architectures,
9326 and don't let the target override. */
9327 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9330 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
9331 "Maximum Operations Per Instruction");
9332 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9333 "Default is_stmt_start flag");
9334 dw2_asm_output_data (1, DWARF_LINE_BASE,
9335 "Line Base Value (Special Opcodes)");
9336 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9337 "Line Range Value (Special Opcodes)");
9338 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9339 "Special Opcode Base");
9341 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9346 case DW_LNS_advance_pc:
9347 case DW_LNS_advance_line:
9348 case DW_LNS_set_file:
9349 case DW_LNS_set_column:
9350 case DW_LNS_fixed_advance_pc:
9351 case DW_LNS_set_isa:
9359 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
9363 /* Write out the information about the files we use. */
9364 output_file_names ();
9365 ASM_OUTPUT_LABEL (asm_out_file, p2);
9367 if (separate_line_info)
9369 dw_line_info_table *table;
9372 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
9375 output_one_line_info_table (table);
9379 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
9381 output_one_line_info_table (cold_text_section_line_info);
9385 /* ??? Some Darwin linkers crash on a .debug_line section with no
9386 sequences. Further, merely a DW_LNE_end_sequence entry is not
9387 sufficient -- the address column must also be initialized.
9388 Make sure to output at least one set_address/end_sequence pair,
9389 choosing .text since that section is always present. */
9390 if (text_section_line_info->in_use || !saw_one)
9391 output_one_line_info_table (text_section_line_info);
9393 /* Output the marker for the end of the line number info. */
9394 ASM_OUTPUT_LABEL (asm_out_file, l2);
9397 /* Given a pointer to a tree node for some base type, return a pointer to
9398 a DIE that describes the given type.
9400 This routine must only be called for GCC type nodes that correspond to
9401 Dwarf base (fundamental) types. */
9404 base_type_die (tree type)
9406 dw_die_ref base_type_result;
9407 enum dwarf_type encoding;
9409 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9412 /* If this is a subtype that should not be emitted as a subrange type,
9413 use the base type. See subrange_type_for_debug_p. */
9414 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
9415 type = TREE_TYPE (type);
9417 switch (TREE_CODE (type))
9420 if ((dwarf_version >= 4 || !dwarf_strict)
9422 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9423 && DECL_IS_BUILTIN (TYPE_NAME (type))
9424 && DECL_NAME (TYPE_NAME (type)))
9426 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
9427 if (strcmp (name, "char16_t") == 0
9428 || strcmp (name, "char32_t") == 0)
9430 encoding = DW_ATE_UTF;
9434 if (TYPE_STRING_FLAG (type))
9436 if (TYPE_UNSIGNED (type))
9437 encoding = DW_ATE_unsigned_char;
9439 encoding = DW_ATE_signed_char;
9441 else if (TYPE_UNSIGNED (type))
9442 encoding = DW_ATE_unsigned;
9444 encoding = DW_ATE_signed;
9448 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9450 if (dwarf_version >= 3 || !dwarf_strict)
9451 encoding = DW_ATE_decimal_float;
9453 encoding = DW_ATE_lo_user;
9456 encoding = DW_ATE_float;
9459 case FIXED_POINT_TYPE:
9460 if (!(dwarf_version >= 3 || !dwarf_strict))
9461 encoding = DW_ATE_lo_user;
9462 else if (TYPE_UNSIGNED (type))
9463 encoding = DW_ATE_unsigned_fixed;
9465 encoding = DW_ATE_signed_fixed;
9468 /* Dwarf2 doesn't know anything about complex ints, so use
9469 a user defined type for it. */
9471 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9472 encoding = DW_ATE_complex_float;
9474 encoding = DW_ATE_lo_user;
9478 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9479 encoding = DW_ATE_boolean;
9483 /* No other TREE_CODEs are Dwarf fundamental types. */
9487 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
9489 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9490 int_size_in_bytes (type));
9491 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9493 return base_type_result;
9496 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9497 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9500 is_base_type (tree type)
9502 switch (TREE_CODE (type))
9508 case FIXED_POINT_TYPE:
9516 case QUAL_UNION_TYPE:
9521 case REFERENCE_TYPE:
9535 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9536 node, return the size in bits for the type if it is a constant, or else
9537 return the alignment for the type if the type's size is not constant, or
9538 else return BITS_PER_WORD if the type actually turns out to be an
9541 static inline unsigned HOST_WIDE_INT
9542 simple_type_size_in_bits (const_tree type)
9544 if (TREE_CODE (type) == ERROR_MARK)
9545 return BITS_PER_WORD;
9546 else if (TYPE_SIZE (type) == NULL_TREE)
9548 else if (host_integerp (TYPE_SIZE (type), 1))
9549 return tree_low_cst (TYPE_SIZE (type), 1);
9551 return TYPE_ALIGN (type);
9554 /* Similarly, but return a double_int instead of UHWI. */
9556 static inline double_int
9557 double_int_type_size_in_bits (const_tree type)
9559 if (TREE_CODE (type) == ERROR_MARK)
9560 return uhwi_to_double_int (BITS_PER_WORD);
9561 else if (TYPE_SIZE (type) == NULL_TREE)
9562 return double_int_zero;
9563 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
9564 return tree_to_double_int (TYPE_SIZE (type));
9566 return uhwi_to_double_int (TYPE_ALIGN (type));
9569 /* Given a pointer to a tree node for a subrange type, return a pointer
9570 to a DIE that describes the given type. */
9573 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
9575 dw_die_ref subrange_die;
9576 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9578 if (context_die == NULL)
9579 context_die = comp_unit_die ();
9581 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9583 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9585 /* The size of the subrange type and its base type do not match,
9586 so we need to generate a size attribute for the subrange type. */
9587 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9591 add_bound_info (subrange_die, DW_AT_lower_bound, low);
9593 add_bound_info (subrange_die, DW_AT_upper_bound, high);
9595 return subrange_die;
9598 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9599 entry that chains various modifiers in front of the given type. */
9602 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9603 dw_die_ref context_die)
9605 enum tree_code code = TREE_CODE (type);
9606 dw_die_ref mod_type_die;
9607 dw_die_ref sub_die = NULL;
9608 tree item_type = NULL;
9609 tree qualified_type;
9610 tree name, low, high;
9612 if (code == ERROR_MARK)
9615 /* See if we already have the appropriately qualified variant of
9618 = get_qualified_type (type,
9619 ((is_const_type ? TYPE_QUAL_CONST : 0)
9620 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9622 if (qualified_type == sizetype
9623 && TYPE_NAME (qualified_type)
9624 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
9626 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
9628 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
9629 && TYPE_PRECISION (t)
9630 == TYPE_PRECISION (qualified_type)
9631 && TYPE_UNSIGNED (t)
9632 == TYPE_UNSIGNED (qualified_type));
9636 /* If we do, then we can just use its DIE, if it exists. */
9639 mod_type_die = lookup_type_die (qualified_type);
9641 return mod_type_die;
9644 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9646 /* Handle C typedef types. */
9647 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
9648 && !DECL_ARTIFICIAL (name))
9650 tree dtype = TREE_TYPE (name);
9652 if (qualified_type == dtype)
9654 /* For a named type, use the typedef. */
9655 gen_type_die (qualified_type, context_die);
9656 return lookup_type_die (qualified_type);
9658 else if (is_const_type < TYPE_READONLY (dtype)
9659 || is_volatile_type < TYPE_VOLATILE (dtype)
9660 || (is_const_type <= TYPE_READONLY (dtype)
9661 && is_volatile_type <= TYPE_VOLATILE (dtype)
9662 && DECL_ORIGINAL_TYPE (name) != type))
9663 /* cv-unqualified version of named type. Just use the unnamed
9664 type to which it refers. */
9665 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9666 is_const_type, is_volatile_type,
9668 /* Else cv-qualified version of named type; fall through. */
9672 /* If both is_const_type and is_volatile_type, prefer the path
9673 which leads to a qualified type. */
9674 && (!is_volatile_type
9675 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
9676 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
9678 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
9679 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9681 else if (is_volatile_type)
9683 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
9684 sub_die = modified_type_die (type, is_const_type, 0, context_die);
9686 else if (code == POINTER_TYPE)
9688 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
9689 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9690 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9691 item_type = TREE_TYPE (type);
9692 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
9693 add_AT_unsigned (mod_type_die, DW_AT_address_class,
9694 TYPE_ADDR_SPACE (item_type));
9696 else if (code == REFERENCE_TYPE)
9698 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
9699 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
9702 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
9703 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9704 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9705 item_type = TREE_TYPE (type);
9706 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
9707 add_AT_unsigned (mod_type_die, DW_AT_address_class,
9708 TYPE_ADDR_SPACE (item_type));
9710 else if (code == INTEGER_TYPE
9711 && TREE_TYPE (type) != NULL_TREE
9712 && subrange_type_for_debug_p (type, &low, &high))
9714 mod_type_die = subrange_type_die (type, low, high, context_die);
9715 item_type = TREE_TYPE (type);
9717 else if (is_base_type (type))
9718 mod_type_die = base_type_die (type);
9721 gen_type_die (type, context_die);
9723 /* We have to get the type_main_variant here (and pass that to the
9724 `lookup_type_die' routine) because the ..._TYPE node we have
9725 might simply be a *copy* of some original type node (where the
9726 copy was created to help us keep track of typedef names) and
9727 that copy might have a different TYPE_UID from the original
9729 if (TREE_CODE (type) != VECTOR_TYPE)
9730 return lookup_type_die (type_main_variant (type));
9732 /* Vectors have the debugging information in the type,
9733 not the main variant. */
9734 return lookup_type_die (type);
9737 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9738 don't output a DW_TAG_typedef, since there isn't one in the
9739 user's program; just attach a DW_AT_name to the type.
9740 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
9741 if the base type already has the same name. */
9743 && ((TREE_CODE (name) != TYPE_DECL
9744 && (qualified_type == TYPE_MAIN_VARIANT (type)
9745 || (!is_const_type && !is_volatile_type)))
9746 || (TREE_CODE (name) == TYPE_DECL
9747 && TREE_TYPE (name) == qualified_type
9748 && DECL_NAME (name))))
9750 if (TREE_CODE (name) == TYPE_DECL)
9751 /* Could just call add_name_and_src_coords_attributes here,
9752 but since this is a builtin type it doesn't have any
9753 useful source coordinates anyway. */
9754 name = DECL_NAME (name);
9755 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9756 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
9757 if (TYPE_ARTIFICIAL (type))
9758 add_AT_flag (mod_type_die, DW_AT_artificial, 1);
9760 /* This probably indicates a bug. */
9761 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
9762 add_name_attribute (mod_type_die, "__unknown__");
9765 equate_type_number_to_die (qualified_type, mod_type_die);
9768 /* We must do this after the equate_type_number_to_die call, in case
9769 this is a recursive type. This ensures that the modified_type_die
9770 recursion will terminate even if the type is recursive. Recursive
9771 types are possible in Ada. */
9772 sub_die = modified_type_die (item_type,
9773 TYPE_READONLY (item_type),
9774 TYPE_VOLATILE (item_type),
9777 if (sub_die != NULL)
9778 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9780 return mod_type_die;
9783 /* Generate DIEs for the generic parameters of T.
9784 T must be either a generic type or a generic function.
9785 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
9788 gen_generic_params_dies (tree t)
9792 dw_die_ref die = NULL;
9794 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
9798 die = lookup_type_die (t);
9799 else if (DECL_P (t))
9800 die = lookup_decl_die (t);
9804 parms = lang_hooks.get_innermost_generic_parms (t);
9806 /* T has no generic parameter. It means T is neither a generic type
9807 or function. End of story. */
9810 parms_num = TREE_VEC_LENGTH (parms);
9811 args = lang_hooks.get_innermost_generic_args (t);
9812 for (i = 0; i < parms_num; i++)
9814 tree parm, arg, arg_pack_elems;
9816 parm = TREE_VEC_ELT (parms, i);
9817 arg = TREE_VEC_ELT (args, i);
9818 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
9819 gcc_assert (parm && TREE_VALUE (parm) && arg);
9821 if (parm && TREE_VALUE (parm) && arg)
9823 /* If PARM represents a template parameter pack,
9824 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
9825 by DW_TAG_template_*_parameter DIEs for the argument
9826 pack elements of ARG. Note that ARG would then be
9827 an argument pack. */
9829 template_parameter_pack_die (TREE_VALUE (parm),
9833 generic_parameter_die (TREE_VALUE (parm), arg,
9834 true /* Emit DW_AT_name */, die);
9839 /* Create and return a DIE for PARM which should be
9840 the representation of a generic type parameter.
9841 For instance, in the C++ front end, PARM would be a template parameter.
9842 ARG is the argument to PARM.
9843 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
9845 PARENT_DIE is the parent DIE which the new created DIE should be added to,
9849 generic_parameter_die (tree parm, tree arg,
9851 dw_die_ref parent_die)
9853 dw_die_ref tmpl_die = NULL;
9854 const char *name = NULL;
9856 if (!parm || !DECL_NAME (parm) || !arg)
9859 /* We support non-type generic parameters and arguments,
9860 type generic parameters and arguments, as well as
9861 generic generic parameters (a.k.a. template template parameters in C++)
9863 if (TREE_CODE (parm) == PARM_DECL)
9864 /* PARM is a nontype generic parameter */
9865 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
9866 else if (TREE_CODE (parm) == TYPE_DECL)
9867 /* PARM is a type generic parameter. */
9868 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
9869 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
9870 /* PARM is a generic generic parameter.
9871 Its DIE is a GNU extension. It shall have a
9872 DW_AT_name attribute to represent the name of the template template
9873 parameter, and a DW_AT_GNU_template_name attribute to represent the
9874 name of the template template argument. */
9875 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
9884 /* If PARM is a generic parameter pack, it means we are
9885 emitting debug info for a template argument pack element.
9886 In other terms, ARG is a template argument pack element.
9887 In that case, we don't emit any DW_AT_name attribute for
9891 name = IDENTIFIER_POINTER (DECL_NAME (parm));
9893 add_AT_string (tmpl_die, DW_AT_name, name);
9896 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
9898 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
9899 TMPL_DIE should have a child DW_AT_type attribute that is set
9900 to the type of the argument to PARM, which is ARG.
9901 If PARM is a type generic parameter, TMPL_DIE should have a
9902 child DW_AT_type that is set to ARG. */
9903 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
9904 add_type_attribute (tmpl_die, tmpl_type, 0,
9905 TREE_THIS_VOLATILE (tmpl_type),
9910 /* So TMPL_DIE is a DIE representing a
9911 a generic generic template parameter, a.k.a template template
9912 parameter in C++ and arg is a template. */
9914 /* The DW_AT_GNU_template_name attribute of the DIE must be set
9915 to the name of the argument. */
9916 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
9918 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
9921 if (TREE_CODE (parm) == PARM_DECL)
9922 /* So PARM is a non-type generic parameter.
9923 DWARF3 5.6.8 says we must set a DW_AT_const_value child
9924 attribute of TMPL_DIE which value represents the value
9926 We must be careful here:
9927 The value of ARG might reference some function decls.
9928 We might currently be emitting debug info for a generic
9929 type and types are emitted before function decls, we don't
9930 know if the function decls referenced by ARG will actually be
9931 emitted after cgraph computations.
9932 So must defer the generation of the DW_AT_const_value to
9933 after cgraph is ready. */
9934 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
9940 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
9941 PARM_PACK must be a template parameter pack. The returned DIE
9942 will be child DIE of PARENT_DIE. */
9945 template_parameter_pack_die (tree parm_pack,
9946 tree parm_pack_args,
9947 dw_die_ref parent_die)
9952 gcc_assert (parent_die && parm_pack);
9954 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
9955 add_name_and_src_coords_attributes (die, parm_pack);
9956 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
9957 generic_parameter_die (parm_pack,
9958 TREE_VEC_ELT (parm_pack_args, j),
9959 false /* Don't emit DW_AT_name */,
9964 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9965 an enumerated type. */
9968 type_is_enum (const_tree type)
9970 return TREE_CODE (type) == ENUMERAL_TYPE;
9973 /* Return the DBX register number described by a given RTL node. */
9976 dbx_reg_number (const_rtx rtl)
9978 unsigned regno = REGNO (rtl);
9980 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
9982 #ifdef LEAF_REG_REMAP
9983 if (current_function_uses_only_leaf_regs)
9985 int leaf_reg = LEAF_REG_REMAP (regno);
9987 regno = (unsigned) leaf_reg;
9991 return DBX_REGISTER_NUMBER (regno);
9994 /* Optionally add a DW_OP_piece term to a location description expression.
9995 DW_OP_piece is only added if the location description expression already
9996 doesn't end with DW_OP_piece. */
9999 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10001 dw_loc_descr_ref loc;
10003 if (*list_head != NULL)
10005 /* Find the end of the chain. */
10006 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10009 if (loc->dw_loc_opc != DW_OP_piece)
10010 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10014 /* Return a location descriptor that designates a machine register or
10015 zero if there is none. */
10017 static dw_loc_descr_ref
10018 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10022 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10025 /* We only use "frame base" when we're sure we're talking about the
10026 post-prologue local stack frame. We do this by *not* running
10027 register elimination until this point, and recognizing the special
10028 argument pointer and soft frame pointer rtx's.
10029 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10030 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
10031 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
10033 dw_loc_descr_ref result = NULL;
10035 if (dwarf_version >= 4 || !dwarf_strict)
10037 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
10040 add_loc_descr (&result,
10041 new_loc_descr (DW_OP_stack_value, 0, 0));
10046 regs = targetm.dwarf_register_span (rtl);
10048 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10049 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10051 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10054 /* Return a location descriptor that designates a machine register for
10055 a given hard register number. */
10057 static dw_loc_descr_ref
10058 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10060 dw_loc_descr_ref reg_loc_descr;
10064 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10066 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10068 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10069 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10071 return reg_loc_descr;
10074 /* Given an RTL of a register, return a location descriptor that
10075 designates a value that spans more than one register. */
10077 static dw_loc_descr_ref
10078 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10079 enum var_init_status initialized)
10081 int nregs, size, i;
10083 dw_loc_descr_ref loc_result = NULL;
10086 #ifdef LEAF_REG_REMAP
10087 if (current_function_uses_only_leaf_regs)
10089 int leaf_reg = LEAF_REG_REMAP (reg);
10090 if (leaf_reg != -1)
10091 reg = (unsigned) leaf_reg;
10094 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10095 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10097 /* Simple, contiguous registers. */
10098 if (regs == NULL_RTX)
10100 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10105 dw_loc_descr_ref t;
10107 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10108 VAR_INIT_STATUS_INITIALIZED);
10109 add_loc_descr (&loc_result, t);
10110 add_loc_descr_op_piece (&loc_result, size);
10116 /* Now onto stupid register sets in non contiguous locations. */
10118 gcc_assert (GET_CODE (regs) == PARALLEL);
10120 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10123 for (i = 0; i < XVECLEN (regs, 0); ++i)
10125 dw_loc_descr_ref t;
10127 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10128 VAR_INIT_STATUS_INITIALIZED);
10129 add_loc_descr (&loc_result, t);
10130 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10131 add_loc_descr_op_piece (&loc_result, size);
10134 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10135 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10139 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
10141 /* Return a location descriptor that designates a constant i,
10142 as a compound operation from constant (i >> shift), constant shift
10145 static dw_loc_descr_ref
10146 int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
10148 dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
10149 add_loc_descr (&ret, int_loc_descriptor (shift));
10150 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
10154 /* Return a location descriptor that designates a constant. */
10156 static dw_loc_descr_ref
10157 int_loc_descriptor (HOST_WIDE_INT i)
10159 enum dwarf_location_atom op;
10161 /* Pick the smallest representation of a constant, rather than just
10162 defaulting to the LEB encoding. */
10165 int clz = clz_hwi (i);
10166 int ctz = ctz_hwi (i);
10168 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10169 else if (i <= 0xff)
10170 op = DW_OP_const1u;
10171 else if (i <= 0xffff)
10172 op = DW_OP_const2u;
10173 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
10174 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
10175 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10176 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10177 while DW_OP_const4u is 5 bytes. */
10178 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
10179 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10180 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
10181 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10182 while DW_OP_const4u is 5 bytes. */
10183 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
10184 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
10185 op = DW_OP_const4u;
10186 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10187 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
10188 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10189 while DW_OP_constu of constant >= 0x100000000 takes at least
10191 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
10192 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
10193 && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
10194 >= HOST_BITS_PER_WIDE_INT)
10195 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10196 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10197 while DW_OP_constu takes in this case at least 6 bytes. */
10198 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
10199 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
10200 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
10201 && size_of_uleb128 (i) > 6)
10202 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10203 return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
10210 op = DW_OP_const1s;
10211 else if (i >= -0x8000)
10212 op = DW_OP_const2s;
10213 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
10215 if (size_of_int_loc_descriptor (i) < 5)
10217 dw_loc_descr_ref ret = int_loc_descriptor (-i);
10218 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
10221 op = DW_OP_const4s;
10225 if (size_of_int_loc_descriptor (i)
10226 < (unsigned long) 1 + size_of_sleb128 (i))
10228 dw_loc_descr_ref ret = int_loc_descriptor (-i);
10229 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
10236 return new_loc_descr (op, i, 0);
10239 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10240 without actually allocating it. */
10242 static unsigned long
10243 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
10245 return size_of_int_loc_descriptor (i >> shift)
10246 + size_of_int_loc_descriptor (shift)
10250 /* Return size_of_locs (int_loc_descriptor (i)) without
10251 actually allocating it. */
10253 static unsigned long
10254 size_of_int_loc_descriptor (HOST_WIDE_INT i)
10263 else if (i <= 0xff)
10265 else if (i <= 0xffff)
10269 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
10270 && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
10271 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10273 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10274 && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
10275 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10277 else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
10279 s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
10280 if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
10281 && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
10282 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10284 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
10285 && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
10286 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10288 else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
10289 && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
10291 return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
10300 else if (i >= -0x8000)
10302 else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
10304 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
10306 s = size_of_int_loc_descriptor (-i) + 1;
10314 unsigned long r = 1 + size_of_sleb128 (i);
10315 if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
10317 s = size_of_int_loc_descriptor (-i) + 1;
10326 /* Return loc description representing "address" of integer value.
10327 This can appear only as toplevel expression. */
10329 static dw_loc_descr_ref
10330 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
10333 dw_loc_descr_ref loc_result = NULL;
10335 if (!(dwarf_version >= 4 || !dwarf_strict))
10338 litsize = size_of_int_loc_descriptor (i);
10339 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10340 is more compact. For DW_OP_stack_value we need:
10341 litsize + 1 (DW_OP_stack_value)
10342 and for DW_OP_implicit_value:
10343 1 (DW_OP_implicit_value) + 1 (length) + size. */
10344 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
10346 loc_result = int_loc_descriptor (i);
10347 add_loc_descr (&loc_result,
10348 new_loc_descr (DW_OP_stack_value, 0, 0));
10352 loc_result = new_loc_descr (DW_OP_implicit_value,
10354 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
10355 loc_result->dw_loc_oprnd2.v.val_int = i;
10359 /* Return a location descriptor that designates a base+offset location. */
10361 static dw_loc_descr_ref
10362 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10363 enum var_init_status initialized)
10365 unsigned int regno;
10366 dw_loc_descr_ref result;
10367 dw_fde_ref fde = cfun->fde;
10369 /* We only use "frame base" when we're sure we're talking about the
10370 post-prologue local stack frame. We do this by *not* running
10371 register elimination until this point, and recognizing the special
10372 argument pointer and soft frame pointer rtx's. */
10373 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10375 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10379 if (GET_CODE (elim) == PLUS)
10381 offset += INTVAL (XEXP (elim, 1));
10382 elim = XEXP (elim, 0);
10384 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10385 && (elim == hard_frame_pointer_rtx
10386 || elim == stack_pointer_rtx))
10387 || elim == (frame_pointer_needed
10388 ? hard_frame_pointer_rtx
10389 : stack_pointer_rtx));
10391 /* If drap register is used to align stack, use frame
10392 pointer + offset to access stack variables. If stack
10393 is aligned without drap, use stack pointer + offset to
10394 access stack variables. */
10395 if (crtl->stack_realign_tried
10396 && reg == frame_pointer_rtx)
10399 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10400 ? HARD_FRAME_POINTER_REGNUM
10402 return new_reg_loc_descr (base_reg, offset);
10405 gcc_assert (frame_pointer_fb_offset_valid);
10406 offset += frame_pointer_fb_offset;
10407 return new_loc_descr (DW_OP_fbreg, offset, 0);
10411 regno = DWARF_FRAME_REGNUM (REGNO (reg));
10413 if (!optimize && fde
10414 && (fde->drap_reg == regno || fde->vdrap_reg == regno))
10416 /* Use cfa+offset to represent the location of arguments passed
10417 on the stack when drap is used to align stack.
10418 Only do this when not optimizing, for optimized code var-tracking
10419 is supposed to track where the arguments live and the register
10420 used as vdrap or drap in some spot might be used for something
10421 else in other part of the routine. */
10422 return new_loc_descr (DW_OP_fbreg, offset, 0);
10426 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10429 result = new_loc_descr (DW_OP_bregx, regno, offset);
10431 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10432 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10437 /* Return true if this RTL expression describes a base+offset calculation. */
10440 is_based_loc (const_rtx rtl)
10442 return (GET_CODE (rtl) == PLUS
10443 && ((REG_P (XEXP (rtl, 0))
10444 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10445 && CONST_INT_P (XEXP (rtl, 1)))));
10448 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10451 static dw_loc_descr_ref
10452 tls_mem_loc_descriptor (rtx mem)
10455 dw_loc_descr_ref loc_result;
10457 if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
10460 base = get_base_address (MEM_EXPR (mem));
10462 || TREE_CODE (base) != VAR_DECL
10463 || !DECL_THREAD_LOCAL_P (base))
10466 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
10467 if (loc_result == NULL)
10470 if (MEM_OFFSET (mem))
10471 loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
10476 /* Output debug info about reason why we failed to expand expression as dwarf
10480 expansion_failed (tree expr, rtx rtl, char const *reason)
10482 if (dump_file && (dump_flags & TDF_DETAILS))
10484 fprintf (dump_file, "Failed to expand as dwarf: ");
10486 print_generic_expr (dump_file, expr, dump_flags);
10489 fprintf (dump_file, "\n");
10490 print_rtl (dump_file, rtl);
10492 fprintf (dump_file, "\nReason: %s\n", reason);
10496 /* Helper function for const_ok_for_output, called either directly
10497 or via for_each_rtx. */
10500 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
10504 if (GET_CODE (rtl) == UNSPEC)
10506 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10507 we can't express it in the debug info. */
10508 #ifdef ENABLE_CHECKING
10509 /* Don't complain about TLS UNSPECs, those are just too hard to
10511 if (XVECLEN (rtl, 0) != 1
10512 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
10513 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
10514 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
10515 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
10516 inform (current_function_decl
10517 ? DECL_SOURCE_LOCATION (current_function_decl)
10518 : UNKNOWN_LOCATION,
10519 #if NUM_UNSPEC_VALUES > 0
10520 "non-delegitimized UNSPEC %s (%d) found in variable location",
10521 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
10522 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
10525 "non-delegitimized UNSPEC %d found in variable location",
10529 expansion_failed (NULL_TREE, rtl,
10530 "UNSPEC hasn't been delegitimized.\n");
10534 if (GET_CODE (rtl) != SYMBOL_REF)
10537 if (CONSTANT_POOL_ADDRESS_P (rtl))
10540 get_pool_constant_mark (rtl, &marked);
10541 /* If all references to this pool constant were optimized away,
10542 it was not output and thus we can't represent it. */
10545 expansion_failed (NULL_TREE, rtl,
10546 "Constant was removed from constant pool.\n");
10551 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
10554 /* Avoid references to external symbols in debug info, on several targets
10555 the linker might even refuse to link when linking a shared library,
10556 and in many other cases the relocations for .debug_info/.debug_loc are
10557 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
10558 to be defined within the same shared library or executable are fine. */
10559 if (SYMBOL_REF_EXTERNAL_P (rtl))
10561 tree decl = SYMBOL_REF_DECL (rtl);
10563 if (decl == NULL || !targetm.binds_local_p (decl))
10565 expansion_failed (NULL_TREE, rtl,
10566 "Symbol not defined in current TU.\n");
10574 /* Return true if constant RTL can be emitted in DW_OP_addr or
10575 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
10576 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
10579 const_ok_for_output (rtx rtl)
10581 if (GET_CODE (rtl) == SYMBOL_REF)
10582 return const_ok_for_output_1 (&rtl, NULL) == 0;
10584 if (GET_CODE (rtl) == CONST)
10585 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
10590 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
10591 if possible, NULL otherwise. */
10594 base_type_for_mode (enum machine_mode mode, bool unsignedp)
10596 dw_die_ref type_die;
10597 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
10601 switch (TREE_CODE (type))
10609 type_die = lookup_type_die (type);
10611 type_die = modified_type_die (type, false, false, comp_unit_die ());
10612 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
10617 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
10618 type matching MODE, or, if MODE is narrower than or as wide as
10619 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
10622 static dw_loc_descr_ref
10623 convert_descriptor_to_mode (enum machine_mode mode, dw_loc_descr_ref op)
10625 enum machine_mode outer_mode = mode;
10626 dw_die_ref type_die;
10627 dw_loc_descr_ref cvt;
10629 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
10631 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
10634 type_die = base_type_for_mode (outer_mode, 1);
10635 if (type_die == NULL)
10637 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10638 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10639 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10640 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10641 add_loc_descr (&op, cvt);
10645 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
10647 static dw_loc_descr_ref
10648 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
10649 dw_loc_descr_ref op1)
10651 dw_loc_descr_ref ret = op0;
10652 add_loc_descr (&ret, op1);
10653 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10654 if (STORE_FLAG_VALUE != 1)
10656 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
10657 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
10662 /* Return location descriptor for signed comparison OP RTL. */
10664 static dw_loc_descr_ref
10665 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
10666 enum machine_mode mem_mode)
10668 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
10669 dw_loc_descr_ref op0, op1;
10672 if (op_mode == VOIDmode)
10673 op_mode = GET_MODE (XEXP (rtl, 1));
10674 if (op_mode == VOIDmode)
10678 && (GET_MODE_CLASS (op_mode) != MODE_INT
10679 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
10682 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
10683 VAR_INIT_STATUS_INITIALIZED);
10684 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
10685 VAR_INIT_STATUS_INITIALIZED);
10687 if (op0 == NULL || op1 == NULL)
10690 if (GET_MODE_CLASS (op_mode) != MODE_INT
10691 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
10692 return compare_loc_descriptor (op, op0, op1);
10694 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
10696 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
10697 dw_loc_descr_ref cvt;
10699 if (type_die == NULL)
10701 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10702 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10703 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10704 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10705 add_loc_descr (&op0, cvt);
10706 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10707 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10708 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10709 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10710 add_loc_descr (&op1, cvt);
10711 return compare_loc_descriptor (op, op0, op1);
10714 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
10715 /* For eq/ne, if the operands are known to be zero-extended,
10716 there is no need to do the fancy shifting up. */
10717 if (op == DW_OP_eq || op == DW_OP_ne)
10719 dw_loc_descr_ref last0, last1;
10720 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
10722 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
10724 /* deref_size zero extends, and for constants we can check
10725 whether they are zero extended or not. */
10726 if (((last0->dw_loc_opc == DW_OP_deref_size
10727 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
10728 || (CONST_INT_P (XEXP (rtl, 0))
10729 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
10730 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
10731 && ((last1->dw_loc_opc == DW_OP_deref_size
10732 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
10733 || (CONST_INT_P (XEXP (rtl, 1))
10734 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
10735 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
10736 return compare_loc_descriptor (op, op0, op1);
10738 /* EQ/NE comparison against constant in narrower type than
10739 DWARF2_ADDR_SIZE can be performed either as
10740 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
10743 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
10744 DW_OP_{eq,ne}. Pick whatever is shorter. */
10745 if (CONST_INT_P (XEXP (rtl, 1))
10746 && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
10747 && (size_of_int_loc_descriptor (shift) + 1
10748 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift)
10749 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
10750 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
10751 & GET_MODE_MASK (op_mode))))
10753 add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
10754 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10755 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
10756 & GET_MODE_MASK (op_mode));
10757 return compare_loc_descriptor (op, op0, op1);
10760 add_loc_descr (&op0, int_loc_descriptor (shift));
10761 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
10762 if (CONST_INT_P (XEXP (rtl, 1)))
10763 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
10766 add_loc_descr (&op1, int_loc_descriptor (shift));
10767 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
10769 return compare_loc_descriptor (op, op0, op1);
10772 /* Return location descriptor for unsigned comparison OP RTL. */
10774 static dw_loc_descr_ref
10775 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
10776 enum machine_mode mem_mode)
10778 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
10779 dw_loc_descr_ref op0, op1;
10781 if (op_mode == VOIDmode)
10782 op_mode = GET_MODE (XEXP (rtl, 1));
10783 if (op_mode == VOIDmode)
10785 if (GET_MODE_CLASS (op_mode) != MODE_INT)
10788 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
10791 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
10792 VAR_INIT_STATUS_INITIALIZED);
10793 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
10794 VAR_INIT_STATUS_INITIALIZED);
10796 if (op0 == NULL || op1 == NULL)
10799 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
10801 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
10802 dw_loc_descr_ref last0, last1;
10803 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
10805 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
10807 if (CONST_INT_P (XEXP (rtl, 0)))
10808 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
10809 /* deref_size zero extends, so no need to mask it again. */
10810 else if (last0->dw_loc_opc != DW_OP_deref_size
10811 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
10813 add_loc_descr (&op0, int_loc_descriptor (mask));
10814 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10816 if (CONST_INT_P (XEXP (rtl, 1)))
10817 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
10818 /* deref_size zero extends, so no need to mask it again. */
10819 else if (last1->dw_loc_opc != DW_OP_deref_size
10820 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
10822 add_loc_descr (&op1, int_loc_descriptor (mask));
10823 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
10826 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
10828 HOST_WIDE_INT bias = 1;
10829 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
10830 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
10831 if (CONST_INT_P (XEXP (rtl, 1)))
10832 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
10833 + INTVAL (XEXP (rtl, 1)));
10835 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
10838 return compare_loc_descriptor (op, op0, op1);
10841 /* Return location descriptor for {U,S}{MIN,MAX}. */
10843 static dw_loc_descr_ref
10844 minmax_loc_descriptor (rtx rtl, enum machine_mode mode,
10845 enum machine_mode mem_mode)
10847 enum dwarf_location_atom op;
10848 dw_loc_descr_ref op0, op1, ret;
10849 dw_loc_descr_ref bra_node, drop_node;
10852 && (GET_MODE_CLASS (mode) != MODE_INT
10853 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
10856 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
10857 VAR_INIT_STATUS_INITIALIZED);
10858 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
10859 VAR_INIT_STATUS_INITIALIZED);
10861 if (op0 == NULL || op1 == NULL)
10864 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
10865 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
10866 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
10867 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
10869 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
10871 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
10872 add_loc_descr (&op0, int_loc_descriptor (mask));
10873 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
10874 add_loc_descr (&op1, int_loc_descriptor (mask));
10875 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
10877 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
10879 HOST_WIDE_INT bias = 1;
10880 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
10881 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
10882 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
10885 else if (GET_MODE_CLASS (mode) == MODE_INT
10886 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
10888 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
10889 add_loc_descr (&op0, int_loc_descriptor (shift));
10890 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
10891 add_loc_descr (&op1, int_loc_descriptor (shift));
10892 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
10894 else if (GET_MODE_CLASS (mode) == MODE_INT
10895 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
10897 dw_die_ref type_die = base_type_for_mode (mode, 0);
10898 dw_loc_descr_ref cvt;
10899 if (type_die == NULL)
10901 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10902 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10903 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10904 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10905 add_loc_descr (&op0, cvt);
10906 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10907 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10908 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10909 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10910 add_loc_descr (&op1, cvt);
10913 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
10918 add_loc_descr (&ret, op1);
10919 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10920 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
10921 add_loc_descr (&ret, bra_node);
10922 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
10923 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
10924 add_loc_descr (&ret, drop_node);
10925 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10926 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
10927 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
10928 && GET_MODE_CLASS (mode) == MODE_INT
10929 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
10930 ret = convert_descriptor_to_mode (mode, ret);
10934 /* Helper function for mem_loc_descriptor. Perform OP binary op,
10935 but after converting arguments to type_die, afterwards
10936 convert back to unsigned. */
10938 static dw_loc_descr_ref
10939 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
10940 enum machine_mode mode, enum machine_mode mem_mode)
10942 dw_loc_descr_ref cvt, op0, op1;
10944 if (type_die == NULL)
10946 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
10947 VAR_INIT_STATUS_INITIALIZED);
10948 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
10949 VAR_INIT_STATUS_INITIALIZED);
10950 if (op0 == NULL || op1 == NULL)
10952 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10953 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10954 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10955 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10956 add_loc_descr (&op0, cvt);
10957 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
10958 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
10959 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
10960 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
10961 add_loc_descr (&op1, cvt);
10962 add_loc_descr (&op0, op1);
10963 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
10964 return convert_descriptor_to_mode (mode, op0);
10967 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
10968 const0 is DW_OP_lit0 or corresponding typed constant,
10969 const1 is DW_OP_lit1 or corresponding typed constant
10970 and constMSB is constant with just the MSB bit set
10972 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
10973 L1: const0 DW_OP_swap
10974 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
10975 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
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 const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
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 const0 DW_OP_skip <L4>
10989 L1: const1 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>
10995 static dw_loc_descr_ref
10996 clz_loc_descriptor (rtx rtl, enum machine_mode mode,
10997 enum machine_mode mem_mode)
10999 dw_loc_descr_ref op0, ret, tmp;
11000 HOST_WIDE_INT valv;
11001 dw_loc_descr_ref l1jump, l1label;
11002 dw_loc_descr_ref l2jump, l2label;
11003 dw_loc_descr_ref l3jump, l3label;
11004 dw_loc_descr_ref l4jump, l4label;
11007 if (GET_MODE_CLASS (mode) != MODE_INT
11008 || GET_MODE (XEXP (rtl, 0)) != mode
11009 || (GET_CODE (rtl) == CLZ
11010 && GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT))
11013 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11014 VAR_INIT_STATUS_INITIALIZED);
11018 if (GET_CODE (rtl) == CLZ)
11020 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11021 valv = GET_MODE_BITSIZE (mode);
11023 else if (GET_CODE (rtl) == FFS)
11025 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11026 valv = GET_MODE_BITSIZE (mode);
11027 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11028 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
11029 add_loc_descr (&ret, l1jump);
11030 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11031 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
11032 VAR_INIT_STATUS_INITIALIZED);
11035 add_loc_descr (&ret, tmp);
11036 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
11037 add_loc_descr (&ret, l4jump);
11038 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
11039 ? const1_rtx : const0_rtx,
11041 VAR_INIT_STATUS_INITIALIZED);
11042 if (l1label == NULL)
11044 add_loc_descr (&ret, l1label);
11045 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11046 l2label = new_loc_descr (DW_OP_dup, 0, 0);
11047 add_loc_descr (&ret, l2label);
11048 if (GET_CODE (rtl) != CLZ)
11050 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
11051 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
11052 << (GET_MODE_BITSIZE (mode) - 1));
11054 msb = immed_double_const (0, (unsigned HOST_WIDE_INT) 1
11055 << (GET_MODE_BITSIZE (mode)
11056 - HOST_BITS_PER_WIDE_INT - 1), mode);
11057 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
11058 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11059 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
11060 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
11062 tmp = mem_loc_descriptor (msb, mode, mem_mode,
11063 VAR_INIT_STATUS_INITIALIZED);
11066 add_loc_descr (&ret, tmp);
11067 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11068 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
11069 add_loc_descr (&ret, l3jump);
11070 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11071 VAR_INIT_STATUS_INITIALIZED);
11074 add_loc_descr (&ret, tmp);
11075 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
11076 ? DW_OP_shl : DW_OP_shr, 0, 0));
11077 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11078 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
11079 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11080 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
11081 add_loc_descr (&ret, l2jump);
11082 l3label = new_loc_descr (DW_OP_drop, 0, 0);
11083 add_loc_descr (&ret, l3label);
11084 l4label = new_loc_descr (DW_OP_nop, 0, 0);
11085 add_loc_descr (&ret, l4label);
11086 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11087 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11088 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11089 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11090 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11091 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
11092 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11093 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
11097 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11098 const1 is DW_OP_lit1 or corresponding typed constant):
11100 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11101 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11105 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11106 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11109 static dw_loc_descr_ref
11110 popcount_loc_descriptor (rtx rtl, enum machine_mode mode,
11111 enum machine_mode mem_mode)
11113 dw_loc_descr_ref op0, ret, tmp;
11114 dw_loc_descr_ref l1jump, l1label;
11115 dw_loc_descr_ref l2jump, l2label;
11117 if (GET_MODE_CLASS (mode) != MODE_INT
11118 || GET_MODE (XEXP (rtl, 0)) != mode)
11121 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11122 VAR_INIT_STATUS_INITIALIZED);
11126 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11127 VAR_INIT_STATUS_INITIALIZED);
11130 add_loc_descr (&ret, tmp);
11131 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11132 l1label = new_loc_descr (DW_OP_dup, 0, 0);
11133 add_loc_descr (&ret, l1label);
11134 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11135 add_loc_descr (&ret, l2jump);
11136 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11137 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11138 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11139 VAR_INIT_STATUS_INITIALIZED);
11142 add_loc_descr (&ret, tmp);
11143 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11144 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
11145 ? DW_OP_plus : DW_OP_xor, 0, 0));
11146 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11147 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11148 VAR_INIT_STATUS_INITIALIZED);
11149 add_loc_descr (&ret, tmp);
11150 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11151 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11152 add_loc_descr (&ret, l1jump);
11153 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11154 add_loc_descr (&ret, l2label);
11155 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11156 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11157 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11158 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11162 /* BSWAP (constS is initial shift count, either 56 or 24):
11164 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11165 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11166 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11167 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11168 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11170 static dw_loc_descr_ref
11171 bswap_loc_descriptor (rtx rtl, enum machine_mode mode,
11172 enum machine_mode mem_mode)
11174 dw_loc_descr_ref op0, ret, tmp;
11175 dw_loc_descr_ref l1jump, l1label;
11176 dw_loc_descr_ref l2jump, l2label;
11178 if (GET_MODE_CLASS (mode) != MODE_INT
11179 || BITS_PER_UNIT != 8
11180 || (GET_MODE_BITSIZE (mode) != 32
11181 && GET_MODE_BITSIZE (mode) != 64))
11184 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11185 VAR_INIT_STATUS_INITIALIZED);
11190 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11192 VAR_INIT_STATUS_INITIALIZED);
11195 add_loc_descr (&ret, tmp);
11196 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11197 VAR_INIT_STATUS_INITIALIZED);
11200 add_loc_descr (&ret, tmp);
11201 l1label = new_loc_descr (DW_OP_pick, 2, 0);
11202 add_loc_descr (&ret, l1label);
11203 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11205 VAR_INIT_STATUS_INITIALIZED);
11206 add_loc_descr (&ret, tmp);
11207 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
11208 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11209 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11210 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
11211 VAR_INIT_STATUS_INITIALIZED);
11214 add_loc_descr (&ret, tmp);
11215 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11216 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
11217 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11218 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11219 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11220 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11221 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11222 VAR_INIT_STATUS_INITIALIZED);
11223 add_loc_descr (&ret, tmp);
11224 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
11225 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11226 add_loc_descr (&ret, l2jump);
11227 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
11228 VAR_INIT_STATUS_INITIALIZED);
11229 add_loc_descr (&ret, tmp);
11230 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11231 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11232 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11233 add_loc_descr (&ret, l1jump);
11234 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11235 add_loc_descr (&ret, l2label);
11236 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11237 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11238 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11239 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11240 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11241 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11245 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11246 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11247 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11248 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11250 ROTATERT is similar:
11251 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11252 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11253 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11255 static dw_loc_descr_ref
11256 rotate_loc_descriptor (rtx rtl, enum machine_mode mode,
11257 enum machine_mode mem_mode)
11259 rtx rtlop1 = XEXP (rtl, 1);
11260 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
11263 if (GET_MODE_CLASS (mode) != MODE_INT)
11266 if (GET_MODE (rtlop1) != VOIDmode
11267 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
11268 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11269 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11270 VAR_INIT_STATUS_INITIALIZED);
11271 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11272 VAR_INIT_STATUS_INITIALIZED);
11273 if (op0 == NULL || op1 == NULL)
11275 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11276 for (i = 0; i < 2; i++)
11278 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
11279 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
11281 VAR_INIT_STATUS_INITIALIZED);
11282 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
11283 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11285 : HOST_BITS_PER_WIDE_INT == 64
11286 ? DW_OP_const8u : DW_OP_constu,
11287 GET_MODE_MASK (mode), 0);
11290 if (mask[i] == NULL)
11292 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
11295 add_loc_descr (&ret, op1);
11296 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11297 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11298 if (GET_CODE (rtl) == ROTATERT)
11300 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11301 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11302 GET_MODE_BITSIZE (mode), 0));
11304 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11305 if (mask[0] != NULL)
11306 add_loc_descr (&ret, mask[0]);
11307 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11308 if (mask[1] != NULL)
11310 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11311 add_loc_descr (&ret, mask[1]);
11312 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11314 if (GET_CODE (rtl) == ROTATE)
11316 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11317 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11318 GET_MODE_BITSIZE (mode), 0));
11320 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11321 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11325 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11326 for DEBUG_PARAMETER_REF RTL. */
11328 static dw_loc_descr_ref
11329 parameter_ref_descriptor (rtx rtl)
11331 dw_loc_descr_ref ret;
11336 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
11337 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
11338 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
11341 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11342 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
11343 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
11347 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
11348 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
11353 /* Helper function to get mode of MEM's address. */
11356 get_address_mode (rtx mem)
11358 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
11359 if (mode != VOIDmode)
11361 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
11364 /* The following routine converts the RTL for a variable or parameter
11365 (resident in memory) into an equivalent Dwarf representation of a
11366 mechanism for getting the address of that same variable onto the top of a
11367 hypothetical "address evaluation" stack.
11369 When creating memory location descriptors, we are effectively transforming
11370 the RTL for a memory-resident object into its Dwarf postfix expression
11371 equivalent. This routine recursively descends an RTL tree, turning
11372 it into Dwarf postfix code as it goes.
11374 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11376 MEM_MODE is the mode of the memory reference, needed to handle some
11377 autoincrement addressing modes.
11379 Return 0 if we can't represent the location. */
11382 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11383 enum machine_mode mem_mode,
11384 enum var_init_status initialized)
11386 dw_loc_descr_ref mem_loc_result = NULL;
11387 enum dwarf_location_atom op;
11388 dw_loc_descr_ref op0, op1;
11390 if (mode == VOIDmode)
11391 mode = GET_MODE (rtl);
11393 /* Note that for a dynamically sized array, the location we will generate a
11394 description of here will be the lowest numbered location which is
11395 actually within the array. That's *not* necessarily the same as the
11396 zeroth element of the array. */
11398 rtl = targetm.delegitimize_address (rtl);
11400 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
11403 switch (GET_CODE (rtl))
11408 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
11411 /* The case of a subreg may arise when we have a local (register)
11412 variable or a formal (register) parameter which doesn't quite fill
11413 up an entire register. For now, just assume that it is
11414 legitimate to make the Dwarf info refer to the whole register which
11415 contains the given subreg. */
11416 if (!subreg_lowpart_p (rtl))
11418 if (GET_MODE_CLASS (mode) == MODE_INT
11419 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
11420 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11421 #ifdef POINTERS_EXTEND_UNSIGNED
11422 || (mode == Pmode && mem_mode != VOIDmode)
11425 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
11427 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11428 GET_MODE (SUBREG_REG (rtl)),
11429 mem_mode, initialized);
11434 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11436 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
11437 && (GET_MODE_CLASS (mode) != MODE_INT
11438 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
11442 dw_die_ref type_die;
11443 dw_loc_descr_ref cvt;
11445 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11446 GET_MODE (SUBREG_REG (rtl)),
11447 mem_mode, initialized);
11448 if (mem_loc_result == NULL)
11450 type_die = base_type_for_mode (mode,
11451 GET_MODE_CLASS (mode) == MODE_INT);
11452 if (type_die == NULL)
11454 mem_loc_result = NULL;
11457 if (GET_MODE_SIZE (mode)
11458 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11459 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11461 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
11462 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11463 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11464 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11465 add_loc_descr (&mem_loc_result, cvt);
11470 if (GET_MODE_CLASS (mode) != MODE_INT
11471 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11472 #ifdef POINTERS_EXTEND_UNSIGNED
11473 && (mode != Pmode || mem_mode == VOIDmode)
11477 dw_die_ref type_die;
11481 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
11483 type_die = base_type_for_mode (mode,
11484 GET_MODE_CLASS (mode) == MODE_INT);
11485 if (type_die == NULL)
11487 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
11488 dbx_reg_number (rtl), 0);
11489 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
11490 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
11491 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
11494 /* Whenever a register number forms a part of the description of the
11495 method for calculating the (dynamic) address of a memory resident
11496 object, DWARF rules require the register number be referred to as
11497 a "base register". This distinction is not based in any way upon
11498 what category of register the hardware believes the given register
11499 belongs to. This is strictly DWARF terminology we're dealing with
11500 here. Note that in cases where the location of a memory-resident
11501 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11502 OP_CONST (0)) the actual DWARF location descriptor that we generate
11503 may just be OP_BASEREG (basereg). This may look deceptively like
11504 the object in question was allocated to a register (rather than in
11505 memory) so DWARF consumers need to be aware of the subtle
11506 distinction between OP_REG and OP_BASEREG. */
11507 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
11508 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
11509 else if (stack_realign_drap
11511 && crtl->args.internal_arg_pointer == rtl
11512 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
11514 /* If RTL is internal_arg_pointer, which has been optimized
11515 out, use DRAP instead. */
11516 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
11517 VAR_INIT_STATUS_INITIALIZED);
11523 if (GET_MODE_CLASS (mode) != MODE_INT)
11525 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
11526 mem_mode, VAR_INIT_STATUS_INITIALIZED);
11529 else if (GET_CODE (rtl) == ZERO_EXTEND
11530 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11531 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
11532 < HOST_BITS_PER_WIDE_INT
11533 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11534 to expand zero extend as two shifts instead of
11536 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
11538 enum machine_mode imode = GET_MODE (XEXP (rtl, 0));
11539 mem_loc_result = op0;
11540 add_loc_descr (&mem_loc_result,
11541 int_loc_descriptor (GET_MODE_MASK (imode)));
11542 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
11544 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11546 int shift = DWARF2_ADDR_SIZE
11547 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11548 shift *= BITS_PER_UNIT;
11549 if (GET_CODE (rtl) == SIGN_EXTEND)
11553 mem_loc_result = op0;
11554 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11555 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11556 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11557 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11559 else if (!dwarf_strict)
11561 dw_die_ref type_die1, type_die2;
11562 dw_loc_descr_ref cvt;
11564 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
11565 GET_CODE (rtl) == ZERO_EXTEND);
11566 if (type_die1 == NULL)
11568 type_die2 = base_type_for_mode (mode, 1);
11569 if (type_die2 == NULL)
11571 mem_loc_result = op0;
11572 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11573 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11574 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
11575 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11576 add_loc_descr (&mem_loc_result, cvt);
11577 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11578 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11579 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
11580 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11581 add_loc_descr (&mem_loc_result, cvt);
11586 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
11587 get_address_mode (rtl), mode,
11588 VAR_INIT_STATUS_INITIALIZED);
11589 if (mem_loc_result == NULL)
11590 mem_loc_result = tls_mem_loc_descriptor (rtl);
11591 if (mem_loc_result != 0)
11593 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11594 || GET_MODE_CLASS (mode) != MODE_INT)
11596 dw_die_ref type_die;
11597 dw_loc_descr_ref deref;
11602 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
11603 if (type_die == NULL)
11605 deref = new_loc_descr (DW_OP_GNU_deref_type,
11606 GET_MODE_SIZE (mode), 0);
11607 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
11608 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
11609 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
11610 add_loc_descr (&mem_loc_result, deref);
11612 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
11613 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
11615 add_loc_descr (&mem_loc_result,
11616 new_loc_descr (DW_OP_deref_size,
11617 GET_MODE_SIZE (mode), 0));
11621 rtx new_rtl = avoid_constant_pool_reference (rtl);
11622 if (new_rtl != rtl)
11623 return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized);
11628 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
11631 /* Some ports can transform a symbol ref into a label ref, because
11632 the symbol ref is too far away and has to be dumped into a constant
11636 if (GET_MODE_CLASS (mode) != MODE_INT
11637 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
11638 #ifdef POINTERS_EXTEND_UNSIGNED
11639 && (mode != Pmode || mem_mode == VOIDmode)
11643 if (GET_CODE (rtl) == SYMBOL_REF
11644 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11646 dw_loc_descr_ref temp;
11648 /* If this is not defined, we have no way to emit the data. */
11649 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
11652 /* We used to emit DW_OP_addr here, but that's wrong, since
11653 DW_OP_addr should be relocated by the debug info consumer,
11654 while DW_OP_GNU_push_tls_address operand should not. */
11655 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
11656 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
11657 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
11658 temp->dw_loc_oprnd1.v.val_addr = rtl;
11659 temp->dtprel = true;
11661 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
11662 add_loc_descr (&mem_loc_result, temp);
11667 if (!const_ok_for_output (rtl))
11671 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
11672 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
11673 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
11674 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11680 case DEBUG_IMPLICIT_PTR:
11681 expansion_failed (NULL_TREE, rtl,
11682 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11688 if (REG_P (ENTRY_VALUE_EXP (rtl)))
11690 if (GET_MODE_CLASS (mode) != MODE_INT
11691 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11692 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
11693 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11696 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
11697 VAR_INIT_STATUS_INITIALIZED);
11699 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
11700 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
11702 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
11703 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11704 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
11708 gcc_unreachable ();
11711 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
11712 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
11713 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
11716 case DEBUG_PARAMETER_REF:
11717 mem_loc_result = parameter_ref_descriptor (rtl);
11721 /* Extract the PLUS expression nested inside and fall into
11722 PLUS code below. */
11723 rtl = XEXP (rtl, 1);
11728 /* Turn these into a PLUS expression and fall into the PLUS code
11730 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
11731 GEN_INT (GET_CODE (rtl) == PRE_INC
11732 ? GET_MODE_UNIT_SIZE (mem_mode)
11733 : -GET_MODE_UNIT_SIZE (mem_mode)));
11735 /* ... fall through ... */
11739 if (is_based_loc (rtl)
11740 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11741 && GET_MODE_CLASS (mode) == MODE_INT)
11742 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
11743 INTVAL (XEXP (rtl, 1)),
11744 VAR_INIT_STATUS_INITIALIZED);
11747 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11748 VAR_INIT_STATUS_INITIALIZED);
11749 if (mem_loc_result == 0)
11752 if (CONST_INT_P (XEXP (rtl, 1))
11753 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11754 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
11757 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11758 VAR_INIT_STATUS_INITIALIZED);
11761 add_loc_descr (&mem_loc_result, op1);
11762 add_loc_descr (&mem_loc_result,
11763 new_loc_descr (DW_OP_plus, 0, 0));
11768 /* If a pseudo-reg is optimized away, it is possible for it to
11769 be replaced with a MEM containing a multiply or shift. */
11780 && GET_MODE_CLASS (mode) == MODE_INT
11781 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11783 mem_loc_result = typed_binop (DW_OP_div, rtl,
11784 base_type_for_mode (mode, 0),
11808 if (GET_MODE_CLASS (mode) != MODE_INT)
11810 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11811 VAR_INIT_STATUS_INITIALIZED);
11813 rtx rtlop1 = XEXP (rtl, 1);
11814 if (GET_MODE (rtlop1) != VOIDmode
11815 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
11816 < GET_MODE_BITSIZE (mode))
11817 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11818 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11819 VAR_INIT_STATUS_INITIALIZED);
11822 if (op0 == 0 || op1 == 0)
11825 mem_loc_result = op0;
11826 add_loc_descr (&mem_loc_result, op1);
11827 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11843 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11844 VAR_INIT_STATUS_INITIALIZED);
11845 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11846 VAR_INIT_STATUS_INITIALIZED);
11848 if (op0 == 0 || op1 == 0)
11851 mem_loc_result = op0;
11852 add_loc_descr (&mem_loc_result, op1);
11853 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11857 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
11859 mem_loc_result = typed_binop (DW_OP_mod, rtl,
11860 base_type_for_mode (mode, 0),
11865 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11866 VAR_INIT_STATUS_INITIALIZED);
11867 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11868 VAR_INIT_STATUS_INITIALIZED);
11870 if (op0 == 0 || op1 == 0)
11873 mem_loc_result = op0;
11874 add_loc_descr (&mem_loc_result, op1);
11875 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
11876 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
11877 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
11878 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
11879 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
11883 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
11885 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
11890 mem_loc_result = typed_binop (DW_OP_div, rtl,
11891 base_type_for_mode (mode, 1),
11909 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11910 VAR_INIT_STATUS_INITIALIZED);
11915 mem_loc_result = op0;
11916 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11920 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11921 #ifdef POINTERS_EXTEND_UNSIGNED
11923 && mem_mode != VOIDmode
11924 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
11928 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
11932 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
11933 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
11935 dw_die_ref type_die = base_type_for_mode (mode, 1);
11936 enum machine_mode amode;
11937 if (type_die == NULL)
11939 amode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
11941 if (INTVAL (rtl) >= 0
11942 && amode != BLKmode
11943 && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
11944 /* const DW_OP_GNU_convert <XXX> vs.
11945 DW_OP_GNU_const_type <XXX, 1, const>. */
11946 && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
11947 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode))
11949 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
11950 op0 = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11951 op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11952 op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11953 op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
11954 add_loc_descr (&mem_loc_result, op0);
11955 return mem_loc_result;
11957 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
11959 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11960 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11961 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
11962 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
11963 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
11966 mem_loc_result->dw_loc_oprnd2.val_class
11967 = dw_val_class_const_double;
11968 mem_loc_result->dw_loc_oprnd2.v.val_double
11969 = shwi_to_double_int (INTVAL (rtl));
11977 dw_die_ref type_die;
11979 /* Note that a CONST_DOUBLE rtx could represent either an integer
11980 or a floating-point constant. A CONST_DOUBLE is used whenever
11981 the constant requires more than one word in order to be
11982 adequately represented. We output CONST_DOUBLEs as blocks. */
11983 if (mode == VOIDmode
11984 || (GET_MODE (rtl) == VOIDmode
11985 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
11987 type_die = base_type_for_mode (mode,
11988 GET_MODE_CLASS (mode) == MODE_INT);
11989 if (type_die == NULL)
11991 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
11992 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11993 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11994 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
11995 if (SCALAR_FLOAT_MODE_P (mode))
11997 unsigned int length = GET_MODE_SIZE (mode);
11998 unsigned char *array
11999 = (unsigned char*) ggc_alloc_atomic (length);
12001 insert_float (rtl, array);
12002 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12003 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12004 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12005 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12009 mem_loc_result->dw_loc_oprnd2.val_class
12010 = dw_val_class_const_double;
12011 mem_loc_result->dw_loc_oprnd2.v.val_double
12012 = rtx_to_double_int (rtl);
12018 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
12022 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12026 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12030 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12034 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12038 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
12042 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12046 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12050 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12054 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12059 if (GET_MODE_CLASS (mode) != MODE_INT)
12064 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
12069 if (CONST_INT_P (XEXP (rtl, 1))
12070 && CONST_INT_P (XEXP (rtl, 2))
12071 && ((unsigned) INTVAL (XEXP (rtl, 1))
12072 + (unsigned) INTVAL (XEXP (rtl, 2))
12073 <= GET_MODE_BITSIZE (mode))
12074 && GET_MODE_CLASS (mode) == MODE_INT
12075 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12076 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
12079 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12080 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12083 if (GET_CODE (rtl) == SIGN_EXTRACT)
12087 mem_loc_result = op0;
12088 size = INTVAL (XEXP (rtl, 1));
12089 shift = INTVAL (XEXP (rtl, 2));
12090 if (BITS_BIG_ENDIAN)
12091 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
12093 if (shift + size != (int) DWARF2_ADDR_SIZE)
12095 add_loc_descr (&mem_loc_result,
12096 int_loc_descriptor (DWARF2_ADDR_SIZE
12098 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
12100 if (size != (int) DWARF2_ADDR_SIZE)
12102 add_loc_descr (&mem_loc_result,
12103 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
12104 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12111 dw_loc_descr_ref op2, bra_node, drop_node;
12112 op0 = mem_loc_descriptor (XEXP (rtl, 0),
12113 GET_MODE (XEXP (rtl, 0)) == VOIDmode
12114 ? word_mode : GET_MODE (XEXP (rtl, 0)),
12115 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12116 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12117 VAR_INIT_STATUS_INITIALIZED);
12118 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
12119 VAR_INIT_STATUS_INITIALIZED);
12120 if (op0 == NULL || op1 == NULL || op2 == NULL)
12123 mem_loc_result = op1;
12124 add_loc_descr (&mem_loc_result, op2);
12125 add_loc_descr (&mem_loc_result, op0);
12126 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12127 add_loc_descr (&mem_loc_result, bra_node);
12128 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
12129 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
12130 add_loc_descr (&mem_loc_result, drop_node);
12131 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12132 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
12137 case FLOAT_TRUNCATE:
12139 case UNSIGNED_FLOAT:
12144 dw_die_ref type_die;
12145 dw_loc_descr_ref cvt;
12147 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12148 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12151 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
12152 && (GET_CODE (rtl) == FLOAT
12153 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
12154 <= DWARF2_ADDR_SIZE))
12156 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12157 GET_CODE (rtl) == UNSIGNED_FLOAT);
12158 if (type_die == NULL)
12160 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12161 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12162 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12163 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12164 add_loc_descr (&op0, cvt);
12166 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
12167 if (type_die == NULL)
12169 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12170 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12171 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12172 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12173 add_loc_descr (&op0, cvt);
12174 if (GET_MODE_CLASS (mode) == MODE_INT
12175 && (GET_CODE (rtl) == FIX
12176 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
12178 op0 = convert_descriptor_to_mode (mode, op0);
12182 mem_loc_result = op0;
12189 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
12194 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
12198 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
12203 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
12208 /* In theory, we could implement the above. */
12209 /* DWARF cannot represent the unsigned compare operations
12234 case FRACT_CONVERT:
12235 case UNSIGNED_FRACT_CONVERT:
12237 case UNSIGNED_SAT_FRACT:
12243 case VEC_DUPLICATE:
12247 case STRICT_LOW_PART:
12251 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12252 can't express it in the debug info. This can happen e.g. with some
12257 resolve_one_addr (&rtl, NULL);
12261 #ifdef ENABLE_CHECKING
12262 print_rtl (stderr, rtl);
12263 gcc_unreachable ();
12269 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12270 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12272 return mem_loc_result;
12275 /* Return a descriptor that describes the concatenation of two locations.
12276 This is typically a complex variable. */
12278 static dw_loc_descr_ref
12279 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
12281 dw_loc_descr_ref cc_loc_result = NULL;
12282 dw_loc_descr_ref x0_ref
12283 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12284 dw_loc_descr_ref x1_ref
12285 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12287 if (x0_ref == 0 || x1_ref == 0)
12290 cc_loc_result = x0_ref;
12291 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
12293 add_loc_descr (&cc_loc_result, x1_ref);
12294 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
12296 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
12297 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12299 return cc_loc_result;
12302 /* Return a descriptor that describes the concatenation of N
12305 static dw_loc_descr_ref
12306 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
12309 dw_loc_descr_ref cc_loc_result = NULL;
12310 unsigned int n = XVECLEN (concatn, 0);
12312 for (i = 0; i < n; ++i)
12314 dw_loc_descr_ref ref;
12315 rtx x = XVECEXP (concatn, 0, i);
12317 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12321 add_loc_descr (&cc_loc_result, ref);
12322 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
12325 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12326 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12328 return cc_loc_result;
12331 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12332 for DEBUG_IMPLICIT_PTR RTL. */
12334 static dw_loc_descr_ref
12335 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
12337 dw_loc_descr_ref ret;
12342 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
12343 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
12344 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
12345 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
12346 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
12347 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
12350 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12351 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
12352 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
12356 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
12357 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
12362 /* Output a proper Dwarf location descriptor for a variable or parameter
12363 which is either allocated in a register or in a memory location. For a
12364 register, we just generate an OP_REG and the register number. For a
12365 memory location we provide a Dwarf postfix expression describing how to
12366 generate the (dynamic) address of the object onto the address stack.
12368 MODE is mode of the decl if this loc_descriptor is going to be used in
12369 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12370 allowed, VOIDmode otherwise.
12372 If we don't know how to describe it, return 0. */
12374 static dw_loc_descr_ref
12375 loc_descriptor (rtx rtl, enum machine_mode mode,
12376 enum var_init_status initialized)
12378 dw_loc_descr_ref loc_result = NULL;
12380 switch (GET_CODE (rtl))
12383 /* The case of a subreg may arise when we have a local (register)
12384 variable or a formal (register) parameter which doesn't quite fill
12385 up an entire register. For now, just assume that it is
12386 legitimate to make the Dwarf info refer to the whole register which
12387 contains the given subreg. */
12388 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
12389 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
12395 loc_result = reg_loc_descriptor (rtl, initialized);
12399 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
12400 GET_MODE (rtl), initialized);
12401 if (loc_result == NULL)
12402 loc_result = tls_mem_loc_descriptor (rtl);
12403 if (loc_result == NULL)
12405 rtx new_rtl = avoid_constant_pool_reference (rtl);
12406 if (new_rtl != rtl)
12407 loc_result = loc_descriptor (new_rtl, mode, initialized);
12412 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
12417 loc_result = concatn_loc_descriptor (rtl, initialized);
12422 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
12424 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
12425 if (GET_CODE (loc) == EXPR_LIST)
12426 loc = XEXP (loc, 0);
12427 loc_result = loc_descriptor (loc, mode, initialized);
12431 rtl = XEXP (rtl, 1);
12436 rtvec par_elems = XVEC (rtl, 0);
12437 int num_elem = GET_NUM_ELEM (par_elems);
12438 enum machine_mode mode;
12441 /* Create the first one, so we have something to add to. */
12442 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
12443 VOIDmode, initialized);
12444 if (loc_result == NULL)
12446 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
12447 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12448 for (i = 1; i < num_elem; i++)
12450 dw_loc_descr_ref temp;
12452 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
12453 VOIDmode, initialized);
12456 add_loc_descr (&loc_result, temp);
12457 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
12458 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12464 if (mode != VOIDmode && mode != BLKmode)
12465 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
12470 if (mode == VOIDmode)
12471 mode = GET_MODE (rtl);
12473 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12475 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12477 /* Note that a CONST_DOUBLE rtx could represent either an integer
12478 or a floating-point constant. A CONST_DOUBLE is used whenever
12479 the constant requires more than one word in order to be
12480 adequately represented. We output CONST_DOUBLEs as blocks. */
12481 loc_result = new_loc_descr (DW_OP_implicit_value,
12482 GET_MODE_SIZE (mode), 0);
12483 if (SCALAR_FLOAT_MODE_P (mode))
12485 unsigned int length = GET_MODE_SIZE (mode);
12486 unsigned char *array
12487 = (unsigned char*) ggc_alloc_atomic (length);
12489 insert_float (rtl, array);
12490 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12491 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12492 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12493 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12497 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
12498 loc_result->dw_loc_oprnd2.v.val_double
12499 = rtx_to_double_int (rtl);
12505 if (mode == VOIDmode)
12506 mode = GET_MODE (rtl);
12508 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12510 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
12511 unsigned int length = CONST_VECTOR_NUNITS (rtl);
12512 unsigned char *array = (unsigned char *)
12513 ggc_alloc_atomic (length * elt_size);
12517 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12518 switch (GET_MODE_CLASS (mode))
12520 case MODE_VECTOR_INT:
12521 for (i = 0, p = array; i < length; i++, p += elt_size)
12523 rtx elt = CONST_VECTOR_ELT (rtl, i);
12524 double_int val = rtx_to_double_int (elt);
12526 if (elt_size <= sizeof (HOST_WIDE_INT))
12527 insert_int (double_int_to_shwi (val), elt_size, p);
12530 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
12531 insert_double (val, p);
12536 case MODE_VECTOR_FLOAT:
12537 for (i = 0, p = array; i < length; i++, p += elt_size)
12539 rtx elt = CONST_VECTOR_ELT (rtl, i);
12540 insert_float (elt, p);
12545 gcc_unreachable ();
12548 loc_result = new_loc_descr (DW_OP_implicit_value,
12549 length * elt_size, 0);
12550 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12551 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
12552 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
12553 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12558 if (mode == VOIDmode
12559 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
12560 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
12561 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
12563 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
12568 if (!const_ok_for_output (rtl))
12571 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
12572 && (dwarf_version >= 4 || !dwarf_strict))
12574 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
12575 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
12576 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
12577 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
12578 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12582 case DEBUG_IMPLICIT_PTR:
12583 loc_result = implicit_ptr_descriptor (rtl, 0);
12587 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
12588 && CONST_INT_P (XEXP (rtl, 1)))
12591 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
12597 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
12598 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
12599 && dwarf_version >= 4)
12600 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
12602 /* Value expression. */
12603 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
12605 add_loc_descr (&loc_result,
12606 new_loc_descr (DW_OP_stack_value, 0, 0));
12614 /* We need to figure out what section we should use as the base for the
12615 address ranges where a given location is valid.
12616 1. If this particular DECL has a section associated with it, use that.
12617 2. If this function has a section associated with it, use that.
12618 3. Otherwise, use the text section.
12619 XXX: If you split a variable across multiple sections, we won't notice. */
12621 static const char *
12622 secname_for_decl (const_tree decl)
12624 const char *secname;
12626 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
12628 tree sectree = DECL_SECTION_NAME (decl);
12629 secname = TREE_STRING_POINTER (sectree);
12631 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
12633 tree sectree = DECL_SECTION_NAME (current_function_decl);
12634 secname = TREE_STRING_POINTER (sectree);
12636 else if (cfun && in_cold_section_p)
12637 secname = crtl->subsections.cold_section_label;
12639 secname = text_section_label;
12644 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12647 decl_by_reference_p (tree decl)
12649 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
12650 || TREE_CODE (decl) == VAR_DECL)
12651 && DECL_BY_REFERENCE (decl));
12654 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12657 static dw_loc_descr_ref
12658 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
12659 enum var_init_status initialized)
12661 int have_address = 0;
12662 dw_loc_descr_ref descr;
12663 enum machine_mode mode;
12665 if (want_address != 2)
12667 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12669 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
12671 varloc = PAT_VAR_LOCATION_LOC (varloc);
12672 if (GET_CODE (varloc) == EXPR_LIST)
12673 varloc = XEXP (varloc, 0);
12674 mode = GET_MODE (varloc);
12675 if (MEM_P (varloc))
12677 rtx addr = XEXP (varloc, 0);
12678 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
12679 mode, initialized);
12684 rtx x = avoid_constant_pool_reference (varloc);
12686 descr = mem_loc_descriptor (x, mode, VOIDmode,
12691 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
12698 if (GET_CODE (varloc) == VAR_LOCATION)
12699 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
12701 mode = DECL_MODE (loc);
12702 descr = loc_descriptor (varloc, mode, initialized);
12709 if (want_address == 2 && !have_address
12710 && (dwarf_version >= 4 || !dwarf_strict))
12712 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
12714 expansion_failed (loc, NULL_RTX,
12715 "DWARF address size mismatch");
12718 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
12721 /* Show if we can't fill the request for an address. */
12722 if (want_address && !have_address)
12724 expansion_failed (loc, NULL_RTX,
12725 "Want address and only have value");
12729 /* If we've got an address and don't want one, dereference. */
12730 if (!want_address && have_address)
12732 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
12733 enum dwarf_location_atom op;
12735 if (size > DWARF2_ADDR_SIZE || size == -1)
12737 expansion_failed (loc, NULL_RTX,
12738 "DWARF address size mismatch");
12741 else if (size == DWARF2_ADDR_SIZE)
12744 op = DW_OP_deref_size;
12746 add_loc_descr (&descr, new_loc_descr (op, size, 0));
12752 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
12753 if it is not possible. */
12755 static dw_loc_descr_ref
12756 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
12758 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
12759 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
12760 else if (dwarf_version >= 3 || !dwarf_strict)
12761 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
12766 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
12767 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
12769 static dw_loc_descr_ref
12770 dw_sra_loc_expr (tree decl, rtx loc)
12773 unsigned int padsize = 0;
12774 dw_loc_descr_ref descr, *descr_tail;
12775 unsigned HOST_WIDE_INT decl_size;
12777 enum var_init_status initialized;
12779 if (DECL_SIZE (decl) == NULL
12780 || !host_integerp (DECL_SIZE (decl), 1))
12783 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
12785 descr_tail = &descr;
12787 for (p = loc; p; p = XEXP (p, 1))
12789 unsigned int bitsize = decl_piece_bitsize (p);
12790 rtx loc_note = *decl_piece_varloc_ptr (p);
12791 dw_loc_descr_ref cur_descr;
12792 dw_loc_descr_ref *tail, last = NULL;
12793 unsigned int opsize = 0;
12795 if (loc_note == NULL_RTX
12796 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
12798 padsize += bitsize;
12801 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
12802 varloc = NOTE_VAR_LOCATION (loc_note);
12803 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
12804 if (cur_descr == NULL)
12806 padsize += bitsize;
12810 /* Check that cur_descr either doesn't use
12811 DW_OP_*piece operations, or their sum is equal
12812 to bitsize. Otherwise we can't embed it. */
12813 for (tail = &cur_descr; *tail != NULL;
12814 tail = &(*tail)->dw_loc_next)
12815 if ((*tail)->dw_loc_opc == DW_OP_piece)
12817 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
12821 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
12823 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
12827 if (last != NULL && opsize != bitsize)
12829 padsize += bitsize;
12833 /* If there is a hole, add DW_OP_*piece after empty DWARF
12834 expression, which means that those bits are optimized out. */
12837 if (padsize > decl_size)
12839 decl_size -= padsize;
12840 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
12841 if (*descr_tail == NULL)
12843 descr_tail = &(*descr_tail)->dw_loc_next;
12846 *descr_tail = cur_descr;
12848 if (bitsize > decl_size)
12850 decl_size -= bitsize;
12853 HOST_WIDE_INT offset = 0;
12854 if (GET_CODE (varloc) == VAR_LOCATION
12855 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
12857 varloc = PAT_VAR_LOCATION_LOC (varloc);
12858 if (GET_CODE (varloc) == EXPR_LIST)
12859 varloc = XEXP (varloc, 0);
12863 if (GET_CODE (varloc) == CONST
12864 || GET_CODE (varloc) == SIGN_EXTEND
12865 || GET_CODE (varloc) == ZERO_EXTEND)
12866 varloc = XEXP (varloc, 0);
12867 else if (GET_CODE (varloc) == SUBREG)
12868 varloc = SUBREG_REG (varloc);
12873 /* DW_OP_bit_size offset should be zero for register
12874 or implicit location descriptions and empty location
12875 descriptions, but for memory addresses needs big endian
12877 if (MEM_P (varloc))
12879 unsigned HOST_WIDE_INT memsize
12880 = MEM_SIZE (varloc) * BITS_PER_UNIT;
12881 if (memsize != bitsize)
12883 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
12884 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
12886 if (memsize < bitsize)
12888 if (BITS_BIG_ENDIAN)
12889 offset = memsize - bitsize;
12893 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
12894 if (*descr_tail == NULL)
12896 descr_tail = &(*descr_tail)->dw_loc_next;
12900 /* If there were any non-empty expressions, add padding till the end of
12902 if (descr != NULL && decl_size != 0)
12904 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
12905 if (*descr_tail == NULL)
12911 /* Return the dwarf representation of the location list LOC_LIST of
12912 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
12915 static dw_loc_list_ref
12916 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
12918 const char *endname, *secname;
12920 enum var_init_status initialized;
12921 struct var_loc_node *node;
12922 dw_loc_descr_ref descr;
12923 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12924 dw_loc_list_ref list = NULL;
12925 dw_loc_list_ref *listp = &list;
12927 /* Now that we know what section we are using for a base,
12928 actually construct the list of locations.
12929 The first location information is what is passed to the
12930 function that creates the location list, and the remaining
12931 locations just get added on to that list.
12932 Note that we only know the start address for a location
12933 (IE location changes), so to build the range, we use
12934 the range [current location start, next location start].
12935 This means we have to special case the last node, and generate
12936 a range of [last location start, end of function label]. */
12938 secname = secname_for_decl (decl);
12940 for (node = loc_list->first; node; node = node->next)
12941 if (GET_CODE (node->loc) == EXPR_LIST
12942 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
12944 if (GET_CODE (node->loc) == EXPR_LIST)
12946 /* This requires DW_OP_{,bit_}piece, which is not usable
12947 inside DWARF expressions. */
12948 if (want_address != 2)
12950 descr = dw_sra_loc_expr (decl, node->loc);
12956 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
12957 varloc = NOTE_VAR_LOCATION (node->loc);
12958 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
12962 bool range_across_switch = false;
12963 /* If section switch happens in between node->label
12964 and node->next->label (or end of function) and
12965 we can't emit it as a single entry list,
12966 emit two ranges, first one ending at the end
12967 of first partition and second one starting at the
12968 beginning of second partition. */
12969 if (node == loc_list->last_before_switch
12970 && (node != loc_list->first || loc_list->first->next)
12971 && current_function_decl)
12973 endname = cfun->fde->dw_fde_end;
12974 range_across_switch = true;
12976 /* The variable has a location between NODE->LABEL and
12977 NODE->NEXT->LABEL. */
12978 else if (node->next)
12979 endname = node->next->label;
12980 /* If the variable has a location at the last label
12981 it keeps its location until the end of function. */
12982 else if (!current_function_decl)
12983 endname = text_end_label;
12986 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12987 current_function_funcdef_no);
12988 endname = ggc_strdup (label_id);
12991 *listp = new_loc_list (descr, node->label, endname, secname);
12992 if (TREE_CODE (decl) == PARM_DECL
12993 && node == loc_list->first
12994 && GET_CODE (node->loc) == NOTE
12995 && strcmp (node->label, endname) == 0)
12996 (*listp)->force = true;
12997 listp = &(*listp)->dw_loc_next;
12999 if (range_across_switch)
13001 if (GET_CODE (node->loc) == EXPR_LIST)
13002 descr = dw_sra_loc_expr (decl, node->loc);
13005 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
13006 varloc = NOTE_VAR_LOCATION (node->loc);
13007 descr = dw_loc_list_1 (decl, varloc, want_address,
13010 gcc_assert (descr);
13011 /* The variable has a location between NODE->LABEL and
13012 NODE->NEXT->LABEL. */
13014 endname = node->next->label;
13016 endname = cfun->fde->dw_fde_second_end;
13017 *listp = new_loc_list (descr,
13018 cfun->fde->dw_fde_second_begin,
13020 listp = &(*listp)->dw_loc_next;
13025 /* Try to avoid the overhead of a location list emitting a location
13026 expression instead, but only if we didn't have more than one
13027 location entry in the first place. If some entries were not
13028 representable, we don't want to pretend a single entry that was
13029 applies to the entire scope in which the variable is
13031 if (list && loc_list->first->next)
13037 /* Return if the loc_list has only single element and thus can be represented
13038 as location description. */
13041 single_element_loc_list_p (dw_loc_list_ref list)
13043 gcc_assert (!list->dw_loc_next || list->ll_symbol);
13044 return !list->ll_symbol;
13047 /* To each location in list LIST add loc descr REF. */
13050 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
13052 dw_loc_descr_ref copy;
13053 add_loc_descr (&list->expr, ref);
13054 list = list->dw_loc_next;
13057 copy = ggc_alloc_dw_loc_descr_node ();
13058 memcpy (copy, ref, sizeof (dw_loc_descr_node));
13059 add_loc_descr (&list->expr, copy);
13060 while (copy->dw_loc_next)
13062 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
13063 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
13064 copy->dw_loc_next = new_copy;
13067 list = list->dw_loc_next;
13071 /* Given two lists RET and LIST
13072 produce location list that is result of adding expression in LIST
13073 to expression in RET on each possition in program.
13074 Might be destructive on both RET and LIST.
13076 TODO: We handle only simple cases of RET or LIST having at most one
13077 element. General case would inolve sorting the lists in program order
13078 and merging them that will need some additional work.
13079 Adding that will improve quality of debug info especially for SRA-ed
13083 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
13092 if (!list->dw_loc_next)
13094 add_loc_descr_to_each (*ret, list->expr);
13097 if (!(*ret)->dw_loc_next)
13099 add_loc_descr_to_each (list, (*ret)->expr);
13103 expansion_failed (NULL_TREE, NULL_RTX,
13104 "Don't know how to merge two non-trivial"
13105 " location lists.\n");
13110 /* LOC is constant expression. Try a luck, look it up in constant
13111 pool and return its loc_descr of its address. */
13113 static dw_loc_descr_ref
13114 cst_pool_loc_descr (tree loc)
13116 /* Get an RTL for this, if something has been emitted. */
13117 rtx rtl = lookup_constant_def (loc);
13119 if (!rtl || !MEM_P (rtl))
13124 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
13126 /* TODO: We might get more coverage if we was actually delaying expansion
13127 of all expressions till end of compilation when constant pools are fully
13129 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
13131 expansion_failed (loc, NULL_RTX,
13132 "CST value in contant pool but not marked.");
13135 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
13136 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
13139 /* Return dw_loc_list representing address of addr_expr LOC
13140 by looking for innder INDIRECT_REF expression and turing it
13141 into simple arithmetics. */
13143 static dw_loc_list_ref
13144 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
13147 HOST_WIDE_INT bitsize, bitpos, bytepos;
13148 enum machine_mode mode;
13150 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13151 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13153 obj = get_inner_reference (TREE_OPERAND (loc, 0),
13154 &bitsize, &bitpos, &offset, &mode,
13155 &unsignedp, &volatilep, false);
13157 if (bitpos % BITS_PER_UNIT)
13159 expansion_failed (loc, NULL_RTX, "bitfield access");
13162 if (!INDIRECT_REF_P (obj))
13164 expansion_failed (obj,
13165 NULL_RTX, "no indirect ref in inner refrence");
13168 if (!offset && !bitpos)
13169 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
13171 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
13172 && (dwarf_version >= 4 || !dwarf_strict))
13174 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
13179 /* Variable offset. */
13180 list_ret1 = loc_list_from_tree (offset, 0);
13181 if (list_ret1 == 0)
13183 add_loc_list (&list_ret, list_ret1);
13186 add_loc_descr_to_each (list_ret,
13187 new_loc_descr (DW_OP_plus, 0, 0));
13189 bytepos = bitpos / BITS_PER_UNIT;
13191 add_loc_descr_to_each (list_ret,
13192 new_loc_descr (DW_OP_plus_uconst,
13194 else if (bytepos < 0)
13195 loc_list_plus_const (list_ret, bytepos);
13196 add_loc_descr_to_each (list_ret,
13197 new_loc_descr (DW_OP_stack_value, 0, 0));
13203 /* Generate Dwarf location list representing LOC.
13204 If WANT_ADDRESS is false, expression computing LOC will be computed
13205 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13206 if WANT_ADDRESS is 2, expression computing address useable in location
13207 will be returned (i.e. DW_OP_reg can be used
13208 to refer to register values). */
13210 static dw_loc_list_ref
13211 loc_list_from_tree (tree loc, int want_address)
13213 dw_loc_descr_ref ret = NULL, ret1 = NULL;
13214 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13215 int have_address = 0;
13216 enum dwarf_location_atom op;
13218 /* ??? Most of the time we do not take proper care for sign/zero
13219 extending the values properly. Hopefully this won't be a real
13222 switch (TREE_CODE (loc))
13225 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
13228 case PLACEHOLDER_EXPR:
13229 /* This case involves extracting fields from an object to determine the
13230 position of other fields. We don't try to encode this here. The
13231 only user of this is Ada, which encodes the needed information using
13232 the names of types. */
13233 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
13237 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
13238 /* There are no opcodes for these operations. */
13241 case PREINCREMENT_EXPR:
13242 case PREDECREMENT_EXPR:
13243 case POSTINCREMENT_EXPR:
13244 case POSTDECREMENT_EXPR:
13245 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
13246 /* There are no opcodes for these operations. */
13250 /* If we already want an address, see if there is INDIRECT_REF inside
13251 e.g. for &this->field. */
13254 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
13255 (loc, want_address == 2);
13258 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
13259 && (ret = cst_pool_loc_descr (loc)))
13262 /* Otherwise, process the argument and look for the address. */
13263 if (!list_ret && !ret)
13264 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
13268 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
13274 if (DECL_THREAD_LOCAL_P (loc))
13277 enum dwarf_location_atom first_op;
13278 enum dwarf_location_atom second_op;
13279 bool dtprel = false;
13281 if (targetm.have_tls)
13283 /* If this is not defined, we have no way to emit the
13285 if (!targetm.asm_out.output_dwarf_dtprel)
13288 /* The way DW_OP_GNU_push_tls_address is specified, we
13289 can only look up addresses of objects in the current
13290 module. We used DW_OP_addr as first op, but that's
13291 wrong, because DW_OP_addr is relocated by the debug
13292 info consumer, while DW_OP_GNU_push_tls_address
13293 operand shouldn't be. */
13294 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
13296 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
13298 second_op = DW_OP_GNU_push_tls_address;
13302 if (!targetm.emutls.debug_form_tls_address
13303 || !(dwarf_version >= 3 || !dwarf_strict))
13305 /* We stuffed the control variable into the DECL_VALUE_EXPR
13306 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13307 no longer appear in gimple code. We used the control
13308 variable in specific so that we could pick it up here. */
13309 loc = DECL_VALUE_EXPR (loc);
13310 first_op = DW_OP_addr;
13311 second_op = DW_OP_form_tls_address;
13314 rtl = rtl_for_decl_location (loc);
13315 if (rtl == NULL_RTX)
13320 rtl = XEXP (rtl, 0);
13321 if (! CONSTANT_P (rtl))
13324 ret = new_loc_descr (first_op, 0, 0);
13325 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13326 ret->dw_loc_oprnd1.v.val_addr = rtl;
13327 ret->dtprel = dtprel;
13329 ret1 = new_loc_descr (second_op, 0, 0);
13330 add_loc_descr (&ret, ret1);
13339 if (DECL_HAS_VALUE_EXPR_P (loc))
13340 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
13344 case FUNCTION_DECL:
13347 var_loc_list *loc_list = lookup_decl_loc (loc);
13349 if (loc_list && loc_list->first)
13351 list_ret = dw_loc_list (loc_list, loc, want_address);
13352 have_address = want_address != 0;
13355 rtl = rtl_for_decl_location (loc);
13356 if (rtl == NULL_RTX)
13358 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
13361 else if (CONST_INT_P (rtl))
13363 HOST_WIDE_INT val = INTVAL (rtl);
13364 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13365 val &= GET_MODE_MASK (DECL_MODE (loc));
13366 ret = int_loc_descriptor (val);
13368 else if (GET_CODE (rtl) == CONST_STRING)
13370 expansion_failed (loc, NULL_RTX, "CONST_STRING");
13373 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
13375 ret = new_loc_descr (DW_OP_addr, 0, 0);
13376 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13377 ret->dw_loc_oprnd1.v.val_addr = rtl;
13381 enum machine_mode mode, mem_mode;
13383 /* Certain constructs can only be represented at top-level. */
13384 if (want_address == 2)
13386 ret = loc_descriptor (rtl, VOIDmode,
13387 VAR_INIT_STATUS_INITIALIZED);
13392 mode = GET_MODE (rtl);
13393 mem_mode = VOIDmode;
13397 mode = get_address_mode (rtl);
13398 rtl = XEXP (rtl, 0);
13401 ret = mem_loc_descriptor (rtl, mode, mem_mode,
13402 VAR_INIT_STATUS_INITIALIZED);
13405 expansion_failed (loc, rtl,
13406 "failed to produce loc descriptor for rtl");
13413 if (!integer_zerop (TREE_OPERAND (loc, 1)))
13417 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13421 case COMPOUND_EXPR:
13422 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
13425 case VIEW_CONVERT_EXPR:
13428 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
13430 case COMPONENT_REF:
13431 case BIT_FIELD_REF:
13433 case ARRAY_RANGE_REF:
13434 case REALPART_EXPR:
13435 case IMAGPART_EXPR:
13438 HOST_WIDE_INT bitsize, bitpos, bytepos;
13439 enum machine_mode mode;
13441 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13443 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
13444 &unsignedp, &volatilep, false);
13446 gcc_assert (obj != loc);
13448 list_ret = loc_list_from_tree (obj,
13450 && !bitpos && !offset ? 2 : 1);
13451 /* TODO: We can extract value of the small expression via shifting even
13452 for nonzero bitpos. */
13455 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
13457 expansion_failed (loc, NULL_RTX,
13458 "bitfield access");
13462 if (offset != NULL_TREE)
13464 /* Variable offset. */
13465 list_ret1 = loc_list_from_tree (offset, 0);
13466 if (list_ret1 == 0)
13468 add_loc_list (&list_ret, list_ret1);
13471 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
13474 bytepos = bitpos / BITS_PER_UNIT;
13476 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
13477 else if (bytepos < 0)
13478 loc_list_plus_const (list_ret, bytepos);
13485 if ((want_address || !host_integerp (loc, 0))
13486 && (ret = cst_pool_loc_descr (loc)))
13488 else if (want_address == 2
13489 && host_integerp (loc, 0)
13490 && (ret = address_of_int_loc_descriptor
13491 (int_size_in_bytes (TREE_TYPE (loc)),
13492 tree_low_cst (loc, 0))))
13494 else if (host_integerp (loc, 0))
13495 ret = int_loc_descriptor (tree_low_cst (loc, 0));
13498 expansion_failed (loc, NULL_RTX,
13499 "Integer operand is not host integer");
13508 if ((ret = cst_pool_loc_descr (loc)))
13511 /* We can construct small constants here using int_loc_descriptor. */
13512 expansion_failed (loc, NULL_RTX,
13513 "constructor or constant not in constant pool");
13516 case TRUTH_AND_EXPR:
13517 case TRUTH_ANDIF_EXPR:
13522 case TRUTH_XOR_EXPR:
13527 case TRUTH_OR_EXPR:
13528 case TRUTH_ORIF_EXPR:
13533 case FLOOR_DIV_EXPR:
13534 case CEIL_DIV_EXPR:
13535 case ROUND_DIV_EXPR:
13536 case TRUNC_DIV_EXPR:
13537 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13546 case FLOOR_MOD_EXPR:
13547 case CEIL_MOD_EXPR:
13548 case ROUND_MOD_EXPR:
13549 case TRUNC_MOD_EXPR:
13550 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13555 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13556 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
13557 if (list_ret == 0 || list_ret1 == 0)
13560 add_loc_list (&list_ret, list_ret1);
13563 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
13564 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
13565 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
13566 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
13567 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
13579 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
13582 case POINTER_PLUS_EXPR:
13584 if (host_integerp (TREE_OPERAND (loc, 1), 0))
13586 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13590 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
13598 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13605 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13612 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13619 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
13634 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13635 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
13636 if (list_ret == 0 || list_ret1 == 0)
13639 add_loc_list (&list_ret, list_ret1);
13642 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
13645 case TRUTH_NOT_EXPR:
13659 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13663 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
13669 const enum tree_code code =
13670 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
13672 loc = build3 (COND_EXPR, TREE_TYPE (loc),
13673 build2 (code, integer_type_node,
13674 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
13675 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
13678 /* ... fall through ... */
13682 dw_loc_descr_ref lhs
13683 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
13684 dw_loc_list_ref rhs
13685 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
13686 dw_loc_descr_ref bra_node, jump_node, tmp;
13688 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13689 if (list_ret == 0 || lhs == 0 || rhs == 0)
13692 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
13693 add_loc_descr_to_each (list_ret, bra_node);
13695 add_loc_list (&list_ret, rhs);
13696 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
13697 add_loc_descr_to_each (list_ret, jump_node);
13699 add_loc_descr_to_each (list_ret, lhs);
13700 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13701 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
13703 /* ??? Need a node to point the skip at. Use a nop. */
13704 tmp = new_loc_descr (DW_OP_nop, 0, 0);
13705 add_loc_descr_to_each (list_ret, tmp);
13706 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
13707 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
13711 case FIX_TRUNC_EXPR:
13715 /* Leave front-end specific codes as simply unknown. This comes
13716 up, for instance, with the C STMT_EXPR. */
13717 if ((unsigned int) TREE_CODE (loc)
13718 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
13720 expansion_failed (loc, NULL_RTX,
13721 "language specific tree node");
13725 #ifdef ENABLE_CHECKING
13726 /* Otherwise this is a generic code; we should just lists all of
13727 these explicitly. We forgot one. */
13728 gcc_unreachable ();
13730 /* In a release build, we want to degrade gracefully: better to
13731 generate incomplete debugging information than to crash. */
13736 if (!ret && !list_ret)
13739 if (want_address == 2 && !have_address
13740 && (dwarf_version >= 4 || !dwarf_strict))
13742 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
13744 expansion_failed (loc, NULL_RTX,
13745 "DWARF address size mismatch");
13749 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
13751 add_loc_descr_to_each (list_ret,
13752 new_loc_descr (DW_OP_stack_value, 0, 0));
13755 /* Show if we can't fill the request for an address. */
13756 if (want_address && !have_address)
13758 expansion_failed (loc, NULL_RTX,
13759 "Want address and only have value");
13763 gcc_assert (!ret || !list_ret);
13765 /* If we've got an address and don't want one, dereference. */
13766 if (!want_address && have_address)
13768 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
13770 if (size > DWARF2_ADDR_SIZE || size == -1)
13772 expansion_failed (loc, NULL_RTX,
13773 "DWARF address size mismatch");
13776 else if (size == DWARF2_ADDR_SIZE)
13779 op = DW_OP_deref_size;
13782 add_loc_descr (&ret, new_loc_descr (op, size, 0));
13784 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
13787 list_ret = new_loc_list (ret, NULL, NULL, NULL);
13792 /* Same as above but return only single location expression. */
13793 static dw_loc_descr_ref
13794 loc_descriptor_from_tree (tree loc, int want_address)
13796 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
13799 if (ret->dw_loc_next)
13801 expansion_failed (loc, NULL_RTX,
13802 "Location list where only loc descriptor needed");
13808 /* Given a value, round it up to the lowest multiple of `boundary'
13809 which is not less than the value itself. */
13811 static inline HOST_WIDE_INT
13812 ceiling (HOST_WIDE_INT value, unsigned int boundary)
13814 return (((value + boundary - 1) / boundary) * boundary);
13817 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
13818 pointer to the declared type for the relevant field variable, or return
13819 `integer_type_node' if the given node turns out to be an
13820 ERROR_MARK node. */
13823 field_type (const_tree decl)
13827 if (TREE_CODE (decl) == ERROR_MARK)
13828 return integer_type_node;
13830 type = DECL_BIT_FIELD_TYPE (decl);
13831 if (type == NULL_TREE)
13832 type = TREE_TYPE (decl);
13837 /* Given a pointer to a tree node, return the alignment in bits for
13838 it, or else return BITS_PER_WORD if the node actually turns out to
13839 be an ERROR_MARK node. */
13841 static inline unsigned
13842 simple_type_align_in_bits (const_tree type)
13844 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
13847 static inline unsigned
13848 simple_decl_align_in_bits (const_tree decl)
13850 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
13853 /* Return the result of rounding T up to ALIGN. */
13855 static inline double_int
13856 round_up_to_align (double_int t, unsigned int align)
13858 double_int alignd = uhwi_to_double_int (align);
13859 t = double_int_add (t, alignd);
13860 t = double_int_add (t, double_int_minus_one);
13861 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
13862 t = double_int_mul (t, alignd);
13866 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
13867 lowest addressed byte of the "containing object" for the given FIELD_DECL,
13868 or return 0 if we are unable to determine what that offset is, either
13869 because the argument turns out to be a pointer to an ERROR_MARK node, or
13870 because the offset is actually variable. (We can't handle the latter case
13873 static HOST_WIDE_INT
13874 field_byte_offset (const_tree decl)
13876 double_int object_offset_in_bits;
13877 double_int object_offset_in_bytes;
13878 double_int bitpos_int;
13880 if (TREE_CODE (decl) == ERROR_MARK)
13883 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
13885 /* We cannot yet cope with fields whose positions are variable, so
13886 for now, when we see such things, we simply return 0. Someday, we may
13887 be able to handle such cases, but it will be damn difficult. */
13888 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
13891 bitpos_int = tree_to_double_int (bit_position (decl));
13893 #ifdef PCC_BITFIELD_TYPE_MATTERS
13894 if (PCC_BITFIELD_TYPE_MATTERS)
13897 tree field_size_tree;
13898 double_int deepest_bitpos;
13899 double_int field_size_in_bits;
13900 unsigned int type_align_in_bits;
13901 unsigned int decl_align_in_bits;
13902 double_int type_size_in_bits;
13904 type = field_type (decl);
13905 type_size_in_bits = double_int_type_size_in_bits (type);
13906 type_align_in_bits = simple_type_align_in_bits (type);
13908 field_size_tree = DECL_SIZE (decl);
13910 /* The size could be unspecified if there was an error, or for
13911 a flexible array member. */
13912 if (!field_size_tree)
13913 field_size_tree = bitsize_zero_node;
13915 /* If the size of the field is not constant, use the type size. */
13916 if (TREE_CODE (field_size_tree) == INTEGER_CST)
13917 field_size_in_bits = tree_to_double_int (field_size_tree);
13919 field_size_in_bits = type_size_in_bits;
13921 decl_align_in_bits = simple_decl_align_in_bits (decl);
13923 /* The GCC front-end doesn't make any attempt to keep track of the
13924 starting bit offset (relative to the start of the containing
13925 structure type) of the hypothetical "containing object" for a
13926 bit-field. Thus, when computing the byte offset value for the
13927 start of the "containing object" of a bit-field, we must deduce
13928 this information on our own. This can be rather tricky to do in
13929 some cases. For example, handling the following structure type
13930 definition when compiling for an i386/i486 target (which only
13931 aligns long long's to 32-bit boundaries) can be very tricky:
13933 struct S { int field1; long long field2:31; };
13935 Fortunately, there is a simple rule-of-thumb which can be used
13936 in such cases. When compiling for an i386/i486, GCC will
13937 allocate 8 bytes for the structure shown above. It decides to
13938 do this based upon one simple rule for bit-field allocation.
13939 GCC allocates each "containing object" for each bit-field at
13940 the first (i.e. lowest addressed) legitimate alignment boundary
13941 (based upon the required minimum alignment for the declared
13942 type of the field) which it can possibly use, subject to the
13943 condition that there is still enough available space remaining
13944 in the containing object (when allocated at the selected point)
13945 to fully accommodate all of the bits of the bit-field itself.
13947 This simple rule makes it obvious why GCC allocates 8 bytes for
13948 each object of the structure type shown above. When looking
13949 for a place to allocate the "containing object" for `field2',
13950 the compiler simply tries to allocate a 64-bit "containing
13951 object" at each successive 32-bit boundary (starting at zero)
13952 until it finds a place to allocate that 64- bit field such that
13953 at least 31 contiguous (and previously unallocated) bits remain
13954 within that selected 64 bit field. (As it turns out, for the
13955 example above, the compiler finds it is OK to allocate the
13956 "containing object" 64-bit field at bit-offset zero within the
13959 Here we attempt to work backwards from the limited set of facts
13960 we're given, and we try to deduce from those facts, where GCC
13961 must have believed that the containing object started (within
13962 the structure type). The value we deduce is then used (by the
13963 callers of this routine) to generate DW_AT_location and
13964 DW_AT_bit_offset attributes for fields (both bit-fields and, in
13965 the case of DW_AT_location, regular fields as well). */
13967 /* Figure out the bit-distance from the start of the structure to
13968 the "deepest" bit of the bit-field. */
13969 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
13971 /* This is the tricky part. Use some fancy footwork to deduce
13972 where the lowest addressed bit of the containing object must
13974 object_offset_in_bits
13975 = double_int_sub (deepest_bitpos, type_size_in_bits);
13977 /* Round up to type_align by default. This works best for
13979 object_offset_in_bits
13980 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
13982 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
13984 object_offset_in_bits
13985 = double_int_sub (deepest_bitpos, type_size_in_bits);
13987 /* Round up to decl_align instead. */
13988 object_offset_in_bits
13989 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
13993 #endif /* PCC_BITFIELD_TYPE_MATTERS */
13994 object_offset_in_bits = bitpos_int;
13996 object_offset_in_bytes
13997 = double_int_div (object_offset_in_bits,
13998 uhwi_to_double_int (BITS_PER_UNIT), true,
14000 return double_int_to_shwi (object_offset_in_bytes);
14003 /* The following routines define various Dwarf attributes and any data
14004 associated with them. */
14006 /* Add a location description attribute value to a DIE.
14008 This emits location attributes suitable for whole variables and
14009 whole parameters. Note that the location attributes for struct fields are
14010 generated by the routine `data_member_location_attribute' below. */
14013 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
14014 dw_loc_list_ref descr)
14018 if (single_element_loc_list_p (descr))
14019 add_AT_loc (die, attr_kind, descr->expr);
14021 add_AT_loc_list (die, attr_kind, descr);
14024 /* Add DW_AT_accessibility attribute to DIE if needed. */
14027 add_accessibility_attribute (dw_die_ref die, tree decl)
14029 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14030 children, otherwise the default is DW_ACCESS_public. In DWARF2
14031 the default has always been DW_ACCESS_public. */
14032 if (TREE_PROTECTED (decl))
14033 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14034 else if (TREE_PRIVATE (decl))
14036 if (dwarf_version == 2
14037 || die->die_parent == NULL
14038 || die->die_parent->die_tag != DW_TAG_class_type)
14039 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
14041 else if (dwarf_version > 2
14043 && die->die_parent->die_tag == DW_TAG_class_type)
14044 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14047 /* Attach the specialized form of location attribute used for data members of
14048 struct and union types. In the special case of a FIELD_DECL node which
14049 represents a bit-field, the "offset" part of this special location
14050 descriptor must indicate the distance in bytes from the lowest-addressed
14051 byte of the containing struct or union type to the lowest-addressed byte of
14052 the "containing object" for the bit-field. (See the `field_byte_offset'
14055 For any given bit-field, the "containing object" is a hypothetical object
14056 (of some integral or enum type) within which the given bit-field lives. The
14057 type of this hypothetical "containing object" is always the same as the
14058 declared type of the individual bit-field itself (for GCC anyway... the
14059 DWARF spec doesn't actually mandate this). Note that it is the size (in
14060 bytes) of the hypothetical "containing object" which will be given in the
14061 DW_AT_byte_size attribute for this bit-field. (See the
14062 `byte_size_attribute' function below.) It is also used when calculating the
14063 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14064 function below.) */
14067 add_data_member_location_attribute (dw_die_ref die, tree decl)
14069 HOST_WIDE_INT offset;
14070 dw_loc_descr_ref loc_descr = 0;
14072 if (TREE_CODE (decl) == TREE_BINFO)
14074 /* We're working on the TAG_inheritance for a base class. */
14075 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
14077 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14078 aren't at a fixed offset from all (sub)objects of the same
14079 type. We need to extract the appropriate offset from our
14080 vtable. The following dwarf expression means
14082 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14084 This is specific to the V3 ABI, of course. */
14086 dw_loc_descr_ref tmp;
14088 /* Make a copy of the object address. */
14089 tmp = new_loc_descr (DW_OP_dup, 0, 0);
14090 add_loc_descr (&loc_descr, tmp);
14092 /* Extract the vtable address. */
14093 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14094 add_loc_descr (&loc_descr, tmp);
14096 /* Calculate the address of the offset. */
14097 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
14098 gcc_assert (offset < 0);
14100 tmp = int_loc_descriptor (-offset);
14101 add_loc_descr (&loc_descr, tmp);
14102 tmp = new_loc_descr (DW_OP_minus, 0, 0);
14103 add_loc_descr (&loc_descr, tmp);
14105 /* Extract the offset. */
14106 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14107 add_loc_descr (&loc_descr, tmp);
14109 /* Add it to the object address. */
14110 tmp = new_loc_descr (DW_OP_plus, 0, 0);
14111 add_loc_descr (&loc_descr, tmp);
14114 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
14117 offset = field_byte_offset (decl);
14121 if (dwarf_version > 2)
14123 /* Don't need to output a location expression, just the constant. */
14125 add_AT_int (die, DW_AT_data_member_location, offset);
14127 add_AT_unsigned (die, DW_AT_data_member_location, offset);
14132 enum dwarf_location_atom op;
14134 /* The DWARF2 standard says that we should assume that the structure
14135 address is already on the stack, so we can specify a structure
14136 field address by using DW_OP_plus_uconst. */
14138 #ifdef MIPS_DEBUGGING_INFO
14139 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
14140 operator correctly. It works only if we leave the offset on the
14144 op = DW_OP_plus_uconst;
14147 loc_descr = new_loc_descr (op, offset, 0);
14151 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
14154 /* Writes integer values to dw_vec_const array. */
14157 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
14161 *dest++ = val & 0xff;
14167 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14169 static HOST_WIDE_INT
14170 extract_int (const unsigned char *src, unsigned int size)
14172 HOST_WIDE_INT val = 0;
14178 val |= *--src & 0xff;
14184 /* Writes double_int values to dw_vec_const array. */
14187 insert_double (double_int val, unsigned char *dest)
14189 unsigned char *p0 = dest;
14190 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
14192 if (WORDS_BIG_ENDIAN)
14198 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
14199 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
14202 /* Writes floating point values to dw_vec_const array. */
14205 insert_float (const_rtx rtl, unsigned char *array)
14207 REAL_VALUE_TYPE rv;
14211 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
14212 real_to_target (val, &rv, GET_MODE (rtl));
14214 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14215 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
14217 insert_int (val[i], 4, array);
14222 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14223 does not have a "location" either in memory or in a register. These
14224 things can arise in GNU C when a constant is passed as an actual parameter
14225 to an inlined function. They can also arise in C++ where declared
14226 constants do not necessarily get memory "homes". */
14229 add_const_value_attribute (dw_die_ref die, rtx rtl)
14231 switch (GET_CODE (rtl))
14235 HOST_WIDE_INT val = INTVAL (rtl);
14238 add_AT_int (die, DW_AT_const_value, val);
14240 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
14245 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14246 floating-point constant. A CONST_DOUBLE is used whenever the
14247 constant requires more than one word in order to be adequately
14250 enum machine_mode mode = GET_MODE (rtl);
14252 if (SCALAR_FLOAT_MODE_P (mode))
14254 unsigned int length = GET_MODE_SIZE (mode);
14255 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
14257 insert_float (rtl, array);
14258 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
14261 add_AT_double (die, DW_AT_const_value,
14262 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
14268 enum machine_mode mode = GET_MODE (rtl);
14269 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
14270 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14271 unsigned char *array = (unsigned char *) ggc_alloc_atomic
14272 (length * elt_size);
14276 switch (GET_MODE_CLASS (mode))
14278 case MODE_VECTOR_INT:
14279 for (i = 0, p = array; i < length; i++, p += elt_size)
14281 rtx elt = CONST_VECTOR_ELT (rtl, i);
14282 double_int val = rtx_to_double_int (elt);
14284 if (elt_size <= sizeof (HOST_WIDE_INT))
14285 insert_int (double_int_to_shwi (val), elt_size, p);
14288 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14289 insert_double (val, p);
14294 case MODE_VECTOR_FLOAT:
14295 for (i = 0, p = array; i < length; i++, p += elt_size)
14297 rtx elt = CONST_VECTOR_ELT (rtl, i);
14298 insert_float (elt, p);
14303 gcc_unreachable ();
14306 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
14311 if (dwarf_version >= 4 || !dwarf_strict)
14313 dw_loc_descr_ref loc_result;
14314 resolve_one_addr (&rtl, NULL);
14316 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14317 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14318 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14319 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14320 add_AT_loc (die, DW_AT_location, loc_result);
14321 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14327 if (CONSTANT_P (XEXP (rtl, 0)))
14328 return add_const_value_attribute (die, XEXP (rtl, 0));
14331 if (!const_ok_for_output (rtl))
14334 if (dwarf_version >= 4 || !dwarf_strict)
14339 /* In cases where an inlined instance of an inline function is passed
14340 the address of an `auto' variable (which is local to the caller) we
14341 can get a situation where the DECL_RTL of the artificial local
14342 variable (for the inlining) which acts as a stand-in for the
14343 corresponding formal parameter (of the inline function) will look
14344 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14345 exactly a compile-time constant expression, but it isn't the address
14346 of the (artificial) local variable either. Rather, it represents the
14347 *value* which the artificial local variable always has during its
14348 lifetime. We currently have no way to represent such quasi-constant
14349 values in Dwarf, so for now we just punt and generate nothing. */
14357 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
14358 && MEM_READONLY_P (rtl)
14359 && GET_MODE (rtl) == BLKmode)
14361 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
14367 /* No other kinds of rtx should be possible here. */
14368 gcc_unreachable ();
14373 /* Determine whether the evaluation of EXPR references any variables
14374 or functions which aren't otherwise used (and therefore may not be
14377 reference_to_unused (tree * tp, int * walk_subtrees,
14378 void * data ATTRIBUTE_UNUSED)
14380 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
14381 *walk_subtrees = 0;
14383 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
14384 && ! TREE_ASM_WRITTEN (*tp))
14386 /* ??? The C++ FE emits debug information for using decls, so
14387 putting gcc_unreachable here falls over. See PR31899. For now
14388 be conservative. */
14389 else if (!cgraph_global_info_ready
14390 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
14392 else if (TREE_CODE (*tp) == VAR_DECL)
14394 struct varpool_node *node = varpool_get_node (*tp);
14395 if (!node || !node->needed)
14398 else if (TREE_CODE (*tp) == FUNCTION_DECL
14399 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
14401 /* The call graph machinery must have finished analyzing,
14402 optimizing and gimplifying the CU by now.
14403 So if *TP has no call graph node associated
14404 to it, it means *TP will not be emitted. */
14405 if (!cgraph_get_node (*tp))
14408 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
14414 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14415 for use in a later add_const_value_attribute call. */
14418 rtl_for_decl_init (tree init, tree type)
14420 rtx rtl = NULL_RTX;
14424 /* If a variable is initialized with a string constant without embedded
14425 zeros, build CONST_STRING. */
14426 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
14428 tree enttype = TREE_TYPE (type);
14429 tree domain = TYPE_DOMAIN (type);
14430 enum machine_mode mode = TYPE_MODE (enttype);
14432 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
14434 && integer_zerop (TYPE_MIN_VALUE (domain))
14435 && compare_tree_int (TYPE_MAX_VALUE (domain),
14436 TREE_STRING_LENGTH (init) - 1) == 0
14437 && ((size_t) TREE_STRING_LENGTH (init)
14438 == strlen (TREE_STRING_POINTER (init)) + 1))
14440 rtl = gen_rtx_CONST_STRING (VOIDmode,
14441 ggc_strdup (TREE_STRING_POINTER (init)));
14442 rtl = gen_rtx_MEM (BLKmode, rtl);
14443 MEM_READONLY_P (rtl) = 1;
14446 /* Other aggregates, and complex values, could be represented using
14448 else if (AGGREGATE_TYPE_P (type)
14449 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
14450 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
14451 || TREE_CODE (type) == COMPLEX_TYPE)
14453 /* Vectors only work if their mode is supported by the target.
14454 FIXME: generic vectors ought to work too. */
14455 else if (TREE_CODE (type) == VECTOR_TYPE
14456 && !VECTOR_MODE_P (TYPE_MODE (type)))
14458 /* If the initializer is something that we know will expand into an
14459 immediate RTL constant, expand it now. We must be careful not to
14460 reference variables which won't be output. */
14461 else if (initializer_constant_valid_p (init, type)
14462 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
14464 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14466 if (TREE_CODE (type) == VECTOR_TYPE)
14467 switch (TREE_CODE (init))
14472 if (TREE_CONSTANT (init))
14474 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
14475 bool constant_p = true;
14477 unsigned HOST_WIDE_INT ix;
14479 /* Even when ctor is constant, it might contain non-*_CST
14480 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14481 belong into VECTOR_CST nodes. */
14482 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
14483 if (!CONSTANT_CLASS_P (value))
14485 constant_p = false;
14491 init = build_vector_from_ctor (type, elts);
14501 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
14503 /* If expand_expr returns a MEM, it wasn't immediate. */
14504 gcc_assert (!rtl || !MEM_P (rtl));
14510 /* Generate RTL for the variable DECL to represent its location. */
14513 rtl_for_decl_location (tree decl)
14517 /* Here we have to decide where we are going to say the parameter "lives"
14518 (as far as the debugger is concerned). We only have a couple of
14519 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14521 DECL_RTL normally indicates where the parameter lives during most of the
14522 activation of the function. If optimization is enabled however, this
14523 could be either NULL or else a pseudo-reg. Both of those cases indicate
14524 that the parameter doesn't really live anywhere (as far as the code
14525 generation parts of GCC are concerned) during most of the function's
14526 activation. That will happen (for example) if the parameter is never
14527 referenced within the function.
14529 We could just generate a location descriptor here for all non-NULL
14530 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14531 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14532 where DECL_RTL is NULL or is a pseudo-reg.
14534 Note however that we can only get away with using DECL_INCOMING_RTL as
14535 a backup substitute for DECL_RTL in certain limited cases. In cases
14536 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14537 we can be sure that the parameter was passed using the same type as it is
14538 declared to have within the function, and that its DECL_INCOMING_RTL
14539 points us to a place where a value of that type is passed.
14541 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14542 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14543 because in these cases DECL_INCOMING_RTL points us to a value of some
14544 type which is *different* from the type of the parameter itself. Thus,
14545 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14546 such cases, the debugger would end up (for example) trying to fetch a
14547 `float' from a place which actually contains the first part of a
14548 `double'. That would lead to really incorrect and confusing
14549 output at debug-time.
14551 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14552 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14553 are a couple of exceptions however. On little-endian machines we can
14554 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14555 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14556 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14557 when (on a little-endian machine) a non-prototyped function has a
14558 parameter declared to be of type `short' or `char'. In such cases,
14559 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14560 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14561 passed `int' value. If the debugger then uses that address to fetch
14562 a `short' or a `char' (on a little-endian machine) the result will be
14563 the correct data, so we allow for such exceptional cases below.
14565 Note that our goal here is to describe the place where the given formal
14566 parameter lives during most of the function's activation (i.e. between the
14567 end of the prologue and the start of the epilogue). We'll do that as best
14568 as we can. Note however that if the given formal parameter is modified
14569 sometime during the execution of the function, then a stack backtrace (at
14570 debug-time) will show the function as having been called with the *new*
14571 value rather than the value which was originally passed in. This happens
14572 rarely enough that it is not a major problem, but it *is* a problem, and
14573 I'd like to fix it.
14575 A future version of dwarf2out.c may generate two additional attributes for
14576 any given DW_TAG_formal_parameter DIE which will describe the "passed
14577 type" and the "passed location" for the given formal parameter in addition
14578 to the attributes we now generate to indicate the "declared type" and the
14579 "active location" for each parameter. This additional set of attributes
14580 could be used by debuggers for stack backtraces. Separately, note that
14581 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
14582 This happens (for example) for inlined-instances of inline function formal
14583 parameters which are never referenced. This really shouldn't be
14584 happening. All PARM_DECL nodes should get valid non-NULL
14585 DECL_INCOMING_RTL values. FIXME. */
14587 /* Use DECL_RTL as the "location" unless we find something better. */
14588 rtl = DECL_RTL_IF_SET (decl);
14590 /* When generating abstract instances, ignore everything except
14591 constants, symbols living in memory, and symbols living in
14592 fixed registers. */
14593 if (! reload_completed)
14596 && (CONSTANT_P (rtl)
14598 && CONSTANT_P (XEXP (rtl, 0)))
14600 && TREE_CODE (decl) == VAR_DECL
14601 && TREE_STATIC (decl))))
14603 rtl = targetm.delegitimize_address (rtl);
14608 else if (TREE_CODE (decl) == PARM_DECL)
14610 if (rtl == NULL_RTX
14611 || is_pseudo_reg (rtl)
14613 && is_pseudo_reg (XEXP (rtl, 0))
14614 && DECL_INCOMING_RTL (decl)
14615 && MEM_P (DECL_INCOMING_RTL (decl))
14616 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
14618 tree declared_type = TREE_TYPE (decl);
14619 tree passed_type = DECL_ARG_TYPE (decl);
14620 enum machine_mode dmode = TYPE_MODE (declared_type);
14621 enum machine_mode pmode = TYPE_MODE (passed_type);
14623 /* This decl represents a formal parameter which was optimized out.
14624 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
14625 all cases where (rtl == NULL_RTX) just below. */
14626 if (dmode == pmode)
14627 rtl = DECL_INCOMING_RTL (decl);
14628 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
14629 && SCALAR_INT_MODE_P (dmode)
14630 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
14631 && DECL_INCOMING_RTL (decl))
14633 rtx inc = DECL_INCOMING_RTL (decl);
14636 else if (MEM_P (inc))
14638 if (BYTES_BIG_ENDIAN)
14639 rtl = adjust_address_nv (inc, dmode,
14640 GET_MODE_SIZE (pmode)
14641 - GET_MODE_SIZE (dmode));
14648 /* If the parm was passed in registers, but lives on the stack, then
14649 make a big endian correction if the mode of the type of the
14650 parameter is not the same as the mode of the rtl. */
14651 /* ??? This is the same series of checks that are made in dbxout.c before
14652 we reach the big endian correction code there. It isn't clear if all
14653 of these checks are necessary here, but keeping them all is the safe
14655 else if (MEM_P (rtl)
14656 && XEXP (rtl, 0) != const0_rtx
14657 && ! CONSTANT_P (XEXP (rtl, 0))
14658 /* Not passed in memory. */
14659 && !MEM_P (DECL_INCOMING_RTL (decl))
14660 /* Not passed by invisible reference. */
14661 && (!REG_P (XEXP (rtl, 0))
14662 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
14663 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
14664 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
14665 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
14668 /* Big endian correction check. */
14669 && BYTES_BIG_ENDIAN
14670 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
14671 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
14674 int offset = (UNITS_PER_WORD
14675 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
14677 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
14678 plus_constant (XEXP (rtl, 0), offset));
14681 else if (TREE_CODE (decl) == VAR_DECL
14684 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
14685 && BYTES_BIG_ENDIAN)
14687 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
14688 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
14690 /* If a variable is declared "register" yet is smaller than
14691 a register, then if we store the variable to memory, it
14692 looks like we're storing a register-sized value, when in
14693 fact we are not. We need to adjust the offset of the
14694 storage location to reflect the actual value's bytes,
14695 else gdb will not be able to display it. */
14697 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
14698 plus_constant (XEXP (rtl, 0), rsize-dsize));
14701 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
14702 and will have been substituted directly into all expressions that use it.
14703 C does not have such a concept, but C++ and other languages do. */
14704 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
14705 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
14708 rtl = targetm.delegitimize_address (rtl);
14710 /* If we don't look past the constant pool, we risk emitting a
14711 reference to a constant pool entry that isn't referenced from
14712 code, and thus is not emitted. */
14714 rtl = avoid_constant_pool_reference (rtl);
14716 /* Try harder to get a rtl. If this symbol ends up not being emitted
14717 in the current CU, resolve_addr will remove the expression referencing
14719 if (rtl == NULL_RTX
14720 && TREE_CODE (decl) == VAR_DECL
14721 && !DECL_EXTERNAL (decl)
14722 && TREE_STATIC (decl)
14723 && DECL_NAME (decl)
14724 && !DECL_HARD_REGISTER (decl)
14725 && DECL_MODE (decl) != VOIDmode)
14727 rtl = make_decl_rtl_for_debug (decl);
14729 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
14730 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
14737 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
14738 returned. If so, the decl for the COMMON block is returned, and the
14739 value is the offset into the common block for the symbol. */
14742 fortran_common (tree decl, HOST_WIDE_INT *value)
14744 tree val_expr, cvar;
14745 enum machine_mode mode;
14746 HOST_WIDE_INT bitsize, bitpos;
14748 int volatilep = 0, unsignedp = 0;
14750 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
14751 it does not have a value (the offset into the common area), or if it
14752 is thread local (as opposed to global) then it isn't common, and shouldn't
14753 be handled as such. */
14754 if (TREE_CODE (decl) != VAR_DECL
14755 || !TREE_STATIC (decl)
14756 || !DECL_HAS_VALUE_EXPR_P (decl)
14760 val_expr = DECL_VALUE_EXPR (decl);
14761 if (TREE_CODE (val_expr) != COMPONENT_REF)
14764 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
14765 &mode, &unsignedp, &volatilep, true);
14767 if (cvar == NULL_TREE
14768 || TREE_CODE (cvar) != VAR_DECL
14769 || DECL_ARTIFICIAL (cvar)
14770 || !TREE_PUBLIC (cvar))
14774 if (offset != NULL)
14776 if (!host_integerp (offset, 0))
14778 *value = tree_low_cst (offset, 0);
14781 *value += bitpos / BITS_PER_UNIT;
14786 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
14787 data attribute for a variable or a parameter. We generate the
14788 DW_AT_const_value attribute only in those cases where the given variable
14789 or parameter does not have a true "location" either in memory or in a
14790 register. This can happen (for example) when a constant is passed as an
14791 actual argument in a call to an inline function. (It's possible that
14792 these things can crop up in other ways also.) Note that one type of
14793 constant value which can be passed into an inlined function is a constant
14794 pointer. This can happen for example if an actual argument in an inlined
14795 function call evaluates to a compile-time constant address.
14797 CACHE_P is true if it is worth caching the location list for DECL,
14798 so that future calls can reuse it rather than regenerate it from scratch.
14799 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
14800 since we will need to refer to them each time the function is inlined. */
14803 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
14804 enum dwarf_attribute attr)
14807 dw_loc_list_ref list;
14808 var_loc_list *loc_list;
14809 cached_dw_loc_list *cache;
14812 if (TREE_CODE (decl) == ERROR_MARK)
14815 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
14816 || TREE_CODE (decl) == RESULT_DECL);
14818 /* Try to get some constant RTL for this decl, and use that as the value of
14821 rtl = rtl_for_decl_location (decl);
14822 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
14823 && add_const_value_attribute (die, rtl))
14826 /* See if we have single element location list that is equivalent to
14827 a constant value. That way we are better to use add_const_value_attribute
14828 rather than expanding constant value equivalent. */
14829 loc_list = lookup_decl_loc (decl);
14832 && loc_list->first->next == NULL
14833 && NOTE_P (loc_list->first->loc)
14834 && NOTE_VAR_LOCATION (loc_list->first->loc)
14835 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
14837 struct var_loc_node *node;
14839 node = loc_list->first;
14840 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
14841 if (GET_CODE (rtl) == EXPR_LIST)
14842 rtl = XEXP (rtl, 0);
14843 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
14844 && add_const_value_attribute (die, rtl))
14847 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
14848 list several times. See if we've already cached the contents. */
14850 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
14854 cache = (cached_dw_loc_list *)
14855 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
14857 list = cache->loc_list;
14861 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
14862 /* It is usually worth caching this result if the decl is from
14863 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
14864 if (cache_p && list && list->dw_loc_next)
14866 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
14867 DECL_UID (decl), INSERT);
14868 cache = ggc_alloc_cleared_cached_dw_loc_list ();
14869 cache->decl_id = DECL_UID (decl);
14870 cache->loc_list = list;
14876 add_AT_location_description (die, attr, list);
14879 /* None of that worked, so it must not really have a location;
14880 try adding a constant value attribute from the DECL_INITIAL. */
14881 return tree_add_const_value_attribute_for_decl (die, decl);
14884 /* Add VARIABLE and DIE into deferred locations list. */
14887 defer_location (tree variable, dw_die_ref die)
14889 deferred_locations entry;
14890 entry.variable = variable;
14892 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
14895 /* Helper function for tree_add_const_value_attribute. Natively encode
14896 initializer INIT into an array. Return true if successful. */
14899 native_encode_initializer (tree init, unsigned char *array, int size)
14903 if (init == NULL_TREE)
14907 switch (TREE_CODE (init))
14910 type = TREE_TYPE (init);
14911 if (TREE_CODE (type) == ARRAY_TYPE)
14913 tree enttype = TREE_TYPE (type);
14914 enum machine_mode mode = TYPE_MODE (enttype);
14916 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
14918 if (int_size_in_bytes (type) != size)
14920 if (size > TREE_STRING_LENGTH (init))
14922 memcpy (array, TREE_STRING_POINTER (init),
14923 TREE_STRING_LENGTH (init));
14924 memset (array + TREE_STRING_LENGTH (init),
14925 '\0', size - TREE_STRING_LENGTH (init));
14928 memcpy (array, TREE_STRING_POINTER (init), size);
14933 type = TREE_TYPE (init);
14934 if (int_size_in_bytes (type) != size)
14936 if (TREE_CODE (type) == ARRAY_TYPE)
14938 HOST_WIDE_INT min_index;
14939 unsigned HOST_WIDE_INT cnt;
14940 int curpos = 0, fieldsize;
14941 constructor_elt *ce;
14943 if (TYPE_DOMAIN (type) == NULL_TREE
14944 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
14947 fieldsize = int_size_in_bytes (TREE_TYPE (type));
14948 if (fieldsize <= 0)
14951 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
14952 memset (array, '\0', size);
14953 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
14955 tree val = ce->value;
14956 tree index = ce->index;
14958 if (index && TREE_CODE (index) == RANGE_EXPR)
14959 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
14962 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
14967 if (!native_encode_initializer (val, array + pos, fieldsize))
14970 curpos = pos + fieldsize;
14971 if (index && TREE_CODE (index) == RANGE_EXPR)
14973 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
14974 - tree_low_cst (TREE_OPERAND (index, 0), 0);
14975 while (count-- > 0)
14978 memcpy (array + curpos, array + pos, fieldsize);
14979 curpos += fieldsize;
14982 gcc_assert (curpos <= size);
14986 else if (TREE_CODE (type) == RECORD_TYPE
14987 || TREE_CODE (type) == UNION_TYPE)
14989 tree field = NULL_TREE;
14990 unsigned HOST_WIDE_INT cnt;
14991 constructor_elt *ce;
14993 if (int_size_in_bytes (type) != size)
14996 if (TREE_CODE (type) == RECORD_TYPE)
14997 field = TYPE_FIELDS (type);
14999 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
15001 tree val = ce->value;
15002 int pos, fieldsize;
15004 if (ce->index != 0)
15010 if (field == NULL_TREE || DECL_BIT_FIELD (field))
15013 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
15014 && TYPE_DOMAIN (TREE_TYPE (field))
15015 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
15017 else if (DECL_SIZE_UNIT (field) == NULL_TREE
15018 || !host_integerp (DECL_SIZE_UNIT (field), 0))
15020 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
15021 pos = int_byte_position (field);
15022 gcc_assert (pos + fieldsize <= size);
15024 && !native_encode_initializer (val, array + pos, fieldsize))
15030 case VIEW_CONVERT_EXPR:
15031 case NON_LVALUE_EXPR:
15032 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
15034 return native_encode_expr (init, array, size) == size;
15038 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15039 attribute is the const value T. */
15042 tree_add_const_value_attribute (dw_die_ref die, tree t)
15045 tree type = TREE_TYPE (t);
15048 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
15052 gcc_assert (!DECL_P (init));
15054 rtl = rtl_for_decl_init (init, type);
15056 return add_const_value_attribute (die, rtl);
15057 /* If the host and target are sane, try harder. */
15058 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
15059 && initializer_constant_valid_p (init, type))
15061 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
15062 if (size > 0 && (int) size == size)
15064 unsigned char *array = (unsigned char *)
15065 ggc_alloc_cleared_atomic (size);
15067 if (native_encode_initializer (init, array, size))
15069 add_AT_vec (die, DW_AT_const_value, size, 1, array);
15077 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15078 attribute is the const value of T, where T is an integral constant
15079 variable with static storage duration
15080 (so it can't be a PARM_DECL or a RESULT_DECL). */
15083 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
15087 || (TREE_CODE (decl) != VAR_DECL
15088 && TREE_CODE (decl) != CONST_DECL)
15089 || (TREE_CODE (decl) == VAR_DECL
15090 && !TREE_STATIC (decl)))
15093 if (TREE_READONLY (decl)
15094 && ! TREE_THIS_VOLATILE (decl)
15095 && DECL_INITIAL (decl))
15100 /* Don't add DW_AT_const_value if abstract origin already has one. */
15101 if (get_AT (var_die, DW_AT_const_value))
15104 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
15107 /* Convert the CFI instructions for the current function into a
15108 location list. This is used for DW_AT_frame_base when we targeting
15109 a dwarf2 consumer that does not support the dwarf3
15110 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15113 static dw_loc_list_ref
15114 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
15118 dw_loc_list_ref list, *list_tail;
15120 dw_cfa_location last_cfa, next_cfa;
15121 const char *start_label, *last_label, *section;
15122 dw_cfa_location remember;
15125 gcc_assert (fde != NULL);
15127 section = secname_for_decl (current_function_decl);
15131 memset (&next_cfa, 0, sizeof (next_cfa));
15132 next_cfa.reg = INVALID_REGNUM;
15133 remember = next_cfa;
15135 start_label = fde->dw_fde_begin;
15137 /* ??? Bald assumption that the CIE opcode list does not contain
15138 advance opcodes. */
15139 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
15140 lookup_cfa_1 (cfi, &next_cfa, &remember);
15142 last_cfa = next_cfa;
15143 last_label = start_label;
15145 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
15147 /* If the first partition contained no CFI adjustments, the
15148 CIE opcodes apply to the whole first partition. */
15149 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15150 fde->dw_fde_begin, fde->dw_fde_end, section);
15151 list_tail =&(*list_tail)->dw_loc_next;
15152 start_label = last_label = fde->dw_fde_second_begin;
15155 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
15157 switch (cfi->dw_cfi_opc)
15159 case DW_CFA_set_loc:
15160 case DW_CFA_advance_loc1:
15161 case DW_CFA_advance_loc2:
15162 case DW_CFA_advance_loc4:
15163 if (!cfa_equal_p (&last_cfa, &next_cfa))
15165 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15166 start_label, last_label, section);
15168 list_tail = &(*list_tail)->dw_loc_next;
15169 last_cfa = next_cfa;
15170 start_label = last_label;
15172 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
15175 case DW_CFA_advance_loc:
15176 /* The encoding is complex enough that we should never emit this. */
15177 gcc_unreachable ();
15180 lookup_cfa_1 (cfi, &next_cfa, &remember);
15183 if (ix + 1 == fde->dw_fde_switch_cfi_index)
15185 if (!cfa_equal_p (&last_cfa, &next_cfa))
15187 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15188 start_label, last_label, section);
15190 list_tail = &(*list_tail)->dw_loc_next;
15191 last_cfa = next_cfa;
15192 start_label = last_label;
15194 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15195 start_label, fde->dw_fde_end, section);
15196 list_tail = &(*list_tail)->dw_loc_next;
15197 start_label = last_label = fde->dw_fde_second_begin;
15201 if (!cfa_equal_p (&last_cfa, &next_cfa))
15203 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15204 start_label, last_label, section);
15205 list_tail = &(*list_tail)->dw_loc_next;
15206 start_label = last_label;
15209 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
15211 fde->dw_fde_second_begin
15212 ? fde->dw_fde_second_end : fde->dw_fde_end,
15215 if (list && list->dw_loc_next)
15221 /* Compute a displacement from the "steady-state frame pointer" to the
15222 frame base (often the same as the CFA), and store it in
15223 frame_pointer_fb_offset. OFFSET is added to the displacement
15224 before the latter is negated. */
15227 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
15231 #ifdef FRAME_POINTER_CFA_OFFSET
15232 reg = frame_pointer_rtx;
15233 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
15235 reg = arg_pointer_rtx;
15236 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
15239 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
15240 if (GET_CODE (elim) == PLUS)
15242 offset += INTVAL (XEXP (elim, 1));
15243 elim = XEXP (elim, 0);
15246 frame_pointer_fb_offset = -offset;
15248 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15249 in which to eliminate. This is because it's stack pointer isn't
15250 directly accessible as a register within the ISA. To work around
15251 this, assume that while we cannot provide a proper value for
15252 frame_pointer_fb_offset, we won't need one either. */
15253 frame_pointer_fb_offset_valid
15254 = ((SUPPORTS_STACK_ALIGNMENT
15255 && (elim == hard_frame_pointer_rtx
15256 || elim == stack_pointer_rtx))
15257 || elim == (frame_pointer_needed
15258 ? hard_frame_pointer_rtx
15259 : stack_pointer_rtx));
15262 /* Generate a DW_AT_name attribute given some string value to be included as
15263 the value of the attribute. */
15266 add_name_attribute (dw_die_ref die, const char *name_string)
15268 if (name_string != NULL && *name_string != 0)
15270 if (demangle_name_func)
15271 name_string = (*demangle_name_func) (name_string);
15273 add_AT_string (die, DW_AT_name, name_string);
15277 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15278 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15279 of TYPE accordingly.
15281 ??? This is a temporary measure until after we're able to generate
15282 regular DWARF for the complex Ada type system. */
15285 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
15286 dw_die_ref context_die)
15289 dw_die_ref dtype_die;
15291 if (!lang_hooks.types.descriptive_type)
15294 dtype = lang_hooks.types.descriptive_type (type);
15298 dtype_die = lookup_type_die (dtype);
15301 gen_type_die (dtype, context_die);
15302 dtype_die = lookup_type_die (dtype);
15303 gcc_assert (dtype_die);
15306 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
15309 /* Generate a DW_AT_comp_dir attribute for DIE. */
15312 add_comp_dir_attribute (dw_die_ref die)
15314 const char *wd = get_src_pwd ();
15320 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
15324 wdlen = strlen (wd);
15325 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
15327 wd1 [wdlen] = DIR_SEPARATOR;
15328 wd1 [wdlen + 1] = 0;
15332 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
15335 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15339 lower_bound_default (void)
15341 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
15346 case DW_LANG_C_plus_plus:
15348 case DW_LANG_ObjC_plus_plus:
15351 case DW_LANG_Fortran77:
15352 case DW_LANG_Fortran90:
15353 case DW_LANG_Fortran95:
15357 case DW_LANG_Python:
15358 return dwarf_version >= 4 ? 0 : -1;
15359 case DW_LANG_Ada95:
15360 case DW_LANG_Ada83:
15361 case DW_LANG_Cobol74:
15362 case DW_LANG_Cobol85:
15363 case DW_LANG_Pascal83:
15364 case DW_LANG_Modula2:
15366 return dwarf_version >= 4 ? 1 : -1;
15372 /* Given a tree node describing an array bound (either lower or upper) output
15373 a representation for that bound. */
15376 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
15378 switch (TREE_CODE (bound))
15383 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15386 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
15389 /* Use the default if possible. */
15390 if (bound_attr == DW_AT_lower_bound
15391 && host_integerp (bound, 0)
15392 && (dflt = lower_bound_default ()) != -1
15393 && tree_low_cst (bound, 0) == dflt)
15396 /* Otherwise represent the bound as an unsigned value with the
15397 precision of its type. The precision and signedness of the
15398 type will be necessary to re-interpret it unambiguously. */
15399 else if (prec < HOST_BITS_PER_WIDE_INT)
15401 unsigned HOST_WIDE_INT mask
15402 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
15403 add_AT_unsigned (subrange_die, bound_attr,
15404 TREE_INT_CST_LOW (bound) & mask);
15406 else if (prec == HOST_BITS_PER_WIDE_INT
15407 || TREE_INT_CST_HIGH (bound) == 0)
15408 add_AT_unsigned (subrange_die, bound_attr,
15409 TREE_INT_CST_LOW (bound));
15411 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
15412 TREE_INT_CST_LOW (bound));
15417 case VIEW_CONVERT_EXPR:
15418 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
15428 dw_die_ref decl_die = lookup_decl_die (bound);
15430 /* ??? Can this happen, or should the variable have been bound
15431 first? Probably it can, since I imagine that we try to create
15432 the types of parameters in the order in which they exist in
15433 the list, and won't have created a forward reference to a
15434 later parameter. */
15435 if (decl_die != NULL)
15437 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15445 /* Otherwise try to create a stack operation procedure to
15446 evaluate the value of the array bound. */
15448 dw_die_ref ctx, decl_die;
15449 dw_loc_list_ref list;
15451 list = loc_list_from_tree (bound, 2);
15452 if (list == NULL || single_element_loc_list_p (list))
15454 /* If DW_AT_*bound is not a reference nor constant, it is
15455 a DWARF expression rather than location description.
15456 For that loc_list_from_tree (bound, 0) is needed.
15457 If that fails to give a single element list,
15458 fall back to outputting this as a reference anyway. */
15459 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
15460 if (list2 && single_element_loc_list_p (list2))
15462 add_AT_loc (subrange_die, bound_attr, list2->expr);
15469 if (current_function_decl == 0)
15470 ctx = comp_unit_die ();
15472 ctx = lookup_decl_die (current_function_decl);
15474 decl_die = new_die (DW_TAG_variable, ctx, bound);
15475 add_AT_flag (decl_die, DW_AT_artificial, 1);
15476 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
15477 add_AT_location_description (decl_die, DW_AT_location, list);
15478 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15484 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15485 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15486 Note that the block of subscript information for an array type also
15487 includes information about the element type of the given array type. */
15490 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
15492 unsigned dimension_number;
15494 dw_die_ref subrange_die;
15496 for (dimension_number = 0;
15497 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
15498 type = TREE_TYPE (type), dimension_number++)
15500 tree domain = TYPE_DOMAIN (type);
15502 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
15505 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15506 and (in GNU C only) variable bounds. Handle all three forms
15508 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
15511 /* We have an array type with specified bounds. */
15512 lower = TYPE_MIN_VALUE (domain);
15513 upper = TYPE_MAX_VALUE (domain);
15515 /* Define the index type. */
15516 if (TREE_TYPE (domain))
15518 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15519 TREE_TYPE field. We can't emit debug info for this
15520 because it is an unnamed integral type. */
15521 if (TREE_CODE (domain) == INTEGER_TYPE
15522 && TYPE_NAME (domain) == NULL_TREE
15523 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
15524 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
15527 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
15531 /* ??? If upper is NULL, the array has unspecified length,
15532 but it does have a lower bound. This happens with Fortran
15534 Since the debugger is definitely going to need to know N
15535 to produce useful results, go ahead and output the lower
15536 bound solo, and hope the debugger can cope. */
15538 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
15540 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
15543 /* Otherwise we have an array type with an unspecified length. The
15544 DWARF-2 spec does not say how to handle this; let's just leave out the
15550 add_byte_size_attribute (dw_die_ref die, tree tree_node)
15554 switch (TREE_CODE (tree_node))
15559 case ENUMERAL_TYPE:
15562 case QUAL_UNION_TYPE:
15563 size = int_size_in_bytes (tree_node);
15566 /* For a data member of a struct or union, the DW_AT_byte_size is
15567 generally given as the number of bytes normally allocated for an
15568 object of the *declared* type of the member itself. This is true
15569 even for bit-fields. */
15570 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
15573 gcc_unreachable ();
15576 /* Note that `size' might be -1 when we get to this point. If it is, that
15577 indicates that the byte size of the entity in question is variable. We
15578 have no good way of expressing this fact in Dwarf at the present time,
15579 so just let the -1 pass on through. */
15580 add_AT_unsigned (die, DW_AT_byte_size, size);
15583 /* For a FIELD_DECL node which represents a bit-field, output an attribute
15584 which specifies the distance in bits from the highest order bit of the
15585 "containing object" for the bit-field to the highest order bit of the
15588 For any given bit-field, the "containing object" is a hypothetical object
15589 (of some integral or enum type) within which the given bit-field lives. The
15590 type of this hypothetical "containing object" is always the same as the
15591 declared type of the individual bit-field itself. The determination of the
15592 exact location of the "containing object" for a bit-field is rather
15593 complicated. It's handled by the `field_byte_offset' function (above).
15595 Note that it is the size (in bytes) of the hypothetical "containing object"
15596 which will be given in the DW_AT_byte_size attribute for this bit-field.
15597 (See `byte_size_attribute' above). */
15600 add_bit_offset_attribute (dw_die_ref die, tree decl)
15602 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
15603 tree type = DECL_BIT_FIELD_TYPE (decl);
15604 HOST_WIDE_INT bitpos_int;
15605 HOST_WIDE_INT highest_order_object_bit_offset;
15606 HOST_WIDE_INT highest_order_field_bit_offset;
15607 HOST_WIDE_INT bit_offset;
15609 /* Must be a field and a bit field. */
15610 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
15612 /* We can't yet handle bit-fields whose offsets are variable, so if we
15613 encounter such things, just return without generating any attribute
15614 whatsoever. Likewise for variable or too large size. */
15615 if (! host_integerp (bit_position (decl), 0)
15616 || ! host_integerp (DECL_SIZE (decl), 1))
15619 bitpos_int = int_bit_position (decl);
15621 /* Note that the bit offset is always the distance (in bits) from the
15622 highest-order bit of the "containing object" to the highest-order bit of
15623 the bit-field itself. Since the "high-order end" of any object or field
15624 is different on big-endian and little-endian machines, the computation
15625 below must take account of these differences. */
15626 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
15627 highest_order_field_bit_offset = bitpos_int;
15629 if (! BYTES_BIG_ENDIAN)
15631 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
15632 highest_order_object_bit_offset += simple_type_size_in_bits (type);
15636 = (! BYTES_BIG_ENDIAN
15637 ? highest_order_object_bit_offset - highest_order_field_bit_offset
15638 : highest_order_field_bit_offset - highest_order_object_bit_offset);
15640 if (bit_offset < 0)
15641 add_AT_int (die, DW_AT_bit_offset, bit_offset);
15643 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
15646 /* For a FIELD_DECL node which represents a bit field, output an attribute
15647 which specifies the length in bits of the given field. */
15650 add_bit_size_attribute (dw_die_ref die, tree decl)
15652 /* Must be a field and a bit field. */
15653 gcc_assert (TREE_CODE (decl) == FIELD_DECL
15654 && DECL_BIT_FIELD_TYPE (decl));
15656 if (host_integerp (DECL_SIZE (decl), 1))
15657 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
15660 /* If the compiled language is ANSI C, then add a 'prototyped'
15661 attribute, if arg types are given for the parameters of a function. */
15664 add_prototyped_attribute (dw_die_ref die, tree func_type)
15666 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
15667 && prototype_p (func_type))
15668 add_AT_flag (die, DW_AT_prototyped, 1);
15671 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
15672 by looking in either the type declaration or object declaration
15675 static inline dw_die_ref
15676 add_abstract_origin_attribute (dw_die_ref die, tree origin)
15678 dw_die_ref origin_die = NULL;
15680 if (TREE_CODE (origin) != FUNCTION_DECL)
15682 /* We may have gotten separated from the block for the inlined
15683 function, if we're in an exception handler or some such; make
15684 sure that the abstract function has been written out.
15686 Doing this for nested functions is wrong, however; functions are
15687 distinct units, and our context might not even be inline. */
15691 fn = TYPE_STUB_DECL (fn);
15693 fn = decl_function_context (fn);
15695 dwarf2out_abstract_function (fn);
15698 if (DECL_P (origin))
15699 origin_die = lookup_decl_die (origin);
15700 else if (TYPE_P (origin))
15701 origin_die = lookup_type_die (origin);
15703 /* XXX: Functions that are never lowered don't always have correct block
15704 trees (in the case of java, they simply have no block tree, in some other
15705 languages). For these functions, there is nothing we can really do to
15706 output correct debug info for inlined functions in all cases. Rather
15707 than die, we'll just produce deficient debug info now, in that we will
15708 have variables without a proper abstract origin. In the future, when all
15709 functions are lowered, we should re-add a gcc_assert (origin_die)
15713 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
15717 /* We do not currently support the pure_virtual attribute. */
15720 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
15722 if (DECL_VINDEX (func_decl))
15724 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
15726 if (host_integerp (DECL_VINDEX (func_decl), 0))
15727 add_AT_loc (die, DW_AT_vtable_elem_location,
15728 new_loc_descr (DW_OP_constu,
15729 tree_low_cst (DECL_VINDEX (func_decl), 0),
15732 /* GNU extension: Record what type this method came from originally. */
15733 if (debug_info_level > DINFO_LEVEL_TERSE
15734 && DECL_CONTEXT (func_decl))
15735 add_AT_die_ref (die, DW_AT_containing_type,
15736 lookup_type_die (DECL_CONTEXT (func_decl)));
15740 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
15741 given decl. This used to be a vendor extension until after DWARF 4
15742 standardized it. */
15745 add_linkage_attr (dw_die_ref die, tree decl)
15747 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15749 /* Mimic what assemble_name_raw does with a leading '*'. */
15750 if (name[0] == '*')
15753 if (dwarf_version >= 4)
15754 add_AT_string (die, DW_AT_linkage_name, name);
15756 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
15759 /* Add source coordinate attributes for the given decl. */
15762 add_src_coords_attributes (dw_die_ref die, tree decl)
15764 expanded_location s;
15766 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
15768 s = expand_location (DECL_SOURCE_LOCATION (decl));
15769 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
15770 add_AT_unsigned (die, DW_AT_decl_line, s.line);
15773 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
15776 add_linkage_name (dw_die_ref die, tree decl)
15778 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
15779 && TREE_PUBLIC (decl)
15780 && !DECL_ABSTRACT (decl)
15781 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
15782 && die->die_tag != DW_TAG_member)
15784 /* Defer until we have an assembler name set. */
15785 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
15787 limbo_die_node *asm_name;
15789 asm_name = ggc_alloc_cleared_limbo_die_node ();
15790 asm_name->die = die;
15791 asm_name->created_for = decl;
15792 asm_name->next = deferred_asm_name;
15793 deferred_asm_name = asm_name;
15795 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
15796 add_linkage_attr (die, decl);
15800 /* Add a DW_AT_name attribute and source coordinate attribute for the
15801 given decl, but only if it actually has a name. */
15804 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
15808 decl_name = DECL_NAME (decl);
15809 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
15811 const char *name = dwarf2_name (decl, 0);
15813 add_name_attribute (die, name);
15814 if (! DECL_ARTIFICIAL (decl))
15815 add_src_coords_attributes (die, decl);
15817 add_linkage_name (die, decl);
15820 #ifdef VMS_DEBUGGING_INFO
15821 /* Get the function's name, as described by its RTL. This may be different
15822 from the DECL_NAME name used in the source file. */
15823 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
15825 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
15826 XEXP (DECL_RTL (decl), 0));
15827 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
15829 #endif /* VMS_DEBUGGING_INFO */
15832 #ifdef VMS_DEBUGGING_INFO
15833 /* Output the debug main pointer die for VMS */
15836 dwarf2out_vms_debug_main_pointer (void)
15838 char label[MAX_ARTIFICIAL_LABEL_BYTES];
15841 /* Allocate the VMS debug main subprogram die. */
15842 die = ggc_alloc_cleared_die_node ();
15843 die->die_tag = DW_TAG_subprogram;
15844 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
15845 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
15846 current_function_funcdef_no);
15847 add_AT_lbl_id (die, DW_AT_entry_pc, label);
15849 /* Make it the first child of comp_unit_die (). */
15850 die->die_parent = comp_unit_die ();
15851 if (comp_unit_die ()->die_child)
15853 die->die_sib = comp_unit_die ()->die_child->die_sib;
15854 comp_unit_die ()->die_child->die_sib = die;
15858 die->die_sib = die;
15859 comp_unit_die ()->die_child = die;
15862 #endif /* VMS_DEBUGGING_INFO */
15864 /* Push a new declaration scope. */
15867 push_decl_scope (tree scope)
15869 VEC_safe_push (tree, gc, decl_scope_table, scope);
15872 /* Pop a declaration scope. */
15875 pop_decl_scope (void)
15877 VEC_pop (tree, decl_scope_table);
15880 /* Return the DIE for the scope that immediately contains this type.
15881 Non-named types get global scope. Named types nested in other
15882 types get their containing scope if it's open, or global scope
15883 otherwise. All other types (i.e. function-local named types) get
15884 the current active scope. */
15887 scope_die_for (tree t, dw_die_ref context_die)
15889 dw_die_ref scope_die = NULL;
15890 tree containing_scope;
15893 /* Non-types always go in the current scope. */
15894 gcc_assert (TYPE_P (t));
15896 containing_scope = TYPE_CONTEXT (t);
15898 /* Use the containing namespace if it was passed in (for a declaration). */
15899 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
15901 if (context_die == lookup_decl_die (containing_scope))
15904 containing_scope = NULL_TREE;
15907 /* Ignore function type "scopes" from the C frontend. They mean that
15908 a tagged type is local to a parmlist of a function declarator, but
15909 that isn't useful to DWARF. */
15910 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
15911 containing_scope = NULL_TREE;
15913 if (SCOPE_FILE_SCOPE_P (containing_scope))
15914 scope_die = comp_unit_die ();
15915 else if (TYPE_P (containing_scope))
15917 /* For types, we can just look up the appropriate DIE. But
15918 first we check to see if we're in the middle of emitting it
15919 so we know where the new DIE should go. */
15920 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
15921 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
15926 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
15927 || TREE_ASM_WRITTEN (containing_scope));
15928 /*We are not in the middle of emitting the type
15929 CONTAINING_SCOPE. Let's see if it's emitted already. */
15930 scope_die = lookup_type_die (containing_scope);
15932 /* If none of the current dies are suitable, we get file scope. */
15933 if (scope_die == NULL)
15934 scope_die = comp_unit_die ();
15937 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
15940 scope_die = context_die;
15945 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
15948 local_scope_p (dw_die_ref context_die)
15950 for (; context_die; context_die = context_die->die_parent)
15951 if (context_die->die_tag == DW_TAG_inlined_subroutine
15952 || context_die->die_tag == DW_TAG_subprogram)
15958 /* Returns nonzero if CONTEXT_DIE is a class. */
15961 class_scope_p (dw_die_ref context_die)
15963 return (context_die
15964 && (context_die->die_tag == DW_TAG_structure_type
15965 || context_die->die_tag == DW_TAG_class_type
15966 || context_die->die_tag == DW_TAG_interface_type
15967 || context_die->die_tag == DW_TAG_union_type));
15970 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
15971 whether or not to treat a DIE in this context as a declaration. */
15974 class_or_namespace_scope_p (dw_die_ref context_die)
15976 return (class_scope_p (context_die)
15977 || (context_die && context_die->die_tag == DW_TAG_namespace));
15980 /* Many forms of DIEs require a "type description" attribute. This
15981 routine locates the proper "type descriptor" die for the type given
15982 by 'type', and adds a DW_AT_type attribute below the given die. */
15985 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
15986 int decl_volatile, dw_die_ref context_die)
15988 enum tree_code code = TREE_CODE (type);
15989 dw_die_ref type_die = NULL;
15991 /* ??? If this type is an unnamed subrange type of an integral, floating-point
15992 or fixed-point type, use the inner type. This is because we have no
15993 support for unnamed types in base_type_die. This can happen if this is
15994 an Ada subrange type. Correct solution is emit a subrange type die. */
15995 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
15996 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
15997 type = TREE_TYPE (type), code = TREE_CODE (type);
15999 if (code == ERROR_MARK
16000 /* Handle a special case. For functions whose return type is void, we
16001 generate *no* type attribute. (Note that no object may have type
16002 `void', so this only applies to function return types). */
16003 || code == VOID_TYPE)
16006 type_die = modified_type_die (type,
16007 decl_const || TYPE_READONLY (type),
16008 decl_volatile || TYPE_VOLATILE (type),
16011 if (type_die != NULL)
16012 add_AT_die_ref (object_die, DW_AT_type, type_die);
16015 /* Given an object die, add the calling convention attribute for the
16016 function call type. */
16018 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
16020 enum dwarf_calling_convention value = DW_CC_normal;
16022 value = ((enum dwarf_calling_convention)
16023 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
16026 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
16028 /* DWARF 2 doesn't provide a way to identify a program's source-level
16029 entry point. DW_AT_calling_convention attributes are only meant
16030 to describe functions' calling conventions. However, lacking a
16031 better way to signal the Fortran main program, we used this for
16032 a long time, following existing custom. Now, DWARF 4 has
16033 DW_AT_main_subprogram, which we add below, but some tools still
16034 rely on the old way, which we thus keep. */
16035 value = DW_CC_program;
16037 if (dwarf_version >= 4 || !dwarf_strict)
16038 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
16041 /* Only add the attribute if the backend requests it, and
16042 is not DW_CC_normal. */
16043 if (value && (value != DW_CC_normal))
16044 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
16047 /* Given a tree pointer to a struct, class, union, or enum type node, return
16048 a pointer to the (string) tag name for the given type, or zero if the type
16049 was declared without a tag. */
16051 static const char *
16052 type_tag (const_tree type)
16054 const char *name = 0;
16056 if (TYPE_NAME (type) != 0)
16060 /* Find the IDENTIFIER_NODE for the type name. */
16061 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
16062 && !TYPE_NAMELESS (type))
16063 t = TYPE_NAME (type);
16065 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16066 a TYPE_DECL node, regardless of whether or not a `typedef' was
16068 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16069 && ! DECL_IGNORED_P (TYPE_NAME (type)))
16071 /* We want to be extra verbose. Don't call dwarf_name if
16072 DECL_NAME isn't set. The default hook for decl_printable_name
16073 doesn't like that, and in this context it's correct to return
16074 0, instead of "<anonymous>" or the like. */
16075 if (DECL_NAME (TYPE_NAME (type))
16076 && !DECL_NAMELESS (TYPE_NAME (type)))
16077 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
16080 /* Now get the name as a string, or invent one. */
16081 if (!name && t != 0)
16082 name = IDENTIFIER_POINTER (t);
16085 return (name == 0 || *name == '\0') ? 0 : name;
16088 /* Return the type associated with a data member, make a special check
16089 for bit field types. */
16092 member_declared_type (const_tree member)
16094 return (DECL_BIT_FIELD_TYPE (member)
16095 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
16098 /* Get the decl's label, as described by its RTL. This may be different
16099 from the DECL_NAME name used in the source file. */
16102 static const char *
16103 decl_start_label (tree decl)
16106 const char *fnname;
16108 x = DECL_RTL (decl);
16109 gcc_assert (MEM_P (x));
16112 gcc_assert (GET_CODE (x) == SYMBOL_REF);
16114 fnname = XSTR (x, 0);
16119 /* These routines generate the internal representation of the DIE's for
16120 the compilation unit. Debugging information is collected by walking
16121 the declaration trees passed in from dwarf2out_decl(). */
16124 gen_array_type_die (tree type, dw_die_ref context_die)
16126 dw_die_ref scope_die = scope_die_for (type, context_die);
16127 dw_die_ref array_die;
16129 /* GNU compilers represent multidimensional array types as sequences of one
16130 dimensional array types whose element types are themselves array types.
16131 We sometimes squish that down to a single array_type DIE with multiple
16132 subscripts in the Dwarf debugging info. The draft Dwarf specification
16133 say that we are allowed to do this kind of compression in C, because
16134 there is no difference between an array of arrays and a multidimensional
16135 array. We don't do this for Ada to remain as close as possible to the
16136 actual representation, which is especially important against the language
16137 flexibilty wrt arrays of variable size. */
16139 bool collapse_nested_arrays = !is_ada ();
16142 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16143 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16144 if (TYPE_STRING_FLAG (type)
16145 && TREE_CODE (type) == ARRAY_TYPE
16147 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
16149 HOST_WIDE_INT size;
16151 array_die = new_die (DW_TAG_string_type, scope_die, type);
16152 add_name_attribute (array_die, type_tag (type));
16153 equate_type_number_to_die (type, array_die);
16154 size = int_size_in_bytes (type);
16156 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16157 else if (TYPE_DOMAIN (type) != NULL_TREE
16158 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
16159 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
16161 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
16162 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
16164 size = int_size_in_bytes (TREE_TYPE (szdecl));
16165 if (loc && size > 0)
16167 add_AT_location_description (array_die, DW_AT_string_length, loc);
16168 if (size != DWARF2_ADDR_SIZE)
16169 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16175 /* ??? The SGI dwarf reader fails for array of array of enum types
16176 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
16177 array type comes before the outer array type. We thus call gen_type_die
16178 before we new_die and must prevent nested array types collapsing for this
16181 #ifdef MIPS_DEBUGGING_INFO
16182 gen_type_die (TREE_TYPE (type), context_die);
16183 collapse_nested_arrays = false;
16186 array_die = new_die (DW_TAG_array_type, scope_die, type);
16187 add_name_attribute (array_die, type_tag (type));
16188 add_gnat_descriptive_type_attribute (array_die, type, context_die);
16189 if (TYPE_ARTIFICIAL (type))
16190 add_AT_flag (array_die, DW_AT_artificial, 1);
16191 equate_type_number_to_die (type, array_die);
16193 if (TREE_CODE (type) == VECTOR_TYPE)
16194 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
16196 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16198 && TREE_CODE (type) == ARRAY_TYPE
16199 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
16200 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
16201 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16204 /* We default the array ordering. SDB will probably do
16205 the right things even if DW_AT_ordering is not present. It's not even
16206 an issue until we start to get into multidimensional arrays anyway. If
16207 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16208 then we'll have to put the DW_AT_ordering attribute back in. (But if
16209 and when we find out that we need to put these in, we will only do so
16210 for multidimensional arrays. */
16211 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
16214 #ifdef MIPS_DEBUGGING_INFO
16215 /* The SGI compilers handle arrays of unknown bound by setting
16216 AT_declaration and not emitting any subrange DIEs. */
16217 if (TREE_CODE (type) == ARRAY_TYPE
16218 && ! TYPE_DOMAIN (type))
16219 add_AT_flag (array_die, DW_AT_declaration, 1);
16222 if (TREE_CODE (type) == VECTOR_TYPE)
16224 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16225 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
16226 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
16227 add_bound_info (subrange_die, DW_AT_upper_bound,
16228 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
16231 add_subscript_info (array_die, type, collapse_nested_arrays);
16233 /* Add representation of the type of the elements of this array type and
16234 emit the corresponding DIE if we haven't done it already. */
16235 element_type = TREE_TYPE (type);
16236 if (collapse_nested_arrays)
16237 while (TREE_CODE (element_type) == ARRAY_TYPE)
16239 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
16241 element_type = TREE_TYPE (element_type);
16244 #ifndef MIPS_DEBUGGING_INFO
16245 gen_type_die (element_type, context_die);
16248 add_type_attribute (array_die, element_type, 0, 0, context_die);
16250 if (get_AT (array_die, DW_AT_name))
16251 add_pubtype (type, array_die);
16254 static dw_loc_descr_ref
16255 descr_info_loc (tree val, tree base_decl)
16257 HOST_WIDE_INT size;
16258 dw_loc_descr_ref loc, loc2;
16259 enum dwarf_location_atom op;
16261 if (val == base_decl)
16262 return new_loc_descr (DW_OP_push_object_address, 0, 0);
16264 switch (TREE_CODE (val))
16267 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16269 return loc_descriptor_from_tree (val, 0);
16271 if (host_integerp (val, 0))
16272 return int_loc_descriptor (tree_low_cst (val, 0));
16275 size = int_size_in_bytes (TREE_TYPE (val));
16278 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16281 if (size == DWARF2_ADDR_SIZE)
16282 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
16284 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
16286 case POINTER_PLUS_EXPR:
16288 if (host_integerp (TREE_OPERAND (val, 1), 1)
16289 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
16292 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16295 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
16301 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16304 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
16307 add_loc_descr (&loc, loc2);
16308 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
16330 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
16331 tree val, tree base_decl)
16333 dw_loc_descr_ref loc;
16335 if (host_integerp (val, 0))
16337 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
16341 loc = descr_info_loc (val, base_decl);
16345 add_AT_loc (die, attr, loc);
16348 /* This routine generates DIE for array with hidden descriptor, details
16349 are filled into *info by a langhook. */
16352 gen_descr_array_type_die (tree type, struct array_descr_info *info,
16353 dw_die_ref context_die)
16355 dw_die_ref scope_die = scope_die_for (type, context_die);
16356 dw_die_ref array_die;
16359 array_die = new_die (DW_TAG_array_type, scope_die, type);
16360 add_name_attribute (array_die, type_tag (type));
16361 equate_type_number_to_die (type, array_die);
16363 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16365 && info->ndimensions >= 2)
16366 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16368 if (info->data_location)
16369 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
16371 if (info->associated)
16372 add_descr_info_field (array_die, DW_AT_associated, info->associated,
16374 if (info->allocated)
16375 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
16378 for (dim = 0; dim < info->ndimensions; dim++)
16380 dw_die_ref subrange_die
16381 = new_die (DW_TAG_subrange_type, array_die, NULL);
16383 if (info->dimen[dim].lower_bound)
16385 /* If it is the default value, omit it. */
16388 if (host_integerp (info->dimen[dim].lower_bound, 0)
16389 && (dflt = lower_bound_default ()) != -1
16390 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
16393 add_descr_info_field (subrange_die, DW_AT_lower_bound,
16394 info->dimen[dim].lower_bound,
16397 if (info->dimen[dim].upper_bound)
16398 add_descr_info_field (subrange_die, DW_AT_upper_bound,
16399 info->dimen[dim].upper_bound,
16401 if (info->dimen[dim].stride)
16402 add_descr_info_field (subrange_die, DW_AT_byte_stride,
16403 info->dimen[dim].stride,
16407 gen_type_die (info->element_type, context_die);
16408 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
16410 if (get_AT (array_die, DW_AT_name))
16411 add_pubtype (type, array_die);
16416 gen_entry_point_die (tree decl, dw_die_ref context_die)
16418 tree origin = decl_ultimate_origin (decl);
16419 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
16421 if (origin != NULL)
16422 add_abstract_origin_attribute (decl_die, origin);
16425 add_name_and_src_coords_attributes (decl_die, decl);
16426 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
16427 0, 0, context_die);
16430 if (DECL_ABSTRACT (decl))
16431 equate_decl_number_to_die (decl, decl_die);
16433 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
16437 /* Walk through the list of incomplete types again, trying once more to
16438 emit full debugging info for them. */
16441 retry_incomplete_types (void)
16445 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
16446 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
16447 DINFO_USAGE_DIR_USE))
16448 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
16451 /* Determine what tag to use for a record type. */
16453 static enum dwarf_tag
16454 record_type_tag (tree type)
16456 if (! lang_hooks.types.classify_record)
16457 return DW_TAG_structure_type;
16459 switch (lang_hooks.types.classify_record (type))
16461 case RECORD_IS_STRUCT:
16462 return DW_TAG_structure_type;
16464 case RECORD_IS_CLASS:
16465 return DW_TAG_class_type;
16467 case RECORD_IS_INTERFACE:
16468 if (dwarf_version >= 3 || !dwarf_strict)
16469 return DW_TAG_interface_type;
16470 return DW_TAG_structure_type;
16473 gcc_unreachable ();
16477 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16478 include all of the information about the enumeration values also. Each
16479 enumerated type name/value is listed as a child of the enumerated type
16483 gen_enumeration_type_die (tree type, dw_die_ref context_die)
16485 dw_die_ref type_die = lookup_type_die (type);
16487 if (type_die == NULL)
16489 type_die = new_die (DW_TAG_enumeration_type,
16490 scope_die_for (type, context_die), type);
16491 equate_type_number_to_die (type, type_die);
16492 add_name_attribute (type_die, type_tag (type));
16493 add_gnat_descriptive_type_attribute (type_die, type, context_die);
16494 if (TYPE_ARTIFICIAL (type))
16495 add_AT_flag (type_die, DW_AT_artificial, 1);
16496 if (dwarf_version >= 4 || !dwarf_strict)
16498 if (ENUM_IS_SCOPED (type))
16499 add_AT_flag (type_die, DW_AT_enum_class, 1);
16500 if (ENUM_IS_OPAQUE (type))
16501 add_AT_flag (type_die, DW_AT_declaration, 1);
16504 else if (! TYPE_SIZE (type))
16507 remove_AT (type_die, DW_AT_declaration);
16509 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16510 given enum type is incomplete, do not generate the DW_AT_byte_size
16511 attribute or the DW_AT_element_list attribute. */
16512 if (TYPE_SIZE (type))
16516 TREE_ASM_WRITTEN (type) = 1;
16517 add_byte_size_attribute (type_die, type);
16518 if (TYPE_STUB_DECL (type) != NULL_TREE)
16520 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
16521 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
16524 /* If the first reference to this type was as the return type of an
16525 inline function, then it may not have a parent. Fix this now. */
16526 if (type_die->die_parent == NULL)
16527 add_child_die (scope_die_for (type, context_die), type_die);
16529 for (link = TYPE_VALUES (type);
16530 link != NULL; link = TREE_CHAIN (link))
16532 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
16533 tree value = TREE_VALUE (link);
16535 add_name_attribute (enum_die,
16536 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
16538 if (TREE_CODE (value) == CONST_DECL)
16539 value = DECL_INITIAL (value);
16541 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
16542 /* DWARF2 does not provide a way of indicating whether or
16543 not enumeration constants are signed or unsigned. GDB
16544 always assumes the values are signed, so we output all
16545 values as if they were signed. That means that
16546 enumeration constants with very large unsigned values
16547 will appear to have negative values in the debugger. */
16548 add_AT_int (enum_die, DW_AT_const_value,
16549 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
16553 add_AT_flag (type_die, DW_AT_declaration, 1);
16555 if (get_AT (type_die, DW_AT_name))
16556 add_pubtype (type, type_die);
16561 /* Generate a DIE to represent either a real live formal parameter decl or to
16562 represent just the type of some formal parameter position in some function
16565 Note that this routine is a bit unusual because its argument may be a
16566 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
16567 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
16568 node. If it's the former then this function is being called to output a
16569 DIE to represent a formal parameter object (or some inlining thereof). If
16570 it's the latter, then this function is only being called to output a
16571 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
16572 argument type of some subprogram type.
16573 If EMIT_NAME_P is true, name and source coordinate attributes
16577 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
16578 dw_die_ref context_die)
16580 tree node_or_origin = node ? node : origin;
16581 tree ultimate_origin;
16582 dw_die_ref parm_die
16583 = new_die (DW_TAG_formal_parameter, context_die, node);
16585 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
16587 case tcc_declaration:
16588 ultimate_origin = decl_ultimate_origin (node_or_origin);
16589 if (node || ultimate_origin)
16590 origin = ultimate_origin;
16591 if (origin != NULL)
16592 add_abstract_origin_attribute (parm_die, origin);
16593 else if (emit_name_p)
16594 add_name_and_src_coords_attributes (parm_die, node);
16596 || (! DECL_ABSTRACT (node_or_origin)
16597 && variably_modified_type_p (TREE_TYPE (node_or_origin),
16598 decl_function_context
16599 (node_or_origin))))
16601 tree type = TREE_TYPE (node_or_origin);
16602 if (decl_by_reference_p (node_or_origin))
16603 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
16606 add_type_attribute (parm_die, type,
16607 TREE_READONLY (node_or_origin),
16608 TREE_THIS_VOLATILE (node_or_origin),
16611 if (origin == NULL && DECL_ARTIFICIAL (node))
16612 add_AT_flag (parm_die, DW_AT_artificial, 1);
16614 if (node && node != origin)
16615 equate_decl_number_to_die (node, parm_die);
16616 if (! DECL_ABSTRACT (node_or_origin))
16617 add_location_or_const_value_attribute (parm_die, node_or_origin,
16618 node == NULL, DW_AT_location);
16623 /* We were called with some kind of a ..._TYPE node. */
16624 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
16628 gcc_unreachable ();
16634 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
16635 children DW_TAG_formal_parameter DIEs representing the arguments of the
16638 PARM_PACK must be a function parameter pack.
16639 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
16640 must point to the subsequent arguments of the function PACK_ARG belongs to.
16641 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
16642 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
16643 following the last one for which a DIE was generated. */
16646 gen_formal_parameter_pack_die (tree parm_pack,
16648 dw_die_ref subr_die,
16652 dw_die_ref parm_pack_die;
16654 gcc_assert (parm_pack
16655 && lang_hooks.function_parameter_pack_p (parm_pack)
16658 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
16659 add_src_coords_attributes (parm_pack_die, parm_pack);
16661 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
16663 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
16666 gen_formal_parameter_die (arg, NULL,
16667 false /* Don't emit name attribute. */,
16672 return parm_pack_die;
16675 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
16676 at the end of an (ANSI prototyped) formal parameters list. */
16679 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
16681 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
16684 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
16685 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
16686 parameters as specified in some function type specification (except for
16687 those which appear as part of a function *definition*). */
16690 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
16693 tree formal_type = NULL;
16694 tree first_parm_type;
16697 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
16699 arg = DECL_ARGUMENTS (function_or_method_type);
16700 function_or_method_type = TREE_TYPE (function_or_method_type);
16705 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
16707 /* Make our first pass over the list of formal parameter types and output a
16708 DW_TAG_formal_parameter DIE for each one. */
16709 for (link = first_parm_type; link; )
16711 dw_die_ref parm_die;
16713 formal_type = TREE_VALUE (link);
16714 if (formal_type == void_type_node)
16717 /* Output a (nameless) DIE to represent the formal parameter itself. */
16718 parm_die = gen_formal_parameter_die (formal_type, NULL,
16719 true /* Emit name attribute. */,
16721 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
16722 && link == first_parm_type)
16724 add_AT_flag (parm_die, DW_AT_artificial, 1);
16725 if (dwarf_version >= 3 || !dwarf_strict)
16726 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
16728 else if (arg && DECL_ARTIFICIAL (arg))
16729 add_AT_flag (parm_die, DW_AT_artificial, 1);
16731 link = TREE_CHAIN (link);
16733 arg = DECL_CHAIN (arg);
16736 /* If this function type has an ellipsis, add a
16737 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
16738 if (formal_type != void_type_node)
16739 gen_unspecified_parameters_die (function_or_method_type, context_die);
16741 /* Make our second (and final) pass over the list of formal parameter types
16742 and output DIEs to represent those types (as necessary). */
16743 for (link = TYPE_ARG_TYPES (function_or_method_type);
16744 link && TREE_VALUE (link);
16745 link = TREE_CHAIN (link))
16746 gen_type_die (TREE_VALUE (link), context_die);
16749 /* We want to generate the DIE for TYPE so that we can generate the
16750 die for MEMBER, which has been defined; we will need to refer back
16751 to the member declaration nested within TYPE. If we're trying to
16752 generate minimal debug info for TYPE, processing TYPE won't do the
16753 trick; we need to attach the member declaration by hand. */
16756 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
16758 gen_type_die (type, context_die);
16760 /* If we're trying to avoid duplicate debug info, we may not have
16761 emitted the member decl for this function. Emit it now. */
16762 if (TYPE_STUB_DECL (type)
16763 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
16764 && ! lookup_decl_die (member))
16766 dw_die_ref type_die;
16767 gcc_assert (!decl_ultimate_origin (member));
16769 push_decl_scope (type);
16770 type_die = lookup_type_die_strip_naming_typedef (type);
16771 if (TREE_CODE (member) == FUNCTION_DECL)
16772 gen_subprogram_die (member, type_die);
16773 else if (TREE_CODE (member) == FIELD_DECL)
16775 /* Ignore the nameless fields that are used to skip bits but handle
16776 C++ anonymous unions and structs. */
16777 if (DECL_NAME (member) != NULL_TREE
16778 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
16779 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
16781 gen_type_die (member_declared_type (member), type_die);
16782 gen_field_die (member, type_die);
16786 gen_variable_die (member, NULL_TREE, type_die);
16792 /* Generate the DWARF2 info for the "abstract" instance of a function which we
16793 may later generate inlined and/or out-of-line instances of. */
16796 dwarf2out_abstract_function (tree decl)
16798 dw_die_ref old_die;
16802 htab_t old_decl_loc_table;
16803 htab_t old_cached_dw_loc_list_table;
16804 int old_call_site_count, old_tail_call_site_count;
16805 struct call_arg_loc_node *old_call_arg_locations;
16807 /* Make sure we have the actual abstract inline, not a clone. */
16808 decl = DECL_ORIGIN (decl);
16810 old_die = lookup_decl_die (decl);
16811 if (old_die && get_AT (old_die, DW_AT_inline))
16812 /* We've already generated the abstract instance. */
16815 /* We can be called while recursively when seeing block defining inlined subroutine
16816 DIE. Be sure to not clobber the outer location table nor use it or we would
16817 get locations in abstract instantces. */
16818 old_decl_loc_table = decl_loc_table;
16819 decl_loc_table = NULL;
16820 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
16821 cached_dw_loc_list_table = NULL;
16822 old_call_arg_locations = call_arg_locations;
16823 call_arg_locations = NULL;
16824 old_call_site_count = call_site_count;
16825 call_site_count = -1;
16826 old_tail_call_site_count = tail_call_site_count;
16827 tail_call_site_count = -1;
16829 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
16830 we don't get confused by DECL_ABSTRACT. */
16831 if (debug_info_level > DINFO_LEVEL_TERSE)
16833 context = decl_class_context (decl);
16835 gen_type_die_for_member
16836 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
16839 /* Pretend we've just finished compiling this function. */
16840 save_fn = current_function_decl;
16841 current_function_decl = decl;
16842 push_cfun (DECL_STRUCT_FUNCTION (decl));
16844 was_abstract = DECL_ABSTRACT (decl);
16845 set_decl_abstract_flags (decl, 1);
16846 dwarf2out_decl (decl);
16847 if (! was_abstract)
16848 set_decl_abstract_flags (decl, 0);
16850 current_function_decl = save_fn;
16851 decl_loc_table = old_decl_loc_table;
16852 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
16853 call_arg_locations = old_call_arg_locations;
16854 call_site_count = old_call_site_count;
16855 tail_call_site_count = old_tail_call_site_count;
16859 /* Helper function of premark_used_types() which gets called through
16862 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16863 marked as unused by prune_unused_types. */
16866 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
16871 type = (tree) *slot;
16872 die = lookup_type_die (type);
16874 die->die_perennial_p = 1;
16878 /* Helper function of premark_types_used_by_global_vars which gets called
16879 through htab_traverse.
16881 Marks the DIE of a given type in *SLOT as perennial, so it never gets
16882 marked as unused by prune_unused_types. The DIE of the type is marked
16883 only if the global variable using the type will actually be emitted. */
16886 premark_types_used_by_global_vars_helper (void **slot,
16887 void *data ATTRIBUTE_UNUSED)
16889 struct types_used_by_vars_entry *entry;
16892 entry = (struct types_used_by_vars_entry *) *slot;
16893 gcc_assert (entry->type != NULL
16894 && entry->var_decl != NULL);
16895 die = lookup_type_die (entry->type);
16898 /* Ask cgraph if the global variable really is to be emitted.
16899 If yes, then we'll keep the DIE of ENTRY->TYPE. */
16900 struct varpool_node *node = varpool_get_node (entry->var_decl);
16901 if (node && node->needed)
16903 die->die_perennial_p = 1;
16904 /* Keep the parent DIEs as well. */
16905 while ((die = die->die_parent) && die->die_perennial_p == 0)
16906 die->die_perennial_p = 1;
16912 /* Mark all members of used_types_hash as perennial. */
16915 premark_used_types (void)
16917 if (cfun && cfun->used_types_hash)
16918 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
16921 /* Mark all members of types_used_by_vars_entry as perennial. */
16924 premark_types_used_by_global_vars (void)
16926 if (types_used_by_vars_hash)
16927 htab_traverse (types_used_by_vars_hash,
16928 premark_types_used_by_global_vars_helper, NULL);
16931 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
16932 for CA_LOC call arg loc node. */
16935 gen_call_site_die (tree decl, dw_die_ref subr_die,
16936 struct call_arg_loc_node *ca_loc)
16938 dw_die_ref stmt_die = NULL, die;
16939 tree block = ca_loc->block;
16942 && block != DECL_INITIAL (decl)
16943 && TREE_CODE (block) == BLOCK)
16945 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
16946 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
16949 block = BLOCK_SUPERCONTEXT (block);
16951 if (stmt_die == NULL)
16952 stmt_die = subr_die;
16953 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
16954 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
16955 if (ca_loc->tail_call_p)
16956 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
16957 if (ca_loc->symbol_ref)
16959 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
16961 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
16963 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
16968 /* Generate a DIE to represent a declared function (either file-scope or
16972 gen_subprogram_die (tree decl, dw_die_ref context_die)
16974 tree origin = decl_ultimate_origin (decl);
16975 dw_die_ref subr_die;
16977 dw_die_ref old_die = lookup_decl_die (decl);
16978 int declaration = (current_function_decl != decl
16979 || class_or_namespace_scope_p (context_die));
16981 premark_used_types ();
16983 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
16984 started to generate the abstract instance of an inline, decided to output
16985 its containing class, and proceeded to emit the declaration of the inline
16986 from the member list for the class. If so, DECLARATION takes priority;
16987 we'll get back to the abstract instance when done with the class. */
16989 /* The class-scope declaration DIE must be the primary DIE. */
16990 if (origin && declaration && class_or_namespace_scope_p (context_die))
16993 gcc_assert (!old_die);
16996 /* Now that the C++ front end lazily declares artificial member fns, we
16997 might need to retrofit the declaration into its class. */
16998 if (!declaration && !origin && !old_die
16999 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
17000 && !class_or_namespace_scope_p (context_die)
17001 && debug_info_level > DINFO_LEVEL_TERSE)
17002 old_die = force_decl_die (decl);
17004 if (origin != NULL)
17006 gcc_assert (!declaration || local_scope_p (context_die));
17008 /* Fixup die_parent for the abstract instance of a nested
17009 inline function. */
17010 if (old_die && old_die->die_parent == NULL)
17011 add_child_die (context_die, old_die);
17013 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17014 add_abstract_origin_attribute (subr_die, origin);
17015 /* This is where the actual code for a cloned function is.
17016 Let's emit linkage name attribute for it. This helps
17017 debuggers to e.g, set breakpoints into
17018 constructors/destructors when the user asks "break
17020 add_linkage_name (subr_die, decl);
17024 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17025 struct dwarf_file_data * file_index = lookup_filename (s.file);
17027 if (!get_AT_flag (old_die, DW_AT_declaration)
17028 /* We can have a normal definition following an inline one in the
17029 case of redefinition of GNU C extern inlines.
17030 It seems reasonable to use AT_specification in this case. */
17031 && !get_AT (old_die, DW_AT_inline))
17033 /* Detect and ignore this case, where we are trying to output
17034 something we have already output. */
17038 /* If the definition comes from the same place as the declaration,
17039 maybe use the old DIE. We always want the DIE for this function
17040 that has the *_pc attributes to be under comp_unit_die so the
17041 debugger can find it. We also need to do this for abstract
17042 instances of inlines, since the spec requires the out-of-line copy
17043 to have the same parent. For local class methods, this doesn't
17044 apply; we just use the old DIE. */
17045 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
17046 && (DECL_ARTIFICIAL (decl)
17047 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
17048 && (get_AT_unsigned (old_die, DW_AT_decl_line)
17049 == (unsigned) s.line))))
17051 subr_die = old_die;
17053 /* Clear out the declaration attribute and the formal parameters.
17054 Do not remove all children, because it is possible that this
17055 declaration die was forced using force_decl_die(). In such
17056 cases die that forced declaration die (e.g. TAG_imported_module)
17057 is one of the children that we do not want to remove. */
17058 remove_AT (subr_die, DW_AT_declaration);
17059 remove_AT (subr_die, DW_AT_object_pointer);
17060 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
17064 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17065 add_AT_specification (subr_die, old_die);
17066 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
17067 add_AT_file (subr_die, DW_AT_decl_file, file_index);
17068 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
17069 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
17074 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17076 if (TREE_PUBLIC (decl))
17077 add_AT_flag (subr_die, DW_AT_external, 1);
17079 add_name_and_src_coords_attributes (subr_die, decl);
17080 if (debug_info_level > DINFO_LEVEL_TERSE)
17082 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
17083 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
17084 0, 0, context_die);
17087 add_pure_or_virtual_attribute (subr_die, decl);
17088 if (DECL_ARTIFICIAL (decl))
17089 add_AT_flag (subr_die, DW_AT_artificial, 1);
17091 add_accessibility_attribute (subr_die, decl);
17096 if (!old_die || !get_AT (old_die, DW_AT_inline))
17098 add_AT_flag (subr_die, DW_AT_declaration, 1);
17100 /* If this is an explicit function declaration then generate
17101 a DW_AT_explicit attribute. */
17102 if (lang_hooks.decls.function_decl_explicit_p (decl)
17103 && (dwarf_version >= 3 || !dwarf_strict))
17104 add_AT_flag (subr_die, DW_AT_explicit, 1);
17106 /* The first time we see a member function, it is in the context of
17107 the class to which it belongs. We make sure of this by emitting
17108 the class first. The next time is the definition, which is
17109 handled above. The two may come from the same source text.
17111 Note that force_decl_die() forces function declaration die. It is
17112 later reused to represent definition. */
17113 equate_decl_number_to_die (decl, subr_die);
17116 else if (DECL_ABSTRACT (decl))
17118 if (DECL_DECLARED_INLINE_P (decl))
17120 if (cgraph_function_possibly_inlined_p (decl))
17121 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
17123 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
17127 if (cgraph_function_possibly_inlined_p (decl))
17128 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
17130 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
17133 if (DECL_DECLARED_INLINE_P (decl)
17134 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
17135 add_AT_flag (subr_die, DW_AT_artificial, 1);
17137 equate_decl_number_to_die (decl, subr_die);
17139 else if (!DECL_EXTERNAL (decl))
17141 HOST_WIDE_INT cfa_fb_offset;
17143 if (!old_die || !get_AT (old_die, DW_AT_inline))
17144 equate_decl_number_to_die (decl, subr_die);
17146 if (!flag_reorder_blocks_and_partition)
17148 dw_fde_ref fde = cfun->fde;
17149 if (fde->dw_fde_begin)
17151 /* We have already generated the labels. */
17152 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17153 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17157 /* Create start/end labels and add the range. */
17158 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
17159 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
17160 current_function_funcdef_no);
17161 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
17162 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
17163 current_function_funcdef_no);
17164 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
17167 #if VMS_DEBUGGING_INFO
17168 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17169 Section 2.3 Prologue and Epilogue Attributes:
17170 When a breakpoint is set on entry to a function, it is generally
17171 desirable for execution to be suspended, not on the very first
17172 instruction of the function, but rather at a point after the
17173 function's frame has been set up, after any language defined local
17174 declaration processing has been completed, and before execution of
17175 the first statement of the function begins. Debuggers generally
17176 cannot properly determine where this point is. Similarly for a
17177 breakpoint set on exit from a function. The prologue and epilogue
17178 attributes allow a compiler to communicate the location(s) to use. */
17181 if (fde->dw_fde_vms_end_prologue)
17182 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
17183 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
17185 if (fde->dw_fde_vms_begin_epilogue)
17186 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
17187 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
17191 add_pubname (decl, subr_die);
17195 /* Generate pubnames entries for the split function code ranges. */
17196 dw_fde_ref fde = cfun->fde;
17198 if (fde->dw_fde_second_begin)
17200 if (dwarf_version >= 3 || !dwarf_strict)
17202 /* We should use ranges for non-contiguous code section
17203 addresses. Use the actual code range for the initial
17204 section, since the HOT/COLD labels might precede an
17205 alignment offset. */
17206 bool range_list_added = false;
17207 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
17208 fde->dw_fde_end, &range_list_added);
17209 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
17210 fde->dw_fde_second_end,
17211 &range_list_added);
17212 add_pubname (decl, subr_die);
17213 if (range_list_added)
17218 /* There is no real support in DW2 for this .. so we make
17219 a work-around. First, emit the pub name for the segment
17220 containing the function label. Then make and emit a
17221 simplified subprogram DIE for the second segment with the
17222 name pre-fixed by __hot/cold_sect_of_. We use the same
17223 linkage name for the second die so that gdb will find both
17224 sections when given "b foo". */
17225 const char *name = NULL;
17226 tree decl_name = DECL_NAME (decl);
17227 dw_die_ref seg_die;
17229 /* Do the 'primary' section. */
17230 add_AT_lbl_id (subr_die, DW_AT_low_pc,
17231 fde->dw_fde_begin);
17232 add_AT_lbl_id (subr_die, DW_AT_high_pc,
17235 add_pubname (decl, subr_die);
17237 /* Build a minimal DIE for the secondary section. */
17238 seg_die = new_die (DW_TAG_subprogram,
17239 subr_die->die_parent, decl);
17241 if (TREE_PUBLIC (decl))
17242 add_AT_flag (seg_die, DW_AT_external, 1);
17244 if (decl_name != NULL
17245 && IDENTIFIER_POINTER (decl_name) != NULL)
17247 name = dwarf2_name (decl, 1);
17248 if (! DECL_ARTIFICIAL (decl))
17249 add_src_coords_attributes (seg_die, decl);
17251 add_linkage_name (seg_die, decl);
17253 gcc_assert (name != NULL);
17254 add_pure_or_virtual_attribute (seg_die, decl);
17255 if (DECL_ARTIFICIAL (decl))
17256 add_AT_flag (seg_die, DW_AT_artificial, 1);
17258 name = concat ("__second_sect_of_", name, NULL);
17259 add_AT_lbl_id (seg_die, DW_AT_low_pc,
17260 fde->dw_fde_second_begin);
17261 add_AT_lbl_id (seg_die, DW_AT_high_pc,
17262 fde->dw_fde_second_end);
17263 add_name_attribute (seg_die, name);
17264 add_pubname_string (name, seg_die);
17269 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17270 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17271 add_pubname (decl, subr_die);
17275 #ifdef MIPS_DEBUGGING_INFO
17276 /* Add a reference to the FDE for this routine. */
17277 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, cfun->fde->fde_index);
17280 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
17282 /* We define the "frame base" as the function's CFA. This is more
17283 convenient for several reasons: (1) It's stable across the prologue
17284 and epilogue, which makes it better than just a frame pointer,
17285 (2) With dwarf3, there exists a one-byte encoding that allows us
17286 to reference the .debug_frame data by proxy, but failing that,
17287 (3) We can at least reuse the code inspection and interpretation
17288 code that determines the CFA position at various points in the
17290 if (dwarf_version >= 3)
17292 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
17293 add_AT_loc (subr_die, DW_AT_frame_base, op);
17297 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
17298 if (list->dw_loc_next)
17299 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
17301 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
17304 /* Compute a displacement from the "steady-state frame pointer" to
17305 the CFA. The former is what all stack slots and argument slots
17306 will reference in the rtl; the later is what we've told the
17307 debugger about. We'll need to adjust all frame_base references
17308 by this displacement. */
17309 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
17311 if (cfun->static_chain_decl)
17312 add_AT_location_description (subr_die, DW_AT_static_link,
17313 loc_list_from_tree (cfun->static_chain_decl, 2));
17316 /* Generate child dies for template paramaters. */
17317 if (debug_info_level > DINFO_LEVEL_TERSE)
17318 gen_generic_params_dies (decl);
17320 /* Now output descriptions of the arguments for this function. This gets
17321 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17322 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17323 `...' at the end of the formal parameter list. In order to find out if
17324 there was a trailing ellipsis or not, we must instead look at the type
17325 associated with the FUNCTION_DECL. This will be a node of type
17326 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17327 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17328 an ellipsis at the end. */
17330 /* In the case where we are describing a mere function declaration, all we
17331 need to do here (and all we *can* do here) is to describe the *types* of
17332 its formal parameters. */
17333 if (debug_info_level <= DINFO_LEVEL_TERSE)
17335 else if (declaration)
17336 gen_formal_types_die (decl, subr_die);
17339 /* Generate DIEs to represent all known formal parameters. */
17340 tree parm = DECL_ARGUMENTS (decl);
17341 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
17342 tree generic_decl_parm = generic_decl
17343 ? DECL_ARGUMENTS (generic_decl)
17346 /* Now we want to walk the list of parameters of the function and
17347 emit their relevant DIEs.
17349 We consider the case of DECL being an instance of a generic function
17350 as well as it being a normal function.
17352 If DECL is an instance of a generic function we walk the
17353 parameters of the generic function declaration _and_ the parameters of
17354 DECL itself. This is useful because we want to emit specific DIEs for
17355 function parameter packs and those are declared as part of the
17356 generic function declaration. In that particular case,
17357 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17358 That DIE has children DIEs representing the set of arguments
17359 of the pack. Note that the set of pack arguments can be empty.
17360 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17363 Otherwise, we just consider the parameters of DECL. */
17364 while (generic_decl_parm || parm)
17366 if (generic_decl_parm
17367 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
17368 gen_formal_parameter_pack_die (generic_decl_parm,
17373 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
17375 if (parm == DECL_ARGUMENTS (decl)
17376 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
17378 && (dwarf_version >= 3 || !dwarf_strict))
17379 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
17381 parm = DECL_CHAIN (parm);
17384 if (generic_decl_parm)
17385 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
17388 /* Decide whether we need an unspecified_parameters DIE at the end.
17389 There are 2 more cases to do this for: 1) the ansi ... declaration -
17390 this is detectable when the end of the arg list is not a
17391 void_type_node 2) an unprototyped function declaration (not a
17392 definition). This just means that we have no info about the
17393 parameters at all. */
17394 if (prototype_p (TREE_TYPE (decl)))
17396 /* This is the prototyped case, check for.... */
17397 if (stdarg_p (TREE_TYPE (decl)))
17398 gen_unspecified_parameters_die (decl, subr_die);
17400 else if (DECL_INITIAL (decl) == NULL_TREE)
17401 gen_unspecified_parameters_die (decl, subr_die);
17404 /* Output Dwarf info for all of the stuff within the body of the function
17405 (if it has one - it may be just a declaration). */
17406 outer_scope = DECL_INITIAL (decl);
17408 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17409 a function. This BLOCK actually represents the outermost binding contour
17410 for the function, i.e. the contour in which the function's formal
17411 parameters and labels get declared. Curiously, it appears that the front
17412 end doesn't actually put the PARM_DECL nodes for the current function onto
17413 the BLOCK_VARS list for this outer scope, but are strung off of the
17414 DECL_ARGUMENTS list for the function instead.
17416 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17417 the LABEL_DECL nodes for the function however, and we output DWARF info
17418 for those in decls_for_scope. Just within the `outer_scope' there will be
17419 a BLOCK node representing the function's outermost pair of curly braces,
17420 and any blocks used for the base and member initializers of a C++
17421 constructor function. */
17422 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
17424 int call_site_note_count = 0;
17425 int tail_call_site_note_count = 0;
17427 /* Emit a DW_TAG_variable DIE for a named return value. */
17428 if (DECL_NAME (DECL_RESULT (decl)))
17429 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
17431 current_function_has_inlines = 0;
17432 decls_for_scope (outer_scope, subr_die, 0);
17434 if (call_arg_locations && !dwarf_strict)
17436 struct call_arg_loc_node *ca_loc;
17437 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
17439 dw_die_ref die = NULL;
17440 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
17443 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
17444 arg; arg = next_arg)
17446 dw_loc_descr_ref reg, val;
17447 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
17448 dw_die_ref cdie, tdie = NULL;
17450 next_arg = XEXP (arg, 1);
17451 if (REG_P (XEXP (XEXP (arg, 0), 0))
17453 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
17454 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
17455 && REGNO (XEXP (XEXP (arg, 0), 0))
17456 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
17457 next_arg = XEXP (next_arg, 1);
17458 if (mode == VOIDmode)
17460 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
17461 if (mode == VOIDmode)
17462 mode = GET_MODE (XEXP (arg, 0));
17464 if (mode == VOIDmode || mode == BLKmode)
17466 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
17468 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17469 tloc = XEXP (XEXP (arg, 0), 1);
17472 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
17473 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
17475 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17476 tlocc = XEXP (XEXP (arg, 0), 1);
17480 if (REG_P (XEXP (XEXP (arg, 0), 0)))
17481 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
17482 VAR_INIT_STATUS_INITIALIZED);
17483 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
17485 rtx mem = XEXP (XEXP (arg, 0), 0);
17486 reg = mem_loc_descriptor (XEXP (mem, 0),
17487 get_address_mode (mem),
17489 VAR_INIT_STATUS_INITIALIZED);
17491 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
17492 == DEBUG_PARAMETER_REF)
17495 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
17496 tdie = lookup_decl_die (tdecl);
17503 && GET_CODE (XEXP (XEXP (arg, 0), 0))
17504 != DEBUG_PARAMETER_REF)
17506 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
17508 VAR_INIT_STATUS_INITIALIZED);
17512 die = gen_call_site_die (decl, subr_die, ca_loc);
17513 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
17516 add_AT_loc (cdie, DW_AT_location, reg);
17517 else if (tdie != NULL)
17518 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
17519 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
17520 if (next_arg != XEXP (arg, 1))
17522 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
17523 if (mode == VOIDmode)
17524 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
17525 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
17528 VAR_INIT_STATUS_INITIALIZED);
17530 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
17534 && (ca_loc->symbol_ref || tloc))
17535 die = gen_call_site_die (decl, subr_die, ca_loc);
17536 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
17538 dw_loc_descr_ref tval = NULL;
17540 if (tloc != NULL_RTX)
17541 tval = mem_loc_descriptor (tloc,
17542 GET_MODE (tloc) == VOIDmode
17543 ? Pmode : GET_MODE (tloc),
17545 VAR_INIT_STATUS_INITIALIZED);
17547 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
17548 else if (tlocc != NULL_RTX)
17550 tval = mem_loc_descriptor (tlocc,
17551 GET_MODE (tlocc) == VOIDmode
17552 ? Pmode : GET_MODE (tlocc),
17554 VAR_INIT_STATUS_INITIALIZED);
17556 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
17562 call_site_note_count++;
17563 if (ca_loc->tail_call_p)
17564 tail_call_site_note_count++;
17568 call_arg_locations = NULL;
17569 call_arg_loc_last = NULL;
17570 if (tail_call_site_count >= 0
17571 && tail_call_site_count == tail_call_site_note_count
17574 if (call_site_count >= 0
17575 && call_site_count == call_site_note_count)
17576 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
17578 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
17580 call_site_count = -1;
17581 tail_call_site_count = -1;
17583 /* Add the calling convention attribute if requested. */
17584 add_calling_convention_attribute (subr_die, decl);
17588 /* Returns a hash value for X (which really is a die_struct). */
17591 common_block_die_table_hash (const void *x)
17593 const_dw_die_ref d = (const_dw_die_ref) x;
17594 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
17597 /* Return nonzero if decl_id and die_parent of die_struct X is the same
17598 as decl_id and die_parent of die_struct Y. */
17601 common_block_die_table_eq (const void *x, const void *y)
17603 const_dw_die_ref d = (const_dw_die_ref) x;
17604 const_dw_die_ref e = (const_dw_die_ref) y;
17605 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
17608 /* Generate a DIE to represent a declared data object.
17609 Either DECL or ORIGIN must be non-null. */
17612 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
17616 tree decl_or_origin = decl ? decl : origin;
17617 tree ultimate_origin;
17618 dw_die_ref var_die;
17619 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
17620 dw_die_ref origin_die;
17621 bool declaration = (DECL_EXTERNAL (decl_or_origin)
17622 || class_or_namespace_scope_p (context_die));
17623 bool specialization_p = false;
17625 ultimate_origin = decl_ultimate_origin (decl_or_origin);
17626 if (decl || ultimate_origin)
17627 origin = ultimate_origin;
17628 com_decl = fortran_common (decl_or_origin, &off);
17630 /* Symbol in common gets emitted as a child of the common block, in the form
17631 of a data member. */
17634 dw_die_ref com_die;
17635 dw_loc_list_ref loc;
17636 die_node com_die_arg;
17638 var_die = lookup_decl_die (decl_or_origin);
17641 if (get_AT (var_die, DW_AT_location) == NULL)
17643 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
17648 /* Optimize the common case. */
17649 if (single_element_loc_list_p (loc)
17650 && loc->expr->dw_loc_opc == DW_OP_addr
17651 && loc->expr->dw_loc_next == NULL
17652 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
17654 loc->expr->dw_loc_oprnd1.v.val_addr
17655 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
17657 loc_list_plus_const (loc, off);
17659 add_AT_location_description (var_die, DW_AT_location, loc);
17660 remove_AT (var_die, DW_AT_declaration);
17666 if (common_block_die_table == NULL)
17667 common_block_die_table
17668 = htab_create_ggc (10, common_block_die_table_hash,
17669 common_block_die_table_eq, NULL);
17671 com_die_arg.decl_id = DECL_UID (com_decl);
17672 com_die_arg.die_parent = context_die;
17673 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
17674 loc = loc_list_from_tree (com_decl, 2);
17675 if (com_die == NULL)
17678 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
17681 com_die = new_die (DW_TAG_common_block, context_die, decl);
17682 add_name_and_src_coords_attributes (com_die, com_decl);
17685 add_AT_location_description (com_die, DW_AT_location, loc);
17686 /* Avoid sharing the same loc descriptor between
17687 DW_TAG_common_block and DW_TAG_variable. */
17688 loc = loc_list_from_tree (com_decl, 2);
17690 else if (DECL_EXTERNAL (decl))
17691 add_AT_flag (com_die, DW_AT_declaration, 1);
17692 add_pubname_string (cnam, com_die); /* ??? needed? */
17693 com_die->decl_id = DECL_UID (com_decl);
17694 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
17695 *slot = (void *) com_die;
17697 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
17699 add_AT_location_description (com_die, DW_AT_location, loc);
17700 loc = loc_list_from_tree (com_decl, 2);
17701 remove_AT (com_die, DW_AT_declaration);
17703 var_die = new_die (DW_TAG_variable, com_die, decl);
17704 add_name_and_src_coords_attributes (var_die, decl);
17705 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
17706 TREE_THIS_VOLATILE (decl), context_die);
17707 add_AT_flag (var_die, DW_AT_external, 1);
17712 /* Optimize the common case. */
17713 if (single_element_loc_list_p (loc)
17714 && loc->expr->dw_loc_opc == DW_OP_addr
17715 && loc->expr->dw_loc_next == NULL
17716 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
17717 loc->expr->dw_loc_oprnd1.v.val_addr
17718 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
17720 loc_list_plus_const (loc, off);
17722 add_AT_location_description (var_die, DW_AT_location, loc);
17724 else if (DECL_EXTERNAL (decl))
17725 add_AT_flag (var_die, DW_AT_declaration, 1);
17726 equate_decl_number_to_die (decl, var_die);
17730 /* If the compiler emitted a definition for the DECL declaration
17731 and if we already emitted a DIE for it, don't emit a second
17732 DIE for it again. Allow re-declarations of DECLs that are
17733 inside functions, though. */
17734 if (old_die && declaration && !local_scope_p (context_die))
17737 /* For static data members, the declaration in the class is supposed
17738 to have DW_TAG_member tag; the specification should still be
17739 DW_TAG_variable referencing the DW_TAG_member DIE. */
17740 if (declaration && class_scope_p (context_die))
17741 var_die = new_die (DW_TAG_member, context_die, decl);
17743 var_die = new_die (DW_TAG_variable, context_die, decl);
17746 if (origin != NULL)
17747 origin_die = add_abstract_origin_attribute (var_die, origin);
17749 /* Loop unrolling can create multiple blocks that refer to the same
17750 static variable, so we must test for the DW_AT_declaration flag.
17752 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
17753 copy decls and set the DECL_ABSTRACT flag on them instead of
17756 ??? Duplicated blocks have been rewritten to use .debug_ranges.
17758 ??? The declare_in_namespace support causes us to get two DIEs for one
17759 variable, both of which are declarations. We want to avoid considering
17760 one to be a specification, so we must test that this DIE is not a
17762 else if (old_die && TREE_STATIC (decl) && ! declaration
17763 && get_AT_flag (old_die, DW_AT_declaration) == 1)
17765 /* This is a definition of a C++ class level static. */
17766 add_AT_specification (var_die, old_die);
17767 specialization_p = true;
17768 if (DECL_NAME (decl))
17770 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17771 struct dwarf_file_data * file_index = lookup_filename (s.file);
17773 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
17774 add_AT_file (var_die, DW_AT_decl_file, file_index);
17776 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
17777 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
17779 if (old_die->die_tag == DW_TAG_member)
17780 add_linkage_name (var_die, decl);
17784 add_name_and_src_coords_attributes (var_die, decl);
17786 if ((origin == NULL && !specialization_p)
17788 && !DECL_ABSTRACT (decl_or_origin)
17789 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
17790 decl_function_context
17791 (decl_or_origin))))
17793 tree type = TREE_TYPE (decl_or_origin);
17795 if (decl_by_reference_p (decl_or_origin))
17796 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
17798 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
17799 TREE_THIS_VOLATILE (decl_or_origin), context_die);
17802 if (origin == NULL && !specialization_p)
17804 if (TREE_PUBLIC (decl))
17805 add_AT_flag (var_die, DW_AT_external, 1);
17807 if (DECL_ARTIFICIAL (decl))
17808 add_AT_flag (var_die, DW_AT_artificial, 1);
17810 add_accessibility_attribute (var_die, decl);
17814 add_AT_flag (var_die, DW_AT_declaration, 1);
17816 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
17817 equate_decl_number_to_die (decl, var_die);
17820 && (! DECL_ABSTRACT (decl_or_origin)
17821 /* Local static vars are shared between all clones/inlines,
17822 so emit DW_AT_location on the abstract DIE if DECL_RTL is
17824 || (TREE_CODE (decl_or_origin) == VAR_DECL
17825 && TREE_STATIC (decl_or_origin)
17826 && DECL_RTL_SET_P (decl_or_origin)))
17827 /* When abstract origin already has DW_AT_location attribute, no need
17828 to add it again. */
17829 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
17831 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
17832 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
17833 defer_location (decl_or_origin, var_die);
17835 add_location_or_const_value_attribute (var_die, decl_or_origin,
17836 decl == NULL, DW_AT_location);
17837 add_pubname (decl_or_origin, var_die);
17840 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
17843 /* Generate a DIE to represent a named constant. */
17846 gen_const_die (tree decl, dw_die_ref context_die)
17848 dw_die_ref const_die;
17849 tree type = TREE_TYPE (decl);
17851 const_die = new_die (DW_TAG_constant, context_die, decl);
17852 add_name_and_src_coords_attributes (const_die, decl);
17853 add_type_attribute (const_die, type, 1, 0, context_die);
17854 if (TREE_PUBLIC (decl))
17855 add_AT_flag (const_die, DW_AT_external, 1);
17856 if (DECL_ARTIFICIAL (decl))
17857 add_AT_flag (const_die, DW_AT_artificial, 1);
17858 tree_add_const_value_attribute_for_decl (const_die, decl);
17861 /* Generate a DIE to represent a label identifier. */
17864 gen_label_die (tree decl, dw_die_ref context_die)
17866 tree origin = decl_ultimate_origin (decl);
17867 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
17869 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17871 if (origin != NULL)
17872 add_abstract_origin_attribute (lbl_die, origin);
17874 add_name_and_src_coords_attributes (lbl_die, decl);
17876 if (DECL_ABSTRACT (decl))
17877 equate_decl_number_to_die (decl, lbl_die);
17880 insn = DECL_RTL_IF_SET (decl);
17882 /* Deleted labels are programmer specified labels which have been
17883 eliminated because of various optimizations. We still emit them
17884 here so that it is possible to put breakpoints on them. */
17888 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
17890 /* When optimization is enabled (via -O) some parts of the compiler
17891 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
17892 represent source-level labels which were explicitly declared by
17893 the user. This really shouldn't be happening though, so catch
17894 it if it ever does happen. */
17895 gcc_assert (!INSN_DELETED_P (insn));
17897 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
17898 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
17903 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
17904 attributes to the DIE for a block STMT, to describe where the inlined
17905 function was called from. This is similar to add_src_coords_attributes. */
17908 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
17910 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
17912 if (dwarf_version >= 3 || !dwarf_strict)
17914 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
17915 add_AT_unsigned (die, DW_AT_call_line, s.line);
17920 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
17921 Add low_pc and high_pc attributes to the DIE for a block STMT. */
17924 add_high_low_attributes (tree stmt, dw_die_ref die)
17926 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17928 if (BLOCK_FRAGMENT_CHAIN (stmt)
17929 && (dwarf_version >= 3 || !dwarf_strict))
17933 if (inlined_function_outer_scope_p (stmt))
17935 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
17936 BLOCK_NUMBER (stmt));
17937 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17940 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
17942 chain = BLOCK_FRAGMENT_CHAIN (stmt);
17945 add_ranges (chain);
17946 chain = BLOCK_FRAGMENT_CHAIN (chain);
17953 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
17954 BLOCK_NUMBER (stmt));
17955 add_AT_lbl_id (die, DW_AT_low_pc, label);
17956 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
17957 BLOCK_NUMBER (stmt));
17958 add_AT_lbl_id (die, DW_AT_high_pc, label);
17962 /* Generate a DIE for a lexical block. */
17965 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
17967 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
17969 if (call_arg_locations)
17971 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
17972 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
17973 BLOCK_NUMBER (stmt) + 1);
17974 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
17977 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
17978 add_high_low_attributes (stmt, stmt_die);
17980 decls_for_scope (stmt, stmt_die, depth);
17983 /* Generate a DIE for an inlined subprogram. */
17986 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
17990 /* The instance of function that is effectively being inlined shall not
17992 gcc_assert (! BLOCK_ABSTRACT (stmt));
17994 decl = block_ultimate_origin (stmt);
17996 /* Emit info for the abstract instance first, if we haven't yet. We
17997 must emit this even if the block is abstract, otherwise when we
17998 emit the block below (or elsewhere), we may end up trying to emit
17999 a die whose origin die hasn't been emitted, and crashing. */
18000 dwarf2out_abstract_function (decl);
18002 if (! BLOCK_ABSTRACT (stmt))
18004 dw_die_ref subr_die
18005 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
18007 if (call_arg_locations)
18009 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
18010 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
18011 BLOCK_NUMBER (stmt) + 1);
18012 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
18014 add_abstract_origin_attribute (subr_die, decl);
18015 if (TREE_ASM_WRITTEN (stmt))
18016 add_high_low_attributes (stmt, subr_die);
18017 add_call_src_coords_attributes (stmt, subr_die);
18019 decls_for_scope (stmt, subr_die, depth);
18020 current_function_has_inlines = 1;
18024 /* Generate a DIE for a field in a record, or structure. */
18027 gen_field_die (tree decl, dw_die_ref context_die)
18029 dw_die_ref decl_die;
18031 if (TREE_TYPE (decl) == error_mark_node)
18034 decl_die = new_die (DW_TAG_member, context_die, decl);
18035 add_name_and_src_coords_attributes (decl_die, decl);
18036 add_type_attribute (decl_die, member_declared_type (decl),
18037 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
18040 if (DECL_BIT_FIELD_TYPE (decl))
18042 add_byte_size_attribute (decl_die, decl);
18043 add_bit_size_attribute (decl_die, decl);
18044 add_bit_offset_attribute (decl_die, decl);
18047 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
18048 add_data_member_location_attribute (decl_die, decl);
18050 if (DECL_ARTIFICIAL (decl))
18051 add_AT_flag (decl_die, DW_AT_artificial, 1);
18053 add_accessibility_attribute (decl_die, decl);
18055 /* Equate decl number to die, so that we can look up this decl later on. */
18056 equate_decl_number_to_die (decl, decl_die);
18060 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18061 Use modified_type_die instead.
18062 We keep this code here just in case these types of DIEs may be needed to
18063 represent certain things in other languages (e.g. Pascal) someday. */
18066 gen_pointer_type_die (tree type, dw_die_ref context_die)
18069 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
18071 equate_type_number_to_die (type, ptr_die);
18072 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18073 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18076 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18077 Use modified_type_die instead.
18078 We keep this code here just in case these types of DIEs may be needed to
18079 represent certain things in other languages (e.g. Pascal) someday. */
18082 gen_reference_type_die (tree type, dw_die_ref context_die)
18084 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
18086 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
18087 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
18089 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
18091 equate_type_number_to_die (type, ref_die);
18092 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
18093 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18097 /* Generate a DIE for a pointer to a member type. */
18100 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
18103 = new_die (DW_TAG_ptr_to_member_type,
18104 scope_die_for (type, context_die), type);
18106 equate_type_number_to_die (type, ptr_die);
18107 add_AT_die_ref (ptr_die, DW_AT_containing_type,
18108 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
18109 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18112 typedef const char *dchar_p; /* For DEF_VEC_P. */
18113 DEF_VEC_P(dchar_p);
18114 DEF_VEC_ALLOC_P(dchar_p,heap);
18116 static char *producer_string;
18118 /* Return a heap allocated producer string including command line options
18119 if -grecord-gcc-switches. */
18122 gen_producer_string (void)
18125 VEC(dchar_p, heap) *switches = NULL;
18126 const char *language_string = lang_hooks.name;
18127 char *producer, *tail;
18129 size_t len = dwarf_record_gcc_switches ? 0 : 3;
18130 size_t plen = strlen (language_string) + 1 + strlen (version_string);
18132 for (j = 1; dwarf_record_gcc_switches && j < save_decoded_options_count; j++)
18133 switch (save_decoded_options[j].opt_index)
18140 case OPT_auxbase_strip:
18149 case OPT_SPECIAL_unknown:
18150 case OPT_SPECIAL_ignore:
18151 case OPT_SPECIAL_program_name:
18152 case OPT_SPECIAL_input_file:
18153 case OPT_grecord_gcc_switches:
18154 case OPT_gno_record_gcc_switches:
18155 case OPT__output_pch_:
18156 case OPT_fdiagnostics_show_location_:
18157 case OPT_fdiagnostics_show_option:
18159 case OPT__sysroot_:
18161 case OPT_nostdinc__:
18162 /* Ignore these. */
18165 gcc_checking_assert (save_decoded_options[j].canonical_option[0][0]
18167 switch (save_decoded_options[j].canonical_option[0][1])
18174 if (strncmp (save_decoded_options[j].canonical_option[0] + 2,
18181 VEC_safe_push (dchar_p, heap, switches,
18182 save_decoded_options[j].orig_option_with_args_text);
18183 len += strlen (save_decoded_options[j].orig_option_with_args_text) + 1;
18187 producer = XNEWVEC (char, plen + 1 + len + 1);
18189 sprintf (tail, "%s %s", language_string, version_string);
18192 if (!dwarf_record_gcc_switches)
18194 #ifdef MIPS_DEBUGGING_INFO
18195 /* The MIPS/SGI compilers place the 'cc' command line options in the
18196 producer string. The SGI debugger looks for -g, -g1, -g2, or -g3;
18197 if they do not appear in the producer string, the debugger reaches
18198 the conclusion that the object file is stripped and has no debugging
18199 information. To get the MIPS/SGI debugger to believe that there is
18200 debugging information in the object file, we add a -g to the producer
18202 if (debug_info_level > DINFO_LEVEL_TERSE)
18204 memcpy (tail, " -g", 3);
18210 FOR_EACH_VEC_ELT (dchar_p, switches, j, p)
18214 memcpy (tail + 1, p, len);
18219 VEC_free (dchar_p, heap, switches);
18223 /* Generate the DIE for the compilation unit. */
18226 gen_compile_unit_die (const char *filename)
18229 const char *language_string = lang_hooks.name;
18232 die = new_die (DW_TAG_compile_unit, NULL, NULL);
18236 add_name_attribute (die, filename);
18237 /* Don't add cwd for <built-in>. */
18238 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
18239 add_comp_dir_attribute (die);
18242 if (producer_string == NULL)
18243 producer_string = gen_producer_string ();
18244 add_AT_string (die, DW_AT_producer, producer_string);
18246 /* If our producer is LTO try to figure out a common language to use
18247 from the global list of translation units. */
18248 if (strcmp (language_string, "GNU GIMPLE") == 0)
18252 const char *common_lang = NULL;
18254 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
18256 if (!TRANSLATION_UNIT_LANGUAGE (t))
18259 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
18260 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
18262 else if (strncmp (common_lang, "GNU C", 5) == 0
18263 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
18264 /* Mixing C and C++ is ok, use C++ in that case. */
18265 common_lang = "GNU C++";
18268 /* Fall back to C. */
18269 common_lang = NULL;
18275 language_string = common_lang;
18278 language = DW_LANG_C89;
18279 if (strcmp (language_string, "GNU C++") == 0)
18280 language = DW_LANG_C_plus_plus;
18281 else if (strcmp (language_string, "GNU F77") == 0)
18282 language = DW_LANG_Fortran77;
18283 else if (strcmp (language_string, "GNU Pascal") == 0)
18284 language = DW_LANG_Pascal83;
18285 else if (dwarf_version >= 3 || !dwarf_strict)
18287 if (strcmp (language_string, "GNU Ada") == 0)
18288 language = DW_LANG_Ada95;
18289 else if (strcmp (language_string, "GNU Fortran") == 0)
18290 language = DW_LANG_Fortran95;
18291 else if (strcmp (language_string, "GNU Java") == 0)
18292 language = DW_LANG_Java;
18293 else if (strcmp (language_string, "GNU Objective-C") == 0)
18294 language = DW_LANG_ObjC;
18295 else if (strcmp (language_string, "GNU Objective-C++") == 0)
18296 language = DW_LANG_ObjC_plus_plus;
18299 add_AT_unsigned (die, DW_AT_language, language);
18303 case DW_LANG_Fortran77:
18304 case DW_LANG_Fortran90:
18305 case DW_LANG_Fortran95:
18306 /* Fortran has case insensitive identifiers and the front-end
18307 lowercases everything. */
18308 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
18311 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18317 /* Generate the DIE for a base class. */
18320 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
18322 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
18324 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
18325 add_data_member_location_attribute (die, binfo);
18327 if (BINFO_VIRTUAL_P (binfo))
18328 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18330 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18331 children, otherwise the default is DW_ACCESS_public. In DWARF2
18332 the default has always been DW_ACCESS_private. */
18333 if (access == access_public_node)
18335 if (dwarf_version == 2
18336 || context_die->die_tag == DW_TAG_class_type)
18337 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
18339 else if (access == access_protected_node)
18340 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
18341 else if (dwarf_version > 2
18342 && context_die->die_tag != DW_TAG_class_type)
18343 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
18346 /* Generate a DIE for a class member. */
18349 gen_member_die (tree type, dw_die_ref context_die)
18352 tree binfo = TYPE_BINFO (type);
18355 /* If this is not an incomplete type, output descriptions of each of its
18356 members. Note that as we output the DIEs necessary to represent the
18357 members of this record or union type, we will also be trying to output
18358 DIEs to represent the *types* of those members. However the `type'
18359 function (above) will specifically avoid generating type DIEs for member
18360 types *within* the list of member DIEs for this (containing) type except
18361 for those types (of members) which are explicitly marked as also being
18362 members of this (containing) type themselves. The g++ front- end can
18363 force any given type to be treated as a member of some other (containing)
18364 type by setting the TYPE_CONTEXT of the given (member) type to point to
18365 the TREE node representing the appropriate (containing) type. */
18367 /* First output info about the base classes. */
18370 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
18374 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
18375 gen_inheritance_die (base,
18376 (accesses ? VEC_index (tree, accesses, i)
18377 : access_public_node), context_die);
18380 /* Now output info about the data members and type members. */
18381 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
18383 /* If we thought we were generating minimal debug info for TYPE
18384 and then changed our minds, some of the member declarations
18385 may have already been defined. Don't define them again, but
18386 do put them in the right order. */
18388 child = lookup_decl_die (member);
18390 splice_child_die (context_die, child);
18392 gen_decl_die (member, NULL, context_die);
18395 /* Now output info about the function members (if any). */
18396 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
18398 /* Don't include clones in the member list. */
18399 if (DECL_ABSTRACT_ORIGIN (member))
18402 child = lookup_decl_die (member);
18404 splice_child_die (context_die, child);
18406 gen_decl_die (member, NULL, context_die);
18410 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18411 is set, we pretend that the type was never defined, so we only get the
18412 member DIEs needed by later specification DIEs. */
18415 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
18416 enum debug_info_usage usage)
18418 dw_die_ref type_die = lookup_type_die (type);
18419 dw_die_ref scope_die = 0;
18421 int complete = (TYPE_SIZE (type)
18422 && (! TYPE_STUB_DECL (type)
18423 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
18424 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
18425 complete = complete && should_emit_struct_debug (type, usage);
18427 if (type_die && ! complete)
18430 if (TYPE_CONTEXT (type) != NULL_TREE
18431 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18432 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
18435 scope_die = scope_die_for (type, context_die);
18437 if (! type_die || (nested && is_cu_die (scope_die)))
18438 /* First occurrence of type or toplevel definition of nested class. */
18440 dw_die_ref old_die = type_die;
18442 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
18443 ? record_type_tag (type) : DW_TAG_union_type,
18445 equate_type_number_to_die (type, type_die);
18447 add_AT_specification (type_die, old_die);
18450 add_name_attribute (type_die, type_tag (type));
18451 add_gnat_descriptive_type_attribute (type_die, type, context_die);
18452 if (TYPE_ARTIFICIAL (type))
18453 add_AT_flag (type_die, DW_AT_artificial, 1);
18457 remove_AT (type_die, DW_AT_declaration);
18459 /* Generate child dies for template paramaters. */
18460 if (debug_info_level > DINFO_LEVEL_TERSE
18461 && COMPLETE_TYPE_P (type))
18462 schedule_generic_params_dies_gen (type);
18464 /* If this type has been completed, then give it a byte_size attribute and
18465 then give a list of members. */
18466 if (complete && !ns_decl)
18468 /* Prevent infinite recursion in cases where the type of some member of
18469 this type is expressed in terms of this type itself. */
18470 TREE_ASM_WRITTEN (type) = 1;
18471 add_byte_size_attribute (type_die, type);
18472 if (TYPE_STUB_DECL (type) != NULL_TREE)
18474 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18475 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18478 /* If the first reference to this type was as the return type of an
18479 inline function, then it may not have a parent. Fix this now. */
18480 if (type_die->die_parent == NULL)
18481 add_child_die (scope_die, type_die);
18483 push_decl_scope (type);
18484 gen_member_die (type, type_die);
18487 /* GNU extension: Record what type our vtable lives in. */
18488 if (TYPE_VFIELD (type))
18490 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
18492 gen_type_die (vtype, context_die);
18493 add_AT_die_ref (type_die, DW_AT_containing_type,
18494 lookup_type_die (vtype));
18499 add_AT_flag (type_die, DW_AT_declaration, 1);
18501 /* We don't need to do this for function-local types. */
18502 if (TYPE_STUB_DECL (type)
18503 && ! decl_function_context (TYPE_STUB_DECL (type)))
18504 VEC_safe_push (tree, gc, incomplete_types, type);
18507 if (get_AT (type_die, DW_AT_name))
18508 add_pubtype (type, type_die);
18511 /* Generate a DIE for a subroutine _type_. */
18514 gen_subroutine_type_die (tree type, dw_die_ref context_die)
18516 tree return_type = TREE_TYPE (type);
18517 dw_die_ref subr_die
18518 = new_die (DW_TAG_subroutine_type,
18519 scope_die_for (type, context_die), type);
18521 equate_type_number_to_die (type, subr_die);
18522 add_prototyped_attribute (subr_die, type);
18523 add_type_attribute (subr_die, return_type, 0, 0, context_die);
18524 gen_formal_types_die (type, subr_die);
18526 if (get_AT (subr_die, DW_AT_name))
18527 add_pubtype (type, subr_die);
18530 /* Generate a DIE for a type definition. */
18533 gen_typedef_die (tree decl, dw_die_ref context_die)
18535 dw_die_ref type_die;
18538 if (TREE_ASM_WRITTEN (decl))
18541 TREE_ASM_WRITTEN (decl) = 1;
18542 type_die = new_die (DW_TAG_typedef, context_die, decl);
18543 origin = decl_ultimate_origin (decl);
18544 if (origin != NULL)
18545 add_abstract_origin_attribute (type_die, origin);
18550 add_name_and_src_coords_attributes (type_die, decl);
18551 if (DECL_ORIGINAL_TYPE (decl))
18553 type = DECL_ORIGINAL_TYPE (decl);
18555 gcc_assert (type != TREE_TYPE (decl));
18556 equate_type_number_to_die (TREE_TYPE (decl), type_die);
18560 type = TREE_TYPE (decl);
18562 if (is_naming_typedef_decl (TYPE_NAME (type)))
18564 /* Here, we are in the case of decl being a typedef naming
18565 an anonymous type, e.g:
18566 typedef struct {...} foo;
18567 In that case TREE_TYPE (decl) is not a typedef variant
18568 type and TYPE_NAME of the anonymous type is set to the
18569 TYPE_DECL of the typedef. This construct is emitted by
18572 TYPE is the anonymous struct named by the typedef
18573 DECL. As we need the DW_AT_type attribute of the
18574 DW_TAG_typedef to point to the DIE of TYPE, let's
18575 generate that DIE right away. add_type_attribute
18576 called below will then pick (via lookup_type_die) that
18577 anonymous struct DIE. */
18578 if (!TREE_ASM_WRITTEN (type))
18579 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
18581 /* This is a GNU Extension. We are adding a
18582 DW_AT_linkage_name attribute to the DIE of the
18583 anonymous struct TYPE. The value of that attribute
18584 is the name of the typedef decl naming the anonymous
18585 struct. This greatly eases the work of consumers of
18586 this debug info. */
18587 add_linkage_attr (lookup_type_die (type), decl);
18591 add_type_attribute (type_die, type, TREE_READONLY (decl),
18592 TREE_THIS_VOLATILE (decl), context_die);
18594 if (is_naming_typedef_decl (decl))
18595 /* We want that all subsequent calls to lookup_type_die with
18596 TYPE in argument yield the DW_TAG_typedef we have just
18598 equate_type_number_to_die (type, type_die);
18600 add_accessibility_attribute (type_die, decl);
18603 if (DECL_ABSTRACT (decl))
18604 equate_decl_number_to_die (decl, type_die);
18606 if (get_AT (type_die, DW_AT_name))
18607 add_pubtype (decl, type_die);
18610 /* Generate a DIE for a struct, class, enum or union type. */
18613 gen_tagged_type_die (tree type,
18614 dw_die_ref context_die,
18615 enum debug_info_usage usage)
18619 if (type == NULL_TREE
18620 || !is_tagged_type (type))
18623 /* If this is a nested type whose containing class hasn't been written
18624 out yet, writing it out will cover this one, too. This does not apply
18625 to instantiations of member class templates; they need to be added to
18626 the containing class as they are generated. FIXME: This hurts the
18627 idea of combining type decls from multiple TUs, since we can't predict
18628 what set of template instantiations we'll get. */
18629 if (TYPE_CONTEXT (type)
18630 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18631 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
18633 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
18635 if (TREE_ASM_WRITTEN (type))
18638 /* If that failed, attach ourselves to the stub. */
18639 push_decl_scope (TYPE_CONTEXT (type));
18640 context_die = lookup_type_die (TYPE_CONTEXT (type));
18643 else if (TYPE_CONTEXT (type) != NULL_TREE
18644 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
18646 /* If this type is local to a function that hasn't been written
18647 out yet, use a NULL context for now; it will be fixed up in
18648 decls_for_scope. */
18649 context_die = lookup_decl_die (TYPE_CONTEXT (type));
18650 /* A declaration DIE doesn't count; nested types need to go in the
18652 if (context_die && is_declaration_die (context_die))
18653 context_die = NULL;
18658 context_die = declare_in_namespace (type, context_die);
18662 if (TREE_CODE (type) == ENUMERAL_TYPE)
18664 /* This might have been written out by the call to
18665 declare_in_namespace. */
18666 if (!TREE_ASM_WRITTEN (type))
18667 gen_enumeration_type_die (type, context_die);
18670 gen_struct_or_union_type_die (type, context_die, usage);
18675 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
18676 it up if it is ever completed. gen_*_type_die will set it for us
18677 when appropriate. */
18680 /* Generate a type description DIE. */
18683 gen_type_die_with_usage (tree type, dw_die_ref context_die,
18684 enum debug_info_usage usage)
18686 struct array_descr_info info;
18688 if (type == NULL_TREE || type == error_mark_node)
18691 if (TYPE_NAME (type) != NULL_TREE
18692 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18693 && is_redundant_typedef (TYPE_NAME (type))
18694 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
18695 /* The DECL of this type is a typedef we don't want to emit debug
18696 info for but we want debug info for its underlying typedef.
18697 This can happen for e.g, the injected-class-name of a C++
18699 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
18701 /* If TYPE is a typedef type variant, let's generate debug info
18702 for the parent typedef which TYPE is a type of. */
18703 if (typedef_variant_p (type))
18705 if (TREE_ASM_WRITTEN (type))
18708 /* Prevent broken recursion; we can't hand off to the same type. */
18709 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
18711 /* Use the DIE of the containing namespace as the parent DIE of
18712 the type description DIE we want to generate. */
18713 if (DECL_CONTEXT (TYPE_NAME (type))
18714 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
18715 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
18717 TREE_ASM_WRITTEN (type) = 1;
18719 gen_decl_die (TYPE_NAME (type), NULL, context_die);
18723 /* If type is an anonymous tagged type named by a typedef, let's
18724 generate debug info for the typedef. */
18725 if (is_naming_typedef_decl (TYPE_NAME (type)))
18727 /* Use the DIE of the containing namespace as the parent DIE of
18728 the type description DIE we want to generate. */
18729 if (DECL_CONTEXT (TYPE_NAME (type))
18730 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
18731 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
18733 gen_decl_die (TYPE_NAME (type), NULL, context_die);
18737 /* If this is an array type with hidden descriptor, handle it first. */
18738 if (!TREE_ASM_WRITTEN (type)
18739 && lang_hooks.types.get_array_descr_info
18740 && lang_hooks.types.get_array_descr_info (type, &info)
18741 && (dwarf_version >= 3 || !dwarf_strict))
18743 gen_descr_array_type_die (type, &info, context_die);
18744 TREE_ASM_WRITTEN (type) = 1;
18748 /* We are going to output a DIE to represent the unqualified version
18749 of this type (i.e. without any const or volatile qualifiers) so
18750 get the main variant (i.e. the unqualified version) of this type
18751 now. (Vectors are special because the debugging info is in the
18752 cloned type itself). */
18753 if (TREE_CODE (type) != VECTOR_TYPE)
18754 type = type_main_variant (type);
18756 if (TREE_ASM_WRITTEN (type))
18759 switch (TREE_CODE (type))
18765 case REFERENCE_TYPE:
18766 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
18767 ensures that the gen_type_die recursion will terminate even if the
18768 type is recursive. Recursive types are possible in Ada. */
18769 /* ??? We could perhaps do this for all types before the switch
18771 TREE_ASM_WRITTEN (type) = 1;
18773 /* For these types, all that is required is that we output a DIE (or a
18774 set of DIEs) to represent the "basis" type. */
18775 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18776 DINFO_USAGE_IND_USE);
18780 /* This code is used for C++ pointer-to-data-member types.
18781 Output a description of the relevant class type. */
18782 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
18783 DINFO_USAGE_IND_USE);
18785 /* Output a description of the type of the object pointed to. */
18786 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18787 DINFO_USAGE_IND_USE);
18789 /* Now output a DIE to represent this pointer-to-data-member type
18791 gen_ptr_to_mbr_type_die (type, context_die);
18794 case FUNCTION_TYPE:
18795 /* Force out return type (in case it wasn't forced out already). */
18796 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18797 DINFO_USAGE_DIR_USE);
18798 gen_subroutine_type_die (type, context_die);
18802 /* Force out return type (in case it wasn't forced out already). */
18803 gen_type_die_with_usage (TREE_TYPE (type), context_die,
18804 DINFO_USAGE_DIR_USE);
18805 gen_subroutine_type_die (type, context_die);
18809 gen_array_type_die (type, context_die);
18813 gen_array_type_die (type, context_die);
18816 case ENUMERAL_TYPE:
18819 case QUAL_UNION_TYPE:
18820 gen_tagged_type_die (type, context_die, usage);
18826 case FIXED_POINT_TYPE:
18829 /* No DIEs needed for fundamental types. */
18834 /* Just use DW_TAG_unspecified_type. */
18836 dw_die_ref type_die = lookup_type_die (type);
18837 if (type_die == NULL)
18839 tree name = TYPE_NAME (type);
18840 if (TREE_CODE (name) == TYPE_DECL)
18841 name = DECL_NAME (name);
18842 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
18843 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
18844 equate_type_number_to_die (type, type_die);
18850 gcc_unreachable ();
18853 TREE_ASM_WRITTEN (type) = 1;
18857 gen_type_die (tree type, dw_die_ref context_die)
18859 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
18862 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
18863 things which are local to the given block. */
18866 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
18868 int must_output_die = 0;
18871 /* Ignore blocks that are NULL. */
18872 if (stmt == NULL_TREE)
18875 inlined_func = inlined_function_outer_scope_p (stmt);
18877 /* If the block is one fragment of a non-contiguous block, do not
18878 process the variables, since they will have been done by the
18879 origin block. Do process subblocks. */
18880 if (BLOCK_FRAGMENT_ORIGIN (stmt))
18884 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
18885 gen_block_die (sub, context_die, depth + 1);
18890 /* Determine if we need to output any Dwarf DIEs at all to represent this
18893 /* The outer scopes for inlinings *must* always be represented. We
18894 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
18895 must_output_die = 1;
18898 /* Determine if this block directly contains any "significant"
18899 local declarations which we will need to output DIEs for. */
18900 if (debug_info_level > DINFO_LEVEL_TERSE)
18901 /* We are not in terse mode so *any* local declaration counts
18902 as being a "significant" one. */
18903 must_output_die = ((BLOCK_VARS (stmt) != NULL
18904 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
18905 && (TREE_USED (stmt)
18906 || TREE_ASM_WRITTEN (stmt)
18907 || BLOCK_ABSTRACT (stmt)));
18908 else if ((TREE_USED (stmt)
18909 || TREE_ASM_WRITTEN (stmt)
18910 || BLOCK_ABSTRACT (stmt))
18911 && !dwarf2out_ignore_block (stmt))
18912 must_output_die = 1;
18915 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
18916 DIE for any block which contains no significant local declarations at
18917 all. Rather, in such cases we just call `decls_for_scope' so that any
18918 needed Dwarf info for any sub-blocks will get properly generated. Note
18919 that in terse mode, our definition of what constitutes a "significant"
18920 local declaration gets restricted to include only inlined function
18921 instances and local (nested) function definitions. */
18922 if (must_output_die)
18926 /* If STMT block is abstract, that means we have been called
18927 indirectly from dwarf2out_abstract_function.
18928 That function rightfully marks the descendent blocks (of
18929 the abstract function it is dealing with) as being abstract,
18930 precisely to prevent us from emitting any
18931 DW_TAG_inlined_subroutine DIE as a descendent
18932 of an abstract function instance. So in that case, we should
18933 not call gen_inlined_subroutine_die.
18935 Later though, when cgraph asks dwarf2out to emit info
18936 for the concrete instance of the function decl into which
18937 the concrete instance of STMT got inlined, the later will lead
18938 to the generation of a DW_TAG_inlined_subroutine DIE. */
18939 if (! BLOCK_ABSTRACT (stmt))
18940 gen_inlined_subroutine_die (stmt, context_die, depth);
18943 gen_lexical_block_die (stmt, context_die, depth);
18946 decls_for_scope (stmt, context_die, depth);
18949 /* Process variable DECL (or variable with origin ORIGIN) within
18950 block STMT and add it to CONTEXT_DIE. */
18952 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
18955 tree decl_or_origin = decl ? decl : origin;
18957 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
18958 die = lookup_decl_die (decl_or_origin);
18959 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
18960 && TYPE_DECL_IS_STUB (decl_or_origin))
18961 die = lookup_type_die (TREE_TYPE (decl_or_origin));
18965 if (die != NULL && die->die_parent == NULL)
18966 add_child_die (context_die, die);
18967 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
18968 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
18969 stmt, context_die);
18971 gen_decl_die (decl, origin, context_die);
18974 /* Generate all of the decls declared within a given scope and (recursively)
18975 all of its sub-blocks. */
18978 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
18984 /* Ignore NULL blocks. */
18985 if (stmt == NULL_TREE)
18988 /* Output the DIEs to represent all of the data objects and typedefs
18989 declared directly within this block but not within any nested
18990 sub-blocks. Also, nested function and tag DIEs have been
18991 generated with a parent of NULL; fix that up now. */
18992 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
18993 process_scope_var (stmt, decl, NULL_TREE, context_die);
18994 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
18995 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
18998 /* If we're at -g1, we're not interested in subblocks. */
18999 if (debug_info_level <= DINFO_LEVEL_TERSE)
19002 /* Output the DIEs to represent all sub-blocks (and the items declared
19003 therein) of this block. */
19004 for (subblocks = BLOCK_SUBBLOCKS (stmt);
19006 subblocks = BLOCK_CHAIN (subblocks))
19007 gen_block_die (subblocks, context_die, depth + 1);
19010 /* Is this a typedef we can avoid emitting? */
19013 is_redundant_typedef (const_tree decl)
19015 if (TYPE_DECL_IS_STUB (decl))
19018 if (DECL_ARTIFICIAL (decl)
19019 && DECL_CONTEXT (decl)
19020 && is_tagged_type (DECL_CONTEXT (decl))
19021 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
19022 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
19023 /* Also ignore the artificial member typedef for the class name. */
19029 /* Return TRUE if TYPE is a typedef that names a type for linkage
19030 purposes. This kind of typedefs is produced by the C++ FE for
19033 typedef struct {...} foo;
19035 In that case, there is no typedef variant type produced for foo.
19036 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19040 is_naming_typedef_decl (const_tree decl)
19042 if (decl == NULL_TREE
19043 || TREE_CODE (decl) != TYPE_DECL
19044 || !is_tagged_type (TREE_TYPE (decl))
19045 || DECL_IS_BUILTIN (decl)
19046 || is_redundant_typedef (decl)
19047 /* It looks like Ada produces TYPE_DECLs that are very similar
19048 to C++ naming typedefs but that have different
19049 semantics. Let's be specific to c++ for now. */
19053 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
19054 && TYPE_NAME (TREE_TYPE (decl)) == decl
19055 && (TYPE_STUB_DECL (TREE_TYPE (decl))
19056 != TYPE_NAME (TREE_TYPE (decl))));
19059 /* Returns the DIE for a context. */
19061 static inline dw_die_ref
19062 get_context_die (tree context)
19066 /* Find die that represents this context. */
19067 if (TYPE_P (context))
19069 context = TYPE_MAIN_VARIANT (context);
19070 return strip_naming_typedef (context, force_type_die (context));
19073 return force_decl_die (context);
19075 return comp_unit_die ();
19078 /* Returns the DIE for decl. A DIE will always be returned. */
19081 force_decl_die (tree decl)
19083 dw_die_ref decl_die;
19084 unsigned saved_external_flag;
19085 tree save_fn = NULL_TREE;
19086 decl_die = lookup_decl_die (decl);
19089 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
19091 decl_die = lookup_decl_die (decl);
19095 switch (TREE_CODE (decl))
19097 case FUNCTION_DECL:
19098 /* Clear current_function_decl, so that gen_subprogram_die thinks
19099 that this is a declaration. At this point, we just want to force
19100 declaration die. */
19101 save_fn = current_function_decl;
19102 current_function_decl = NULL_TREE;
19103 gen_subprogram_die (decl, context_die);
19104 current_function_decl = save_fn;
19108 /* Set external flag to force declaration die. Restore it after
19109 gen_decl_die() call. */
19110 saved_external_flag = DECL_EXTERNAL (decl);
19111 DECL_EXTERNAL (decl) = 1;
19112 gen_decl_die (decl, NULL, context_die);
19113 DECL_EXTERNAL (decl) = saved_external_flag;
19116 case NAMESPACE_DECL:
19117 if (dwarf_version >= 3 || !dwarf_strict)
19118 dwarf2out_decl (decl);
19120 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19121 decl_die = comp_unit_die ();
19124 case TRANSLATION_UNIT_DECL:
19125 decl_die = comp_unit_die ();
19129 gcc_unreachable ();
19132 /* We should be able to find the DIE now. */
19134 decl_die = lookup_decl_die (decl);
19135 gcc_assert (decl_die);
19141 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19142 always returned. */
19145 force_type_die (tree type)
19147 dw_die_ref type_die;
19149 type_die = lookup_type_die (type);
19152 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
19154 type_die = modified_type_die (type, TYPE_READONLY (type),
19155 TYPE_VOLATILE (type), context_die);
19156 gcc_assert (type_die);
19161 /* Force out any required namespaces to be able to output DECL,
19162 and return the new context_die for it, if it's changed. */
19165 setup_namespace_context (tree thing, dw_die_ref context_die)
19167 tree context = (DECL_P (thing)
19168 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
19169 if (context && TREE_CODE (context) == NAMESPACE_DECL)
19170 /* Force out the namespace. */
19171 context_die = force_decl_die (context);
19173 return context_die;
19176 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19177 type) within its namespace, if appropriate.
19179 For compatibility with older debuggers, namespace DIEs only contain
19180 declarations; all definitions are emitted at CU scope. */
19183 declare_in_namespace (tree thing, dw_die_ref context_die)
19185 dw_die_ref ns_context;
19187 if (debug_info_level <= DINFO_LEVEL_TERSE)
19188 return context_die;
19190 /* If this decl is from an inlined function, then don't try to emit it in its
19191 namespace, as we will get confused. It would have already been emitted
19192 when the abstract instance of the inline function was emitted anyways. */
19193 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
19194 return context_die;
19196 ns_context = setup_namespace_context (thing, context_die);
19198 if (ns_context != context_die)
19202 if (DECL_P (thing))
19203 gen_decl_die (thing, NULL, ns_context);
19205 gen_type_die (thing, ns_context);
19207 return context_die;
19210 /* Generate a DIE for a namespace or namespace alias. */
19213 gen_namespace_die (tree decl, dw_die_ref context_die)
19215 dw_die_ref namespace_die;
19217 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19218 they are an alias of. */
19219 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
19221 /* Output a real namespace or module. */
19222 context_die = setup_namespace_context (decl, comp_unit_die ());
19223 namespace_die = new_die (is_fortran ()
19224 ? DW_TAG_module : DW_TAG_namespace,
19225 context_die, decl);
19226 /* For Fortran modules defined in different CU don't add src coords. */
19227 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
19229 const char *name = dwarf2_name (decl, 0);
19231 add_name_attribute (namespace_die, name);
19234 add_name_and_src_coords_attributes (namespace_die, decl);
19235 if (DECL_EXTERNAL (decl))
19236 add_AT_flag (namespace_die, DW_AT_declaration, 1);
19237 equate_decl_number_to_die (decl, namespace_die);
19241 /* Output a namespace alias. */
19243 /* Force out the namespace we are an alias of, if necessary. */
19244 dw_die_ref origin_die
19245 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
19247 if (DECL_FILE_SCOPE_P (decl)
19248 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
19249 context_die = setup_namespace_context (decl, comp_unit_die ());
19250 /* Now create the namespace alias DIE. */
19251 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
19252 add_name_and_src_coords_attributes (namespace_die, decl);
19253 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
19254 equate_decl_number_to_die (decl, namespace_die);
19258 /* Generate Dwarf debug information for a decl described by DECL.
19259 The return value is currently only meaningful for PARM_DECLs,
19260 for all other decls it returns NULL. */
19263 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
19265 tree decl_or_origin = decl ? decl : origin;
19266 tree class_origin = NULL, ultimate_origin;
19268 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
19271 switch (TREE_CODE (decl_or_origin))
19277 if (!is_fortran () && !is_ada ())
19279 /* The individual enumerators of an enum type get output when we output
19280 the Dwarf representation of the relevant enum type itself. */
19284 /* Emit its type. */
19285 gen_type_die (TREE_TYPE (decl), context_die);
19287 /* And its containing namespace. */
19288 context_die = declare_in_namespace (decl, context_die);
19290 gen_const_die (decl, context_die);
19293 case FUNCTION_DECL:
19294 /* Don't output any DIEs to represent mere function declarations,
19295 unless they are class members or explicit block externs. */
19296 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
19297 && DECL_FILE_SCOPE_P (decl_or_origin)
19298 && (current_function_decl == NULL_TREE
19299 || DECL_ARTIFICIAL (decl_or_origin)))
19304 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19305 on local redeclarations of global functions. That seems broken. */
19306 if (current_function_decl != decl)
19307 /* This is only a declaration. */;
19310 /* If we're emitting a clone, emit info for the abstract instance. */
19311 if (origin || DECL_ORIGIN (decl) != decl)
19312 dwarf2out_abstract_function (origin
19313 ? DECL_ORIGIN (origin)
19314 : DECL_ABSTRACT_ORIGIN (decl));
19316 /* If we're emitting an out-of-line copy of an inline function,
19317 emit info for the abstract instance and set up to refer to it. */
19318 else if (cgraph_function_possibly_inlined_p (decl)
19319 && ! DECL_ABSTRACT (decl)
19320 && ! class_or_namespace_scope_p (context_die)
19321 /* dwarf2out_abstract_function won't emit a die if this is just
19322 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19323 that case, because that works only if we have a die. */
19324 && DECL_INITIAL (decl) != NULL_TREE)
19326 dwarf2out_abstract_function (decl);
19327 set_decl_origin_self (decl);
19330 /* Otherwise we're emitting the primary DIE for this decl. */
19331 else if (debug_info_level > DINFO_LEVEL_TERSE)
19333 /* Before we describe the FUNCTION_DECL itself, make sure that we
19334 have its containing type. */
19336 origin = decl_class_context (decl);
19337 if (origin != NULL_TREE)
19338 gen_type_die (origin, context_die);
19340 /* And its return type. */
19341 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
19343 /* And its virtual context. */
19344 if (DECL_VINDEX (decl) != NULL_TREE)
19345 gen_type_die (DECL_CONTEXT (decl), context_die);
19347 /* Make sure we have a member DIE for decl. */
19348 if (origin != NULL_TREE)
19349 gen_type_die_for_member (origin, decl, context_die);
19351 /* And its containing namespace. */
19352 context_die = declare_in_namespace (decl, context_die);
19355 /* Now output a DIE to represent the function itself. */
19357 gen_subprogram_die (decl, context_die);
19361 /* If we are in terse mode, don't generate any DIEs to represent any
19362 actual typedefs. */
19363 if (debug_info_level <= DINFO_LEVEL_TERSE)
19366 /* In the special case of a TYPE_DECL node representing the declaration
19367 of some type tag, if the given TYPE_DECL is marked as having been
19368 instantiated from some other (original) TYPE_DECL node (e.g. one which
19369 was generated within the original definition of an inline function) we
19370 used to generate a special (abbreviated) DW_TAG_structure_type,
19371 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19372 should be actually referencing those DIEs, as variable DIEs with that
19373 type would be emitted already in the abstract origin, so it was always
19374 removed during unused type prunning. Don't add anything in this
19376 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
19379 if (is_redundant_typedef (decl))
19380 gen_type_die (TREE_TYPE (decl), context_die);
19382 /* Output a DIE to represent the typedef itself. */
19383 gen_typedef_die (decl, context_die);
19387 if (debug_info_level >= DINFO_LEVEL_NORMAL)
19388 gen_label_die (decl, context_die);
19393 /* If we are in terse mode, don't generate any DIEs to represent any
19394 variable declarations or definitions. */
19395 if (debug_info_level <= DINFO_LEVEL_TERSE)
19398 /* Output any DIEs that are needed to specify the type of this data
19400 if (decl_by_reference_p (decl_or_origin))
19401 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19403 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19405 /* And its containing type. */
19406 class_origin = decl_class_context (decl_or_origin);
19407 if (class_origin != NULL_TREE)
19408 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
19410 /* And its containing namespace. */
19411 context_die = declare_in_namespace (decl_or_origin, context_die);
19413 /* Now output the DIE to represent the data object itself. This gets
19414 complicated because of the possibility that the VAR_DECL really
19415 represents an inlined instance of a formal parameter for an inline
19417 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19418 if (ultimate_origin != NULL_TREE
19419 && TREE_CODE (ultimate_origin) == PARM_DECL)
19420 gen_formal_parameter_die (decl, origin,
19421 true /* Emit name attribute. */,
19424 gen_variable_die (decl, origin, context_die);
19428 /* Ignore the nameless fields that are used to skip bits but handle C++
19429 anonymous unions and structs. */
19430 if (DECL_NAME (decl) != NULL_TREE
19431 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
19432 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
19434 gen_type_die (member_declared_type (decl), context_die);
19435 gen_field_die (decl, context_die);
19440 if (DECL_BY_REFERENCE (decl_or_origin))
19441 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19443 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19444 return gen_formal_parameter_die (decl, origin,
19445 true /* Emit name attribute. */,
19448 case NAMESPACE_DECL:
19449 case IMPORTED_DECL:
19450 if (dwarf_version >= 3 || !dwarf_strict)
19451 gen_namespace_die (decl, context_die);
19455 /* Probably some frontend-internal decl. Assume we don't care. */
19456 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
19463 /* Output debug information for global decl DECL. Called from toplev.c after
19464 compilation proper has finished. */
19467 dwarf2out_global_decl (tree decl)
19469 /* Output DWARF2 information for file-scope tentative data object
19470 declarations, file-scope (extern) function declarations (which
19471 had no corresponding body) and file-scope tagged type declarations
19472 and definitions which have not yet been forced out. */
19473 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
19474 dwarf2out_decl (decl);
19477 /* Output debug information for type decl DECL. Called from toplev.c
19478 and from language front ends (to record built-in types). */
19480 dwarf2out_type_decl (tree decl, int local)
19483 dwarf2out_decl (decl);
19486 /* Output debug information for imported module or decl DECL.
19487 NAME is non-NULL name in the lexical block if the decl has been renamed.
19488 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19489 that DECL belongs to.
19490 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19492 dwarf2out_imported_module_or_decl_1 (tree decl,
19494 tree lexical_block,
19495 dw_die_ref lexical_block_die)
19497 expanded_location xloc;
19498 dw_die_ref imported_die = NULL;
19499 dw_die_ref at_import_die;
19501 if (TREE_CODE (decl) == IMPORTED_DECL)
19503 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
19504 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
19508 xloc = expand_location (input_location);
19510 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
19512 at_import_die = force_type_die (TREE_TYPE (decl));
19513 /* For namespace N { typedef void T; } using N::T; base_type_die
19514 returns NULL, but DW_TAG_imported_declaration requires
19515 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19516 if (!at_import_die)
19518 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
19519 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
19520 at_import_die = lookup_type_die (TREE_TYPE (decl));
19521 gcc_assert (at_import_die);
19526 at_import_die = lookup_decl_die (decl);
19527 if (!at_import_die)
19529 /* If we're trying to avoid duplicate debug info, we may not have
19530 emitted the member decl for this field. Emit it now. */
19531 if (TREE_CODE (decl) == FIELD_DECL)
19533 tree type = DECL_CONTEXT (decl);
19535 if (TYPE_CONTEXT (type)
19536 && TYPE_P (TYPE_CONTEXT (type))
19537 && !should_emit_struct_debug (TYPE_CONTEXT (type),
19538 DINFO_USAGE_DIR_USE))
19540 gen_type_die_for_member (type, decl,
19541 get_context_die (TYPE_CONTEXT (type)));
19543 at_import_die = force_decl_die (decl);
19547 if (TREE_CODE (decl) == NAMESPACE_DECL)
19549 if (dwarf_version >= 3 || !dwarf_strict)
19550 imported_die = new_die (DW_TAG_imported_module,
19557 imported_die = new_die (DW_TAG_imported_declaration,
19561 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
19562 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
19564 add_AT_string (imported_die, DW_AT_name,
19565 IDENTIFIER_POINTER (name));
19566 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
19569 /* Output debug information for imported module or decl DECL.
19570 NAME is non-NULL name in context if the decl has been renamed.
19571 CHILD is true if decl is one of the renamed decls as part of
19572 importing whole module. */
19575 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
19578 /* dw_die_ref at_import_die; */
19579 dw_die_ref scope_die;
19581 if (debug_info_level <= DINFO_LEVEL_TERSE)
19586 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
19587 We need decl DIE for reference and scope die. First, get DIE for the decl
19590 /* Get the scope die for decl context. Use comp_unit_die for global module
19591 or decl. If die is not found for non globals, force new die. */
19593 && TYPE_P (context)
19594 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
19597 if (!(dwarf_version >= 3 || !dwarf_strict))
19600 scope_die = get_context_die (context);
19604 gcc_assert (scope_die->die_child);
19605 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
19606 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
19607 scope_die = scope_die->die_child;
19610 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
19611 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
19615 /* Write the debugging output for DECL. */
19618 dwarf2out_decl (tree decl)
19620 dw_die_ref context_die = comp_unit_die ();
19622 switch (TREE_CODE (decl))
19627 case FUNCTION_DECL:
19628 /* What we would really like to do here is to filter out all mere
19629 file-scope declarations of file-scope functions which are never
19630 referenced later within this translation unit (and keep all of ones
19631 that *are* referenced later on) but we aren't clairvoyant, so we have
19632 no idea which functions will be referenced in the future (i.e. later
19633 on within the current translation unit). So here we just ignore all
19634 file-scope function declarations which are not also definitions. If
19635 and when the debugger needs to know something about these functions,
19636 it will have to hunt around and find the DWARF information associated
19637 with the definition of the function.
19639 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
19640 nodes represent definitions and which ones represent mere
19641 declarations. We have to check DECL_INITIAL instead. That's because
19642 the C front-end supports some weird semantics for "extern inline"
19643 function definitions. These can get inlined within the current
19644 translation unit (and thus, we need to generate Dwarf info for their
19645 abstract instances so that the Dwarf info for the concrete inlined
19646 instances can have something to refer to) but the compiler never
19647 generates any out-of-lines instances of such things (despite the fact
19648 that they *are* definitions).
19650 The important point is that the C front-end marks these "extern
19651 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
19652 them anyway. Note that the C++ front-end also plays some similar games
19653 for inline function definitions appearing within include files which
19654 also contain `#pragma interface' pragmas. */
19655 if (DECL_INITIAL (decl) == NULL_TREE)
19658 /* If we're a nested function, initially use a parent of NULL; if we're
19659 a plain function, this will be fixed up in decls_for_scope. If
19660 we're a method, it will be ignored, since we already have a DIE. */
19661 if (decl_function_context (decl)
19662 /* But if we're in terse mode, we don't care about scope. */
19663 && debug_info_level > DINFO_LEVEL_TERSE)
19664 context_die = NULL;
19668 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
19669 declaration and if the declaration was never even referenced from
19670 within this entire compilation unit. We suppress these DIEs in
19671 order to save space in the .debug section (by eliminating entries
19672 which are probably useless). Note that we must not suppress
19673 block-local extern declarations (whether used or not) because that
19674 would screw-up the debugger's name lookup mechanism and cause it to
19675 miss things which really ought to be in scope at a given point. */
19676 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
19679 /* For local statics lookup proper context die. */
19680 if (TREE_STATIC (decl) && decl_function_context (decl))
19681 context_die = lookup_decl_die (DECL_CONTEXT (decl));
19683 /* If we are in terse mode, don't generate any DIEs to represent any
19684 variable declarations or definitions. */
19685 if (debug_info_level <= DINFO_LEVEL_TERSE)
19690 if (debug_info_level <= DINFO_LEVEL_TERSE)
19692 if (!is_fortran () && !is_ada ())
19694 if (TREE_STATIC (decl) && decl_function_context (decl))
19695 context_die = lookup_decl_die (DECL_CONTEXT (decl));
19698 case NAMESPACE_DECL:
19699 case IMPORTED_DECL:
19700 if (debug_info_level <= DINFO_LEVEL_TERSE)
19702 if (lookup_decl_die (decl) != NULL)
19707 /* Don't emit stubs for types unless they are needed by other DIEs. */
19708 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
19711 /* Don't bother trying to generate any DIEs to represent any of the
19712 normal built-in types for the language we are compiling. */
19713 if (DECL_IS_BUILTIN (decl))
19716 /* If we are in terse mode, don't generate any DIEs for types. */
19717 if (debug_info_level <= DINFO_LEVEL_TERSE)
19720 /* If we're a function-scope tag, initially use a parent of NULL;
19721 this will be fixed up in decls_for_scope. */
19722 if (decl_function_context (decl))
19723 context_die = NULL;
19731 gen_decl_die (decl, NULL, context_die);
19734 /* Write the debugging output for DECL. */
19737 dwarf2out_function_decl (tree decl)
19739 dwarf2out_decl (decl);
19740 call_arg_locations = NULL;
19741 call_arg_loc_last = NULL;
19742 call_site_count = -1;
19743 tail_call_site_count = -1;
19744 VEC_free (dw_die_ref, heap, block_map);
19745 htab_empty (decl_loc_table);
19746 htab_empty (cached_dw_loc_list_table);
19749 /* Output a marker (i.e. a label) for the beginning of the generated code for
19750 a lexical block. */
19753 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
19754 unsigned int blocknum)
19756 switch_to_section (current_function_section ());
19757 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
19760 /* Output a marker (i.e. a label) for the end of the generated code for a
19764 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
19766 switch_to_section (current_function_section ());
19767 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
19770 /* Returns nonzero if it is appropriate not to emit any debugging
19771 information for BLOCK, because it doesn't contain any instructions.
19773 Don't allow this for blocks with nested functions or local classes
19774 as we would end up with orphans, and in the presence of scheduling
19775 we may end up calling them anyway. */
19778 dwarf2out_ignore_block (const_tree block)
19783 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
19784 if (TREE_CODE (decl) == FUNCTION_DECL
19785 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
19787 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
19789 decl = BLOCK_NONLOCALIZED_VAR (block, i);
19790 if (TREE_CODE (decl) == FUNCTION_DECL
19791 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
19798 /* Hash table routines for file_hash. */
19801 file_table_eq (const void *p1_p, const void *p2_p)
19803 const struct dwarf_file_data *const p1 =
19804 (const struct dwarf_file_data *) p1_p;
19805 const char *const p2 = (const char *) p2_p;
19806 return filename_cmp (p1->filename, p2) == 0;
19810 file_table_hash (const void *p_p)
19812 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
19813 return htab_hash_string (p->filename);
19816 /* Lookup FILE_NAME (in the list of filenames that we know about here in
19817 dwarf2out.c) and return its "index". The index of each (known) filename is
19818 just a unique number which is associated with only that one filename. We
19819 need such numbers for the sake of generating labels (in the .debug_sfnames
19820 section) and references to those files numbers (in the .debug_srcinfo
19821 and.debug_macinfo sections). If the filename given as an argument is not
19822 found in our current list, add it to the list and assign it the next
19823 available unique index number. In order to speed up searches, we remember
19824 the index of the filename was looked up last. This handles the majority of
19827 static struct dwarf_file_data *
19828 lookup_filename (const char *file_name)
19831 struct dwarf_file_data * created;
19833 /* Check to see if the file name that was searched on the previous
19834 call matches this file name. If so, return the index. */
19835 if (file_table_last_lookup
19836 && (file_name == file_table_last_lookup->filename
19837 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
19838 return file_table_last_lookup;
19840 /* Didn't match the previous lookup, search the table. */
19841 slot = htab_find_slot_with_hash (file_table, file_name,
19842 htab_hash_string (file_name), INSERT);
19844 return (struct dwarf_file_data *) *slot;
19846 created = ggc_alloc_dwarf_file_data ();
19847 created->filename = file_name;
19848 created->emitted_number = 0;
19853 /* If the assembler will construct the file table, then translate the compiler
19854 internal file table number into the assembler file table number, and emit
19855 a .file directive if we haven't already emitted one yet. The file table
19856 numbers are different because we prune debug info for unused variables and
19857 types, which may include filenames. */
19860 maybe_emit_file (struct dwarf_file_data * fd)
19862 if (! fd->emitted_number)
19864 if (last_emitted_file)
19865 fd->emitted_number = last_emitted_file->emitted_number + 1;
19867 fd->emitted_number = 1;
19868 last_emitted_file = fd;
19870 if (DWARF2_ASM_LINE_DEBUG_INFO)
19872 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
19873 output_quoted_string (asm_out_file,
19874 remap_debug_filename (fd->filename));
19875 fputc ('\n', asm_out_file);
19879 return fd->emitted_number;
19882 /* Schedule generation of a DW_AT_const_value attribute to DIE.
19883 That generation should happen after function debug info has been
19884 generated. The value of the attribute is the constant value of ARG. */
19887 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
19889 die_arg_entry entry;
19894 if (!tmpl_value_parm_die_table)
19895 tmpl_value_parm_die_table
19896 = VEC_alloc (die_arg_entry, gc, 32);
19900 VEC_safe_push (die_arg_entry, gc,
19901 tmpl_value_parm_die_table,
19905 /* Return TRUE if T is an instance of generic type, FALSE
19909 generic_type_p (tree t)
19911 if (t == NULL_TREE || !TYPE_P (t))
19913 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
19916 /* Schedule the generation of the generic parameter dies for the
19917 instance of generic type T. The proper generation itself is later
19918 done by gen_scheduled_generic_parms_dies. */
19921 schedule_generic_params_dies_gen (tree t)
19923 if (!generic_type_p (t))
19926 if (generic_type_instances == NULL)
19927 generic_type_instances = VEC_alloc (tree, gc, 256);
19929 VEC_safe_push (tree, gc, generic_type_instances, t);
19932 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
19933 by append_entry_to_tmpl_value_parm_die_table. This function must
19934 be called after function DIEs have been generated. */
19937 gen_remaining_tmpl_value_param_die_attribute (void)
19939 if (tmpl_value_parm_die_table)
19944 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
19945 tree_add_const_value_attribute (e->die, e->arg);
19949 /* Generate generic parameters DIEs for instances of generic types
19950 that have been previously scheduled by
19951 schedule_generic_params_dies_gen. This function must be called
19952 after all the types of the CU have been laid out. */
19955 gen_scheduled_generic_parms_dies (void)
19960 if (generic_type_instances == NULL)
19963 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
19964 gen_generic_params_dies (t);
19968 /* Replace DW_AT_name for the decl with name. */
19971 dwarf2out_set_name (tree decl, tree name)
19977 die = TYPE_SYMTAB_DIE (decl);
19981 dname = dwarf2_name (name, 0);
19985 attr = get_AT (die, DW_AT_name);
19988 struct indirect_string_node *node;
19990 node = find_AT_string (dname);
19991 /* replace the string. */
19992 attr->dw_attr_val.v.val_str = node;
19996 add_name_attribute (die, dname);
19999 /* Called by the final INSN scan whenever we see a var location. We
20000 use it to drop labels in the right places, and throw the location in
20001 our lookup table. */
20004 dwarf2out_var_location (rtx loc_note)
20006 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
20007 struct var_loc_node *newloc;
20009 static const char *last_label;
20010 static const char *last_postcall_label;
20011 static bool last_in_cold_section_p;
20015 if (!NOTE_P (loc_note))
20017 if (CALL_P (loc_note))
20020 if (SIBLING_CALL_P (loc_note))
20021 tail_call_site_count++;
20026 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
20027 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
20030 next_real = next_real_insn (loc_note);
20032 /* If there are no instructions which would be affected by this note,
20033 don't do anything. */
20035 && next_real == NULL_RTX
20036 && !NOTE_DURING_CALL_P (loc_note))
20039 if (next_real == NULL_RTX)
20040 next_real = get_last_insn ();
20042 /* If there were any real insns between note we processed last time
20043 and this note (or if it is the first note), clear
20044 last_{,postcall_}label so that they are not reused this time. */
20045 if (last_var_location_insn == NULL_RTX
20046 || last_var_location_insn != next_real
20047 || last_in_cold_section_p != in_cold_section_p)
20050 last_postcall_label = NULL;
20055 decl = NOTE_VAR_LOCATION_DECL (loc_note);
20056 newloc = add_var_loc_to_decl (decl, loc_note,
20057 NOTE_DURING_CALL_P (loc_note)
20058 ? last_postcall_label : last_label);
20059 if (newloc == NULL)
20068 /* If there were no real insns between note we processed last time
20069 and this note, use the label we emitted last time. Otherwise
20070 create a new label and emit it. */
20071 if (last_label == NULL)
20073 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
20074 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
20076 last_label = ggc_strdup (loclabel);
20081 struct call_arg_loc_node *ca_loc
20082 = ggc_alloc_cleared_call_arg_loc_node ();
20083 rtx prev = prev_real_insn (loc_note), x;
20084 ca_loc->call_arg_loc_note = loc_note;
20085 ca_loc->next = NULL;
20086 ca_loc->label = last_label;
20089 || (NONJUMP_INSN_P (prev)
20090 && GET_CODE (PATTERN (prev)) == SEQUENCE
20091 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
20092 if (!CALL_P (prev))
20093 prev = XVECEXP (PATTERN (prev), 0, 0);
20094 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
20095 x = PATTERN (prev);
20096 if (GET_CODE (x) == PARALLEL)
20097 x = XVECEXP (x, 0, 0);
20098 if (GET_CODE (x) == SET)
20100 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
20102 x = XEXP (XEXP (x, 0), 0);
20103 if (GET_CODE (x) == SYMBOL_REF
20104 && SYMBOL_REF_DECL (x)
20105 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
20106 ca_loc->symbol_ref = x;
20108 ca_loc->block = insn_scope (prev);
20109 if (call_arg_locations)
20110 call_arg_loc_last->next = ca_loc;
20112 call_arg_locations = ca_loc;
20113 call_arg_loc_last = ca_loc;
20115 else if (!NOTE_DURING_CALL_P (loc_note))
20116 newloc->label = last_label;
20119 if (!last_postcall_label)
20121 sprintf (loclabel, "%s-1", last_label);
20122 last_postcall_label = ggc_strdup (loclabel);
20124 newloc->label = last_postcall_label;
20127 last_var_location_insn = next_real;
20128 last_in_cold_section_p = in_cold_section_p;
20131 /* Note in one location list that text section has changed. */
20134 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
20136 var_loc_list *list = (var_loc_list *) *slot;
20138 list->last_before_switch
20139 = list->last->next ? list->last->next : list->last;
20143 /* Note in all location lists that text section has changed. */
20146 var_location_switch_text_section (void)
20148 if (decl_loc_table == NULL)
20151 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
20154 /* Create a new line number table. */
20156 static dw_line_info_table *
20157 new_line_info_table (void)
20159 dw_line_info_table *table;
20161 table = ggc_alloc_cleared_dw_line_info_table_struct ();
20162 table->file_num = 1;
20163 table->line_num = 1;
20164 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
20169 /* Lookup the "current" table into which we emit line info, so
20170 that we don't have to do it for every source line. */
20173 set_cur_line_info_table (section *sec)
20175 dw_line_info_table *table;
20177 if (sec == text_section)
20178 table = text_section_line_info;
20179 else if (sec == cold_text_section)
20181 table = cold_text_section_line_info;
20184 cold_text_section_line_info = table = new_line_info_table ();
20185 table->end_label = cold_end_label;
20190 const char *end_label;
20192 if (flag_reorder_blocks_and_partition)
20194 if (in_cold_section_p)
20195 end_label = crtl->subsections.cold_section_end_label;
20197 end_label = crtl->subsections.hot_section_end_label;
20201 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20202 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
20203 current_function_funcdef_no);
20204 end_label = ggc_strdup (label);
20207 table = new_line_info_table ();
20208 table->end_label = end_label;
20210 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
20213 cur_line_info_table = table;
20217 /* We need to reset the locations at the beginning of each
20218 function. We can't do this in the end_function hook, because the
20219 declarations that use the locations won't have been output when
20220 that hook is called. Also compute have_multiple_function_sections here. */
20223 dwarf2out_begin_function (tree fun)
20225 section *sec = function_section (fun);
20227 if (sec != text_section)
20228 have_multiple_function_sections = true;
20230 if (flag_reorder_blocks_and_partition && !cold_text_section)
20232 gcc_assert (current_function_decl == fun);
20233 cold_text_section = unlikely_text_section ();
20234 switch_to_section (cold_text_section);
20235 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
20236 switch_to_section (sec);
20239 dwarf2out_note_section_used ();
20240 call_site_count = 0;
20241 tail_call_site_count = 0;
20243 set_cur_line_info_table (sec);
20246 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20249 push_dw_line_info_entry (dw_line_info_table *table,
20250 enum dw_line_info_opcode opcode, unsigned int val)
20252 dw_line_info_entry e;
20255 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
20258 /* Output a label to mark the beginning of a source code line entry
20259 and record information relating to this source line, in
20260 'line_info_table' for later output of the .debug_line section. */
20261 /* ??? The discriminator parameter ought to be unsigned. */
20264 dwarf2out_source_line (unsigned int line, const char *filename,
20265 int discriminator, bool is_stmt)
20267 unsigned int file_num;
20268 dw_line_info_table *table;
20270 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
20273 /* The discriminator column was added in dwarf4. Simplify the below
20274 by simply removing it if we're not supposed to output it. */
20275 if (dwarf_version < 4 && dwarf_strict)
20278 table = cur_line_info_table;
20279 file_num = maybe_emit_file (lookup_filename (filename));
20281 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20282 the debugger has used the second (possibly duplicate) line number
20283 at the beginning of the function to mark the end of the prologue.
20284 We could eliminate any other duplicates within the function. For
20285 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20286 that second line number entry. */
20287 /* Recall that this end-of-prologue indication is *not* the same thing
20288 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20289 to which the hook corresponds, follows the last insn that was
20290 emitted by gen_prologue. What we need is to preceed the first insn
20291 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20292 insn that corresponds to something the user wrote. These may be
20293 very different locations once scheduling is enabled. */
20295 if (0 && file_num == table->file_num
20296 && line == table->line_num
20297 && discriminator == table->discrim_num
20298 && is_stmt == table->is_stmt)
20301 switch_to_section (current_function_section ());
20303 /* If requested, emit something human-readable. */
20304 if (flag_debug_asm)
20305 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
20307 if (DWARF2_ASM_LINE_DEBUG_INFO)
20309 /* Emit the .loc directive understood by GNU as. */
20310 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
20311 if (is_stmt != table->is_stmt)
20312 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
20313 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
20314 fprintf (asm_out_file, " discriminator %d", discriminator);
20315 fputc ('\n', asm_out_file);
20319 unsigned int label_num = ++line_info_label_num;
20321 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
20323 push_dw_line_info_entry (table, LI_set_address, label_num);
20324 if (file_num != table->file_num)
20325 push_dw_line_info_entry (table, LI_set_file, file_num);
20326 if (discriminator != table->discrim_num)
20327 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
20328 if (is_stmt != table->is_stmt)
20329 push_dw_line_info_entry (table, LI_negate_stmt, 0);
20330 push_dw_line_info_entry (table, LI_set_line, line);
20333 table->file_num = file_num;
20334 table->line_num = line;
20335 table->discrim_num = discriminator;
20336 table->is_stmt = is_stmt;
20337 table->in_use = true;
20340 /* Record the beginning of a new source file. */
20343 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
20345 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20347 /* Record the beginning of the file for break_out_includes. */
20348 dw_die_ref bincl_die;
20350 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
20351 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
20354 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20357 e.code = DW_MACINFO_start_file;
20359 e.info = xstrdup (filename);
20360 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20364 /* Record the end of a source file. */
20367 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
20369 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20370 /* Record the end of the file for break_out_includes. */
20371 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
20373 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20376 e.code = DW_MACINFO_end_file;
20379 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20383 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20384 the tail part of the directive line, i.e. the part which is past the
20385 initial whitespace, #, whitespace, directive-name, whitespace part. */
20388 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
20389 const char *buffer ATTRIBUTE_UNUSED)
20391 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20394 e.code = DW_MACINFO_define;
20396 e.info = xstrdup (buffer);;
20397 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20401 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20402 the tail part of the directive line, i.e. the part which is past the
20403 initial whitespace, #, whitespace, directive-name, whitespace part. */
20406 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
20407 const char *buffer ATTRIBUTE_UNUSED)
20409 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20412 e.code = DW_MACINFO_undef;
20414 e.info = xstrdup (buffer);;
20415 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20420 output_macinfo (void)
20423 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
20424 macinfo_entry *ref;
20429 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
20433 case DW_MACINFO_start_file:
20435 int file_num = maybe_emit_file (lookup_filename (ref->info));
20436 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
20437 dw2_asm_output_data_uleb128
20438 (ref->lineno, "Included from line number %lu",
20439 (unsigned long)ref->lineno);
20440 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
20443 case DW_MACINFO_end_file:
20444 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
20446 case DW_MACINFO_define:
20447 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
20448 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20449 (unsigned long)ref->lineno);
20450 dw2_asm_output_nstring (ref->info, -1, "The macro");
20452 case DW_MACINFO_undef:
20453 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
20454 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20455 (unsigned long)ref->lineno);
20456 dw2_asm_output_nstring (ref->info, -1, "The macro");
20459 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
20460 ASM_COMMENT_START, (unsigned long)ref->code);
20466 /* Set up for Dwarf output at the start of compilation. */
20469 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
20471 /* Allocate the file_table. */
20472 file_table = htab_create_ggc (50, file_table_hash,
20473 file_table_eq, NULL);
20475 /* Allocate the decl_die_table. */
20476 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
20477 decl_die_table_eq, NULL);
20479 /* Allocate the decl_loc_table. */
20480 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
20481 decl_loc_table_eq, NULL);
20483 /* Allocate the cached_dw_loc_list_table. */
20484 cached_dw_loc_list_table
20485 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
20486 cached_dw_loc_list_table_eq, NULL);
20488 /* Allocate the initial hunk of the decl_scope_table. */
20489 decl_scope_table = VEC_alloc (tree, gc, 256);
20491 /* Allocate the initial hunk of the abbrev_die_table. */
20492 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
20493 (ABBREV_DIE_TABLE_INCREMENT);
20494 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
20495 /* Zero-th entry is allocated, but unused. */
20496 abbrev_die_table_in_use = 1;
20498 /* Allocate the pubtypes and pubnames vectors. */
20499 pubname_table = VEC_alloc (pubname_entry, gc, 32);
20500 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
20502 incomplete_types = VEC_alloc (tree, gc, 64);
20504 used_rtx_array = VEC_alloc (rtx, gc, 32);
20506 debug_info_section = get_section (DEBUG_INFO_SECTION,
20507 SECTION_DEBUG, NULL);
20508 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
20509 SECTION_DEBUG, NULL);
20510 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
20511 SECTION_DEBUG, NULL);
20512 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
20513 SECTION_DEBUG, NULL);
20514 debug_line_section = get_section (DEBUG_LINE_SECTION,
20515 SECTION_DEBUG, NULL);
20516 debug_loc_section = get_section (DEBUG_LOC_SECTION,
20517 SECTION_DEBUG, NULL);
20518 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
20519 SECTION_DEBUG, NULL);
20520 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
20521 SECTION_DEBUG, NULL);
20522 debug_str_section = get_section (DEBUG_STR_SECTION,
20523 DEBUG_STR_SECTION_FLAGS, NULL);
20524 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
20525 SECTION_DEBUG, NULL);
20526 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
20527 SECTION_DEBUG, NULL);
20529 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
20530 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
20531 DEBUG_ABBREV_SECTION_LABEL, 0);
20532 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
20533 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
20534 COLD_TEXT_SECTION_LABEL, 0);
20535 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
20537 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
20538 DEBUG_INFO_SECTION_LABEL, 0);
20539 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
20540 DEBUG_LINE_SECTION_LABEL, 0);
20541 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
20542 DEBUG_RANGES_SECTION_LABEL, 0);
20543 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
20544 DEBUG_MACINFO_SECTION_LABEL, 0);
20546 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20547 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
20549 switch_to_section (text_section);
20550 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
20552 /* Make sure the line number table for .text always exists. */
20553 text_section_line_info = new_line_info_table ();
20554 text_section_line_info->end_label = text_end_label;
20557 /* Called before cgraph_optimize starts outputtting functions, variables
20558 and toplevel asms into assembly. */
20561 dwarf2out_assembly_start (void)
20563 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
20564 && dwarf2out_do_cfi_asm ()
20565 && (!(flag_unwind_tables || flag_exceptions)
20566 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
20567 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
20570 /* A helper function for dwarf2out_finish called through
20571 htab_traverse. Emit one queued .debug_str string. */
20574 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
20576 struct indirect_string_node *node = (struct indirect_string_node *) *h;
20578 if (node->form == DW_FORM_strp)
20580 switch_to_section (debug_str_section);
20581 ASM_OUTPUT_LABEL (asm_out_file, node->label);
20582 assemble_string (node->str, strlen (node->str) + 1);
20588 #if ENABLE_ASSERT_CHECKING
20589 /* Verify that all marks are clear. */
20592 verify_marks_clear (dw_die_ref die)
20596 gcc_assert (! die->die_mark);
20597 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
20599 #endif /* ENABLE_ASSERT_CHECKING */
20601 /* Clear the marks for a die and its children.
20602 Be cool if the mark isn't set. */
20605 prune_unmark_dies (dw_die_ref die)
20611 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
20614 /* Given DIE that we're marking as used, find any other dies
20615 it references as attributes and mark them as used. */
20618 prune_unused_types_walk_attribs (dw_die_ref die)
20623 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
20625 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
20627 /* A reference to another DIE.
20628 Make sure that it will get emitted.
20629 If it was broken out into a comdat group, don't follow it. */
20630 if (! use_debug_types
20631 || a->dw_attr == DW_AT_specification
20632 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
20633 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
20635 /* Set the string's refcount to 0 so that prune_unused_types_mark
20636 accounts properly for it. */
20637 if (AT_class (a) == dw_val_class_str)
20638 a->dw_attr_val.v.val_str->refcount = 0;
20642 /* Mark the generic parameters and arguments children DIEs of DIE. */
20645 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
20649 if (die == NULL || die->die_child == NULL)
20651 c = die->die_child;
20654 switch (c->die_tag)
20656 case DW_TAG_template_type_param:
20657 case DW_TAG_template_value_param:
20658 case DW_TAG_GNU_template_template_param:
20659 case DW_TAG_GNU_template_parameter_pack:
20660 prune_unused_types_mark (c, 1);
20666 } while (c && c != die->die_child);
20669 /* Mark DIE as being used. If DOKIDS is true, then walk down
20670 to DIE's children. */
20673 prune_unused_types_mark (dw_die_ref die, int dokids)
20677 if (die->die_mark == 0)
20679 /* We haven't done this node yet. Mark it as used. */
20681 /* If this is the DIE of a generic type instantiation,
20682 mark the children DIEs that describe its generic parms and
20684 prune_unused_types_mark_generic_parms_dies (die);
20686 /* We also have to mark its parents as used.
20687 (But we don't want to mark our parents' kids due to this.) */
20688 if (die->die_parent)
20689 prune_unused_types_mark (die->die_parent, 0);
20691 /* Mark any referenced nodes. */
20692 prune_unused_types_walk_attribs (die);
20694 /* If this node is a specification,
20695 also mark the definition, if it exists. */
20696 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
20697 prune_unused_types_mark (die->die_definition, 1);
20700 if (dokids && die->die_mark != 2)
20702 /* We need to walk the children, but haven't done so yet.
20703 Remember that we've walked the kids. */
20706 /* If this is an array type, we need to make sure our
20707 kids get marked, even if they're types. If we're
20708 breaking out types into comdat sections, do this
20709 for all type definitions. */
20710 if (die->die_tag == DW_TAG_array_type
20711 || (use_debug_types
20712 && is_type_die (die) && ! is_declaration_die (die)))
20713 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
20715 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
20719 /* For local classes, look if any static member functions were emitted
20720 and if so, mark them. */
20723 prune_unused_types_walk_local_classes (dw_die_ref die)
20727 if (die->die_mark == 2)
20730 switch (die->die_tag)
20732 case DW_TAG_structure_type:
20733 case DW_TAG_union_type:
20734 case DW_TAG_class_type:
20737 case DW_TAG_subprogram:
20738 if (!get_AT_flag (die, DW_AT_declaration)
20739 || die->die_definition != NULL)
20740 prune_unused_types_mark (die, 1);
20747 /* Mark children. */
20748 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
20751 /* Walk the tree DIE and mark types that we actually use. */
20754 prune_unused_types_walk (dw_die_ref die)
20758 /* Don't do anything if this node is already marked and
20759 children have been marked as well. */
20760 if (die->die_mark == 2)
20763 switch (die->die_tag)
20765 case DW_TAG_structure_type:
20766 case DW_TAG_union_type:
20767 case DW_TAG_class_type:
20768 if (die->die_perennial_p)
20771 for (c = die->die_parent; c; c = c->die_parent)
20772 if (c->die_tag == DW_TAG_subprogram)
20775 /* Finding used static member functions inside of classes
20776 is needed just for local classes, because for other classes
20777 static member function DIEs with DW_AT_specification
20778 are emitted outside of the DW_TAG_*_type. If we ever change
20779 it, we'd need to call this even for non-local classes. */
20781 prune_unused_types_walk_local_classes (die);
20783 /* It's a type node --- don't mark it. */
20786 case DW_TAG_const_type:
20787 case DW_TAG_packed_type:
20788 case DW_TAG_pointer_type:
20789 case DW_TAG_reference_type:
20790 case DW_TAG_rvalue_reference_type:
20791 case DW_TAG_volatile_type:
20792 case DW_TAG_typedef:
20793 case DW_TAG_array_type:
20794 case DW_TAG_interface_type:
20795 case DW_TAG_friend:
20796 case DW_TAG_variant_part:
20797 case DW_TAG_enumeration_type:
20798 case DW_TAG_subroutine_type:
20799 case DW_TAG_string_type:
20800 case DW_TAG_set_type:
20801 case DW_TAG_subrange_type:
20802 case DW_TAG_ptr_to_member_type:
20803 case DW_TAG_file_type:
20804 if (die->die_perennial_p)
20807 /* It's a type node --- don't mark it. */
20811 /* Mark everything else. */
20815 if (die->die_mark == 0)
20819 /* Now, mark any dies referenced from here. */
20820 prune_unused_types_walk_attribs (die);
20825 /* Mark children. */
20826 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
20829 /* Increment the string counts on strings referred to from DIE's
20833 prune_unused_types_update_strings (dw_die_ref die)
20838 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
20839 if (AT_class (a) == dw_val_class_str)
20841 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
20843 /* Avoid unnecessarily putting strings that are used less than
20844 twice in the hash table. */
20846 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
20849 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
20850 htab_hash_string (s->str),
20852 gcc_assert (*slot == NULL);
20858 /* Remove from the tree DIE any dies that aren't marked. */
20861 prune_unused_types_prune (dw_die_ref die)
20865 gcc_assert (die->die_mark);
20866 prune_unused_types_update_strings (die);
20868 if (! die->die_child)
20871 c = die->die_child;
20873 dw_die_ref prev = c;
20874 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
20875 if (c == die->die_child)
20877 /* No marked children between 'prev' and the end of the list. */
20879 /* No marked children at all. */
20880 die->die_child = NULL;
20883 prev->die_sib = c->die_sib;
20884 die->die_child = prev;
20889 if (c != prev->die_sib)
20891 prune_unused_types_prune (c);
20892 } while (c != die->die_child);
20895 /* Remove dies representing declarations that we never use. */
20898 prune_unused_types (void)
20901 limbo_die_node *node;
20902 comdat_type_node *ctnode;
20904 dw_die_ref base_type;
20906 #if ENABLE_ASSERT_CHECKING
20907 /* All the marks should already be clear. */
20908 verify_marks_clear (comp_unit_die ());
20909 for (node = limbo_die_list; node; node = node->next)
20910 verify_marks_clear (node->die);
20911 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
20912 verify_marks_clear (ctnode->root_die);
20913 #endif /* ENABLE_ASSERT_CHECKING */
20915 /* Mark types that are used in global variables. */
20916 premark_types_used_by_global_vars ();
20918 /* Set the mark on nodes that are actually used. */
20919 prune_unused_types_walk (comp_unit_die ());
20920 for (node = limbo_die_list; node; node = node->next)
20921 prune_unused_types_walk (node->die);
20922 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
20924 prune_unused_types_walk (ctnode->root_die);
20925 prune_unused_types_mark (ctnode->type_die, 1);
20928 /* Also set the mark on nodes referenced from the
20930 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
20931 prune_unused_types_mark (pub->die, 1);
20932 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
20933 prune_unused_types_mark (base_type, 1);
20935 if (debug_str_hash)
20936 htab_empty (debug_str_hash);
20937 prune_unused_types_prune (comp_unit_die ());
20938 for (node = limbo_die_list; node; node = node->next)
20939 prune_unused_types_prune (node->die);
20940 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
20941 prune_unused_types_prune (ctnode->root_die);
20943 /* Leave the marks clear. */
20944 prune_unmark_dies (comp_unit_die ());
20945 for (node = limbo_die_list; node; node = node->next)
20946 prune_unmark_dies (node->die);
20947 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
20948 prune_unmark_dies (ctnode->root_die);
20951 /* Set the parameter to true if there are any relative pathnames in
20954 file_table_relative_p (void ** slot, void *param)
20956 bool *p = (bool *) param;
20957 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
20958 if (!IS_ABSOLUTE_PATH (d->filename))
20966 /* Routines to manipulate hash table of comdat type units. */
20969 htab_ct_hash (const void *of)
20972 const comdat_type_node *const type_node = (const comdat_type_node *) of;
20974 memcpy (&h, type_node->signature, sizeof (h));
20979 htab_ct_eq (const void *of1, const void *of2)
20981 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
20982 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
20984 return (! memcmp (type_node_1->signature, type_node_2->signature,
20985 DWARF_TYPE_SIGNATURE_SIZE));
20988 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
20989 to the location it would have been added, should we know its
20990 DECL_ASSEMBLER_NAME when we added other attributes. This will
20991 probably improve compactness of debug info, removing equivalent
20992 abbrevs, and hide any differences caused by deferring the
20993 computation of the assembler name, triggered by e.g. PCH. */
20996 move_linkage_attr (dw_die_ref die)
20998 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
20999 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
21001 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
21002 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
21006 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
21008 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
21012 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
21014 VEC_pop (dw_attr_node, die->die_attr);
21015 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
21019 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21020 referenced from typed stack ops and count how often they are used. */
21023 mark_base_types (dw_loc_descr_ref loc)
21025 dw_die_ref base_type = NULL;
21027 for (; loc; loc = loc->dw_loc_next)
21029 switch (loc->dw_loc_opc)
21031 case DW_OP_GNU_regval_type:
21032 case DW_OP_GNU_deref_type:
21033 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
21035 case DW_OP_GNU_convert:
21036 case DW_OP_GNU_reinterpret:
21037 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
21040 case DW_OP_GNU_const_type:
21041 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
21043 case DW_OP_GNU_entry_value:
21044 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
21049 gcc_assert (base_type->die_parent == comp_unit_die ());
21050 if (base_type->die_mark)
21051 base_type->die_mark++;
21054 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
21055 base_type->die_mark = 1;
21060 /* Comparison function for sorting marked base types. */
21063 base_type_cmp (const void *x, const void *y)
21065 dw_die_ref dx = *(const dw_die_ref *) x;
21066 dw_die_ref dy = *(const dw_die_ref *) y;
21067 unsigned int byte_size1, byte_size2;
21068 unsigned int encoding1, encoding2;
21069 if (dx->die_mark > dy->die_mark)
21071 if (dx->die_mark < dy->die_mark)
21073 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
21074 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
21075 if (byte_size1 < byte_size2)
21077 if (byte_size1 > byte_size2)
21079 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
21080 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
21081 if (encoding1 < encoding2)
21083 if (encoding1 > encoding2)
21088 /* Move base types marked by mark_base_types as early as possible
21089 in the CU, sorted by decreasing usage count both to make the
21090 uleb128 references as small as possible and to make sure they
21091 will have die_offset already computed by calc_die_sizes when
21092 sizes of typed stack loc ops is computed. */
21095 move_marked_base_types (void)
21098 dw_die_ref base_type, die, c;
21100 if (VEC_empty (dw_die_ref, base_types))
21103 /* Sort by decreasing usage count, they will be added again in that
21105 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
21106 die = comp_unit_die ();
21107 c = die->die_child;
21110 dw_die_ref prev = c;
21112 while (c->die_mark)
21114 remove_child_with_prev (c, prev);
21115 /* As base types got marked, there must be at least
21116 one node other than DW_TAG_base_type. */
21117 gcc_assert (c != c->die_sib);
21121 while (c != die->die_child);
21122 gcc_assert (die->die_child);
21123 c = die->die_child;
21124 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21126 base_type->die_mark = 0;
21127 base_type->die_sib = c->die_sib;
21128 c->die_sib = base_type;
21133 /* Helper function for resolve_addr, attempt to resolve
21134 one CONST_STRING, return non-zero if not successful. Similarly verify that
21135 SYMBOL_REFs refer to variables emitted in the current CU. */
21138 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
21142 if (GET_CODE (rtl) == CONST_STRING)
21144 size_t len = strlen (XSTR (rtl, 0)) + 1;
21145 tree t = build_string (len, XSTR (rtl, 0));
21146 tree tlen = size_int (len - 1);
21148 = build_array_type (char_type_node, build_index_type (tlen));
21149 rtl = lookup_constant_def (t);
21150 if (!rtl || !MEM_P (rtl))
21152 rtl = XEXP (rtl, 0);
21153 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
21158 if (GET_CODE (rtl) == SYMBOL_REF
21159 && SYMBOL_REF_DECL (rtl))
21161 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
21163 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
21166 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
21170 if (GET_CODE (rtl) == CONST
21171 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
21177 /* Helper function for resolve_addr, handle one location
21178 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21179 the location list couldn't be resolved. */
21182 resolve_addr_in_expr (dw_loc_descr_ref loc)
21184 dw_loc_descr_ref keep = NULL;
21185 for (; loc; loc = loc->dw_loc_next)
21186 switch (loc->dw_loc_opc)
21189 if (resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21192 case DW_OP_const4u:
21193 case DW_OP_const8u:
21195 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21198 case DW_OP_plus_uconst:
21199 if (size_of_loc_descr (loc)
21200 > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
21202 && loc->dw_loc_oprnd1.v.val_unsigned > 0)
21204 dw_loc_descr_ref repl
21205 = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
21206 add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
21207 add_loc_descr (&repl, loc->dw_loc_next);
21211 case DW_OP_implicit_value:
21212 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
21213 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL))
21216 case DW_OP_GNU_implicit_pointer:
21217 case DW_OP_GNU_parameter_ref:
21218 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
21221 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
21224 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
21225 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
21226 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
21229 case DW_OP_GNU_const_type:
21230 case DW_OP_GNU_regval_type:
21231 case DW_OP_GNU_deref_type:
21232 case DW_OP_GNU_convert:
21233 case DW_OP_GNU_reinterpret:
21234 while (loc->dw_loc_next
21235 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
21237 dw_die_ref base1, base2;
21238 unsigned enc1, enc2, size1, size2;
21239 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21240 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21241 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
21242 else if (loc->dw_loc_oprnd1.val_class
21243 == dw_val_class_unsigned_const)
21246 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
21247 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
21248 == dw_val_class_unsigned_const)
21250 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
21251 gcc_assert (base1->die_tag == DW_TAG_base_type
21252 && base2->die_tag == DW_TAG_base_type);
21253 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
21254 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
21255 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
21256 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
21258 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
21259 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
21263 /* Optimize away next DW_OP_GNU_convert after
21264 adjusting LOC's base type die reference. */
21265 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21266 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21267 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
21269 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
21270 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
21273 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21274 point typed stack entry. */
21275 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
21276 keep = loc->dw_loc_next;
21286 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21287 an address in .rodata section if the string literal is emitted there,
21288 or remove the containing location list or replace DW_AT_const_value
21289 with DW_AT_location and empty location expression, if it isn't found
21290 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21291 to something that has been emitted in the current CU. */
21294 resolve_addr (dw_die_ref die)
21298 dw_loc_list_ref *curr, *start, loc;
21301 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21302 switch (AT_class (a))
21304 case dw_val_class_loc_list:
21305 start = curr = AT_loc_list_ptr (a);
21308 /* The same list can be referenced more than once. See if we have
21309 already recorded the result from a previous pass. */
21311 *curr = loc->dw_loc_next;
21312 else if (!loc->resolved_addr)
21314 /* As things stand, we do not expect or allow one die to
21315 reference a suffix of another die's location list chain.
21316 References must be identical or completely separate.
21317 There is therefore no need to cache the result of this
21318 pass on any list other than the first; doing so
21319 would lead to unnecessary writes. */
21322 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
21323 if (!resolve_addr_in_expr ((*curr)->expr))
21325 dw_loc_list_ref next = (*curr)->dw_loc_next;
21326 if (next && (*curr)->ll_symbol)
21328 gcc_assert (!next->ll_symbol);
21329 next->ll_symbol = (*curr)->ll_symbol;
21335 mark_base_types ((*curr)->expr);
21336 curr = &(*curr)->dw_loc_next;
21340 loc->resolved_addr = 1;
21344 loc->dw_loc_next = *start;
21349 remove_AT (die, a->dw_attr);
21353 case dw_val_class_loc:
21354 if (!resolve_addr_in_expr (AT_loc (a)))
21356 remove_AT (die, a->dw_attr);
21360 mark_base_types (AT_loc (a));
21362 case dw_val_class_addr:
21363 if (a->dw_attr == DW_AT_const_value
21364 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
21366 remove_AT (die, a->dw_attr);
21369 if (die->die_tag == DW_TAG_GNU_call_site
21370 && a->dw_attr == DW_AT_abstract_origin)
21372 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
21373 dw_die_ref tdie = lookup_decl_die (tdecl);
21375 && DECL_EXTERNAL (tdecl)
21376 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
21378 force_decl_die (tdecl);
21379 tdie = lookup_decl_die (tdecl);
21383 a->dw_attr_val.val_class = dw_val_class_die_ref;
21384 a->dw_attr_val.v.val_die_ref.die = tdie;
21385 a->dw_attr_val.v.val_die_ref.external = 0;
21389 remove_AT (die, a->dw_attr);
21398 FOR_EACH_CHILD (die, c, resolve_addr (c));
21401 /* Helper routines for optimize_location_lists.
21402 This pass tries to share identical local lists in .debug_loc
21405 /* Iteratively hash operands of LOC opcode. */
21407 static inline hashval_t
21408 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
21410 dw_val_ref val1 = &loc->dw_loc_oprnd1;
21411 dw_val_ref val2 = &loc->dw_loc_oprnd2;
21413 switch (loc->dw_loc_opc)
21415 case DW_OP_const4u:
21416 case DW_OP_const8u:
21420 case DW_OP_const1u:
21421 case DW_OP_const1s:
21422 case DW_OP_const2u:
21423 case DW_OP_const2s:
21424 case DW_OP_const4s:
21425 case DW_OP_const8s:
21429 case DW_OP_plus_uconst:
21465 case DW_OP_deref_size:
21466 case DW_OP_xderef_size:
21467 hash = iterative_hash_object (val1->v.val_int, hash);
21474 gcc_assert (val1->val_class == dw_val_class_loc);
21475 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
21476 hash = iterative_hash_object (offset, hash);
21479 case DW_OP_implicit_value:
21480 hash = iterative_hash_object (val1->v.val_unsigned, hash);
21481 switch (val2->val_class)
21483 case dw_val_class_const:
21484 hash = iterative_hash_object (val2->v.val_int, hash);
21486 case dw_val_class_vec:
21488 unsigned int elt_size = val2->v.val_vec.elt_size;
21489 unsigned int len = val2->v.val_vec.length;
21491 hash = iterative_hash_object (elt_size, hash);
21492 hash = iterative_hash_object (len, hash);
21493 hash = iterative_hash (val2->v.val_vec.array,
21494 len * elt_size, hash);
21497 case dw_val_class_const_double:
21498 hash = iterative_hash_object (val2->v.val_double.low, hash);
21499 hash = iterative_hash_object (val2->v.val_double.high, hash);
21501 case dw_val_class_addr:
21502 hash = iterative_hash_rtx (val2->v.val_addr, hash);
21505 gcc_unreachable ();
21509 case DW_OP_bit_piece:
21510 hash = iterative_hash_object (val1->v.val_int, hash);
21511 hash = iterative_hash_object (val2->v.val_int, hash);
21517 unsigned char dtprel = 0xd1;
21518 hash = iterative_hash_object (dtprel, hash);
21520 hash = iterative_hash_rtx (val1->v.val_addr, hash);
21522 case DW_OP_GNU_implicit_pointer:
21523 hash = iterative_hash_object (val2->v.val_int, hash);
21525 case DW_OP_GNU_entry_value:
21526 hash = hash_loc_operands (val1->v.val_loc, hash);
21528 case DW_OP_GNU_regval_type:
21529 case DW_OP_GNU_deref_type:
21531 unsigned int byte_size
21532 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
21533 unsigned int encoding
21534 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
21535 hash = iterative_hash_object (val1->v.val_int, hash);
21536 hash = iterative_hash_object (byte_size, hash);
21537 hash = iterative_hash_object (encoding, hash);
21540 case DW_OP_GNU_convert:
21541 case DW_OP_GNU_reinterpret:
21542 if (val1->val_class == dw_val_class_unsigned_const)
21544 hash = iterative_hash_object (val1->v.val_unsigned, hash);
21548 case DW_OP_GNU_const_type:
21550 unsigned int byte_size
21551 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
21552 unsigned int encoding
21553 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
21554 hash = iterative_hash_object (byte_size, hash);
21555 hash = iterative_hash_object (encoding, hash);
21556 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
21558 hash = iterative_hash_object (val2->val_class, hash);
21559 switch (val2->val_class)
21561 case dw_val_class_const:
21562 hash = iterative_hash_object (val2->v.val_int, hash);
21564 case dw_val_class_vec:
21566 unsigned int elt_size = val2->v.val_vec.elt_size;
21567 unsigned int len = val2->v.val_vec.length;
21569 hash = iterative_hash_object (elt_size, hash);
21570 hash = iterative_hash_object (len, hash);
21571 hash = iterative_hash (val2->v.val_vec.array,
21572 len * elt_size, hash);
21575 case dw_val_class_const_double:
21576 hash = iterative_hash_object (val2->v.val_double.low, hash);
21577 hash = iterative_hash_object (val2->v.val_double.high, hash);
21580 gcc_unreachable ();
21586 /* Other codes have no operands. */
21592 /* Iteratively hash the whole DWARF location expression LOC. */
21594 static inline hashval_t
21595 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
21597 dw_loc_descr_ref l;
21598 bool sizes_computed = false;
21599 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
21600 size_of_locs (loc);
21602 for (l = loc; l != NULL; l = l->dw_loc_next)
21604 enum dwarf_location_atom opc = l->dw_loc_opc;
21605 hash = iterative_hash_object (opc, hash);
21606 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
21608 size_of_locs (loc);
21609 sizes_computed = true;
21611 hash = hash_loc_operands (l, hash);
21616 /* Compute hash of the whole location list LIST_HEAD. */
21619 hash_loc_list (dw_loc_list_ref list_head)
21621 dw_loc_list_ref curr = list_head;
21622 hashval_t hash = 0;
21624 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
21626 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
21627 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
21629 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
21631 hash = hash_locs (curr->expr, hash);
21633 list_head->hash = hash;
21636 /* Return true if X and Y opcodes have the same operands. */
21639 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
21641 dw_val_ref valx1 = &x->dw_loc_oprnd1;
21642 dw_val_ref valx2 = &x->dw_loc_oprnd2;
21643 dw_val_ref valy1 = &y->dw_loc_oprnd1;
21644 dw_val_ref valy2 = &y->dw_loc_oprnd2;
21646 switch (x->dw_loc_opc)
21648 case DW_OP_const4u:
21649 case DW_OP_const8u:
21653 case DW_OP_const1u:
21654 case DW_OP_const1s:
21655 case DW_OP_const2u:
21656 case DW_OP_const2s:
21657 case DW_OP_const4s:
21658 case DW_OP_const8s:
21662 case DW_OP_plus_uconst:
21698 case DW_OP_deref_size:
21699 case DW_OP_xderef_size:
21700 return valx1->v.val_int == valy1->v.val_int;
21703 gcc_assert (valx1->val_class == dw_val_class_loc
21704 && valy1->val_class == dw_val_class_loc
21705 && x->dw_loc_addr == y->dw_loc_addr);
21706 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
21707 case DW_OP_implicit_value:
21708 if (valx1->v.val_unsigned != valy1->v.val_unsigned
21709 || valx2->val_class != valy2->val_class)
21711 switch (valx2->val_class)
21713 case dw_val_class_const:
21714 return valx2->v.val_int == valy2->v.val_int;
21715 case dw_val_class_vec:
21716 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
21717 && valx2->v.val_vec.length == valy2->v.val_vec.length
21718 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
21719 valx2->v.val_vec.elt_size
21720 * valx2->v.val_vec.length) == 0;
21721 case dw_val_class_const_double:
21722 return valx2->v.val_double.low == valy2->v.val_double.low
21723 && valx2->v.val_double.high == valy2->v.val_double.high;
21724 case dw_val_class_addr:
21725 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
21727 gcc_unreachable ();
21730 case DW_OP_bit_piece:
21731 return valx1->v.val_int == valy1->v.val_int
21732 && valx2->v.val_int == valy2->v.val_int;
21735 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
21736 case DW_OP_GNU_implicit_pointer:
21737 return valx1->val_class == dw_val_class_die_ref
21738 && valx1->val_class == valy1->val_class
21739 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
21740 && valx2->v.val_int == valy2->v.val_int;
21741 case DW_OP_GNU_entry_value:
21742 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
21743 case DW_OP_GNU_const_type:
21744 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
21745 || valx2->val_class != valy2->val_class)
21747 switch (valx2->val_class)
21749 case dw_val_class_const:
21750 return valx2->v.val_int == valy2->v.val_int;
21751 case dw_val_class_vec:
21752 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
21753 && valx2->v.val_vec.length == valy2->v.val_vec.length
21754 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
21755 valx2->v.val_vec.elt_size
21756 * valx2->v.val_vec.length) == 0;
21757 case dw_val_class_const_double:
21758 return valx2->v.val_double.low == valy2->v.val_double.low
21759 && valx2->v.val_double.high == valy2->v.val_double.high;
21761 gcc_unreachable ();
21763 case DW_OP_GNU_regval_type:
21764 case DW_OP_GNU_deref_type:
21765 return valx1->v.val_int == valy1->v.val_int
21766 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
21767 case DW_OP_GNU_convert:
21768 case DW_OP_GNU_reinterpret:
21769 if (valx1->val_class != valy1->val_class)
21771 if (valx1->val_class == dw_val_class_unsigned_const)
21772 return valx1->v.val_unsigned == valy1->v.val_unsigned;
21773 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
21774 case DW_OP_GNU_parameter_ref:
21775 return valx1->val_class == dw_val_class_die_ref
21776 && valx1->val_class == valy1->val_class
21777 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
21779 /* Other codes have no operands. */
21784 /* Return true if DWARF location expressions X and Y are the same. */
21787 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
21789 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
21790 if (x->dw_loc_opc != y->dw_loc_opc
21791 || x->dtprel != y->dtprel
21792 || !compare_loc_operands (x, y))
21794 return x == NULL && y == NULL;
21797 /* Return precomputed hash of location list X. */
21800 loc_list_hash (const void *x)
21802 return ((const struct dw_loc_list_struct *) x)->hash;
21805 /* Return 1 if location lists X and Y are the same. */
21808 loc_list_eq (const void *x, const void *y)
21810 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
21811 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
21814 if (a->hash != b->hash)
21816 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
21817 if (strcmp (a->begin, b->begin) != 0
21818 || strcmp (a->end, b->end) != 0
21819 || (a->section == NULL) != (b->section == NULL)
21820 || (a->section && strcmp (a->section, b->section) != 0)
21821 || !compare_locs (a->expr, b->expr))
21823 return a == NULL && b == NULL;
21826 /* Recursively optimize location lists referenced from DIE
21827 children and share them whenever possible. */
21830 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
21837 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21838 if (AT_class (a) == dw_val_class_loc_list)
21840 dw_loc_list_ref list = AT_loc_list (a);
21841 /* TODO: perform some optimizations here, before hashing
21842 it and storing into the hash table. */
21843 hash_loc_list (list);
21844 slot = htab_find_slot_with_hash (htab, list, list->hash,
21847 *slot = (void *) list;
21849 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
21852 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
21855 /* Optimize location lists referenced from DIE
21856 children and share them whenever possible. */
21859 optimize_location_lists (dw_die_ref die)
21861 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
21862 optimize_location_lists_1 (die, htab);
21863 htab_delete (htab);
21866 /* Output stuff that dwarf requires at the end of every file,
21867 and generate the DWARF-2 debugging info. */
21870 dwarf2out_finish (const char *filename)
21872 limbo_die_node *node, *next_node;
21873 comdat_type_node *ctnode;
21874 htab_t comdat_type_table;
21877 /* PCH might result in DW_AT_producer string being restored from the
21878 header compilation, fix it up if needed. */
21879 dw_attr_ref producer = get_AT (comp_unit_die (), DW_AT_producer);
21880 if (strcmp (AT_string (producer), producer_string) != 0)
21882 struct indirect_string_node *node = find_AT_string (producer_string);
21883 producer->dw_attr_val.v.val_str = node;
21886 gen_scheduled_generic_parms_dies ();
21887 gen_remaining_tmpl_value_param_die_attribute ();
21889 /* Add the name for the main input file now. We delayed this from
21890 dwarf2out_init to avoid complications with PCH. */
21891 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
21892 if (!IS_ABSOLUTE_PATH (filename))
21893 add_comp_dir_attribute (comp_unit_die ());
21894 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
21897 htab_traverse (file_table, file_table_relative_p, &p);
21899 add_comp_dir_attribute (comp_unit_die ());
21902 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
21904 add_location_or_const_value_attribute (
21905 VEC_index (deferred_locations, deferred_locations_list, i)->die,
21906 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
21911 /* Traverse the limbo die list, and add parent/child links. The only
21912 dies without parents that should be here are concrete instances of
21913 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
21914 For concrete instances, we can get the parent die from the abstract
21916 for (node = limbo_die_list; node; node = next_node)
21918 dw_die_ref die = node->die;
21919 next_node = node->next;
21921 if (die->die_parent == NULL)
21923 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
21925 if (origin && origin->die_parent)
21926 add_child_die (origin->die_parent, die);
21927 else if (is_cu_die (die))
21929 else if (seen_error ())
21930 /* It's OK to be confused by errors in the input. */
21931 add_child_die (comp_unit_die (), die);
21934 /* In certain situations, the lexical block containing a
21935 nested function can be optimized away, which results
21936 in the nested function die being orphaned. Likewise
21937 with the return type of that nested function. Force
21938 this to be a child of the containing function.
21940 It may happen that even the containing function got fully
21941 inlined and optimized out. In that case we are lost and
21942 assign the empty child. This should not be big issue as
21943 the function is likely unreachable too. */
21944 tree context = NULL_TREE;
21946 gcc_assert (node->created_for);
21948 if (DECL_P (node->created_for))
21949 context = DECL_CONTEXT (node->created_for);
21950 else if (TYPE_P (node->created_for))
21951 context = TYPE_CONTEXT (node->created_for);
21953 gcc_assert (context
21954 && (TREE_CODE (context) == FUNCTION_DECL
21955 || TREE_CODE (context) == NAMESPACE_DECL));
21957 origin = lookup_decl_die (context);
21959 add_child_die (origin, die);
21961 add_child_die (comp_unit_die (), die);
21966 limbo_die_list = NULL;
21968 #if ENABLE_ASSERT_CHECKING
21970 dw_die_ref die = comp_unit_die (), c;
21971 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
21974 resolve_addr (comp_unit_die ());
21975 move_marked_base_types ();
21977 for (node = deferred_asm_name; node; node = node->next)
21979 tree decl = node->created_for;
21980 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
21982 add_linkage_attr (node->die, decl);
21983 move_linkage_attr (node->die);
21987 deferred_asm_name = NULL;
21989 /* Walk through the list of incomplete types again, trying once more to
21990 emit full debugging info for them. */
21991 retry_incomplete_types ();
21993 if (flag_eliminate_unused_debug_types)
21994 prune_unused_types ();
21996 /* Generate separate CUs for each of the include files we've seen.
21997 They will go into limbo_die_list. */
21998 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
21999 break_out_includes (comp_unit_die ());
22001 /* Generate separate COMDAT sections for type DIEs. */
22002 if (use_debug_types)
22004 break_out_comdat_types (comp_unit_die ());
22006 /* Each new type_unit DIE was added to the limbo die list when created.
22007 Since these have all been added to comdat_type_list, clear the
22009 limbo_die_list = NULL;
22011 /* For each new comdat type unit, copy declarations for incomplete
22012 types to make the new unit self-contained (i.e., no direct
22013 references to the main compile unit). */
22014 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22015 copy_decls_for_unworthy_types (ctnode->root_die);
22016 copy_decls_for_unworthy_types (comp_unit_die ());
22018 /* In the process of copying declarations from one unit to another,
22019 we may have left some declarations behind that are no longer
22020 referenced. Prune them. */
22021 prune_unused_types ();
22024 /* Traverse the DIE's and add add sibling attributes to those DIE's
22025 that have children. */
22026 add_sibling_attributes (comp_unit_die ());
22027 for (node = limbo_die_list; node; node = node->next)
22028 add_sibling_attributes (node->die);
22029 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22030 add_sibling_attributes (ctnode->root_die);
22032 /* Output a terminator label for the .text section. */
22033 switch_to_section (text_section);
22034 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
22035 if (cold_text_section)
22037 switch_to_section (cold_text_section);
22038 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
22041 /* We can only use the low/high_pc attributes if all of the code was
22043 if (!have_multiple_function_sections
22044 || (dwarf_version < 3 && dwarf_strict))
22046 /* Don't add if the CU has no associated code. */
22047 if (text_section_used)
22049 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
22050 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
22057 bool range_list_added = false;
22059 if (text_section_used)
22060 add_ranges_by_labels (comp_unit_die (), text_section_label,
22061 text_end_label, &range_list_added);
22062 if (cold_text_section_used)
22063 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
22064 cold_end_label, &range_list_added);
22066 FOR_EACH_VEC_ELT (dw_fde_ref, fde_vec, fde_idx, fde)
22068 if (!fde->in_std_section)
22069 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
22070 fde->dw_fde_end, &range_list_added);
22071 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
22072 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
22073 fde->dw_fde_second_end, &range_list_added);
22076 if (range_list_added)
22078 /* We need to give .debug_loc and .debug_ranges an appropriate
22079 "base address". Use zero so that these addresses become
22080 absolute. Historically, we've emitted the unexpected
22081 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22082 Emit both to give time for other tools to adapt. */
22083 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
22084 if (! dwarf_strict && dwarf_version < 4)
22085 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
22091 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22092 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
22093 debug_line_section_label);
22095 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22096 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
22098 if (have_location_lists)
22099 optimize_location_lists (comp_unit_die ());
22101 /* Output all of the compilation units. We put the main one last so that
22102 the offsets are available to output_pubnames. */
22103 for (node = limbo_die_list; node; node = node->next)
22104 output_comp_unit (node->die, 0);
22106 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
22107 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22109 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
22111 /* Don't output duplicate types. */
22112 if (*slot != HTAB_EMPTY_ENTRY)
22115 /* Add a pointer to the line table for the main compilation unit
22116 so that the debugger can make sense of DW_AT_decl_file
22118 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22119 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
22120 debug_line_section_label);
22122 output_comdat_type_unit (ctnode);
22125 htab_delete (comdat_type_table);
22127 /* Output the main compilation unit if non-empty or if .debug_macinfo
22128 will be emitted. */
22129 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
22131 /* Output the abbreviation table. */
22132 if (abbrev_die_table_in_use != 1)
22134 switch_to_section (debug_abbrev_section);
22135 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
22136 output_abbrev_section ();
22139 /* Output location list section if necessary. */
22140 if (have_location_lists)
22142 /* Output the location lists info. */
22143 switch_to_section (debug_loc_section);
22144 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
22145 DEBUG_LOC_SECTION_LABEL, 0);
22146 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
22147 output_location_lists (comp_unit_die ());
22150 /* Output public names table if necessary. */
22151 if (!VEC_empty (pubname_entry, pubname_table))
22153 gcc_assert (info_section_emitted);
22154 switch_to_section (debug_pubnames_section);
22155 output_pubnames (pubname_table);
22158 /* Output public types table if necessary. */
22159 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22160 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22161 simply won't look for the section. */
22162 if (!VEC_empty (pubname_entry, pubtype_table))
22164 bool empty = false;
22166 if (flag_eliminate_unused_debug_types)
22168 /* The pubtypes table might be emptied by pruning unused items. */
22172 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
22173 if (p->die->die_offset != 0)
22181 gcc_assert (info_section_emitted);
22182 switch_to_section (debug_pubtypes_section);
22183 output_pubnames (pubtype_table);
22187 /* Output the address range information if a CU (.debug_info section)
22188 was emitted. We output an empty table even if we had no functions
22189 to put in it. This because the consumer has no way to tell the
22190 difference between an empty table that we omitted and failure to
22191 generate a table that would have contained data. */
22192 if (info_section_emitted)
22194 unsigned long aranges_length = size_of_aranges ();
22196 switch_to_section (debug_aranges_section);
22197 output_aranges (aranges_length);
22200 /* Output ranges section if necessary. */
22201 if (ranges_table_in_use)
22203 switch_to_section (debug_ranges_section);
22204 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
22208 /* Output the source line correspondence table. We must do this
22209 even if there is no line information. Otherwise, on an empty
22210 translation unit, we will generate a present, but empty,
22211 .debug_info section. IRIX 6.5 `nm' will then complain when
22212 examining the file. This is done late so that any filenames
22213 used by the debug_info section are marked as 'used'. */
22214 switch_to_section (debug_line_section);
22215 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
22216 if (! DWARF2_ASM_LINE_DEBUG_INFO)
22217 output_line_info ();
22219 /* Have to end the macro section. */
22220 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22222 switch_to_section (debug_macinfo_section);
22223 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
22224 if (!VEC_empty (macinfo_entry, macinfo_table))
22226 dw2_asm_output_data (1, 0, "End compilation unit");
22229 /* If we emitted any DW_FORM_strp form attribute, output the string
22231 if (debug_str_hash)
22232 htab_traverse (debug_str_hash, output_indirect_string, NULL);
22235 #include "gt-dwarf2out.h"