1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "common/common-target.h"
89 #include "langhooks.h"
94 #include "tree-pass.h"
95 #include "tree-flow.h"
96 #include "cfglayout.h"
98 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
99 static rtx last_var_location_insn;
101 #ifdef VMS_DEBUGGING_INFO
102 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
104 /* Define this macro to be a nonzero value if the directory specifications
105 which are output in the debug info should end with a separator. */
106 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
107 /* Define this macro to evaluate to a nonzero value if GCC should refrain
108 from generating indirect strings in DWARF2 debug information, for instance
109 if your target is stuck with an old version of GDB that is unable to
110 process them properly or uses VMS Debug. */
111 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
113 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
114 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
117 /* ??? Poison these here until it can be done generically. They've been
118 totally replaced in this file; make sure it stays that way. */
119 #undef DWARF2_UNWIND_INFO
120 #undef DWARF2_FRAME_INFO
121 #if (GCC_VERSION >= 3000)
122 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
125 #ifndef INCOMING_RETURN_ADDR_RTX
126 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
129 /* Map register numbers held in the call frame info that gcc has
130 collected using DWARF_FRAME_REGNUM to those that should be output in
131 .debug_frame and .eh_frame. */
132 #ifndef DWARF2_FRAME_REG_OUT
133 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
136 /* The size of the target's pointer type. */
138 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
141 /* Array of RTXes referenced by the debugging information, which therefore
142 must be kept around forever. */
143 static GTY(()) VEC(rtx,gc) *used_rtx_array;
145 /* A pointer to the base of a list of incomplete types which might be
146 completed at some later time. incomplete_types_list needs to be a
147 VEC(tree,gc) because we want to tell the garbage collector about
149 static GTY(()) VEC(tree,gc) *incomplete_types;
151 /* A pointer to the base of a table of references to declaration
152 scopes. This table is a display which tracks the nesting
153 of declaration scopes at the current scope and containing
154 scopes. This table is used to find the proper place to
155 define type declaration DIE's. */
156 static GTY(()) VEC(tree,gc) *decl_scope_table;
158 /* Pointers to various DWARF2 sections. */
159 static GTY(()) section *debug_info_section;
160 static GTY(()) section *debug_abbrev_section;
161 static GTY(()) section *debug_aranges_section;
162 static GTY(()) section *debug_macinfo_section;
163 static GTY(()) section *debug_line_section;
164 static GTY(()) section *debug_loc_section;
165 static GTY(()) section *debug_pubnames_section;
166 static GTY(()) section *debug_pubtypes_section;
167 static GTY(()) section *debug_str_section;
168 static GTY(()) section *debug_ranges_section;
169 static GTY(()) section *debug_frame_section;
171 /* How to start an assembler comment. */
172 #ifndef ASM_COMMENT_START
173 #define ASM_COMMENT_START ";#"
176 /* Maximum size (in bytes) of an artificially generated label. */
177 #define MAX_ARTIFICIAL_LABEL_BYTES 30
179 /* The size of addresses as they appear in the Dwarf 2 data.
180 Some architectures use word addresses to refer to code locations,
181 but Dwarf 2 info always uses byte addresses. On such machines,
182 Dwarf 2 addresses need to be larger than the architecture's
184 #ifndef DWARF2_ADDR_SIZE
185 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
188 /* The size in bytes of a DWARF field indicating an offset or length
189 relative to a debug info section, specified to be 4 bytes in the
190 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
193 #ifndef DWARF_OFFSET_SIZE
194 #define DWARF_OFFSET_SIZE 4
197 /* The size in bytes of a DWARF 4 type signature. */
199 #ifndef DWARF_TYPE_SIGNATURE_SIZE
200 #define DWARF_TYPE_SIGNATURE_SIZE 8
203 /* According to the (draft) DWARF 3 specification, the initial length
204 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
205 bytes are 0xffffffff, followed by the length stored in the next 8
208 However, the SGI/MIPS ABI uses an initial length which is equal to
209 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
211 #ifndef DWARF_INITIAL_LENGTH_SIZE
212 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
215 /* Round SIZE up to the nearest BOUNDARY. */
216 #define DWARF_ROUND(SIZE,BOUNDARY) \
217 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
219 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
220 #ifndef DWARF_CIE_DATA_ALIGNMENT
221 #ifdef STACK_GROWS_DOWNWARD
222 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
224 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
228 /* CIE identifier. */
229 #if HOST_BITS_PER_WIDE_INT >= 64
230 #define DWARF_CIE_ID \
231 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
233 #define DWARF_CIE_ID DW_CIE_ID
236 /* A pointer to the base of a table that contains frame description
237 information for each routine. */
238 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
240 /* Number of elements currently allocated for fde_table. */
241 static GTY(()) unsigned fde_table_allocated;
243 /* Number of elements in fde_table currently in use. */
244 static GTY(()) unsigned fde_table_in_use;
246 /* Size (in elements) of increments by which we may expand the
248 #define FDE_TABLE_INCREMENT 256
250 /* Get the current fde_table entry we should use. */
255 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
258 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
259 attribute that accelerates the lookup of the FDE associated
260 with the subprogram. This variable holds the table index of the FDE
261 associated with the current function (body) definition. */
262 static unsigned current_funcdef_fde;
264 struct GTY(()) indirect_string_node {
266 unsigned int refcount;
267 enum dwarf_form form;
271 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
273 static GTY(()) int dw2_string_counter;
275 /* True if the compilation unit places functions in more than one section. */
276 static GTY(()) bool have_multiple_function_sections = false;
278 /* Whether the default text and cold text sections have been used at all. */
280 static GTY(()) bool text_section_used = false;
281 static GTY(()) bool cold_text_section_used = false;
283 /* The default cold text section. */
284 static GTY(()) section *cold_text_section;
286 /* Forward declarations for functions defined in this file. */
288 static char *stripattributes (const char *);
289 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
290 static void output_call_frame_info (int);
291 static void dwarf2out_note_section_used (void);
293 /* Support for complex CFA locations. */
294 static void output_cfa_loc (dw_cfi_ref, int);
295 static void output_cfa_loc_raw (dw_cfi_ref);
297 /* Personality decl of current unit. Used only when assembler does not support
299 static GTY(()) rtx current_unit_personality;
301 /* How to start an assembler comment. */
302 #ifndef ASM_COMMENT_START
303 #define ASM_COMMENT_START ";#"
306 /* Data and reference forms for relocatable data. */
307 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
308 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
310 #ifndef DEBUG_FRAME_SECTION
311 #define DEBUG_FRAME_SECTION ".debug_frame"
314 #ifndef FUNC_BEGIN_LABEL
315 #define FUNC_BEGIN_LABEL "LFB"
318 #ifndef FUNC_END_LABEL
319 #define FUNC_END_LABEL "LFE"
322 #ifndef PROLOGUE_END_LABEL
323 #define PROLOGUE_END_LABEL "LPE"
326 #ifndef EPILOGUE_BEGIN_LABEL
327 #define EPILOGUE_BEGIN_LABEL "LEB"
330 #ifndef FRAME_BEGIN_LABEL
331 #define FRAME_BEGIN_LABEL "Lframe"
333 #define CIE_AFTER_SIZE_LABEL "LSCIE"
334 #define CIE_END_LABEL "LECIE"
335 #define FDE_LABEL "LSFDE"
336 #define FDE_AFTER_SIZE_LABEL "LASFDE"
337 #define FDE_END_LABEL "LEFDE"
338 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
339 #define LINE_NUMBER_END_LABEL "LELT"
340 #define LN_PROLOG_AS_LABEL "LASLTP"
341 #define LN_PROLOG_END_LABEL "LELTP"
342 #define DIE_LABEL_PREFIX "DW"
344 /* The DWARF 2 CFA column which tracks the return address. Normally this
345 is the column for PC, or the first column after all of the hard
347 #ifndef DWARF_FRAME_RETURN_COLUMN
349 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
351 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
355 /* The mapping from gcc register number to DWARF 2 CFA column number. By
356 default, we just provide columns for all registers. */
357 #ifndef DWARF_FRAME_REGNUM
358 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
361 /* Match the base name of a file to the base name of a compilation unit. */
364 matches_main_base (const char *path)
366 /* Cache the last query. */
367 static const char *last_path = NULL;
368 static int last_match = 0;
369 if (path != last_path)
372 int length = base_of_path (path, &base);
374 last_match = (length == main_input_baselength
375 && memcmp (base, main_input_basename, length) == 0);
380 #ifdef DEBUG_DEBUG_STRUCT
383 dump_struct_debug (tree type, enum debug_info_usage usage,
384 enum debug_struct_file criterion, int generic,
385 int matches, int result)
387 /* Find the type name. */
388 tree type_decl = TYPE_STUB_DECL (type);
390 const char *name = 0;
391 if (TREE_CODE (t) == TYPE_DECL)
394 name = IDENTIFIER_POINTER (t);
396 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
398 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
399 matches ? "bas" : "hdr",
400 generic ? "gen" : "ord",
401 usage == DINFO_USAGE_DFN ? ";" :
402 usage == DINFO_USAGE_DIR_USE ? "." : "*",
404 (void*) type_decl, name);
407 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
408 dump_struct_debug (type, usage, criterion, generic, matches, result)
412 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
418 should_emit_struct_debug (tree type, enum debug_info_usage usage)
420 enum debug_struct_file criterion;
422 bool generic = lang_hooks.types.generic_p (type);
425 criterion = debug_struct_generic[usage];
427 criterion = debug_struct_ordinary[usage];
429 if (criterion == DINFO_STRUCT_FILE_NONE)
430 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
431 if (criterion == DINFO_STRUCT_FILE_ANY)
432 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
434 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
436 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
437 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
439 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
440 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
441 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
444 /* Return a pointer to a copy of the section string name S with all
445 attributes stripped off, and an asterisk prepended (for assemble_name). */
448 stripattributes (const char *s)
450 char *stripped = XNEWVEC (char, strlen (s) + 2);
455 while (*s && *s != ',')
462 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
464 static inline HOST_WIDE_INT
465 div_data_align (HOST_WIDE_INT off)
467 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
468 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
472 /* Return true if we need a signed version of a given opcode
473 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
476 need_data_align_sf_opcode (HOST_WIDE_INT off)
478 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
481 /* Convert a DWARF call frame info. operation to its string name */
484 dwarf_cfi_name (unsigned int cfi_opc)
488 case DW_CFA_advance_loc:
489 return "DW_CFA_advance_loc";
491 return "DW_CFA_offset";
493 return "DW_CFA_restore";
497 return "DW_CFA_set_loc";
498 case DW_CFA_advance_loc1:
499 return "DW_CFA_advance_loc1";
500 case DW_CFA_advance_loc2:
501 return "DW_CFA_advance_loc2";
502 case DW_CFA_advance_loc4:
503 return "DW_CFA_advance_loc4";
504 case DW_CFA_offset_extended:
505 return "DW_CFA_offset_extended";
506 case DW_CFA_restore_extended:
507 return "DW_CFA_restore_extended";
508 case DW_CFA_undefined:
509 return "DW_CFA_undefined";
510 case DW_CFA_same_value:
511 return "DW_CFA_same_value";
512 case DW_CFA_register:
513 return "DW_CFA_register";
514 case DW_CFA_remember_state:
515 return "DW_CFA_remember_state";
516 case DW_CFA_restore_state:
517 return "DW_CFA_restore_state";
519 return "DW_CFA_def_cfa";
520 case DW_CFA_def_cfa_register:
521 return "DW_CFA_def_cfa_register";
522 case DW_CFA_def_cfa_offset:
523 return "DW_CFA_def_cfa_offset";
526 case DW_CFA_def_cfa_expression:
527 return "DW_CFA_def_cfa_expression";
528 case DW_CFA_expression:
529 return "DW_CFA_expression";
530 case DW_CFA_offset_extended_sf:
531 return "DW_CFA_offset_extended_sf";
532 case DW_CFA_def_cfa_sf:
533 return "DW_CFA_def_cfa_sf";
534 case DW_CFA_def_cfa_offset_sf:
535 return "DW_CFA_def_cfa_offset_sf";
537 /* SGI/MIPS specific */
538 case DW_CFA_MIPS_advance_loc8:
539 return "DW_CFA_MIPS_advance_loc8";
542 case DW_CFA_GNU_window_save:
543 return "DW_CFA_GNU_window_save";
544 case DW_CFA_GNU_args_size:
545 return "DW_CFA_GNU_args_size";
546 case DW_CFA_GNU_negative_offset_extended:
547 return "DW_CFA_GNU_negative_offset_extended";
550 return "DW_CFA_<unknown>";
554 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
555 switch to the data section instead, and write out a synthetic start label
556 for collect2 the first time around. */
559 switch_to_eh_frame_section (bool back)
563 #ifdef EH_FRAME_SECTION_NAME
564 if (eh_frame_section == 0)
568 if (EH_TABLES_CAN_BE_READ_ONLY)
574 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
576 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
578 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
581 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
582 && (fde_encoding & 0x70) != DW_EH_PE_aligned
583 && (per_encoding & 0x70) != DW_EH_PE_absptr
584 && (per_encoding & 0x70) != DW_EH_PE_aligned
585 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
586 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
587 ? 0 : SECTION_WRITE);
590 flags = SECTION_WRITE;
591 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
593 #endif /* EH_FRAME_SECTION_NAME */
595 if (eh_frame_section)
596 switch_to_section (eh_frame_section);
599 /* We have no special eh_frame section. Put the information in
600 the data section and emit special labels to guide collect2. */
601 switch_to_section (data_section);
605 label = get_file_function_name ("F");
606 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
607 targetm.asm_out.globalize_label (asm_out_file,
608 IDENTIFIER_POINTER (label));
609 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
614 /* Switch [BACK] to the eh or debug frame table section, depending on
618 switch_to_frame_table_section (int for_eh, bool back)
621 switch_to_eh_frame_section (back);
624 if (!debug_frame_section)
625 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
626 SECTION_DEBUG, NULL);
627 switch_to_section (debug_frame_section);
631 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
633 enum dw_cfi_oprnd_type
634 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
639 case DW_CFA_GNU_window_save:
640 case DW_CFA_remember_state:
641 case DW_CFA_restore_state:
642 return dw_cfi_oprnd_unused;
645 case DW_CFA_advance_loc1:
646 case DW_CFA_advance_loc2:
647 case DW_CFA_advance_loc4:
648 case DW_CFA_MIPS_advance_loc8:
649 return dw_cfi_oprnd_addr;
652 case DW_CFA_offset_extended:
654 case DW_CFA_offset_extended_sf:
655 case DW_CFA_def_cfa_sf:
657 case DW_CFA_restore_extended:
658 case DW_CFA_undefined:
659 case DW_CFA_same_value:
660 case DW_CFA_def_cfa_register:
661 case DW_CFA_register:
662 case DW_CFA_expression:
663 return dw_cfi_oprnd_reg_num;
665 case DW_CFA_def_cfa_offset:
666 case DW_CFA_GNU_args_size:
667 case DW_CFA_def_cfa_offset_sf:
668 return dw_cfi_oprnd_offset;
670 case DW_CFA_def_cfa_expression:
671 return dw_cfi_oprnd_loc;
678 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
680 enum dw_cfi_oprnd_type
681 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
686 case DW_CFA_def_cfa_sf:
688 case DW_CFA_offset_extended_sf:
689 case DW_CFA_offset_extended:
690 return dw_cfi_oprnd_offset;
692 case DW_CFA_register:
693 return dw_cfi_oprnd_reg_num;
695 case DW_CFA_expression:
696 return dw_cfi_oprnd_loc;
699 return dw_cfi_oprnd_unused;
703 /* Output a Call Frame Information opcode and its operand(s). */
706 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
711 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
712 dw2_asm_output_data (1, (cfi->dw_cfi_opc
713 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
714 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
715 ((unsigned HOST_WIDE_INT)
716 cfi->dw_cfi_oprnd1.dw_cfi_offset));
717 else if (cfi->dw_cfi_opc == DW_CFA_offset)
719 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
720 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
721 "DW_CFA_offset, column %#lx", r);
722 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
723 dw2_asm_output_data_uleb128 (off, NULL);
725 else if (cfi->dw_cfi_opc == DW_CFA_restore)
727 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
728 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
729 "DW_CFA_restore, column %#lx", r);
733 dw2_asm_output_data (1, cfi->dw_cfi_opc,
734 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
736 switch (cfi->dw_cfi_opc)
740 dw2_asm_output_encoded_addr_rtx (
741 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
742 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
745 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
746 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
747 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
750 case DW_CFA_advance_loc1:
751 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
752 fde->dw_fde_current_label, NULL);
753 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
756 case DW_CFA_advance_loc2:
757 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
758 fde->dw_fde_current_label, NULL);
759 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
762 case DW_CFA_advance_loc4:
763 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
764 fde->dw_fde_current_label, NULL);
765 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
768 case DW_CFA_MIPS_advance_loc8:
769 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
770 fde->dw_fde_current_label, NULL);
771 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
774 case DW_CFA_offset_extended:
775 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
776 dw2_asm_output_data_uleb128 (r, NULL);
777 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
778 dw2_asm_output_data_uleb128 (off, NULL);
782 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
783 dw2_asm_output_data_uleb128 (r, NULL);
784 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
787 case DW_CFA_offset_extended_sf:
788 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
789 dw2_asm_output_data_uleb128 (r, NULL);
790 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
791 dw2_asm_output_data_sleb128 (off, NULL);
794 case DW_CFA_def_cfa_sf:
795 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
796 dw2_asm_output_data_uleb128 (r, NULL);
797 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
798 dw2_asm_output_data_sleb128 (off, NULL);
801 case DW_CFA_restore_extended:
802 case DW_CFA_undefined:
803 case DW_CFA_same_value:
804 case DW_CFA_def_cfa_register:
805 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
806 dw2_asm_output_data_uleb128 (r, NULL);
809 case DW_CFA_register:
810 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
811 dw2_asm_output_data_uleb128 (r, NULL);
812 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
813 dw2_asm_output_data_uleb128 (r, NULL);
816 case DW_CFA_def_cfa_offset:
817 case DW_CFA_GNU_args_size:
818 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
821 case DW_CFA_def_cfa_offset_sf:
822 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
823 dw2_asm_output_data_sleb128 (off, NULL);
826 case DW_CFA_GNU_window_save:
829 case DW_CFA_def_cfa_expression:
830 case DW_CFA_expression:
831 output_cfa_loc (cfi, for_eh);
834 case DW_CFA_GNU_negative_offset_extended:
835 /* Obsoleted by DW_CFA_offset_extended_sf. */
844 /* Similar, but do it via assembler directives instead. */
847 output_cfi_directive (dw_cfi_ref cfi)
851 switch (cfi->dw_cfi_opc)
853 case DW_CFA_advance_loc:
854 case DW_CFA_advance_loc1:
855 case DW_CFA_advance_loc2:
856 case DW_CFA_advance_loc4:
857 case DW_CFA_MIPS_advance_loc8:
859 /* Should only be created by add_fde_cfi in a code path not
860 followed when emitting via directives. The assembler is
861 going to take care of this for us. */
865 case DW_CFA_offset_extended:
866 case DW_CFA_offset_extended_sf:
867 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
868 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
869 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
873 case DW_CFA_restore_extended:
874 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
875 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
878 case DW_CFA_undefined:
879 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
880 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
883 case DW_CFA_same_value:
884 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
885 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
889 case DW_CFA_def_cfa_sf:
890 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
891 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
892 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
895 case DW_CFA_def_cfa_register:
896 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
897 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
900 case DW_CFA_register:
901 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
902 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
903 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
906 case DW_CFA_def_cfa_offset:
907 case DW_CFA_def_cfa_offset_sf:
908 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
909 HOST_WIDE_INT_PRINT_DEC"\n",
910 cfi->dw_cfi_oprnd1.dw_cfi_offset);
913 case DW_CFA_remember_state:
914 fprintf (asm_out_file, "\t.cfi_remember_state\n");
916 case DW_CFA_restore_state:
917 fprintf (asm_out_file, "\t.cfi_restore_state\n");
920 case DW_CFA_GNU_args_size:
921 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
922 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
924 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
925 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
926 fputc ('\n', asm_out_file);
929 case DW_CFA_GNU_window_save:
930 fprintf (asm_out_file, "\t.cfi_window_save\n");
933 case DW_CFA_def_cfa_expression:
934 case DW_CFA_expression:
935 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
936 output_cfa_loc_raw (cfi);
937 fputc ('\n', asm_out_file);
945 /* Output CFIs from VEC, up to index UPTO, to bring current FDE to the
946 same state as after executing CFIs in CFI chain. DO_CFI_ASM is
947 true if .cfi_* directives shall be emitted, false otherwise. If it
948 is false, FDE and FOR_EH are the other arguments to pass to
952 output_cfis (cfi_vec vec, int upto, bool do_cfi_asm,
953 dw_fde_ref fde, bool for_eh)
956 struct dw_cfi_struct cfi_buf;
958 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
959 VEC(dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
960 unsigned int len, idx;
962 for (ix = 0; ix < upto + 1; ix++)
964 dw_cfi_ref cfi = ix < upto ? VEC_index (dw_cfi_ref, vec, ix) : NULL;
965 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
967 case DW_CFA_advance_loc:
968 case DW_CFA_advance_loc1:
969 case DW_CFA_advance_loc2:
970 case DW_CFA_advance_loc4:
971 case DW_CFA_MIPS_advance_loc8:
973 /* All advances should be ignored. */
975 case DW_CFA_remember_state:
977 dw_cfi_ref args_size = cfi_args_size;
979 /* Skip everything between .cfi_remember_state and
980 .cfi_restore_state. */
985 for (; ix < upto; ix++)
987 cfi2 = VEC_index (dw_cfi_ref, vec, ix);
988 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
990 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
993 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
996 cfi_args_size = args_size;
999 case DW_CFA_GNU_args_size:
1000 cfi_args_size = cfi;
1002 case DW_CFA_GNU_window_save:
1005 case DW_CFA_offset_extended:
1006 case DW_CFA_offset_extended_sf:
1007 case DW_CFA_restore:
1008 case DW_CFA_restore_extended:
1009 case DW_CFA_undefined:
1010 case DW_CFA_same_value:
1011 case DW_CFA_register:
1012 case DW_CFA_val_offset:
1013 case DW_CFA_val_offset_sf:
1014 case DW_CFA_expression:
1015 case DW_CFA_val_expression:
1016 case DW_CFA_GNU_negative_offset_extended:
1017 if (VEC_length (dw_cfi_ref, regs)
1018 <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
1019 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
1020 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
1021 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1024 case DW_CFA_def_cfa:
1025 case DW_CFA_def_cfa_sf:
1026 case DW_CFA_def_cfa_expression:
1028 cfi_cfa_offset = cfi;
1030 case DW_CFA_def_cfa_register:
1033 case DW_CFA_def_cfa_offset:
1034 case DW_CFA_def_cfa_offset_sf:
1035 cfi_cfa_offset = cfi;
1038 gcc_assert (cfi == NULL);
1040 len = VEC_length (dw_cfi_ref, regs);
1041 for (idx = 0; idx < len; idx++)
1043 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
1045 && cfi2->dw_cfi_opc != DW_CFA_restore
1046 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
1049 output_cfi_directive (cfi2);
1051 output_cfi (cfi2, fde, for_eh);
1054 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
1056 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
1058 switch (cfi_cfa_offset->dw_cfi_opc)
1060 case DW_CFA_def_cfa_offset:
1061 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
1062 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
1064 case DW_CFA_def_cfa_offset_sf:
1065 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
1066 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
1068 case DW_CFA_def_cfa:
1069 case DW_CFA_def_cfa_sf:
1070 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
1071 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
1078 else if (cfi_cfa_offset)
1079 cfi_cfa = cfi_cfa_offset;
1083 output_cfi_directive (cfi_cfa);
1085 output_cfi (cfi_cfa, fde, for_eh);
1088 cfi_cfa_offset = NULL;
1090 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
1093 output_cfi_directive (cfi_args_size);
1095 output_cfi (cfi_args_size, fde, for_eh);
1097 cfi_args_size = NULL;
1100 VEC_free (dw_cfi_ref, heap, regs);
1103 else if (do_cfi_asm)
1104 output_cfi_directive (cfi);
1106 output_cfi (cfi, fde, for_eh);
1114 /* Like output_cfis, but emit all CFIs in the vector. */
1116 output_all_cfis (cfi_vec vec, bool do_cfi_asm,
1117 dw_fde_ref fde, bool for_eh)
1119 output_cfis (vec, VEC_length (dw_cfi_ref, vec), do_cfi_asm, fde, for_eh);
1122 /* Output one FDE. */
1125 output_fde (dw_fde_ref fde, bool for_eh, bool second,
1126 char *section_start_label, int fde_encoding, char *augmentation,
1127 bool any_lsda_needed, int lsda_encoding)
1130 const char *begin, *end;
1131 static unsigned int j;
1132 char l1[20], l2[20];
1135 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
1137 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
1139 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
1140 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
1141 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
1142 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
1143 " indicating 64-bit DWARF extension");
1144 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1146 ASM_OUTPUT_LABEL (asm_out_file, l1);
1149 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1151 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1152 debug_frame_section, "FDE CIE offset");
1154 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
1155 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
1159 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
1160 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
1161 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
1162 "FDE initial location");
1163 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1164 end, begin, "FDE address range");
1168 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
1169 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
1172 if (augmentation[0])
1174 if (any_lsda_needed)
1176 int size = size_of_encoded_value (lsda_encoding);
1178 if (lsda_encoding == DW_EH_PE_aligned)
1180 int offset = ( 4 /* Length */
1181 + 4 /* CIE offset */
1182 + 2 * size_of_encoded_value (fde_encoding)
1183 + 1 /* Augmentation size */ );
1184 int pad = -offset & (PTR_SIZE - 1);
1187 gcc_assert (size_of_uleb128 (size) == 1);
1190 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1192 if (fde->uses_eh_lsda)
1194 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
1195 fde->funcdef_number);
1196 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
1197 gen_rtx_SYMBOL_REF (Pmode, l1),
1199 "Language Specific Data Area");
1203 if (lsda_encoding == DW_EH_PE_aligned)
1204 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1205 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
1206 "Language Specific Data Area (none)");
1210 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1213 /* Loop through the Call Frame Instructions associated with
1215 fde->dw_fde_current_label = begin;
1216 if (fde->dw_fde_second_begin == NULL)
1217 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
1218 output_cfi (cfi, fde, for_eh);
1221 if (fde->dw_fde_switch_cfi_index > 0)
1222 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
1224 if (ix == fde->dw_fde_switch_cfi_index)
1226 output_cfi (cfi, fde, for_eh);
1232 int until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
1234 if (fde->dw_fde_switch_cfi_index > 0)
1236 from = fde->dw_fde_switch_cfi_index;
1237 output_cfis (fde->dw_fde_cfi, from, false, fde, for_eh);
1239 for (i = from; i < until; i++)
1240 output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i),
1244 /* If we are to emit a ref/link from function bodies to their frame tables,
1245 do it now. This is typically performed to make sure that tables
1246 associated with functions are dragged with them and not discarded in
1247 garbage collecting links. We need to do this on a per function basis to
1248 cope with -ffunction-sections. */
1250 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
1251 /* Switch to the function section, emit the ref to the tables, and
1252 switch *back* into the table section. */
1253 switch_to_section (function_section (fde->decl));
1254 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
1255 switch_to_frame_table_section (for_eh, true);
1258 /* Pad the FDE out to an address sized boundary. */
1259 ASM_OUTPUT_ALIGN (asm_out_file,
1260 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1261 ASM_OUTPUT_LABEL (asm_out_file, l2);
1266 /* Return true if frame description entry FDE is needed for EH. */
1269 fde_needed_for_eh_p (dw_fde_ref fde)
1271 if (flag_asynchronous_unwind_tables)
1274 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
1277 if (fde->uses_eh_lsda)
1280 /* If exceptions are enabled, we have collected nothrow info. */
1281 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
1287 /* Output the call frame information used to record information
1288 that relates to calculating the frame pointer, and records the
1289 location of saved registers. */
1292 output_call_frame_info (int for_eh)
1297 char l1[20], l2[20], section_start_label[20];
1298 bool any_lsda_needed = false;
1299 char augmentation[6];
1300 int augmentation_size;
1301 int fde_encoding = DW_EH_PE_absptr;
1302 int per_encoding = DW_EH_PE_absptr;
1303 int lsda_encoding = DW_EH_PE_absptr;
1305 rtx personality = NULL;
1308 /* Don't emit a CIE if there won't be any FDEs. */
1309 if (fde_table_in_use == 0)
1312 /* Nothing to do if the assembler's doing it all. */
1313 if (dwarf2out_do_cfi_asm ())
1316 /* If we don't have any functions we'll want to unwind out of, don't emit
1317 any EH unwind information. If we make FDEs linkonce, we may have to
1318 emit an empty label for an FDE that wouldn't otherwise be emitted. We
1319 want to avoid having an FDE kept around when the function it refers to
1320 is discarded. Example where this matters: a primary function template
1321 in C++ requires EH information, an explicit specialization doesn't. */
1324 bool any_eh_needed = false;
1326 for (i = 0; i < fde_table_in_use; i++)
1327 if (fde_table[i].uses_eh_lsda)
1328 any_eh_needed = any_lsda_needed = true;
1329 else if (fde_needed_for_eh_p (&fde_table[i]))
1330 any_eh_needed = true;
1331 else if (TARGET_USES_WEAK_UNWIND_INFO)
1332 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
1339 /* We're going to be generating comments, so turn on app. */
1343 /* Switch to the proper frame section, first time. */
1344 switch_to_frame_table_section (for_eh, false);
1346 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1347 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1349 /* Output the CIE. */
1350 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1351 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1352 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
1353 dw2_asm_output_data (4, 0xffffffff,
1354 "Initial length escape value indicating 64-bit DWARF extension");
1355 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1356 "Length of Common Information Entry");
1357 ASM_OUTPUT_LABEL (asm_out_file, l1);
1359 /* Now that the CIE pointer is PC-relative for EH,
1360 use 0 to identify the CIE. */
1361 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1362 (for_eh ? 0 : DWARF_CIE_ID),
1363 "CIE Identifier Tag");
1365 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
1366 use CIE version 1, unless that would produce incorrect results
1367 due to overflowing the return register column. */
1368 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
1370 if (return_reg >= 256 || dwarf_version > 2)
1372 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
1374 augmentation[0] = 0;
1375 augmentation_size = 0;
1377 personality = current_unit_personality;
1383 z Indicates that a uleb128 is present to size the
1384 augmentation section.
1385 L Indicates the encoding (and thus presence) of
1386 an LSDA pointer in the FDE augmentation.
1387 R Indicates a non-default pointer encoding for
1389 P Indicates the presence of an encoding + language
1390 personality routine in the CIE augmentation. */
1392 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1393 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1394 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1396 p = augmentation + 1;
1400 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1401 assemble_external_libcall (personality);
1403 if (any_lsda_needed)
1406 augmentation_size += 1;
1408 if (fde_encoding != DW_EH_PE_absptr)
1411 augmentation_size += 1;
1413 if (p > augmentation + 1)
1415 augmentation[0] = 'z';
1419 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1420 if (personality && per_encoding == DW_EH_PE_aligned)
1422 int offset = ( 4 /* Length */
1424 + 1 /* CIE version */
1425 + strlen (augmentation) + 1 /* Augmentation */
1426 + size_of_uleb128 (1) /* Code alignment */
1427 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1429 + 1 /* Augmentation size */
1430 + 1 /* Personality encoding */ );
1431 int pad = -offset & (PTR_SIZE - 1);
1433 augmentation_size += pad;
1435 /* Augmentations should be small, so there's scarce need to
1436 iterate for a solution. Die if we exceed one uleb128 byte. */
1437 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
1441 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1442 if (dw_cie_version >= 4)
1444 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
1445 dw2_asm_output_data (1, 0, "CIE Segment Size");
1447 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1448 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1449 "CIE Data Alignment Factor");
1451 if (dw_cie_version == 1)
1452 dw2_asm_output_data (1, return_reg, "CIE RA Column");
1454 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
1456 if (augmentation[0])
1458 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1461 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1462 eh_data_format_name (per_encoding));
1463 dw2_asm_output_encoded_addr_rtx (per_encoding,
1468 if (any_lsda_needed)
1469 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1470 eh_data_format_name (lsda_encoding));
1472 if (fde_encoding != DW_EH_PE_absptr)
1473 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1474 eh_data_format_name (fde_encoding));
1477 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, i, cfi)
1478 output_cfi (cfi, NULL, for_eh);
1480 /* Pad the CIE out to an address sized boundary. */
1481 ASM_OUTPUT_ALIGN (asm_out_file,
1482 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1483 ASM_OUTPUT_LABEL (asm_out_file, l2);
1485 /* Loop through all of the FDE's. */
1486 for (i = 0; i < fde_table_in_use; i++)
1489 fde = &fde_table[i];
1491 /* Don't emit EH unwind info for leaf functions that don't need it. */
1492 if (for_eh && !fde_needed_for_eh_p (fde))
1495 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
1496 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
1497 augmentation, any_lsda_needed, lsda_encoding);
1500 if (for_eh && targetm.terminate_dw2_eh_frame_info)
1501 dw2_asm_output_data (4, 0, "End of Table");
1502 #ifdef MIPS_DEBUGGING_INFO
1503 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1504 get a value of 0. Putting .align 0 after the label fixes it. */
1505 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1508 /* Turn off app to make assembly quicker. */
1513 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
1516 dwarf2out_do_cfi_startproc (bool second)
1520 rtx personality = get_personality_function (current_function_decl);
1522 fprintf (asm_out_file, "\t.cfi_startproc\n");
1526 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1529 /* ??? The GAS support isn't entirely consistent. We have to
1530 handle indirect support ourselves, but PC-relative is done
1531 in the assembler. Further, the assembler can't handle any
1532 of the weirder relocation types. */
1533 if (enc & DW_EH_PE_indirect)
1534 ref = dw2_force_const_mem (ref, true);
1536 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
1537 output_addr_const (asm_out_file, ref);
1538 fputc ('\n', asm_out_file);
1541 if (crtl->uses_eh_lsda)
1545 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1546 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
1547 current_function_funcdef_no);
1548 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
1549 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
1551 if (enc & DW_EH_PE_indirect)
1552 ref = dw2_force_const_mem (ref, true);
1554 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
1555 output_addr_const (asm_out_file, ref);
1556 fputc ('\n', asm_out_file);
1560 /* Output a marker (i.e. a label) for the beginning of a function, before
1564 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
1565 const char *file ATTRIBUTE_UNUSED)
1567 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1573 current_function_func_begin_label = NULL;
1575 do_frame = dwarf2out_do_frame ();
1577 /* ??? current_function_func_begin_label is also used by except.c for
1578 call-site information. We must emit this label if it might be used. */
1580 && (!flag_exceptions
1581 || targetm_common.except_unwind_info (&global_options) != UI_TARGET))
1584 fnsec = function_section (current_function_decl);
1585 switch_to_section (fnsec);
1586 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1587 current_function_funcdef_no);
1588 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1589 current_function_funcdef_no);
1590 dup_label = xstrdup (label);
1591 current_function_func_begin_label = dup_label;
1593 /* We can elide the fde allocation if we're not emitting debug info. */
1597 /* Expand the fde table if necessary. */
1598 if (fde_table_in_use == fde_table_allocated)
1600 fde_table_allocated += FDE_TABLE_INCREMENT;
1601 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
1602 memset (fde_table + fde_table_in_use, 0,
1603 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
1606 /* Record the FDE associated with this function. */
1607 current_funcdef_fde = fde_table_in_use;
1609 /* Add the new FDE at the end of the fde_table. */
1610 fde = &fde_table[fde_table_in_use++];
1611 fde->decl = current_function_decl;
1612 fde->dw_fde_begin = dup_label;
1613 fde->dw_fde_end = NULL;
1614 fde->dw_fde_current_label = dup_label;
1615 fde->dw_fde_second_begin = NULL;
1616 fde->dw_fde_second_end = NULL;
1617 fde->dw_fde_vms_end_prologue = NULL;
1618 fde->dw_fde_vms_begin_epilogue = NULL;
1619 fde->dw_fde_cfi = VEC_alloc (dw_cfi_ref, gc, 20);
1620 fde->dw_fde_switch_cfi_index = 0;
1621 fde->funcdef_number = current_function_funcdef_no;
1622 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
1623 fde->uses_eh_lsda = crtl->uses_eh_lsda;
1624 fde->nothrow = crtl->nothrow;
1625 fde->drap_reg = INVALID_REGNUM;
1626 fde->vdrap_reg = INVALID_REGNUM;
1627 fde->in_std_section = (fnsec == text_section
1628 || (cold_text_section && fnsec == cold_text_section));
1629 fde->second_in_std_section = 0;
1631 dwarf2cfi_function_init ();
1633 /* We only want to output line number information for the genuine dwarf2
1634 prologue case, not the eh frame case. */
1635 #ifdef DWARF2_DEBUGGING_INFO
1637 dwarf2out_source_line (line, file, 0, true);
1640 if (dwarf2out_do_cfi_asm ())
1641 dwarf2out_do_cfi_startproc (false);
1644 rtx personality = get_personality_function (current_function_decl);
1645 if (!current_unit_personality)
1646 current_unit_personality = personality;
1648 /* We cannot keep a current personality per function as without CFI
1649 asm, at the point where we emit the CFI data, there is no current
1650 function anymore. */
1651 if (personality && current_unit_personality != personality)
1652 sorry ("multiple EH personalities are supported only with assemblers "
1653 "supporting .cfi_personality directive");
1657 /* Output a marker (i.e. a label) for the end of the generated code
1658 for a function prologue. This gets called *after* the prologue code has
1662 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
1663 const char *file ATTRIBUTE_UNUSED)
1666 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1668 /* Output a label to mark the endpoint of the code generated for this
1670 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
1671 current_function_funcdef_no);
1672 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
1673 current_function_funcdef_no);
1674 fde = &fde_table[fde_table_in_use - 1];
1675 fde->dw_fde_vms_end_prologue = xstrdup (label);
1678 /* Output a marker (i.e. a label) for the beginning of the generated code
1679 for a function epilogue. This gets called *before* the prologue code has
1683 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1684 const char *file ATTRIBUTE_UNUSED)
1687 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1689 fde = &fde_table[fde_table_in_use - 1];
1690 if (fde->dw_fde_vms_begin_epilogue)
1693 /* Output a label to mark the endpoint of the code generated for this
1695 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
1696 current_function_funcdef_no);
1697 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
1698 current_function_funcdef_no);
1699 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
1702 /* Output a marker (i.e. a label) for the absolute end of the generated code
1703 for a function definition. This gets called *after* the epilogue code has
1707 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1708 const char *file ATTRIBUTE_UNUSED)
1711 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1713 last_var_location_insn = NULL_RTX;
1715 if (dwarf2out_do_cfi_asm ())
1716 fprintf (asm_out_file, "\t.cfi_endproc\n");
1718 /* Output a label to mark the endpoint of the code generated for this
1720 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1721 current_function_funcdef_no);
1722 ASM_OUTPUT_LABEL (asm_out_file, label);
1723 fde = current_fde ();
1724 gcc_assert (fde != NULL);
1725 if (fde->dw_fde_second_begin == NULL)
1726 fde->dw_fde_end = xstrdup (label);
1730 dwarf2out_frame_init (void)
1732 /* Allocate the initial hunk of the fde_table. */
1733 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
1734 fde_table_allocated = FDE_TABLE_INCREMENT;
1735 fde_table_in_use = 0;
1737 dwarf2cfi_frame_init ();
1741 dwarf2out_frame_finish (void)
1743 /* Output call frame information. */
1744 if (targetm.debug_unwind_info () == UI_DWARF2)
1745 output_call_frame_info (0);
1747 /* Output another copy for the unwinder. */
1748 if ((flag_unwind_tables || flag_exceptions)
1749 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
1750 output_call_frame_info (1);
1753 /* Note that the current function section is being used for code. */
1756 dwarf2out_note_section_used (void)
1758 section *sec = current_function_section ();
1759 if (sec == text_section)
1760 text_section_used = true;
1761 else if (sec == cold_text_section)
1762 cold_text_section_used = true;
1765 static void var_location_switch_text_section (void);
1766 static void set_cur_line_info_table (section *);
1769 dwarf2out_switch_text_section (void)
1772 dw_fde_ref fde = current_fde ();
1774 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1776 if (!in_cold_section_p)
1778 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
1779 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
1780 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
1784 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1785 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
1786 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1788 have_multiple_function_sections = true;
1790 /* Reset the current label on switching text sections, so that we
1791 don't attempt to advance_loc4 between labels in different sections. */
1792 fde->dw_fde_current_label = NULL;
1794 /* There is no need to mark used sections when not debugging. */
1795 if (cold_text_section != NULL)
1796 dwarf2out_note_section_used ();
1798 if (dwarf2out_do_cfi_asm ())
1799 fprintf (asm_out_file, "\t.cfi_endproc\n");
1801 /* Now do the real section switch. */
1802 sect = current_function_section ();
1803 switch_to_section (sect);
1805 fde->second_in_std_section
1806 = (sect == text_section
1807 || (cold_text_section && sect == cold_text_section));
1809 if (dwarf2out_do_cfi_asm ())
1811 dwarf2out_do_cfi_startproc (true);
1812 /* As this is a different FDE, insert all current CFI instructions
1814 output_all_cfis (fde->dw_fde_cfi, true, fde, true);
1816 fde->dw_fde_switch_cfi_index = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
1817 var_location_switch_text_section ();
1819 set_cur_line_info_table (sect);
1822 /* And now, the subset of the debugging information support code necessary
1823 for emitting location expressions. */
1825 /* Data about a single source file. */
1826 struct GTY(()) dwarf_file_data {
1827 const char * filename;
1831 typedef struct GTY(()) deferred_locations_struct
1835 } deferred_locations;
1837 DEF_VEC_O(deferred_locations);
1838 DEF_VEC_ALLOC_O(deferred_locations,gc);
1840 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
1842 DEF_VEC_P(dw_die_ref);
1843 DEF_VEC_ALLOC_P(dw_die_ref,heap);
1845 /* Location lists are ranges + location descriptions for that range,
1846 so you can track variables that are in different places over
1847 their entire life. */
1848 typedef struct GTY(()) dw_loc_list_struct {
1849 dw_loc_list_ref dw_loc_next;
1850 const char *begin; /* Label for begin address of range */
1851 const char *end; /* Label for end address of range */
1852 char *ll_symbol; /* Label for beginning of location list.
1853 Only on head of list */
1854 const char *section; /* Section this loclist is relative to */
1855 dw_loc_descr_ref expr;
1857 /* True if all addresses in this and subsequent lists are known to be
1860 /* True if this list has been replaced by dw_loc_next. */
1863 /* True if the range should be emitted even if begin and end
1868 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
1870 /* Convert a DWARF stack opcode into its string name. */
1873 dwarf_stack_op_name (unsigned int op)
1878 return "DW_OP_addr";
1880 return "DW_OP_deref";
1882 return "DW_OP_const1u";
1884 return "DW_OP_const1s";
1886 return "DW_OP_const2u";
1888 return "DW_OP_const2s";
1890 return "DW_OP_const4u";
1892 return "DW_OP_const4s";
1894 return "DW_OP_const8u";
1896 return "DW_OP_const8s";
1898 return "DW_OP_constu";
1900 return "DW_OP_consts";
1904 return "DW_OP_drop";
1906 return "DW_OP_over";
1908 return "DW_OP_pick";
1910 return "DW_OP_swap";
1914 return "DW_OP_xderef";
1922 return "DW_OP_minus";
1934 return "DW_OP_plus";
1935 case DW_OP_plus_uconst:
1936 return "DW_OP_plus_uconst";
1942 return "DW_OP_shra";
1960 return "DW_OP_skip";
1962 return "DW_OP_lit0";
1964 return "DW_OP_lit1";
1966 return "DW_OP_lit2";
1968 return "DW_OP_lit3";
1970 return "DW_OP_lit4";
1972 return "DW_OP_lit5";
1974 return "DW_OP_lit6";
1976 return "DW_OP_lit7";
1978 return "DW_OP_lit8";
1980 return "DW_OP_lit9";
1982 return "DW_OP_lit10";
1984 return "DW_OP_lit11";
1986 return "DW_OP_lit12";
1988 return "DW_OP_lit13";
1990 return "DW_OP_lit14";
1992 return "DW_OP_lit15";
1994 return "DW_OP_lit16";
1996 return "DW_OP_lit17";
1998 return "DW_OP_lit18";
2000 return "DW_OP_lit19";
2002 return "DW_OP_lit20";
2004 return "DW_OP_lit21";
2006 return "DW_OP_lit22";
2008 return "DW_OP_lit23";
2010 return "DW_OP_lit24";
2012 return "DW_OP_lit25";
2014 return "DW_OP_lit26";
2016 return "DW_OP_lit27";
2018 return "DW_OP_lit28";
2020 return "DW_OP_lit29";
2022 return "DW_OP_lit30";
2024 return "DW_OP_lit31";
2026 return "DW_OP_reg0";
2028 return "DW_OP_reg1";
2030 return "DW_OP_reg2";
2032 return "DW_OP_reg3";
2034 return "DW_OP_reg4";
2036 return "DW_OP_reg5";
2038 return "DW_OP_reg6";
2040 return "DW_OP_reg7";
2042 return "DW_OP_reg8";
2044 return "DW_OP_reg9";
2046 return "DW_OP_reg10";
2048 return "DW_OP_reg11";
2050 return "DW_OP_reg12";
2052 return "DW_OP_reg13";
2054 return "DW_OP_reg14";
2056 return "DW_OP_reg15";
2058 return "DW_OP_reg16";
2060 return "DW_OP_reg17";
2062 return "DW_OP_reg18";
2064 return "DW_OP_reg19";
2066 return "DW_OP_reg20";
2068 return "DW_OP_reg21";
2070 return "DW_OP_reg22";
2072 return "DW_OP_reg23";
2074 return "DW_OP_reg24";
2076 return "DW_OP_reg25";
2078 return "DW_OP_reg26";
2080 return "DW_OP_reg27";
2082 return "DW_OP_reg28";
2084 return "DW_OP_reg29";
2086 return "DW_OP_reg30";
2088 return "DW_OP_reg31";
2090 return "DW_OP_breg0";
2092 return "DW_OP_breg1";
2094 return "DW_OP_breg2";
2096 return "DW_OP_breg3";
2098 return "DW_OP_breg4";
2100 return "DW_OP_breg5";
2102 return "DW_OP_breg6";
2104 return "DW_OP_breg7";
2106 return "DW_OP_breg8";
2108 return "DW_OP_breg9";
2110 return "DW_OP_breg10";
2112 return "DW_OP_breg11";
2114 return "DW_OP_breg12";
2116 return "DW_OP_breg13";
2118 return "DW_OP_breg14";
2120 return "DW_OP_breg15";
2122 return "DW_OP_breg16";
2124 return "DW_OP_breg17";
2126 return "DW_OP_breg18";
2128 return "DW_OP_breg19";
2130 return "DW_OP_breg20";
2132 return "DW_OP_breg21";
2134 return "DW_OP_breg22";
2136 return "DW_OP_breg23";
2138 return "DW_OP_breg24";
2140 return "DW_OP_breg25";
2142 return "DW_OP_breg26";
2144 return "DW_OP_breg27";
2146 return "DW_OP_breg28";
2148 return "DW_OP_breg29";
2150 return "DW_OP_breg30";
2152 return "DW_OP_breg31";
2154 return "DW_OP_regx";
2156 return "DW_OP_fbreg";
2158 return "DW_OP_bregx";
2160 return "DW_OP_piece";
2161 case DW_OP_deref_size:
2162 return "DW_OP_deref_size";
2163 case DW_OP_xderef_size:
2164 return "DW_OP_xderef_size";
2168 case DW_OP_push_object_address:
2169 return "DW_OP_push_object_address";
2171 return "DW_OP_call2";
2173 return "DW_OP_call4";
2174 case DW_OP_call_ref:
2175 return "DW_OP_call_ref";
2176 case DW_OP_implicit_value:
2177 return "DW_OP_implicit_value";
2178 case DW_OP_stack_value:
2179 return "DW_OP_stack_value";
2180 case DW_OP_form_tls_address:
2181 return "DW_OP_form_tls_address";
2182 case DW_OP_call_frame_cfa:
2183 return "DW_OP_call_frame_cfa";
2184 case DW_OP_bit_piece:
2185 return "DW_OP_bit_piece";
2187 case DW_OP_GNU_push_tls_address:
2188 return "DW_OP_GNU_push_tls_address";
2189 case DW_OP_GNU_uninit:
2190 return "DW_OP_GNU_uninit";
2191 case DW_OP_GNU_encoded_addr:
2192 return "DW_OP_GNU_encoded_addr";
2193 case DW_OP_GNU_implicit_pointer:
2194 return "DW_OP_GNU_implicit_pointer";
2195 case DW_OP_GNU_entry_value:
2196 return "DW_OP_GNU_entry_value";
2197 case DW_OP_GNU_const_type:
2198 return "DW_OP_GNU_const_type";
2199 case DW_OP_GNU_regval_type:
2200 return "DW_OP_GNU_regval_type";
2201 case DW_OP_GNU_deref_type:
2202 return "DW_OP_GNU_deref_type";
2203 case DW_OP_GNU_convert:
2204 return "DW_OP_GNU_convert";
2205 case DW_OP_GNU_reinterpret:
2206 return "DW_OP_GNU_reinterpret";
2207 case DW_OP_GNU_parameter_ref:
2208 return "DW_OP_GNU_parameter_ref";
2211 return "OP_<unknown>";
2215 /* Return a pointer to a newly allocated location description. Location
2216 descriptions are simple expression terms that can be strung
2217 together to form more complicated location (address) descriptions. */
2219 static inline dw_loc_descr_ref
2220 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
2221 unsigned HOST_WIDE_INT oprnd2)
2223 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
2225 descr->dw_loc_opc = op;
2226 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2227 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2228 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2229 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2234 /* Return a pointer to a newly allocated location description for
2237 static inline dw_loc_descr_ref
2238 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
2241 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
2244 return new_loc_descr (DW_OP_bregx, reg, offset);
2247 /* Add a location description term to a location description expression. */
2250 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2252 dw_loc_descr_ref *d;
2254 /* Find the end of the chain. */
2255 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2261 /* Add a constant OFFSET to a location expression. */
2264 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
2266 dw_loc_descr_ref loc;
2269 gcc_assert (*list_head != NULL);
2274 /* Find the end of the chain. */
2275 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
2279 if (loc->dw_loc_opc == DW_OP_fbreg
2280 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
2281 p = &loc->dw_loc_oprnd1.v.val_int;
2282 else if (loc->dw_loc_opc == DW_OP_bregx)
2283 p = &loc->dw_loc_oprnd2.v.val_int;
2285 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
2286 offset. Don't optimize if an signed integer overflow would happen. */
2288 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
2289 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
2292 else if (offset > 0)
2293 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
2297 loc->dw_loc_next = int_loc_descriptor (-offset);
2298 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
2302 /* Add a constant OFFSET to a location list. */
2305 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
2308 for (d = list_head; d != NULL; d = d->dw_loc_next)
2309 loc_descr_plus_const (&d->expr, offset);
2312 #define DWARF_REF_SIZE \
2313 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
2315 static unsigned long size_of_locs (dw_loc_descr_ref);
2316 static unsigned long int get_base_type_offset (dw_die_ref);
2318 /* Return the size of a location descriptor. */
2320 static unsigned long
2321 size_of_loc_descr (dw_loc_descr_ref loc)
2323 unsigned long size = 1;
2325 switch (loc->dw_loc_opc)
2328 size += DWARF2_ADDR_SIZE;
2347 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2350 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2355 case DW_OP_plus_uconst:
2356 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2394 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2397 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2400 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2403 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2404 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2407 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2409 case DW_OP_bit_piece:
2410 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2411 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
2413 case DW_OP_deref_size:
2414 case DW_OP_xderef_size:
2423 case DW_OP_call_ref:
2424 size += DWARF_REF_SIZE;
2426 case DW_OP_implicit_value:
2427 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
2428 + loc->dw_loc_oprnd1.v.val_unsigned;
2430 case DW_OP_GNU_implicit_pointer:
2431 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2433 case DW_OP_GNU_entry_value:
2435 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
2436 size += size_of_uleb128 (op_size) + op_size;
2439 case DW_OP_GNU_const_type:
2442 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
2443 size += size_of_uleb128 (o) + 1;
2444 switch (loc->dw_loc_oprnd2.val_class)
2446 case dw_val_class_vec:
2447 size += loc->dw_loc_oprnd2.v.val_vec.length
2448 * loc->dw_loc_oprnd2.v.val_vec.elt_size;
2450 case dw_val_class_const:
2451 size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
2453 case dw_val_class_const_double:
2454 size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
2461 case DW_OP_GNU_regval_type:
2464 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
2465 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
2466 + size_of_uleb128 (o);
2469 case DW_OP_GNU_deref_type:
2472 = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
2473 size += 1 + size_of_uleb128 (o);
2476 case DW_OP_GNU_convert:
2477 case DW_OP_GNU_reinterpret:
2478 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2479 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2483 = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
2484 size += size_of_uleb128 (o);
2487 case DW_OP_GNU_parameter_ref:
2497 /* Return the size of a series of location descriptors. */
2499 static unsigned long
2500 size_of_locs (dw_loc_descr_ref loc)
2505 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
2506 field, to avoid writing to a PCH file. */
2507 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
2509 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
2511 size += size_of_loc_descr (l);
2516 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
2518 l->dw_loc_addr = size;
2519 size += size_of_loc_descr (l);
2525 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
2526 static void get_ref_die_offset_label (char *, dw_die_ref);
2527 static unsigned long int get_ref_die_offset (dw_die_ref);
2528 static void output_loc_sequence (dw_loc_descr_ref, int);
2530 /* Output location description stack opcode's operands (if any).
2531 The for_eh_or_skip parameter controls whether register numbers are
2532 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2533 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2534 info). This should be suppressed for the cases that have not been converted
2535 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2538 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
2540 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2541 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2543 switch (loc->dw_loc_opc)
2545 #ifdef DWARF2_DEBUGGING_INFO
2548 dw2_asm_output_data (2, val1->v.val_int, NULL);
2553 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2554 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
2556 fputc ('\n', asm_out_file);
2561 dw2_asm_output_data (4, val1->v.val_int, NULL);
2566 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2567 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
2569 fputc ('\n', asm_out_file);
2574 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2575 dw2_asm_output_data (8, val1->v.val_int, NULL);
2582 gcc_assert (val1->val_class == dw_val_class_loc);
2583 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2585 dw2_asm_output_data (2, offset, NULL);
2588 case DW_OP_implicit_value:
2589 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2590 switch (val2->val_class)
2592 case dw_val_class_const:
2593 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
2595 case dw_val_class_vec:
2597 unsigned int elt_size = val2->v.val_vec.elt_size;
2598 unsigned int len = val2->v.val_vec.length;
2602 if (elt_size > sizeof (HOST_WIDE_INT))
2607 for (i = 0, p = val2->v.val_vec.array;
2610 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2611 "fp or vector constant word %u", i);
2614 case dw_val_class_const_double:
2616 unsigned HOST_WIDE_INT first, second;
2618 if (WORDS_BIG_ENDIAN)
2620 first = val2->v.val_double.high;
2621 second = val2->v.val_double.low;
2625 first = val2->v.val_double.low;
2626 second = val2->v.val_double.high;
2628 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2630 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2634 case dw_val_class_addr:
2635 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
2636 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
2651 case DW_OP_implicit_value:
2652 /* We currently don't make any attempt to make sure these are
2653 aligned properly like we do for the main unwind info, so
2654 don't support emitting things larger than a byte if we're
2655 only doing unwinding. */
2660 dw2_asm_output_data (1, val1->v.val_int, NULL);
2663 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2666 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2669 dw2_asm_output_data (1, val1->v.val_int, NULL);
2671 case DW_OP_plus_uconst:
2672 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2706 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2710 unsigned r = val1->v.val_unsigned;
2711 if (for_eh_or_skip >= 0)
2712 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2713 gcc_assert (size_of_uleb128 (r)
2714 == size_of_uleb128 (val1->v.val_unsigned));
2715 dw2_asm_output_data_uleb128 (r, NULL);
2719 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2723 unsigned r = val1->v.val_unsigned;
2724 if (for_eh_or_skip >= 0)
2725 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2726 gcc_assert (size_of_uleb128 (r)
2727 == size_of_uleb128 (val1->v.val_unsigned));
2728 dw2_asm_output_data_uleb128 (r, NULL);
2729 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2733 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2735 case DW_OP_bit_piece:
2736 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2737 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
2739 case DW_OP_deref_size:
2740 case DW_OP_xderef_size:
2741 dw2_asm_output_data (1, val1->v.val_int, NULL);
2747 if (targetm.asm_out.output_dwarf_dtprel)
2749 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
2752 fputc ('\n', asm_out_file);
2759 #ifdef DWARF2_DEBUGGING_INFO
2760 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2767 case DW_OP_GNU_implicit_pointer:
2769 char label[MAX_ARTIFICIAL_LABEL_BYTES
2770 + HOST_BITS_PER_WIDE_INT / 2 + 2];
2771 gcc_assert (val1->val_class == dw_val_class_die_ref);
2772 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2773 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2774 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2778 case DW_OP_GNU_entry_value:
2779 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2780 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2783 case DW_OP_GNU_const_type:
2785 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2787 dw2_asm_output_data_uleb128 (o, NULL);
2788 switch (val2->val_class)
2790 case dw_val_class_const:
2791 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2792 dw2_asm_output_data (1, l, NULL);
2793 dw2_asm_output_data (l, val2->v.val_int, NULL);
2795 case dw_val_class_vec:
2797 unsigned int elt_size = val2->v.val_vec.elt_size;
2798 unsigned int len = val2->v.val_vec.length;
2803 dw2_asm_output_data (1, l, NULL);
2804 if (elt_size > sizeof (HOST_WIDE_INT))
2809 for (i = 0, p = val2->v.val_vec.array;
2812 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2813 "fp or vector constant word %u", i);
2816 case dw_val_class_const_double:
2818 unsigned HOST_WIDE_INT first, second;
2819 l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2821 dw2_asm_output_data (1, 2 * l, NULL);
2822 if (WORDS_BIG_ENDIAN)
2824 first = val2->v.val_double.high;
2825 second = val2->v.val_double.low;
2829 first = val2->v.val_double.low;
2830 second = val2->v.val_double.high;
2832 dw2_asm_output_data (l, first, NULL);
2833 dw2_asm_output_data (l, second, NULL);
2841 case DW_OP_GNU_regval_type:
2843 unsigned r = val1->v.val_unsigned;
2844 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2846 if (for_eh_or_skip >= 0)
2848 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2849 gcc_assert (size_of_uleb128 (r)
2850 == size_of_uleb128 (val1->v.val_unsigned));
2852 dw2_asm_output_data_uleb128 (r, NULL);
2853 dw2_asm_output_data_uleb128 (o, NULL);
2856 case DW_OP_GNU_deref_type:
2858 unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2860 dw2_asm_output_data (1, val1->v.val_int, NULL);
2861 dw2_asm_output_data_uleb128 (o, NULL);
2864 case DW_OP_GNU_convert:
2865 case DW_OP_GNU_reinterpret:
2866 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2867 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2870 unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2872 dw2_asm_output_data_uleb128 (o, NULL);
2876 case DW_OP_GNU_parameter_ref:
2879 gcc_assert (val1->val_class == dw_val_class_die_ref);
2880 o = get_ref_die_offset (val1->v.val_die_ref.die);
2881 dw2_asm_output_data (4, o, NULL);
2886 /* Other codes have no operands. */
2891 /* Output a sequence of location operations.
2892 The for_eh_or_skip parameter controls whether register numbers are
2893 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2894 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2895 info). This should be suppressed for the cases that have not been converted
2896 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2899 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2901 for (; loc != NULL; loc = loc->dw_loc_next)
2903 enum dwarf_location_atom opc = loc->dw_loc_opc;
2904 /* Output the opcode. */
2905 if (for_eh_or_skip >= 0
2906 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2908 unsigned r = (opc - DW_OP_breg0);
2909 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2910 gcc_assert (r <= 31);
2911 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2913 else if (for_eh_or_skip >= 0
2914 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2916 unsigned r = (opc - DW_OP_reg0);
2917 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2918 gcc_assert (r <= 31);
2919 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2922 dw2_asm_output_data (1, opc,
2923 "%s", dwarf_stack_op_name (opc));
2925 /* Output the operand(s) (if any). */
2926 output_loc_operands (loc, for_eh_or_skip);
2930 /* Output location description stack opcode's operands (if any).
2931 The output is single bytes on a line, suitable for .cfi_escape. */
2934 output_loc_operands_raw (dw_loc_descr_ref loc)
2936 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2937 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2939 switch (loc->dw_loc_opc)
2942 case DW_OP_implicit_value:
2943 /* We cannot output addresses in .cfi_escape, only bytes. */
2949 case DW_OP_deref_size:
2950 case DW_OP_xderef_size:
2951 fputc (',', asm_out_file);
2952 dw2_asm_output_data_raw (1, val1->v.val_int);
2957 fputc (',', asm_out_file);
2958 dw2_asm_output_data_raw (2, val1->v.val_int);
2963 fputc (',', asm_out_file);
2964 dw2_asm_output_data_raw (4, val1->v.val_int);
2969 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2970 fputc (',', asm_out_file);
2971 dw2_asm_output_data_raw (8, val1->v.val_int);
2979 gcc_assert (val1->val_class == dw_val_class_loc);
2980 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2982 fputc (',', asm_out_file);
2983 dw2_asm_output_data_raw (2, offset);
2989 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2990 gcc_assert (size_of_uleb128 (r)
2991 == size_of_uleb128 (val1->v.val_unsigned));
2992 fputc (',', asm_out_file);
2993 dw2_asm_output_data_uleb128_raw (r);
2998 case DW_OP_plus_uconst:
3000 fputc (',', asm_out_file);
3001 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
3004 case DW_OP_bit_piece:
3005 fputc (',', asm_out_file);
3006 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
3007 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
3044 fputc (',', asm_out_file);
3045 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
3050 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
3051 gcc_assert (size_of_uleb128 (r)
3052 == size_of_uleb128 (val1->v.val_unsigned));
3053 fputc (',', asm_out_file);
3054 dw2_asm_output_data_uleb128_raw (r);
3055 fputc (',', asm_out_file);
3056 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
3060 case DW_OP_GNU_implicit_pointer:
3061 case DW_OP_GNU_entry_value:
3062 case DW_OP_GNU_const_type:
3063 case DW_OP_GNU_regval_type:
3064 case DW_OP_GNU_deref_type:
3065 case DW_OP_GNU_convert:
3066 case DW_OP_GNU_reinterpret:
3067 case DW_OP_GNU_parameter_ref:
3072 /* Other codes have no operands. */
3078 output_loc_sequence_raw (dw_loc_descr_ref loc)
3082 enum dwarf_location_atom opc = loc->dw_loc_opc;
3083 /* Output the opcode. */
3084 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
3086 unsigned r = (opc - DW_OP_breg0);
3087 r = DWARF2_FRAME_REG_OUT (r, 1);
3088 gcc_assert (r <= 31);
3089 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
3091 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
3093 unsigned r = (opc - DW_OP_reg0);
3094 r = DWARF2_FRAME_REG_OUT (r, 1);
3095 gcc_assert (r <= 31);
3096 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
3098 /* Output the opcode. */
3099 fprintf (asm_out_file, "%#x", opc);
3100 output_loc_operands_raw (loc);
3102 if (!loc->dw_loc_next)
3104 loc = loc->dw_loc_next;
3106 fputc (',', asm_out_file);
3110 /* This routine will generate the correct assembly data for a location
3111 description based on a cfi entry with a complex address. */
3114 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
3116 dw_loc_descr_ref loc;
3119 if (cfi->dw_cfi_opc == DW_CFA_expression)
3122 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3123 dw2_asm_output_data (1, r, NULL);
3124 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
3127 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3129 /* Output the size of the block. */
3130 size = size_of_locs (loc);
3131 dw2_asm_output_data_uleb128 (size, NULL);
3133 /* Now output the operations themselves. */
3134 output_loc_sequence (loc, for_eh);
3137 /* Similar, but used for .cfi_escape. */
3140 output_cfa_loc_raw (dw_cfi_ref cfi)
3142 dw_loc_descr_ref loc;
3145 if (cfi->dw_cfi_opc == DW_CFA_expression)
3148 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3149 fprintf (asm_out_file, "%#x,", r);
3150 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
3153 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3155 /* Output the size of the block. */
3156 size = size_of_locs (loc);
3157 dw2_asm_output_data_uleb128_raw (size);
3158 fputc (',', asm_out_file);
3160 /* Now output the operations themselves. */
3161 output_loc_sequence_raw (loc);
3164 /* This function builds a dwarf location descriptor sequence from a
3165 dw_cfa_location, adding the given OFFSET to the result of the
3168 struct dw_loc_descr_struct *
3169 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3171 struct dw_loc_descr_struct *head, *tmp;
3173 offset += cfa->offset;
3177 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
3178 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3179 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3180 add_loc_descr (&head, tmp);
3183 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3184 add_loc_descr (&head, tmp);
3188 head = new_reg_loc_descr (cfa->reg, offset);
3193 /* This function builds a dwarf location descriptor sequence for
3194 the address at OFFSET from the CFA when stack is aligned to
3197 struct dw_loc_descr_struct *
3198 build_cfa_aligned_loc (dw_cfa_location *cfa,
3199 HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
3201 struct dw_loc_descr_struct *head;
3202 unsigned int dwarf_fp
3203 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
3205 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
3206 if (cfa->reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
3208 head = new_reg_loc_descr (dwarf_fp, 0);
3209 add_loc_descr (&head, int_loc_descriptor (alignment));
3210 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
3211 loc_descr_plus_const (&head, offset);
3214 head = new_reg_loc_descr (dwarf_fp, offset);
3218 /* And now, the support for symbolic debugging information. */
3220 /* .debug_str support. */
3221 static int output_indirect_string (void **, void *);
3223 static void dwarf2out_init (const char *);
3224 static void dwarf2out_finish (const char *);
3225 static void dwarf2out_assembly_start (void);
3226 static void dwarf2out_define (unsigned int, const char *);
3227 static void dwarf2out_undef (unsigned int, const char *);
3228 static void dwarf2out_start_source_file (unsigned, const char *);
3229 static void dwarf2out_end_source_file (unsigned);
3230 static void dwarf2out_function_decl (tree);
3231 static void dwarf2out_begin_block (unsigned, unsigned);
3232 static void dwarf2out_end_block (unsigned, unsigned);
3233 static bool dwarf2out_ignore_block (const_tree);
3234 static void dwarf2out_global_decl (tree);
3235 static void dwarf2out_type_decl (tree, int);
3236 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
3237 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
3239 static void dwarf2out_abstract_function (tree);
3240 static void dwarf2out_var_location (rtx);
3241 static void dwarf2out_begin_function (tree);
3242 static void dwarf2out_set_name (tree, tree);
3244 /* The debug hooks structure. */
3246 const struct gcc_debug_hooks dwarf2_debug_hooks =
3250 dwarf2out_assembly_start,
3253 dwarf2out_start_source_file,
3254 dwarf2out_end_source_file,
3255 dwarf2out_begin_block,
3256 dwarf2out_end_block,
3257 dwarf2out_ignore_block,
3258 dwarf2out_source_line,
3259 dwarf2out_begin_prologue,
3260 #if VMS_DEBUGGING_INFO
3261 dwarf2out_vms_end_prologue,
3262 dwarf2out_vms_begin_epilogue,
3264 debug_nothing_int_charstar,
3265 debug_nothing_int_charstar,
3267 dwarf2out_end_epilogue,
3268 dwarf2out_begin_function,
3269 debug_nothing_int, /* end_function */
3270 dwarf2out_function_decl, /* function_decl */
3271 dwarf2out_global_decl,
3272 dwarf2out_type_decl, /* type_decl */
3273 dwarf2out_imported_module_or_decl,
3274 debug_nothing_tree, /* deferred_inline_function */
3275 /* The DWARF 2 backend tries to reduce debugging bloat by not
3276 emitting the abstract description of inline functions until
3277 something tries to reference them. */
3278 dwarf2out_abstract_function, /* outlining_inline_function */
3279 debug_nothing_rtx, /* label */
3280 debug_nothing_int, /* handle_pch */
3281 dwarf2out_var_location,
3282 dwarf2out_switch_text_section,
3284 1, /* start_end_main_source_file */
3285 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
3288 /* NOTE: In the comments in this file, many references are made to
3289 "Debugging Information Entries". This term is abbreviated as `DIE'
3290 throughout the remainder of this file. */
3292 /* An internal representation of the DWARF output is built, and then
3293 walked to generate the DWARF debugging info. The walk of the internal
3294 representation is done after the entire program has been compiled.
3295 The types below are used to describe the internal representation. */
3297 /* Whether to put type DIEs into their own section .debug_types instead
3298 of making them part of the .debug_info section. Only supported for
3299 Dwarf V4 or higher and the user didn't disable them through
3300 -fno-debug-types-section. It is more efficient to put them in a
3301 separate comdat sections since the linker will then be able to
3302 remove duplicates. But not all tools support .debug_types sections
3305 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
3307 /* Various DIE's use offsets relative to the beginning of the
3308 .debug_info section to refer to each other. */
3310 typedef long int dw_offset;
3312 /* Define typedefs here to avoid circular dependencies. */
3314 typedef struct dw_attr_struct *dw_attr_ref;
3315 typedef struct dw_line_info_struct *dw_line_info_ref;
3316 typedef struct pubname_struct *pubname_ref;
3317 typedef struct dw_ranges_struct *dw_ranges_ref;
3318 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
3319 typedef struct comdat_type_struct *comdat_type_node_ref;
3321 /* The entries in the line_info table more-or-less mirror the opcodes
3322 that are used in the real dwarf line table. Arrays of these entries
3323 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
3326 enum dw_line_info_opcode {
3327 /* Emit DW_LNE_set_address; the operand is the label index. */
3330 /* Emit a row to the matrix with the given line. This may be done
3331 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
3335 /* Emit a DW_LNS_set_file. */
3338 /* Emit a DW_LNS_set_column. */
3341 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
3344 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
3345 LI_set_prologue_end,
3346 LI_set_epilogue_begin,
3348 /* Emit a DW_LNE_set_discriminator. */
3349 LI_set_discriminator
3352 typedef struct GTY(()) dw_line_info_struct {
3353 enum dw_line_info_opcode opcode;
3355 } dw_line_info_entry;
3357 DEF_VEC_O(dw_line_info_entry);
3358 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
3360 typedef struct GTY(()) dw_line_info_table_struct {
3361 /* The label that marks the end of this section. */
3362 const char *end_label;
3364 /* The values for the last row of the matrix, as collected in the table.
3365 These are used to minimize the changes to the next row. */
3366 unsigned int file_num;
3367 unsigned int line_num;
3368 unsigned int column_num;
3373 VEC(dw_line_info_entry, gc) *entries;
3374 } dw_line_info_table;
3376 typedef dw_line_info_table *dw_line_info_table_p;
3378 DEF_VEC_P(dw_line_info_table_p);
3379 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
3381 /* Each DIE attribute has a field specifying the attribute kind,
3382 a link to the next attribute in the chain, and an attribute value.
3383 Attributes are typically linked below the DIE they modify. */
3385 typedef struct GTY(()) dw_attr_struct {
3386 enum dwarf_attribute dw_attr;
3387 dw_val_node dw_attr_val;
3391 DEF_VEC_O(dw_attr_node);
3392 DEF_VEC_ALLOC_O(dw_attr_node,gc);
3394 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3395 The children of each node form a circular list linked by
3396 die_sib. die_child points to the node *before* the "first" child node. */
3398 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
3399 union die_symbol_or_type_node
3401 char * GTY ((tag ("0"))) die_symbol;
3402 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
3404 GTY ((desc ("use_debug_types"))) die_id;
3405 VEC(dw_attr_node,gc) * die_attr;
3406 dw_die_ref die_parent;
3407 dw_die_ref die_child;
3409 dw_die_ref die_definition; /* ref from a specification to its definition */
3410 dw_offset die_offset;
3411 unsigned long die_abbrev;
3413 /* Die is used and must not be pruned as unused. */
3414 int die_perennial_p;
3415 unsigned int decl_id;
3416 enum dwarf_tag die_tag;
3420 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3421 #define FOR_EACH_CHILD(die, c, expr) do { \
3422 c = die->die_child; \
3426 } while (c != die->die_child); \
3429 /* The pubname structure */
3431 typedef struct GTY(()) pubname_struct {
3437 DEF_VEC_O(pubname_entry);
3438 DEF_VEC_ALLOC_O(pubname_entry, gc);
3440 struct GTY(()) dw_ranges_struct {
3441 /* If this is positive, it's a block number, otherwise it's a
3442 bitwise-negated index into dw_ranges_by_label. */
3446 /* A structure to hold a macinfo entry. */
3448 typedef struct GTY(()) macinfo_struct {
3449 unsigned HOST_WIDE_INT code;
3450 unsigned HOST_WIDE_INT lineno;
3455 DEF_VEC_O(macinfo_entry);
3456 DEF_VEC_ALLOC_O(macinfo_entry, gc);
3458 struct GTY(()) dw_ranges_by_label_struct {
3463 /* The comdat type node structure. */
3464 typedef struct GTY(()) comdat_type_struct
3466 dw_die_ref root_die;
3467 dw_die_ref type_die;
3468 char signature[DWARF_TYPE_SIGNATURE_SIZE];
3469 struct comdat_type_struct *next;
3473 /* The limbo die list structure. */
3474 typedef struct GTY(()) limbo_die_struct {
3477 struct limbo_die_struct *next;
3481 typedef struct skeleton_chain_struct
3485 struct skeleton_chain_struct *parent;
3487 skeleton_chain_node;
3489 /* How to start an assembler comment. */
3490 #ifndef ASM_COMMENT_START
3491 #define ASM_COMMENT_START ";#"
3494 /* Define a macro which returns nonzero for a TYPE_DECL which was
3495 implicitly generated for a type.
3497 Note that, unlike the C front-end (which generates a NULL named
3498 TYPE_DECL node for each complete tagged type, each array type,
3499 and each function type node created) the C++ front-end generates
3500 a _named_ TYPE_DECL node for each tagged type node created.
3501 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3502 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3503 front-end, but for each type, tagged or not. */
3505 #define TYPE_DECL_IS_STUB(decl) \
3506 (DECL_NAME (decl) == NULL_TREE \
3507 || (DECL_ARTIFICIAL (decl) \
3508 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3509 /* This is necessary for stub decls that \
3510 appear in nested inline functions. */ \
3511 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3512 && (decl_ultimate_origin (decl) \
3513 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3515 /* Information concerning the compilation unit's programming
3516 language, and compiler version. */
3518 /* Fixed size portion of the DWARF compilation unit header. */
3519 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3520 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3522 /* Fixed size portion of the DWARF comdat type unit header. */
3523 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3524 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
3525 + DWARF_OFFSET_SIZE)
3527 /* Fixed size portion of public names info. */
3528 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3530 /* Fixed size portion of the address range info. */
3531 #define DWARF_ARANGES_HEADER_SIZE \
3532 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3533 DWARF2_ADDR_SIZE * 2) \
3534 - DWARF_INITIAL_LENGTH_SIZE)
3536 /* Size of padding portion in the address range info. It must be
3537 aligned to twice the pointer size. */
3538 #define DWARF_ARANGES_PAD_SIZE \
3539 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3540 DWARF2_ADDR_SIZE * 2) \
3541 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3543 /* Use assembler line directives if available. */
3544 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3545 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3546 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3548 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3552 /* Minimum line offset in a special line info. opcode.
3553 This value was chosen to give a reasonable range of values. */
3554 #define DWARF_LINE_BASE -10
3556 /* First special line opcode - leave room for the standard opcodes. */
3557 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3559 /* Range of line offsets in a special line info. opcode. */
3560 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3562 /* Flag that indicates the initial value of the is_stmt_start flag.
3563 In the present implementation, we do not mark any lines as
3564 the beginning of a source statement, because that information
3565 is not made available by the GCC front-end. */
3566 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3568 /* Maximum number of operations per instruction bundle. */
3569 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3570 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3573 /* This location is used by calc_die_sizes() to keep track
3574 the offset of each DIE within the .debug_info section. */
3575 static unsigned long next_die_offset;
3577 /* Record the root of the DIE's built for the current compilation unit. */
3578 static GTY(()) dw_die_ref single_comp_unit_die;
3580 /* A list of type DIEs that have been separated into comdat sections. */
3581 static GTY(()) comdat_type_node *comdat_type_list;
3583 /* A list of DIEs with a NULL parent waiting to be relocated. */
3584 static GTY(()) limbo_die_node *limbo_die_list;
3586 /* A list of DIEs for which we may have to generate
3587 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3588 static GTY(()) limbo_die_node *deferred_asm_name;
3590 /* Filenames referenced by this compilation unit. */
3591 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
3593 /* A hash table of references to DIE's that describe declarations.
3594 The key is a DECL_UID() which is a unique number identifying each decl. */
3595 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3597 /* A hash table of references to DIE's that describe COMMON blocks.
3598 The key is DECL_UID() ^ die_parent. */
3599 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
3601 typedef struct GTY(()) die_arg_entry_struct {
3606 DEF_VEC_O(die_arg_entry);
3607 DEF_VEC_ALLOC_O(die_arg_entry,gc);
3609 /* Node of the variable location list. */
3610 struct GTY ((chain_next ("%h.next"))) var_loc_node {
3611 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3612 EXPR_LIST chain. For small bitsizes, bitsize is encoded
3613 in mode of the EXPR_LIST node and first EXPR_LIST operand
3614 is either NOTE_INSN_VAR_LOCATION for a piece with a known
3615 location or NULL for padding. For larger bitsizes,
3616 mode is 0 and first operand is a CONCAT with bitsize
3617 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3618 NULL as second operand. */
3620 const char * GTY (()) label;
3621 struct var_loc_node * GTY (()) next;
3624 /* Variable location list. */
3625 struct GTY (()) var_loc_list_def {
3626 struct var_loc_node * GTY (()) first;
3628 /* Pointer to the last but one or last element of the
3629 chained list. If the list is empty, both first and
3630 last are NULL, if the list contains just one node
3631 or the last node certainly is not redundant, it points
3632 to the last node, otherwise points to the last but one.
3633 Do not mark it for GC because it is marked through the chain. */
3634 struct var_loc_node * GTY ((skip ("%h"))) last;
3636 /* Pointer to the last element before section switch,
3637 if NULL, either sections weren't switched or first
3638 is after section switch. */
3639 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
3641 /* DECL_UID of the variable decl. */
3642 unsigned int decl_id;
3644 typedef struct var_loc_list_def var_loc_list;
3646 /* Call argument location list. */
3647 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
3648 rtx GTY (()) call_arg_loc_note;
3649 const char * GTY (()) label;
3650 tree GTY (()) block;
3652 rtx GTY (()) symbol_ref;
3653 struct call_arg_loc_node * GTY (()) next;
3657 /* Table of decl location linked lists. */
3658 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3660 /* Head and tail of call_arg_loc chain. */
3661 static GTY (()) struct call_arg_loc_node *call_arg_locations;
3662 static struct call_arg_loc_node *call_arg_loc_last;
3664 /* Number of call sites in the current function. */
3665 static int call_site_count = -1;
3666 /* Number of tail call sites in the current function. */
3667 static int tail_call_site_count = -1;
3669 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
3671 static VEC (dw_die_ref, heap) *block_map;
3673 /* A cached location list. */
3674 struct GTY (()) cached_dw_loc_list_def {
3675 /* The DECL_UID of the decl that this entry describes. */
3676 unsigned int decl_id;
3678 /* The cached location list. */
3679 dw_loc_list_ref loc_list;
3681 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
3683 /* Table of cached location lists. */
3684 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
3686 /* A pointer to the base of a list of references to DIE's that
3687 are uniquely identified by their tag, presence/absence of
3688 children DIE's, and list of attribute/value pairs. */
3689 static GTY((length ("abbrev_die_table_allocated")))
3690 dw_die_ref *abbrev_die_table;
3692 /* Number of elements currently allocated for abbrev_die_table. */
3693 static GTY(()) unsigned abbrev_die_table_allocated;
3695 /* Number of elements in type_die_table currently in use. */
3696 static GTY(()) unsigned abbrev_die_table_in_use;
3698 /* Size (in elements) of increments by which we may expand the
3699 abbrev_die_table. */
3700 #define ABBREV_DIE_TABLE_INCREMENT 256
3702 /* A global counter for generating labels for line number data. */
3703 static unsigned int line_info_label_num;
3705 /* The current table to which we should emit line number information
3706 for the current function. This will be set up at the beginning of
3707 assembly for the function. */
3708 static dw_line_info_table *cur_line_info_table;
3710 /* The two default tables of line number info. */
3711 static GTY(()) dw_line_info_table *text_section_line_info;
3712 static GTY(()) dw_line_info_table *cold_text_section_line_info;
3714 /* The set of all non-default tables of line number info. */
3715 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
3717 /* A flag to tell pubnames/types export if there is an info section to
3719 static bool info_section_emitted;
3721 /* A pointer to the base of a table that contains a list of publicly
3722 accessible names. */
3723 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
3725 /* A pointer to the base of a table that contains a list of publicly
3726 accessible types. */
3727 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
3729 /* A pointer to the base of a table that contains a list of macro
3730 defines/undefines (and file start/end markers). */
3731 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
3733 /* Array of dies for which we should generate .debug_ranges info. */
3734 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3736 /* Number of elements currently allocated for ranges_table. */
3737 static GTY(()) unsigned ranges_table_allocated;
3739 /* Number of elements in ranges_table currently in use. */
3740 static GTY(()) unsigned ranges_table_in_use;
3742 /* Array of pairs of labels referenced in ranges_table. */
3743 static GTY ((length ("ranges_by_label_allocated")))
3744 dw_ranges_by_label_ref ranges_by_label;
3746 /* Number of elements currently allocated for ranges_by_label. */
3747 static GTY(()) unsigned ranges_by_label_allocated;
3749 /* Number of elements in ranges_by_label currently in use. */
3750 static GTY(()) unsigned ranges_by_label_in_use;
3752 /* Size (in elements) of increments by which we may expand the
3754 #define RANGES_TABLE_INCREMENT 64
3756 /* Whether we have location lists that need outputting */
3757 static GTY(()) bool have_location_lists;
3759 /* Unique label counter. */
3760 static GTY(()) unsigned int loclabel_num;
3762 /* Unique label counter for point-of-call tables. */
3763 static GTY(()) unsigned int poc_label_num;
3765 /* Record whether the function being analyzed contains inlined functions. */
3766 static int current_function_has_inlines;
3768 /* The last file entry emitted by maybe_emit_file(). */
3769 static GTY(()) struct dwarf_file_data * last_emitted_file;
3771 /* Number of internal labels generated by gen_internal_sym(). */
3772 static GTY(()) int label_num;
3774 /* Cached result of previous call to lookup_filename. */
3775 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
3777 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
3779 /* Instances of generic types for which we need to generate debug
3780 info that describe their generic parameters and arguments. That
3781 generation needs to happen once all types are properly laid out so
3782 we do it at the end of compilation. */
3783 static GTY(()) VEC(tree,gc) *generic_type_instances;
3785 /* Offset from the "steady-state frame pointer" to the frame base,
3786 within the current function. */
3787 static HOST_WIDE_INT frame_pointer_fb_offset;
3788 static bool frame_pointer_fb_offset_valid;
3790 static VEC (dw_die_ref, heap) *base_types;
3792 /* Forward declarations for functions defined in this file. */
3794 static int is_pseudo_reg (const_rtx);
3795 static tree type_main_variant (tree);
3796 static int is_tagged_type (const_tree);
3797 static const char *dwarf_tag_name (unsigned);
3798 static const char *dwarf_attr_name (unsigned);
3799 static const char *dwarf_form_name (unsigned);
3800 static tree decl_ultimate_origin (const_tree);
3801 static tree decl_class_context (tree);
3802 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3803 static inline enum dw_val_class AT_class (dw_attr_ref);
3804 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3805 static inline unsigned AT_flag (dw_attr_ref);
3806 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3807 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3808 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3809 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3810 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3811 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3812 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3813 unsigned int, unsigned char *);
3814 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3815 static hashval_t debug_str_do_hash (const void *);
3816 static int debug_str_eq (const void *, const void *);
3817 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3818 static inline const char *AT_string (dw_attr_ref);
3819 static enum dwarf_form AT_string_form (dw_attr_ref);
3820 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3821 static void add_AT_specification (dw_die_ref, dw_die_ref);
3822 static inline dw_die_ref AT_ref (dw_attr_ref);
3823 static inline int AT_ref_external (dw_attr_ref);
3824 static inline void set_AT_ref_external (dw_attr_ref, int);
3825 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3826 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3827 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3828 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3830 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3831 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3832 static inline rtx AT_addr (dw_attr_ref);
3833 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3834 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3835 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3836 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3837 unsigned HOST_WIDE_INT);
3838 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3840 static inline const char *AT_lbl (dw_attr_ref);
3841 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3842 static const char *get_AT_low_pc (dw_die_ref);
3843 static const char *get_AT_hi_pc (dw_die_ref);
3844 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3845 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3846 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3847 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3848 static bool is_cxx (void);
3849 static bool is_fortran (void);
3850 static bool is_ada (void);
3851 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3852 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3853 static void add_child_die (dw_die_ref, dw_die_ref);
3854 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3855 static dw_die_ref lookup_type_die (tree);
3856 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3857 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3858 static void equate_type_number_to_die (tree, dw_die_ref);
3859 static hashval_t decl_die_table_hash (const void *);
3860 static int decl_die_table_eq (const void *, const void *);
3861 static dw_die_ref lookup_decl_die (tree);
3862 static hashval_t common_block_die_table_hash (const void *);
3863 static int common_block_die_table_eq (const void *, const void *);
3864 static hashval_t decl_loc_table_hash (const void *);
3865 static int decl_loc_table_eq (const void *, const void *);
3866 static var_loc_list *lookup_decl_loc (const_tree);
3867 static void equate_decl_number_to_die (tree, dw_die_ref);
3868 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
3869 static void print_spaces (FILE *);
3870 static void print_die (dw_die_ref, FILE *);
3871 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3872 static dw_die_ref pop_compile_unit (dw_die_ref);
3873 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3874 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3875 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3876 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3877 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3878 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3879 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
3880 struct md5_ctx *, int *);
3881 struct checksum_attributes;
3882 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3883 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3884 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3885 static void generate_type_signature (dw_die_ref, comdat_type_node *);
3886 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3887 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3888 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3889 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3890 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3891 static void compute_section_prefix (dw_die_ref);
3892 static int is_type_die (dw_die_ref);
3893 static int is_comdat_die (dw_die_ref);
3894 static int is_symbol_die (dw_die_ref);
3895 static void assign_symbol_names (dw_die_ref);
3896 static void break_out_includes (dw_die_ref);
3897 static int is_declaration_die (dw_die_ref);
3898 static int should_move_die_to_comdat (dw_die_ref);
3899 static dw_die_ref clone_as_declaration (dw_die_ref);
3900 static dw_die_ref clone_die (dw_die_ref);
3901 static dw_die_ref clone_tree (dw_die_ref);
3902 static void copy_declaration_context (dw_die_ref, dw_die_ref);
3903 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3904 static void generate_skeleton_bottom_up (skeleton_chain_node *);
3905 static dw_die_ref generate_skeleton (dw_die_ref);
3906 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3908 static void break_out_comdat_types (dw_die_ref);
3909 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
3910 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
3911 static void copy_decls_for_unworthy_types (dw_die_ref);
3913 static hashval_t htab_cu_hash (const void *);
3914 static int htab_cu_eq (const void *, const void *);
3915 static void htab_cu_del (void *);
3916 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3917 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3918 static void add_sibling_attributes (dw_die_ref);
3919 static void build_abbrev_table (dw_die_ref);
3920 static void output_location_lists (dw_die_ref);
3921 static int constant_size (unsigned HOST_WIDE_INT);
3922 static unsigned long size_of_die (dw_die_ref);
3923 static void calc_die_sizes (dw_die_ref);
3924 static void calc_base_type_die_sizes (void);
3925 static void mark_dies (dw_die_ref);
3926 static void unmark_dies (dw_die_ref);
3927 static void unmark_all_dies (dw_die_ref);
3928 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
3929 static unsigned long size_of_aranges (void);
3930 static enum dwarf_form value_format (dw_attr_ref);
3931 static void output_value_format (dw_attr_ref);
3932 static void output_abbrev_section (void);
3933 static void output_die_symbol (dw_die_ref);
3934 static void output_die (dw_die_ref);
3935 static void output_compilation_unit_header (void);
3936 static void output_comp_unit (dw_die_ref, int);
3937 static void output_comdat_type_unit (comdat_type_node *);
3938 static const char *dwarf2_name (tree, int);
3939 static void add_pubname (tree, dw_die_ref);
3940 static void add_pubname_string (const char *, dw_die_ref);
3941 static void add_pubtype (tree, dw_die_ref);
3942 static void output_pubnames (VEC (pubname_entry,gc) *);
3943 static void output_aranges (unsigned long);
3944 static unsigned int add_ranges_num (int);
3945 static unsigned int add_ranges (const_tree);
3946 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3948 static void output_ranges (void);
3949 static dw_line_info_table *new_line_info_table (void);
3950 static void output_line_info (void);
3951 static void output_file_names (void);
3952 static dw_die_ref base_type_die (tree);
3953 static int is_base_type (tree);
3954 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
3955 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3956 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3957 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3958 static int type_is_enum (const_tree);
3959 static unsigned int dbx_reg_number (const_rtx);
3960 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3961 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3962 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3963 enum var_init_status);
3964 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3965 enum var_init_status);
3966 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
3967 enum var_init_status);
3968 static int is_based_loc (const_rtx);
3969 static int resolve_one_addr (rtx *, void *);
3970 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3971 enum var_init_status);
3972 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
3973 enum var_init_status);
3974 static dw_loc_list_ref loc_list_from_tree (tree, int);
3975 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3976 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3977 static tree field_type (const_tree);
3978 static unsigned int simple_type_align_in_bits (const_tree);
3979 static unsigned int simple_decl_align_in_bits (const_tree);
3980 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3981 static HOST_WIDE_INT field_byte_offset (const_tree);
3982 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3984 static void add_data_member_location_attribute (dw_die_ref, tree);
3985 static bool add_const_value_attribute (dw_die_ref, rtx);
3986 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3987 static void insert_double (double_int, unsigned char *);
3988 static void insert_float (const_rtx, unsigned char *);
3989 static rtx rtl_for_decl_location (tree);
3990 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
3991 enum dwarf_attribute);
3992 static bool tree_add_const_value_attribute (dw_die_ref, tree);
3993 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3994 static void add_name_attribute (dw_die_ref, const char *);
3995 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3996 static void add_comp_dir_attribute (dw_die_ref);
3997 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3998 static void add_subscript_info (dw_die_ref, tree, bool);
3999 static void add_byte_size_attribute (dw_die_ref, tree);
4000 static void add_bit_offset_attribute (dw_die_ref, tree);
4001 static void add_bit_size_attribute (dw_die_ref, tree);
4002 static void add_prototyped_attribute (dw_die_ref, tree);
4003 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
4004 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4005 static void add_src_coords_attributes (dw_die_ref, tree);
4006 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4007 static void push_decl_scope (tree);
4008 static void pop_decl_scope (void);
4009 static dw_die_ref scope_die_for (tree, dw_die_ref);
4010 static inline int local_scope_p (dw_die_ref);
4011 static inline int class_scope_p (dw_die_ref);
4012 static inline int class_or_namespace_scope_p (dw_die_ref);
4013 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4014 static void add_calling_convention_attribute (dw_die_ref, tree);
4015 static const char *type_tag (const_tree);
4016 static tree member_declared_type (const_tree);
4018 static const char *decl_start_label (tree);
4020 static void gen_array_type_die (tree, dw_die_ref);
4021 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
4023 static void gen_entry_point_die (tree, dw_die_ref);
4025 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4026 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
4027 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
4028 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4029 static void gen_formal_types_die (tree, dw_die_ref);
4030 static void gen_subprogram_die (tree, dw_die_ref);
4031 static void gen_variable_die (tree, tree, dw_die_ref);
4032 static void gen_const_die (tree, dw_die_ref);
4033 static void gen_label_die (tree, dw_die_ref);
4034 static void gen_lexical_block_die (tree, dw_die_ref, int);
4035 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4036 static void gen_field_die (tree, dw_die_ref);
4037 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4038 static dw_die_ref gen_compile_unit_die (const char *);
4039 static void gen_inheritance_die (tree, tree, dw_die_ref);
4040 static void gen_member_die (tree, dw_die_ref);
4041 static void gen_struct_or_union_type_die (tree, dw_die_ref,
4042 enum debug_info_usage);
4043 static void gen_subroutine_type_die (tree, dw_die_ref);
4044 static void gen_typedef_die (tree, dw_die_ref);
4045 static void gen_type_die (tree, dw_die_ref);
4046 static void gen_block_die (tree, dw_die_ref, int);
4047 static void decls_for_scope (tree, dw_die_ref, int);
4048 static inline int is_redundant_typedef (const_tree);
4049 static bool is_naming_typedef_decl (const_tree);
4050 static inline dw_die_ref get_context_die (tree);
4051 static void gen_namespace_die (tree, dw_die_ref);
4052 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
4053 static dw_die_ref force_decl_die (tree);
4054 static dw_die_ref force_type_die (tree);
4055 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4056 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
4057 static struct dwarf_file_data * lookup_filename (const char *);
4058 static void retry_incomplete_types (void);
4059 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4060 static void gen_generic_params_dies (tree);
4061 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
4062 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
4063 static void splice_child_die (dw_die_ref, dw_die_ref);
4064 static int file_info_cmp (const void *, const void *);
4065 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4066 const char *, const char *);
4067 static void output_loc_list (dw_loc_list_ref);
4068 static char *gen_internal_sym (const char *);
4070 static void prune_unmark_dies (dw_die_ref);
4071 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
4072 static void prune_unused_types_mark (dw_die_ref, int);
4073 static void prune_unused_types_walk (dw_die_ref);
4074 static void prune_unused_types_walk_attribs (dw_die_ref);
4075 static void prune_unused_types_prune (dw_die_ref);
4076 static void prune_unused_types (void);
4077 static int maybe_emit_file (struct dwarf_file_data *fd);
4078 static inline const char *AT_vms_delta1 (dw_attr_ref);
4079 static inline const char *AT_vms_delta2 (dw_attr_ref);
4080 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
4081 const char *, const char *);
4082 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
4083 static void gen_remaining_tmpl_value_param_die_attribute (void);
4084 static bool generic_type_p (tree);
4085 static void schedule_generic_params_dies_gen (tree t);
4086 static void gen_scheduled_generic_parms_dies (void);
4088 /* Section names used to hold DWARF debugging information. */
4089 #ifndef DEBUG_INFO_SECTION
4090 #define DEBUG_INFO_SECTION ".debug_info"
4092 #ifndef DEBUG_ABBREV_SECTION
4093 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4095 #ifndef DEBUG_ARANGES_SECTION
4096 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4098 #ifndef DEBUG_MACINFO_SECTION
4099 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4101 #ifndef DEBUG_LINE_SECTION
4102 #define DEBUG_LINE_SECTION ".debug_line"
4104 #ifndef DEBUG_LOC_SECTION
4105 #define DEBUG_LOC_SECTION ".debug_loc"
4107 #ifndef DEBUG_PUBNAMES_SECTION
4108 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4110 #ifndef DEBUG_PUBTYPES_SECTION
4111 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
4113 #ifndef DEBUG_STR_SECTION
4114 #define DEBUG_STR_SECTION ".debug_str"
4116 #ifndef DEBUG_RANGES_SECTION
4117 #define DEBUG_RANGES_SECTION ".debug_ranges"
4120 /* Standard ELF section names for compiled code and data. */
4121 #ifndef TEXT_SECTION_NAME
4122 #define TEXT_SECTION_NAME ".text"
4125 /* Section flags for .debug_str section. */
4126 #define DEBUG_STR_SECTION_FLAGS \
4127 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4128 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4131 /* Labels we insert at beginning sections we can reference instead of
4132 the section names themselves. */
4134 #ifndef TEXT_SECTION_LABEL
4135 #define TEXT_SECTION_LABEL "Ltext"
4137 #ifndef COLD_TEXT_SECTION_LABEL
4138 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4140 #ifndef DEBUG_LINE_SECTION_LABEL
4141 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4143 #ifndef DEBUG_INFO_SECTION_LABEL
4144 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4146 #ifndef DEBUG_ABBREV_SECTION_LABEL
4147 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4149 #ifndef DEBUG_LOC_SECTION_LABEL
4150 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4152 #ifndef DEBUG_RANGES_SECTION_LABEL
4153 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4155 #ifndef DEBUG_MACINFO_SECTION_LABEL
4156 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4160 /* Definitions of defaults for formats and names of various special
4161 (artificial) labels which may be generated within this file (when the -g
4162 options is used and DWARF2_DEBUGGING_INFO is in effect.
4163 If necessary, these may be overridden from within the tm.h file, but
4164 typically, overriding these defaults is unnecessary. */
4166 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4167 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4168 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4169 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4170 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4171 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4172 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4173 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4174 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4175 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4177 #ifndef TEXT_END_LABEL
4178 #define TEXT_END_LABEL "Letext"
4180 #ifndef COLD_END_LABEL
4181 #define COLD_END_LABEL "Letext_cold"
4183 #ifndef BLOCK_BEGIN_LABEL
4184 #define BLOCK_BEGIN_LABEL "LBB"
4186 #ifndef BLOCK_END_LABEL
4187 #define BLOCK_END_LABEL "LBE"
4189 #ifndef LINE_CODE_LABEL
4190 #define LINE_CODE_LABEL "LM"
4194 /* Return the root of the DIE's built for the current compilation unit. */
4196 comp_unit_die (void)
4198 if (!single_comp_unit_die)
4199 single_comp_unit_die = gen_compile_unit_die (NULL);
4200 return single_comp_unit_die;
4203 /* We allow a language front-end to designate a function that is to be
4204 called to "demangle" any name before it is put into a DIE. */
4206 static const char *(*demangle_name_func) (const char *);
4209 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4211 demangle_name_func = func;
4214 /* Test if rtl node points to a pseudo register. */
4217 is_pseudo_reg (const_rtx rtl)
4219 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4220 || (GET_CODE (rtl) == SUBREG
4221 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4224 /* Return a reference to a type, with its const and volatile qualifiers
4228 type_main_variant (tree type)
4230 type = TYPE_MAIN_VARIANT (type);
4232 /* ??? There really should be only one main variant among any group of
4233 variants of a given type (and all of the MAIN_VARIANT values for all
4234 members of the group should point to that one type) but sometimes the C
4235 front-end messes this up for array types, so we work around that bug
4237 if (TREE_CODE (type) == ARRAY_TYPE)
4238 while (type != TYPE_MAIN_VARIANT (type))
4239 type = TYPE_MAIN_VARIANT (type);
4244 /* Return nonzero if the given type node represents a tagged type. */
4247 is_tagged_type (const_tree type)
4249 enum tree_code code = TREE_CODE (type);
4251 return (code == RECORD_TYPE || code == UNION_TYPE
4252 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4255 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
4258 get_ref_die_offset_label (char *label, dw_die_ref ref)
4260 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
4263 /* Return die_offset of a DIE reference to a base type. */
4265 static unsigned long int
4266 get_base_type_offset (dw_die_ref ref)
4268 if (ref->die_offset)
4269 return ref->die_offset;
4270 if (comp_unit_die ()->die_abbrev)
4272 calc_base_type_die_sizes ();
4273 gcc_assert (ref->die_offset);
4275 return ref->die_offset;
4278 /* Return die_offset of a DIE reference other than base type. */
4280 static unsigned long int
4281 get_ref_die_offset (dw_die_ref ref)
4283 gcc_assert (ref->die_offset);
4284 return ref->die_offset;
4287 /* Convert a DIE tag into its string name. */
4290 dwarf_tag_name (unsigned int tag)
4294 case DW_TAG_padding:
4295 return "DW_TAG_padding";
4296 case DW_TAG_array_type:
4297 return "DW_TAG_array_type";
4298 case DW_TAG_class_type:
4299 return "DW_TAG_class_type";
4300 case DW_TAG_entry_point:
4301 return "DW_TAG_entry_point";
4302 case DW_TAG_enumeration_type:
4303 return "DW_TAG_enumeration_type";
4304 case DW_TAG_formal_parameter:
4305 return "DW_TAG_formal_parameter";
4306 case DW_TAG_imported_declaration:
4307 return "DW_TAG_imported_declaration";
4309 return "DW_TAG_label";
4310 case DW_TAG_lexical_block:
4311 return "DW_TAG_lexical_block";
4313 return "DW_TAG_member";
4314 case DW_TAG_pointer_type:
4315 return "DW_TAG_pointer_type";
4316 case DW_TAG_reference_type:
4317 return "DW_TAG_reference_type";
4318 case DW_TAG_compile_unit:
4319 return "DW_TAG_compile_unit";
4320 case DW_TAG_string_type:
4321 return "DW_TAG_string_type";
4322 case DW_TAG_structure_type:
4323 return "DW_TAG_structure_type";
4324 case DW_TAG_subroutine_type:
4325 return "DW_TAG_subroutine_type";
4326 case DW_TAG_typedef:
4327 return "DW_TAG_typedef";
4328 case DW_TAG_union_type:
4329 return "DW_TAG_union_type";
4330 case DW_TAG_unspecified_parameters:
4331 return "DW_TAG_unspecified_parameters";
4332 case DW_TAG_variant:
4333 return "DW_TAG_variant";
4334 case DW_TAG_common_block:
4335 return "DW_TAG_common_block";
4336 case DW_TAG_common_inclusion:
4337 return "DW_TAG_common_inclusion";
4338 case DW_TAG_inheritance:
4339 return "DW_TAG_inheritance";
4340 case DW_TAG_inlined_subroutine:
4341 return "DW_TAG_inlined_subroutine";
4343 return "DW_TAG_module";
4344 case DW_TAG_ptr_to_member_type:
4345 return "DW_TAG_ptr_to_member_type";
4346 case DW_TAG_set_type:
4347 return "DW_TAG_set_type";
4348 case DW_TAG_subrange_type:
4349 return "DW_TAG_subrange_type";
4350 case DW_TAG_with_stmt:
4351 return "DW_TAG_with_stmt";
4352 case DW_TAG_access_declaration:
4353 return "DW_TAG_access_declaration";
4354 case DW_TAG_base_type:
4355 return "DW_TAG_base_type";
4356 case DW_TAG_catch_block:
4357 return "DW_TAG_catch_block";
4358 case DW_TAG_const_type:
4359 return "DW_TAG_const_type";
4360 case DW_TAG_constant:
4361 return "DW_TAG_constant";
4362 case DW_TAG_enumerator:
4363 return "DW_TAG_enumerator";
4364 case DW_TAG_file_type:
4365 return "DW_TAG_file_type";
4367 return "DW_TAG_friend";
4368 case DW_TAG_namelist:
4369 return "DW_TAG_namelist";
4370 case DW_TAG_namelist_item:
4371 return "DW_TAG_namelist_item";
4372 case DW_TAG_packed_type:
4373 return "DW_TAG_packed_type";
4374 case DW_TAG_subprogram:
4375 return "DW_TAG_subprogram";
4376 case DW_TAG_template_type_param:
4377 return "DW_TAG_template_type_param";
4378 case DW_TAG_template_value_param:
4379 return "DW_TAG_template_value_param";
4380 case DW_TAG_thrown_type:
4381 return "DW_TAG_thrown_type";
4382 case DW_TAG_try_block:
4383 return "DW_TAG_try_block";
4384 case DW_TAG_variant_part:
4385 return "DW_TAG_variant_part";
4386 case DW_TAG_variable:
4387 return "DW_TAG_variable";
4388 case DW_TAG_volatile_type:
4389 return "DW_TAG_volatile_type";
4390 case DW_TAG_dwarf_procedure:
4391 return "DW_TAG_dwarf_procedure";
4392 case DW_TAG_restrict_type:
4393 return "DW_TAG_restrict_type";
4394 case DW_TAG_interface_type:
4395 return "DW_TAG_interface_type";
4396 case DW_TAG_namespace:
4397 return "DW_TAG_namespace";
4398 case DW_TAG_imported_module:
4399 return "DW_TAG_imported_module";
4400 case DW_TAG_unspecified_type:
4401 return "DW_TAG_unspecified_type";
4402 case DW_TAG_partial_unit:
4403 return "DW_TAG_partial_unit";
4404 case DW_TAG_imported_unit:
4405 return "DW_TAG_imported_unit";
4406 case DW_TAG_condition:
4407 return "DW_TAG_condition";
4408 case DW_TAG_shared_type:
4409 return "DW_TAG_shared_type";
4410 case DW_TAG_type_unit:
4411 return "DW_TAG_type_unit";
4412 case DW_TAG_rvalue_reference_type:
4413 return "DW_TAG_rvalue_reference_type";
4414 case DW_TAG_template_alias:
4415 return "DW_TAG_template_alias";
4416 case DW_TAG_GNU_template_parameter_pack:
4417 return "DW_TAG_GNU_template_parameter_pack";
4418 case DW_TAG_GNU_formal_parameter_pack:
4419 return "DW_TAG_GNU_formal_parameter_pack";
4420 case DW_TAG_MIPS_loop:
4421 return "DW_TAG_MIPS_loop";
4422 case DW_TAG_format_label:
4423 return "DW_TAG_format_label";
4424 case DW_TAG_function_template:
4425 return "DW_TAG_function_template";
4426 case DW_TAG_class_template:
4427 return "DW_TAG_class_template";
4428 case DW_TAG_GNU_BINCL:
4429 return "DW_TAG_GNU_BINCL";
4430 case DW_TAG_GNU_EINCL:
4431 return "DW_TAG_GNU_EINCL";
4432 case DW_TAG_GNU_template_template_param:
4433 return "DW_TAG_GNU_template_template_param";
4434 case DW_TAG_GNU_call_site:
4435 return "DW_TAG_GNU_call_site";
4436 case DW_TAG_GNU_call_site_parameter:
4437 return "DW_TAG_GNU_call_site_parameter";
4439 return "DW_TAG_<unknown>";
4443 /* Convert a DWARF attribute code into its string name. */
4446 dwarf_attr_name (unsigned int attr)
4451 return "DW_AT_sibling";
4452 case DW_AT_location:
4453 return "DW_AT_location";
4455 return "DW_AT_name";
4456 case DW_AT_ordering:
4457 return "DW_AT_ordering";
4458 case DW_AT_subscr_data:
4459 return "DW_AT_subscr_data";
4460 case DW_AT_byte_size:
4461 return "DW_AT_byte_size";
4462 case DW_AT_bit_offset:
4463 return "DW_AT_bit_offset";
4464 case DW_AT_bit_size:
4465 return "DW_AT_bit_size";
4466 case DW_AT_element_list:
4467 return "DW_AT_element_list";
4468 case DW_AT_stmt_list:
4469 return "DW_AT_stmt_list";
4471 return "DW_AT_low_pc";
4473 return "DW_AT_high_pc";
4474 case DW_AT_language:
4475 return "DW_AT_language";
4477 return "DW_AT_member";
4479 return "DW_AT_discr";
4480 case DW_AT_discr_value:
4481 return "DW_AT_discr_value";
4482 case DW_AT_visibility:
4483 return "DW_AT_visibility";
4485 return "DW_AT_import";
4486 case DW_AT_string_length:
4487 return "DW_AT_string_length";
4488 case DW_AT_common_reference:
4489 return "DW_AT_common_reference";
4490 case DW_AT_comp_dir:
4491 return "DW_AT_comp_dir";
4492 case DW_AT_const_value:
4493 return "DW_AT_const_value";
4494 case DW_AT_containing_type:
4495 return "DW_AT_containing_type";
4496 case DW_AT_default_value:
4497 return "DW_AT_default_value";
4499 return "DW_AT_inline";
4500 case DW_AT_is_optional:
4501 return "DW_AT_is_optional";
4502 case DW_AT_lower_bound:
4503 return "DW_AT_lower_bound";
4504 case DW_AT_producer:
4505 return "DW_AT_producer";
4506 case DW_AT_prototyped:
4507 return "DW_AT_prototyped";
4508 case DW_AT_return_addr:
4509 return "DW_AT_return_addr";
4510 case DW_AT_start_scope:
4511 return "DW_AT_start_scope";
4512 case DW_AT_bit_stride:
4513 return "DW_AT_bit_stride";
4514 case DW_AT_upper_bound:
4515 return "DW_AT_upper_bound";
4516 case DW_AT_abstract_origin:
4517 return "DW_AT_abstract_origin";
4518 case DW_AT_accessibility:
4519 return "DW_AT_accessibility";
4520 case DW_AT_address_class:
4521 return "DW_AT_address_class";
4522 case DW_AT_artificial:
4523 return "DW_AT_artificial";
4524 case DW_AT_base_types:
4525 return "DW_AT_base_types";
4526 case DW_AT_calling_convention:
4527 return "DW_AT_calling_convention";
4529 return "DW_AT_count";
4530 case DW_AT_data_member_location:
4531 return "DW_AT_data_member_location";
4532 case DW_AT_decl_column:
4533 return "DW_AT_decl_column";
4534 case DW_AT_decl_file:
4535 return "DW_AT_decl_file";
4536 case DW_AT_decl_line:
4537 return "DW_AT_decl_line";
4538 case DW_AT_declaration:
4539 return "DW_AT_declaration";
4540 case DW_AT_discr_list:
4541 return "DW_AT_discr_list";
4542 case DW_AT_encoding:
4543 return "DW_AT_encoding";
4544 case DW_AT_external:
4545 return "DW_AT_external";
4546 case DW_AT_explicit:
4547 return "DW_AT_explicit";
4548 case DW_AT_frame_base:
4549 return "DW_AT_frame_base";
4551 return "DW_AT_friend";
4552 case DW_AT_identifier_case:
4553 return "DW_AT_identifier_case";
4554 case DW_AT_macro_info:
4555 return "DW_AT_macro_info";
4556 case DW_AT_namelist_items:
4557 return "DW_AT_namelist_items";
4558 case DW_AT_priority:
4559 return "DW_AT_priority";
4561 return "DW_AT_segment";
4562 case DW_AT_specification:
4563 return "DW_AT_specification";
4564 case DW_AT_static_link:
4565 return "DW_AT_static_link";
4567 return "DW_AT_type";
4568 case DW_AT_use_location:
4569 return "DW_AT_use_location";
4570 case DW_AT_variable_parameter:
4571 return "DW_AT_variable_parameter";
4572 case DW_AT_virtuality:
4573 return "DW_AT_virtuality";
4574 case DW_AT_vtable_elem_location:
4575 return "DW_AT_vtable_elem_location";
4577 case DW_AT_allocated:
4578 return "DW_AT_allocated";
4579 case DW_AT_associated:
4580 return "DW_AT_associated";
4581 case DW_AT_data_location:
4582 return "DW_AT_data_location";
4583 case DW_AT_byte_stride:
4584 return "DW_AT_byte_stride";
4585 case DW_AT_entry_pc:
4586 return "DW_AT_entry_pc";
4587 case DW_AT_use_UTF8:
4588 return "DW_AT_use_UTF8";
4589 case DW_AT_extension:
4590 return "DW_AT_extension";
4592 return "DW_AT_ranges";
4593 case DW_AT_trampoline:
4594 return "DW_AT_trampoline";
4595 case DW_AT_call_column:
4596 return "DW_AT_call_column";
4597 case DW_AT_call_file:
4598 return "DW_AT_call_file";
4599 case DW_AT_call_line:
4600 return "DW_AT_call_line";
4601 case DW_AT_object_pointer:
4602 return "DW_AT_object_pointer";
4604 case DW_AT_signature:
4605 return "DW_AT_signature";
4606 case DW_AT_main_subprogram:
4607 return "DW_AT_main_subprogram";
4608 case DW_AT_data_bit_offset:
4609 return "DW_AT_data_bit_offset";
4610 case DW_AT_const_expr:
4611 return "DW_AT_const_expr";
4612 case DW_AT_enum_class:
4613 return "DW_AT_enum_class";
4614 case DW_AT_linkage_name:
4615 return "DW_AT_linkage_name";
4617 case DW_AT_MIPS_fde:
4618 return "DW_AT_MIPS_fde";
4619 case DW_AT_MIPS_loop_begin:
4620 return "DW_AT_MIPS_loop_begin";
4621 case DW_AT_MIPS_tail_loop_begin:
4622 return "DW_AT_MIPS_tail_loop_begin";
4623 case DW_AT_MIPS_epilog_begin:
4624 return "DW_AT_MIPS_epilog_begin";
4625 #if VMS_DEBUGGING_INFO
4626 case DW_AT_HP_prologue:
4627 return "DW_AT_HP_prologue";
4629 case DW_AT_MIPS_loop_unroll_factor:
4630 return "DW_AT_MIPS_loop_unroll_factor";
4632 case DW_AT_MIPS_software_pipeline_depth:
4633 return "DW_AT_MIPS_software_pipeline_depth";
4634 case DW_AT_MIPS_linkage_name:
4635 return "DW_AT_MIPS_linkage_name";
4636 #if VMS_DEBUGGING_INFO
4637 case DW_AT_HP_epilogue:
4638 return "DW_AT_HP_epilogue";
4640 case DW_AT_MIPS_stride:
4641 return "DW_AT_MIPS_stride";
4643 case DW_AT_MIPS_abstract_name:
4644 return "DW_AT_MIPS_abstract_name";
4645 case DW_AT_MIPS_clone_origin:
4646 return "DW_AT_MIPS_clone_origin";
4647 case DW_AT_MIPS_has_inlines:
4648 return "DW_AT_MIPS_has_inlines";
4650 case DW_AT_sf_names:
4651 return "DW_AT_sf_names";
4652 case DW_AT_src_info:
4653 return "DW_AT_src_info";
4654 case DW_AT_mac_info:
4655 return "DW_AT_mac_info";
4656 case DW_AT_src_coords:
4657 return "DW_AT_src_coords";
4658 case DW_AT_body_begin:
4659 return "DW_AT_body_begin";
4660 case DW_AT_body_end:
4661 return "DW_AT_body_end";
4663 case DW_AT_GNU_vector:
4664 return "DW_AT_GNU_vector";
4665 case DW_AT_GNU_guarded_by:
4666 return "DW_AT_GNU_guarded_by";
4667 case DW_AT_GNU_pt_guarded_by:
4668 return "DW_AT_GNU_pt_guarded_by";
4669 case DW_AT_GNU_guarded:
4670 return "DW_AT_GNU_guarded";
4671 case DW_AT_GNU_pt_guarded:
4672 return "DW_AT_GNU_pt_guarded";
4673 case DW_AT_GNU_locks_excluded:
4674 return "DW_AT_GNU_locks_excluded";
4675 case DW_AT_GNU_exclusive_locks_required:
4676 return "DW_AT_GNU_exclusive_locks_required";
4677 case DW_AT_GNU_shared_locks_required:
4678 return "DW_AT_GNU_shared_locks_required";
4679 case DW_AT_GNU_odr_signature:
4680 return "DW_AT_GNU_odr_signature";
4681 case DW_AT_GNU_template_name:
4682 return "DW_AT_GNU_template_name";
4683 case DW_AT_GNU_call_site_value:
4684 return "DW_AT_GNU_call_site_value";
4685 case DW_AT_GNU_call_site_data_value:
4686 return "DW_AT_GNU_call_site_data_value";
4687 case DW_AT_GNU_call_site_target:
4688 return "DW_AT_GNU_call_site_target";
4689 case DW_AT_GNU_call_site_target_clobbered:
4690 return "DW_AT_GNU_call_site_target_clobbered";
4691 case DW_AT_GNU_tail_call:
4692 return "DW_AT_GNU_tail_call";
4693 case DW_AT_GNU_all_tail_call_sites:
4694 return "DW_AT_GNU_all_tail_call_sites";
4695 case DW_AT_GNU_all_call_sites:
4696 return "DW_AT_GNU_all_call_sites";
4697 case DW_AT_GNU_all_source_call_sites:
4698 return "DW_AT_GNU_all_source_call_sites";
4700 case DW_AT_GNAT_descriptive_type:
4701 return "DW_AT_GNAT_descriptive_type";
4703 case DW_AT_VMS_rtnbeg_pd_address:
4704 return "DW_AT_VMS_rtnbeg_pd_address";
4707 return "DW_AT_<unknown>";
4711 /* Convert a DWARF value form code into its string name. */
4714 dwarf_form_name (unsigned int form)
4719 return "DW_FORM_addr";
4720 case DW_FORM_block2:
4721 return "DW_FORM_block2";
4722 case DW_FORM_block4:
4723 return "DW_FORM_block4";
4725 return "DW_FORM_data2";
4727 return "DW_FORM_data4";
4729 return "DW_FORM_data8";
4730 case DW_FORM_string:
4731 return "DW_FORM_string";
4733 return "DW_FORM_block";
4734 case DW_FORM_block1:
4735 return "DW_FORM_block1";
4737 return "DW_FORM_data1";
4739 return "DW_FORM_flag";
4741 return "DW_FORM_sdata";
4743 return "DW_FORM_strp";
4745 return "DW_FORM_udata";
4746 case DW_FORM_ref_addr:
4747 return "DW_FORM_ref_addr";
4749 return "DW_FORM_ref1";
4751 return "DW_FORM_ref2";
4753 return "DW_FORM_ref4";
4755 return "DW_FORM_ref8";
4756 case DW_FORM_ref_udata:
4757 return "DW_FORM_ref_udata";
4758 case DW_FORM_indirect:
4759 return "DW_FORM_indirect";
4760 case DW_FORM_sec_offset:
4761 return "DW_FORM_sec_offset";
4762 case DW_FORM_exprloc:
4763 return "DW_FORM_exprloc";
4764 case DW_FORM_flag_present:
4765 return "DW_FORM_flag_present";
4766 case DW_FORM_ref_sig8:
4767 return "DW_FORM_ref_sig8";
4769 return "DW_FORM_<unknown>";
4773 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4774 instance of an inlined instance of a decl which is local to an inline
4775 function, so we have to trace all of the way back through the origin chain
4776 to find out what sort of node actually served as the original seed for the
4780 decl_ultimate_origin (const_tree decl)
4782 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4785 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4786 nodes in the function to point to themselves; ignore that if
4787 we're trying to output the abstract instance of this function. */
4788 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4791 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4792 most distant ancestor, this should never happen. */
4793 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4795 return DECL_ABSTRACT_ORIGIN (decl);
4798 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4799 of a virtual function may refer to a base class, so we check the 'this'
4803 decl_class_context (tree decl)
4805 tree context = NULL_TREE;
4807 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4808 context = DECL_CONTEXT (decl);
4810 context = TYPE_MAIN_VARIANT
4811 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4813 if (context && !TYPE_P (context))
4814 context = NULL_TREE;
4819 /* Add an attribute/value pair to a DIE. */
4822 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4824 /* Maybe this should be an assert? */
4828 if (die->die_attr == NULL)
4829 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4830 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4833 static inline enum dw_val_class
4834 AT_class (dw_attr_ref a)
4836 return a->dw_attr_val.val_class;
4839 /* Add a flag value attribute to a DIE. */
4842 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4846 attr.dw_attr = attr_kind;
4847 attr.dw_attr_val.val_class = dw_val_class_flag;
4848 attr.dw_attr_val.v.val_flag = flag;
4849 add_dwarf_attr (die, &attr);
4852 static inline unsigned
4853 AT_flag (dw_attr_ref a)
4855 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4856 return a->dw_attr_val.v.val_flag;
4859 /* Add a signed integer attribute value to a DIE. */
4862 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4866 attr.dw_attr = attr_kind;
4867 attr.dw_attr_val.val_class = dw_val_class_const;
4868 attr.dw_attr_val.v.val_int = int_val;
4869 add_dwarf_attr (die, &attr);
4872 static inline HOST_WIDE_INT
4873 AT_int (dw_attr_ref a)
4875 gcc_assert (a && AT_class (a) == dw_val_class_const);
4876 return a->dw_attr_val.v.val_int;
4879 /* Add an unsigned integer attribute value to a DIE. */
4882 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4883 unsigned HOST_WIDE_INT unsigned_val)
4887 attr.dw_attr = attr_kind;
4888 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4889 attr.dw_attr_val.v.val_unsigned = unsigned_val;
4890 add_dwarf_attr (die, &attr);
4893 static inline unsigned HOST_WIDE_INT
4894 AT_unsigned (dw_attr_ref a)
4896 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4897 return a->dw_attr_val.v.val_unsigned;
4900 /* Add an unsigned double integer attribute value to a DIE. */
4903 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
4904 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
4908 attr.dw_attr = attr_kind;
4909 attr.dw_attr_val.val_class = dw_val_class_const_double;
4910 attr.dw_attr_val.v.val_double.high = high;
4911 attr.dw_attr_val.v.val_double.low = low;
4912 add_dwarf_attr (die, &attr);
4915 /* Add a floating point attribute value to a DIE and return it. */
4918 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4919 unsigned int length, unsigned int elt_size, unsigned char *array)
4923 attr.dw_attr = attr_kind;
4924 attr.dw_attr_val.val_class = dw_val_class_vec;
4925 attr.dw_attr_val.v.val_vec.length = length;
4926 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4927 attr.dw_attr_val.v.val_vec.array = array;
4928 add_dwarf_attr (die, &attr);
4931 /* Add an 8-byte data attribute value to a DIE. */
4934 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
4935 unsigned char data8[8])
4939 attr.dw_attr = attr_kind;
4940 attr.dw_attr_val.val_class = dw_val_class_data8;
4941 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
4942 add_dwarf_attr (die, &attr);
4945 /* Hash and equality functions for debug_str_hash. */
4948 debug_str_do_hash (const void *x)
4950 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4954 debug_str_eq (const void *x1, const void *x2)
4956 return strcmp ((((const struct indirect_string_node *)x1)->str),
4957 (const char *)x2) == 0;
4960 /* Add STR to the indirect string hash table. */
4962 static struct indirect_string_node *
4963 find_AT_string (const char *str)
4965 struct indirect_string_node *node;
4968 if (! debug_str_hash)
4969 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4970 debug_str_eq, NULL);
4972 slot = htab_find_slot_with_hash (debug_str_hash, str,
4973 htab_hash_string (str), INSERT);
4976 node = ggc_alloc_cleared_indirect_string_node ();
4977 node->str = ggc_strdup (str);
4981 node = (struct indirect_string_node *) *slot;
4987 /* Add a string attribute value to a DIE. */
4990 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4993 struct indirect_string_node *node;
4995 node = find_AT_string (str);
4997 attr.dw_attr = attr_kind;
4998 attr.dw_attr_val.val_class = dw_val_class_str;
4999 attr.dw_attr_val.v.val_str = node;
5000 add_dwarf_attr (die, &attr);
5003 static inline const char *
5004 AT_string (dw_attr_ref a)
5006 gcc_assert (a && AT_class (a) == dw_val_class_str);
5007 return a->dw_attr_val.v.val_str->str;
5010 /* Find out whether a string should be output inline in DIE
5011 or out-of-line in .debug_str section. */
5013 static enum dwarf_form
5014 AT_string_form (dw_attr_ref a)
5016 struct indirect_string_node *node;
5020 gcc_assert (a && AT_class (a) == dw_val_class_str);
5022 node = a->dw_attr_val.v.val_str;
5026 len = strlen (node->str) + 1;
5028 /* If the string is shorter or equal to the size of the reference, it is
5029 always better to put it inline. */
5030 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5031 return node->form = DW_FORM_string;
5033 /* If we cannot expect the linker to merge strings in .debug_str
5034 section, only put it into .debug_str if it is worth even in this
5036 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
5037 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
5038 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
5039 return node->form = DW_FORM_string;
5041 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5042 ++dw2_string_counter;
5043 node->label = xstrdup (label);
5045 return node->form = DW_FORM_strp;
5048 /* Add a DIE reference attribute value to a DIE. */
5051 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5055 #ifdef ENABLE_CHECKING
5056 gcc_assert (targ_die != NULL);
5058 /* With LTO we can end up trying to reference something we didn't create
5059 a DIE for. Avoid crashing later on a NULL referenced DIE. */
5060 if (targ_die == NULL)
5064 attr.dw_attr = attr_kind;
5065 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5066 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5067 attr.dw_attr_val.v.val_die_ref.external = 0;
5068 add_dwarf_attr (die, &attr);
5071 /* Add an AT_specification attribute to a DIE, and also make the back
5072 pointer from the specification to the definition. */
5075 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5077 add_AT_die_ref (die, DW_AT_specification, targ_die);
5078 gcc_assert (!targ_die->die_definition);
5079 targ_die->die_definition = die;
5082 static inline dw_die_ref
5083 AT_ref (dw_attr_ref a)
5085 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5086 return a->dw_attr_val.v.val_die_ref.die;
5090 AT_ref_external (dw_attr_ref a)
5092 if (a && AT_class (a) == dw_val_class_die_ref)
5093 return a->dw_attr_val.v.val_die_ref.external;
5099 set_AT_ref_external (dw_attr_ref a, int i)
5101 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5102 a->dw_attr_val.v.val_die_ref.external = i;
5105 /* Add an FDE reference attribute value to a DIE. */
5108 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5112 attr.dw_attr = attr_kind;
5113 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
5114 attr.dw_attr_val.v.val_fde_index = targ_fde;
5115 add_dwarf_attr (die, &attr);
5118 /* Add a location description attribute value to a DIE. */
5121 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5125 attr.dw_attr = attr_kind;
5126 attr.dw_attr_val.val_class = dw_val_class_loc;
5127 attr.dw_attr_val.v.val_loc = loc;
5128 add_dwarf_attr (die, &attr);
5131 static inline dw_loc_descr_ref
5132 AT_loc (dw_attr_ref a)
5134 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5135 return a->dw_attr_val.v.val_loc;
5139 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5143 attr.dw_attr = attr_kind;
5144 attr.dw_attr_val.val_class = dw_val_class_loc_list;
5145 attr.dw_attr_val.v.val_loc_list = loc_list;
5146 add_dwarf_attr (die, &attr);
5147 have_location_lists = true;
5150 static inline dw_loc_list_ref
5151 AT_loc_list (dw_attr_ref a)
5153 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5154 return a->dw_attr_val.v.val_loc_list;
5157 static inline dw_loc_list_ref *
5158 AT_loc_list_ptr (dw_attr_ref a)
5160 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5161 return &a->dw_attr_val.v.val_loc_list;
5164 /* Add an address constant attribute value to a DIE. */
5167 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5171 attr.dw_attr = attr_kind;
5172 attr.dw_attr_val.val_class = dw_val_class_addr;
5173 attr.dw_attr_val.v.val_addr = addr;
5174 add_dwarf_attr (die, &attr);
5177 /* Get the RTX from to an address DIE attribute. */
5180 AT_addr (dw_attr_ref a)
5182 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5183 return a->dw_attr_val.v.val_addr;
5186 /* Add a file attribute value to a DIE. */
5189 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5190 struct dwarf_file_data *fd)
5194 attr.dw_attr = attr_kind;
5195 attr.dw_attr_val.val_class = dw_val_class_file;
5196 attr.dw_attr_val.v.val_file = fd;
5197 add_dwarf_attr (die, &attr);
5200 /* Get the dwarf_file_data from a file DIE attribute. */
5202 static inline struct dwarf_file_data *
5203 AT_file (dw_attr_ref a)
5205 gcc_assert (a && AT_class (a) == dw_val_class_file);
5206 return a->dw_attr_val.v.val_file;
5209 /* Add a vms delta attribute value to a DIE. */
5212 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
5213 const char *lbl1, const char *lbl2)
5217 attr.dw_attr = attr_kind;
5218 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
5219 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
5220 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
5221 add_dwarf_attr (die, &attr);
5224 /* Add a label identifier attribute value to a DIE. */
5227 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5231 attr.dw_attr = attr_kind;
5232 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5233 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5234 add_dwarf_attr (die, &attr);
5237 /* Add a section offset attribute value to a DIE, an offset into the
5238 debug_line section. */
5241 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5246 attr.dw_attr = attr_kind;
5247 attr.dw_attr_val.val_class = dw_val_class_lineptr;
5248 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5249 add_dwarf_attr (die, &attr);
5252 /* Add a section offset attribute value to a DIE, an offset into the
5253 debug_macinfo section. */
5256 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5261 attr.dw_attr = attr_kind;
5262 attr.dw_attr_val.val_class = dw_val_class_macptr;
5263 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5264 add_dwarf_attr (die, &attr);
5267 /* Add an offset attribute value to a DIE. */
5270 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5271 unsigned HOST_WIDE_INT offset)
5275 attr.dw_attr = attr_kind;
5276 attr.dw_attr_val.val_class = dw_val_class_offset;
5277 attr.dw_attr_val.v.val_offset = offset;
5278 add_dwarf_attr (die, &attr);
5281 /* Add an range_list attribute value to a DIE. */
5284 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5285 long unsigned int offset)
5289 attr.dw_attr = attr_kind;
5290 attr.dw_attr_val.val_class = dw_val_class_range_list;
5291 attr.dw_attr_val.v.val_offset = offset;
5292 add_dwarf_attr (die, &attr);
5295 /* Return the start label of a delta attribute. */
5297 static inline const char *
5298 AT_vms_delta1 (dw_attr_ref a)
5300 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
5301 return a->dw_attr_val.v.val_vms_delta.lbl1;
5304 /* Return the end label of a delta attribute. */
5306 static inline const char *
5307 AT_vms_delta2 (dw_attr_ref a)
5309 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
5310 return a->dw_attr_val.v.val_vms_delta.lbl2;
5313 static inline const char *
5314 AT_lbl (dw_attr_ref a)
5316 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5317 || AT_class (a) == dw_val_class_lineptr
5318 || AT_class (a) == dw_val_class_macptr));
5319 return a->dw_attr_val.v.val_lbl_id;
5322 /* Get the attribute of type attr_kind. */
5325 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5329 dw_die_ref spec = NULL;
5334 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5335 if (a->dw_attr == attr_kind)
5337 else if (a->dw_attr == DW_AT_specification
5338 || a->dw_attr == DW_AT_abstract_origin)
5342 return get_AT (spec, attr_kind);
5347 /* Return the "low pc" attribute value, typically associated with a subprogram
5348 DIE. Return null if the "low pc" attribute is either not present, or if it
5349 cannot be represented as an assembler label identifier. */
5351 static inline const char *
5352 get_AT_low_pc (dw_die_ref die)
5354 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5356 return a ? AT_lbl (a) : NULL;
5359 /* Return the "high pc" attribute value, typically associated with a subprogram
5360 DIE. Return null if the "high pc" attribute is either not present, or if it
5361 cannot be represented as an assembler label identifier. */
5363 static inline const char *
5364 get_AT_hi_pc (dw_die_ref die)
5366 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5368 return a ? AT_lbl (a) : NULL;
5371 /* Return the value of the string attribute designated by ATTR_KIND, or
5372 NULL if it is not present. */
5374 static inline const char *
5375 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5377 dw_attr_ref a = get_AT (die, attr_kind);
5379 return a ? AT_string (a) : NULL;
5382 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5383 if it is not present. */
5386 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5388 dw_attr_ref a = get_AT (die, attr_kind);
5390 return a ? AT_flag (a) : 0;
5393 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5394 if it is not present. */
5396 static inline unsigned
5397 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5399 dw_attr_ref a = get_AT (die, attr_kind);
5401 return a ? AT_unsigned (a) : 0;
5404 static inline dw_die_ref
5405 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5407 dw_attr_ref a = get_AT (die, attr_kind);
5409 return a ? AT_ref (a) : NULL;
5412 static inline struct dwarf_file_data *
5413 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5415 dw_attr_ref a = get_AT (die, attr_kind);
5417 return a ? AT_file (a) : NULL;
5420 /* Return TRUE if the language is C++. */
5425 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5427 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
5430 /* Return TRUE if the language is Fortran. */
5435 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5437 return (lang == DW_LANG_Fortran77
5438 || lang == DW_LANG_Fortran90
5439 || lang == DW_LANG_Fortran95);
5442 /* Return TRUE if the language is Ada. */
5447 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5449 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5452 /* Remove the specified attribute if present. */
5455 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5463 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
5464 if (a->dw_attr == attr_kind)
5466 if (AT_class (a) == dw_val_class_str)
5467 if (a->dw_attr_val.v.val_str->refcount)
5468 a->dw_attr_val.v.val_str->refcount--;
5470 /* VEC_ordered_remove should help reduce the number of abbrevs
5472 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
5477 /* Remove CHILD from its parent. PREV must have the property that
5478 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5481 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5483 gcc_assert (child->die_parent == prev->die_parent);
5484 gcc_assert (prev->die_sib == child);
5487 gcc_assert (child->die_parent->die_child == child);
5491 prev->die_sib = child->die_sib;
5492 if (child->die_parent->die_child == child)
5493 child->die_parent->die_child = prev;
5496 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5497 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5500 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
5502 dw_die_ref parent = old_child->die_parent;
5504 gcc_assert (parent == prev->die_parent);
5505 gcc_assert (prev->die_sib == old_child);
5507 new_child->die_parent = parent;
5508 if (prev == old_child)
5510 gcc_assert (parent->die_child == old_child);
5511 new_child->die_sib = new_child;
5515 prev->die_sib = new_child;
5516 new_child->die_sib = old_child->die_sib;
5518 if (old_child->die_parent->die_child == old_child)
5519 old_child->die_parent->die_child = new_child;
5522 /* Move all children from OLD_PARENT to NEW_PARENT. */
5525 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
5528 new_parent->die_child = old_parent->die_child;
5529 old_parent->die_child = NULL;
5530 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
5533 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5537 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5543 dw_die_ref prev = c;
5545 while (c->die_tag == tag)
5547 remove_child_with_prev (c, prev);
5548 /* Might have removed every child. */
5549 if (c == c->die_sib)
5553 } while (c != die->die_child);
5556 /* Add a CHILD_DIE as the last child of DIE. */
5559 add_child_die (dw_die_ref die, dw_die_ref child_die)
5561 /* FIXME this should probably be an assert. */
5562 if (! die || ! child_die)
5564 gcc_assert (die != child_die);
5566 child_die->die_parent = die;
5569 child_die->die_sib = die->die_child->die_sib;
5570 die->die_child->die_sib = child_die;
5573 child_die->die_sib = child_die;
5574 die->die_child = child_die;
5577 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5578 is the specification, to the end of PARENT's list of children.
5579 This is done by removing and re-adding it. */
5582 splice_child_die (dw_die_ref parent, dw_die_ref child)
5586 /* We want the declaration DIE from inside the class, not the
5587 specification DIE at toplevel. */
5588 if (child->die_parent != parent)
5590 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5596 gcc_assert (child->die_parent == parent
5597 || (child->die_parent
5598 == get_AT_ref (parent, DW_AT_specification)));
5600 for (p = child->die_parent->die_child; ; p = p->die_sib)
5601 if (p->die_sib == child)
5603 remove_child_with_prev (child, p);
5607 add_child_die (parent, child);
5610 /* Return a pointer to a newly created DIE node. */
5612 static inline dw_die_ref
5613 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5615 dw_die_ref die = ggc_alloc_cleared_die_node ();
5617 die->die_tag = tag_value;
5619 if (parent_die != NULL)
5620 add_child_die (parent_die, die);
5623 limbo_die_node *limbo_node;
5625 limbo_node = ggc_alloc_cleared_limbo_die_node ();
5626 limbo_node->die = die;
5627 limbo_node->created_for = t;
5628 limbo_node->next = limbo_die_list;
5629 limbo_die_list = limbo_node;
5635 /* Return the DIE associated with the given type specifier. */
5637 static inline dw_die_ref
5638 lookup_type_die (tree type)
5640 return TYPE_SYMTAB_DIE (type);
5643 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5644 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5645 anonymous type instead the one of the naming typedef. */
5647 static inline dw_die_ref
5648 strip_naming_typedef (tree type, dw_die_ref type_die)
5651 && TREE_CODE (type) == RECORD_TYPE
5653 && type_die->die_tag == DW_TAG_typedef
5654 && is_naming_typedef_decl (TYPE_NAME (type)))
5655 type_die = get_AT_ref (type_die, DW_AT_type);
5659 /* Like lookup_type_die, but if type is an anonymous type named by a
5660 typedef[1], return the DIE of the anonymous type instead the one of
5661 the naming typedef. This is because in gen_typedef_die, we did
5662 equate the anonymous struct named by the typedef with the DIE of
5663 the naming typedef. So by default, lookup_type_die on an anonymous
5664 struct yields the DIE of the naming typedef.
5666 [1]: Read the comment of is_naming_typedef_decl to learn about what
5667 a naming typedef is. */
5669 static inline dw_die_ref
5670 lookup_type_die_strip_naming_typedef (tree type)
5672 dw_die_ref die = lookup_type_die (type);
5673 return strip_naming_typedef (type, die);
5676 /* Equate a DIE to a given type specifier. */
5679 equate_type_number_to_die (tree type, dw_die_ref type_die)
5681 TYPE_SYMTAB_DIE (type) = type_die;
5684 /* Returns a hash value for X (which really is a die_struct). */
5687 decl_die_table_hash (const void *x)
5689 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5692 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5695 decl_die_table_eq (const void *x, const void *y)
5697 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5700 /* Return the DIE associated with a given declaration. */
5702 static inline dw_die_ref
5703 lookup_decl_die (tree decl)
5705 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5708 /* Returns a hash value for X (which really is a var_loc_list). */
5711 decl_loc_table_hash (const void *x)
5713 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5716 /* Return nonzero if decl_id of var_loc_list X is the same as
5720 decl_loc_table_eq (const void *x, const void *y)
5722 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5725 /* Return the var_loc list associated with a given declaration. */
5727 static inline var_loc_list *
5728 lookup_decl_loc (const_tree decl)
5730 if (!decl_loc_table)
5732 return (var_loc_list *)
5733 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5736 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5739 cached_dw_loc_list_table_hash (const void *x)
5741 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
5744 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5748 cached_dw_loc_list_table_eq (const void *x, const void *y)
5750 return (((const cached_dw_loc_list *) x)->decl_id
5751 == DECL_UID ((const_tree) y));
5754 /* Equate a DIE to a particular declaration. */
5757 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5759 unsigned int decl_id = DECL_UID (decl);
5762 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5764 decl_die->decl_id = decl_id;
5767 /* Return how many bits covers PIECE EXPR_LIST. */
5770 decl_piece_bitsize (rtx piece)
5772 int ret = (int) GET_MODE (piece);
5775 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
5776 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
5777 return INTVAL (XEXP (XEXP (piece, 0), 0));
5780 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5783 decl_piece_varloc_ptr (rtx piece)
5785 if ((int) GET_MODE (piece))
5786 return &XEXP (piece, 0);
5788 return &XEXP (XEXP (piece, 0), 1);
5791 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5792 Next is the chain of following piece nodes. */
5795 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
5797 if (bitsize <= (int) MAX_MACHINE_MODE)
5798 return alloc_EXPR_LIST (bitsize, loc_note, next);
5800 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
5805 /* Return rtx that should be stored into loc field for
5806 LOC_NOTE and BITPOS/BITSIZE. */
5809 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
5810 HOST_WIDE_INT bitsize)
5814 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
5816 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
5821 /* This function either modifies location piece list *DEST in
5822 place (if SRC and INNER is NULL), or copies location piece list
5823 *SRC to *DEST while modifying it. Location BITPOS is modified
5824 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5825 not copied and if needed some padding around it is added.
5826 When modifying in place, DEST should point to EXPR_LIST where
5827 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5828 to the start of the whole list and INNER points to the EXPR_LIST
5829 where earlier pieces cover PIECE_BITPOS bits. */
5832 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
5833 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
5834 HOST_WIDE_INT bitsize, rtx loc_note)
5837 bool copy = inner != NULL;
5841 /* First copy all nodes preceeding the current bitpos. */
5842 while (src != inner)
5844 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5845 decl_piece_bitsize (*src), NULL_RTX);
5846 dest = &XEXP (*dest, 1);
5847 src = &XEXP (*src, 1);
5850 /* Add padding if needed. */
5851 if (bitpos != piece_bitpos)
5853 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
5854 copy ? NULL_RTX : *dest);
5855 dest = &XEXP (*dest, 1);
5857 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
5860 /* A piece with correct bitpos and bitsize already exist,
5861 just update the location for it and return. */
5862 *decl_piece_varloc_ptr (*dest) = loc_note;
5865 /* Add the piece that changed. */
5866 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
5867 dest = &XEXP (*dest, 1);
5868 /* Skip over pieces that overlap it. */
5869 diff = bitpos - piece_bitpos + bitsize;
5872 while (diff > 0 && *src)
5875 diff -= decl_piece_bitsize (piece);
5877 src = &XEXP (piece, 1);
5880 *src = XEXP (piece, 1);
5881 free_EXPR_LIST_node (piece);
5884 /* Add padding if needed. */
5885 if (diff < 0 && *src)
5889 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
5890 dest = &XEXP (*dest, 1);
5894 /* Finally copy all nodes following it. */
5897 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
5898 decl_piece_bitsize (*src), NULL_RTX);
5899 dest = &XEXP (*dest, 1);
5900 src = &XEXP (*src, 1);
5904 /* Add a variable location node to the linked list for DECL. */
5906 static struct var_loc_node *
5907 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
5909 unsigned int decl_id;
5912 struct var_loc_node *loc = NULL;
5913 HOST_WIDE_INT bitsize = -1, bitpos = -1;
5915 if (DECL_DEBUG_EXPR_IS_FROM (decl))
5917 tree realdecl = DECL_DEBUG_EXPR (decl);
5918 if (realdecl && handled_component_p (realdecl))
5920 HOST_WIDE_INT maxsize;
5923 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
5924 if (!DECL_P (innerdecl)
5925 || DECL_IGNORED_P (innerdecl)
5926 || TREE_STATIC (innerdecl)
5928 || bitpos + bitsize > 256
5929 || bitsize != maxsize)
5935 decl_id = DECL_UID (decl);
5936 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5939 temp = ggc_alloc_cleared_var_loc_list ();
5940 temp->decl_id = decl_id;
5944 temp = (var_loc_list *) *slot;
5946 /* For PARM_DECLs try to keep around the original incoming value,
5947 even if that means we'll emit a zero-range .debug_loc entry. */
5949 && temp->first == temp->last
5950 && TREE_CODE (decl) == PARM_DECL
5951 && GET_CODE (temp->first->loc) == NOTE
5952 && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
5953 && DECL_INCOMING_RTL (decl)
5954 && NOTE_VAR_LOCATION_LOC (temp->first->loc)
5955 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
5956 == GET_CODE (DECL_INCOMING_RTL (decl))
5957 && prev_real_insn (temp->first->loc) == NULL_RTX
5959 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
5960 NOTE_VAR_LOCATION_LOC (loc_note))
5961 || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
5962 != NOTE_VAR_LOCATION_STATUS (loc_note))))
5964 loc = ggc_alloc_cleared_var_loc_node ();
5965 temp->first->next = loc;
5967 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
5969 else if (temp->last)
5971 struct var_loc_node *last = temp->last, *unused = NULL;
5972 rtx *piece_loc = NULL, last_loc_note;
5973 int piece_bitpos = 0;
5977 gcc_assert (last->next == NULL);
5979 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
5981 piece_loc = &last->loc;
5984 int cur_bitsize = decl_piece_bitsize (*piece_loc);
5985 if (piece_bitpos + cur_bitsize > bitpos)
5987 piece_bitpos += cur_bitsize;
5988 piece_loc = &XEXP (*piece_loc, 1);
5992 /* TEMP->LAST here is either pointer to the last but one or
5993 last element in the chained list, LAST is pointer to the
5995 if (label && strcmp (last->label, label) == 0)
5997 /* For SRA optimized variables if there weren't any real
5998 insns since last note, just modify the last node. */
5999 if (piece_loc != NULL)
6001 adjust_piece_list (piece_loc, NULL, NULL,
6002 bitpos, piece_bitpos, bitsize, loc_note);
6005 /* If the last note doesn't cover any instructions, remove it. */
6006 if (temp->last != last)
6008 temp->last->next = NULL;
6011 gcc_assert (strcmp (last->label, label) != 0);
6015 gcc_assert (temp->first == temp->last
6016 || (temp->first->next == temp->last
6017 && TREE_CODE (decl) == PARM_DECL));
6018 memset (temp->last, '\0', sizeof (*temp->last));
6019 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
6023 if (bitsize == -1 && NOTE_P (last->loc))
6024 last_loc_note = last->loc;
6025 else if (piece_loc != NULL
6026 && *piece_loc != NULL_RTX
6027 && piece_bitpos == bitpos
6028 && decl_piece_bitsize (*piece_loc) == bitsize)
6029 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
6031 last_loc_note = NULL_RTX;
6032 /* If the current location is the same as the end of the list,
6033 and either both or neither of the locations is uninitialized,
6034 we have nothing to do. */
6035 if (last_loc_note == NULL_RTX
6036 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
6037 NOTE_VAR_LOCATION_LOC (loc_note)))
6038 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
6039 != NOTE_VAR_LOCATION_STATUS (loc_note))
6040 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
6041 == VAR_INIT_STATUS_UNINITIALIZED)
6042 || (NOTE_VAR_LOCATION_STATUS (loc_note)
6043 == VAR_INIT_STATUS_UNINITIALIZED))))
6045 /* Add LOC to the end of list and update LAST. If the last
6046 element of the list has been removed above, reuse its
6047 memory for the new node, otherwise allocate a new one. */
6051 memset (loc, '\0', sizeof (*loc));
6054 loc = ggc_alloc_cleared_var_loc_node ();
6055 if (bitsize == -1 || piece_loc == NULL)
6056 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6058 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
6059 bitpos, piece_bitpos, bitsize, loc_note);
6061 /* Ensure TEMP->LAST will point either to the new last but one
6062 element of the chain, or to the last element in it. */
6063 if (last != temp->last)
6071 loc = ggc_alloc_cleared_var_loc_node ();
6074 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6079 /* Keep track of the number of spaces used to indent the
6080 output of the debugging routines that print the structure of
6081 the DIE internal representation. */
6082 static int print_indent;
6084 /* Indent the line the number of spaces given by print_indent. */
6087 print_spaces (FILE *outfile)
6089 fprintf (outfile, "%*s", print_indent, "");
6092 /* Print a type signature in hex. */
6095 print_signature (FILE *outfile, char *sig)
6099 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
6100 fprintf (outfile, "%02x", sig[i] & 0xff);
6103 /* Print the information associated with a given DIE, and its children.
6104 This routine is a debugging aid only. */
6107 print_die (dw_die_ref die, FILE *outfile)
6113 print_spaces (outfile);
6114 fprintf (outfile, "DIE %4ld: %s (%p)\n",
6115 die->die_offset, dwarf_tag_name (die->die_tag),
6117 print_spaces (outfile);
6118 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
6119 fprintf (outfile, " offset: %ld", die->die_offset);
6120 fprintf (outfile, " mark: %d\n", die->die_mark);
6122 if (use_debug_types && die->die_id.die_type_node)
6124 print_spaces (outfile);
6125 fprintf (outfile, " signature: ");
6126 print_signature (outfile, die->die_id.die_type_node->signature);
6127 fprintf (outfile, "\n");
6130 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6132 print_spaces (outfile);
6133 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
6135 switch (AT_class (a))
6137 case dw_val_class_addr:
6138 fprintf (outfile, "address");
6140 case dw_val_class_offset:
6141 fprintf (outfile, "offset");
6143 case dw_val_class_loc:
6144 fprintf (outfile, "location descriptor");
6146 case dw_val_class_loc_list:
6147 fprintf (outfile, "location list -> label:%s",
6148 AT_loc_list (a)->ll_symbol);
6150 case dw_val_class_range_list:
6151 fprintf (outfile, "range list");
6153 case dw_val_class_const:
6154 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
6156 case dw_val_class_unsigned_const:
6157 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
6159 case dw_val_class_const_double:
6160 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
6161 HOST_WIDE_INT_PRINT_UNSIGNED")",
6162 a->dw_attr_val.v.val_double.high,
6163 a->dw_attr_val.v.val_double.low);
6165 case dw_val_class_vec:
6166 fprintf (outfile, "floating-point or vector constant");
6168 case dw_val_class_flag:
6169 fprintf (outfile, "%u", AT_flag (a));
6171 case dw_val_class_die_ref:
6172 if (AT_ref (a) != NULL)
6174 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
6176 fprintf (outfile, "die -> signature: ");
6177 print_signature (outfile,
6178 AT_ref (a)->die_id.die_type_node->signature);
6180 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
6181 fprintf (outfile, "die -> label: %s",
6182 AT_ref (a)->die_id.die_symbol);
6184 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
6185 fprintf (outfile, " (%p)", (void *) AT_ref (a));
6188 fprintf (outfile, "die -> <null>");
6190 case dw_val_class_vms_delta:
6191 fprintf (outfile, "delta: @slotcount(%s-%s)",
6192 AT_vms_delta2 (a), AT_vms_delta1 (a));
6194 case dw_val_class_lbl_id:
6195 case dw_val_class_lineptr:
6196 case dw_val_class_macptr:
6197 fprintf (outfile, "label: %s", AT_lbl (a));
6199 case dw_val_class_str:
6200 if (AT_string (a) != NULL)
6201 fprintf (outfile, "\"%s\"", AT_string (a));
6203 fprintf (outfile, "<null>");
6205 case dw_val_class_file:
6206 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
6207 AT_file (a)->emitted_number);
6209 case dw_val_class_data8:
6213 for (i = 0; i < 8; i++)
6214 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
6221 fprintf (outfile, "\n");
6224 if (die->die_child != NULL)
6227 FOR_EACH_CHILD (die, c, print_die (c, outfile));
6230 if (print_indent == 0)
6231 fprintf (outfile, "\n");
6234 /* Print the information collected for a given DIE. */
6237 debug_dwarf_die (dw_die_ref die)
6239 print_die (die, stderr);
6242 /* Print all DWARF information collected for the compilation unit.
6243 This routine is a debugging aid only. */
6249 print_die (comp_unit_die (), stderr);
6252 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6253 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6254 DIE that marks the start of the DIEs for this include file. */
6257 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
6259 const char *filename = get_AT_string (bincl_die, DW_AT_name);
6260 dw_die_ref new_unit = gen_compile_unit_die (filename);
6262 new_unit->die_sib = old_unit;
6266 /* Close an include-file CU and reopen the enclosing one. */
6269 pop_compile_unit (dw_die_ref old_unit)
6271 dw_die_ref new_unit = old_unit->die_sib;
6273 old_unit->die_sib = NULL;
6277 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6278 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6280 /* Calculate the checksum of a location expression. */
6283 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6287 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
6289 CHECKSUM (loc->dw_loc_oprnd1);
6290 CHECKSUM (loc->dw_loc_oprnd2);
6293 /* Calculate the checksum of an attribute. */
6296 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6298 dw_loc_descr_ref loc;
6301 CHECKSUM (at->dw_attr);
6303 /* We don't care that this was compiled with a different compiler
6304 snapshot; if the output is the same, that's what matters. */
6305 if (at->dw_attr == DW_AT_producer)
6308 switch (AT_class (at))
6310 case dw_val_class_const:
6311 CHECKSUM (at->dw_attr_val.v.val_int);
6313 case dw_val_class_unsigned_const:
6314 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6316 case dw_val_class_const_double:
6317 CHECKSUM (at->dw_attr_val.v.val_double);
6319 case dw_val_class_vec:
6320 CHECKSUM (at->dw_attr_val.v.val_vec);
6322 case dw_val_class_flag:
6323 CHECKSUM (at->dw_attr_val.v.val_flag);
6325 case dw_val_class_str:
6326 CHECKSUM_STRING (AT_string (at));
6329 case dw_val_class_addr:
6331 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6332 CHECKSUM_STRING (XSTR (r, 0));
6335 case dw_val_class_offset:
6336 CHECKSUM (at->dw_attr_val.v.val_offset);
6339 case dw_val_class_loc:
6340 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6341 loc_checksum (loc, ctx);
6344 case dw_val_class_die_ref:
6345 die_checksum (AT_ref (at), ctx, mark);
6348 case dw_val_class_fde_ref:
6349 case dw_val_class_vms_delta:
6350 case dw_val_class_lbl_id:
6351 case dw_val_class_lineptr:
6352 case dw_val_class_macptr:
6355 case dw_val_class_file:
6356 CHECKSUM_STRING (AT_file (at)->filename);
6359 case dw_val_class_data8:
6360 CHECKSUM (at->dw_attr_val.v.val_data8);
6368 /* Calculate the checksum of a DIE. */
6371 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6377 /* To avoid infinite recursion. */
6380 CHECKSUM (die->die_mark);
6383 die->die_mark = ++(*mark);
6385 CHECKSUM (die->die_tag);
6387 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6388 attr_checksum (a, ctx, mark);
6390 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6394 #undef CHECKSUM_STRING
6396 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6397 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6398 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6399 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6400 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6401 #define CHECKSUM_ATTR(FOO) \
6402 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6404 /* Calculate the checksum of a number in signed LEB128 format. */
6407 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
6414 byte = (value & 0x7f);
6416 more = !((value == 0 && (byte & 0x40) == 0)
6417 || (value == -1 && (byte & 0x40) != 0));
6426 /* Calculate the checksum of a number in unsigned LEB128 format. */
6429 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
6433 unsigned char byte = (value & 0x7f);
6436 /* More bytes to follow. */
6444 /* Checksum the context of the DIE. This adds the names of any
6445 surrounding namespaces or structures to the checksum. */
6448 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
6452 int tag = die->die_tag;
6454 if (tag != DW_TAG_namespace
6455 && tag != DW_TAG_structure_type
6456 && tag != DW_TAG_class_type)
6459 name = get_AT_string (die, DW_AT_name);
6461 spec = get_AT_ref (die, DW_AT_specification);
6465 if (die->die_parent != NULL)
6466 checksum_die_context (die->die_parent, ctx);
6468 CHECKSUM_ULEB128 ('C');
6469 CHECKSUM_ULEB128 (tag);
6471 CHECKSUM_STRING (name);
6474 /* Calculate the checksum of a location expression. */
6477 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6479 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6480 were emitted as a DW_FORM_sdata instead of a location expression. */
6481 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
6483 CHECKSUM_ULEB128 (DW_FORM_sdata);
6484 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
6488 /* Otherwise, just checksum the raw location expression. */
6491 CHECKSUM_ULEB128 (loc->dw_loc_opc);
6492 CHECKSUM (loc->dw_loc_oprnd1);
6493 CHECKSUM (loc->dw_loc_oprnd2);
6494 loc = loc->dw_loc_next;
6498 /* Calculate the checksum of an attribute. */
6501 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
6502 struct md5_ctx *ctx, int *mark)
6504 dw_loc_descr_ref loc;
6507 if (AT_class (at) == dw_val_class_die_ref)
6509 dw_die_ref target_die = AT_ref (at);
6511 /* For pointer and reference types, we checksum only the (qualified)
6512 name of the target type (if there is a name). For friend entries,
6513 we checksum only the (qualified) name of the target type or function.
6514 This allows the checksum to remain the same whether the target type
6515 is complete or not. */
6516 if ((at->dw_attr == DW_AT_type
6517 && (tag == DW_TAG_pointer_type
6518 || tag == DW_TAG_reference_type
6519 || tag == DW_TAG_rvalue_reference_type
6520 || tag == DW_TAG_ptr_to_member_type))
6521 || (at->dw_attr == DW_AT_friend
6522 && tag == DW_TAG_friend))
6524 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
6526 if (name_attr != NULL)
6528 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
6532 CHECKSUM_ULEB128 ('N');
6533 CHECKSUM_ULEB128 (at->dw_attr);
6534 if (decl->die_parent != NULL)
6535 checksum_die_context (decl->die_parent, ctx);
6536 CHECKSUM_ULEB128 ('E');
6537 CHECKSUM_STRING (AT_string (name_attr));
6542 /* For all other references to another DIE, we check to see if the
6543 target DIE has already been visited. If it has, we emit a
6544 backward reference; if not, we descend recursively. */
6545 if (target_die->die_mark > 0)
6547 CHECKSUM_ULEB128 ('R');
6548 CHECKSUM_ULEB128 (at->dw_attr);
6549 CHECKSUM_ULEB128 (target_die->die_mark);
6553 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
6557 target_die->die_mark = ++(*mark);
6558 CHECKSUM_ULEB128 ('T');
6559 CHECKSUM_ULEB128 (at->dw_attr);
6560 if (decl->die_parent != NULL)
6561 checksum_die_context (decl->die_parent, ctx);
6562 die_checksum_ordered (target_die, ctx, mark);
6567 CHECKSUM_ULEB128 ('A');
6568 CHECKSUM_ULEB128 (at->dw_attr);
6570 switch (AT_class (at))
6572 case dw_val_class_const:
6573 CHECKSUM_ULEB128 (DW_FORM_sdata);
6574 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
6577 case dw_val_class_unsigned_const:
6578 CHECKSUM_ULEB128 (DW_FORM_sdata);
6579 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
6582 case dw_val_class_const_double:
6583 CHECKSUM_ULEB128 (DW_FORM_block);
6584 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
6585 CHECKSUM (at->dw_attr_val.v.val_double);
6588 case dw_val_class_vec:
6589 CHECKSUM_ULEB128 (DW_FORM_block);
6590 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
6591 CHECKSUM (at->dw_attr_val.v.val_vec);
6594 case dw_val_class_flag:
6595 CHECKSUM_ULEB128 (DW_FORM_flag);
6596 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
6599 case dw_val_class_str:
6600 CHECKSUM_ULEB128 (DW_FORM_string);
6601 CHECKSUM_STRING (AT_string (at));
6604 case dw_val_class_addr:
6606 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6607 CHECKSUM_ULEB128 (DW_FORM_string);
6608 CHECKSUM_STRING (XSTR (r, 0));
6611 case dw_val_class_offset:
6612 CHECKSUM_ULEB128 (DW_FORM_sdata);
6613 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
6616 case dw_val_class_loc:
6617 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6618 loc_checksum_ordered (loc, ctx);
6621 case dw_val_class_fde_ref:
6622 case dw_val_class_lbl_id:
6623 case dw_val_class_lineptr:
6624 case dw_val_class_macptr:
6627 case dw_val_class_file:
6628 CHECKSUM_ULEB128 (DW_FORM_string);
6629 CHECKSUM_STRING (AT_file (at)->filename);
6632 case dw_val_class_data8:
6633 CHECKSUM (at->dw_attr_val.v.val_data8);
6641 struct checksum_attributes
6643 dw_attr_ref at_name;
6644 dw_attr_ref at_type;
6645 dw_attr_ref at_friend;
6646 dw_attr_ref at_accessibility;
6647 dw_attr_ref at_address_class;
6648 dw_attr_ref at_allocated;
6649 dw_attr_ref at_artificial;
6650 dw_attr_ref at_associated;
6651 dw_attr_ref at_binary_scale;
6652 dw_attr_ref at_bit_offset;
6653 dw_attr_ref at_bit_size;
6654 dw_attr_ref at_bit_stride;
6655 dw_attr_ref at_byte_size;
6656 dw_attr_ref at_byte_stride;
6657 dw_attr_ref at_const_value;
6658 dw_attr_ref at_containing_type;
6659 dw_attr_ref at_count;
6660 dw_attr_ref at_data_location;
6661 dw_attr_ref at_data_member_location;
6662 dw_attr_ref at_decimal_scale;
6663 dw_attr_ref at_decimal_sign;
6664 dw_attr_ref at_default_value;
6665 dw_attr_ref at_digit_count;
6666 dw_attr_ref at_discr;
6667 dw_attr_ref at_discr_list;
6668 dw_attr_ref at_discr_value;
6669 dw_attr_ref at_encoding;
6670 dw_attr_ref at_endianity;
6671 dw_attr_ref at_explicit;
6672 dw_attr_ref at_is_optional;
6673 dw_attr_ref at_location;
6674 dw_attr_ref at_lower_bound;
6675 dw_attr_ref at_mutable;
6676 dw_attr_ref at_ordering;
6677 dw_attr_ref at_picture_string;
6678 dw_attr_ref at_prototyped;
6679 dw_attr_ref at_small;
6680 dw_attr_ref at_segment;
6681 dw_attr_ref at_string_length;
6682 dw_attr_ref at_threads_scaled;
6683 dw_attr_ref at_upper_bound;
6684 dw_attr_ref at_use_location;
6685 dw_attr_ref at_use_UTF8;
6686 dw_attr_ref at_variable_parameter;
6687 dw_attr_ref at_virtuality;
6688 dw_attr_ref at_visibility;
6689 dw_attr_ref at_vtable_elem_location;
6692 /* Collect the attributes that we will want to use for the checksum. */
6695 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
6700 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
6711 attrs->at_friend = a;
6713 case DW_AT_accessibility:
6714 attrs->at_accessibility = a;
6716 case DW_AT_address_class:
6717 attrs->at_address_class = a;
6719 case DW_AT_allocated:
6720 attrs->at_allocated = a;
6722 case DW_AT_artificial:
6723 attrs->at_artificial = a;
6725 case DW_AT_associated:
6726 attrs->at_associated = a;
6728 case DW_AT_binary_scale:
6729 attrs->at_binary_scale = a;
6731 case DW_AT_bit_offset:
6732 attrs->at_bit_offset = a;
6734 case DW_AT_bit_size:
6735 attrs->at_bit_size = a;
6737 case DW_AT_bit_stride:
6738 attrs->at_bit_stride = a;
6740 case DW_AT_byte_size:
6741 attrs->at_byte_size = a;
6743 case DW_AT_byte_stride:
6744 attrs->at_byte_stride = a;
6746 case DW_AT_const_value:
6747 attrs->at_const_value = a;
6749 case DW_AT_containing_type:
6750 attrs->at_containing_type = a;
6753 attrs->at_count = a;
6755 case DW_AT_data_location:
6756 attrs->at_data_location = a;
6758 case DW_AT_data_member_location:
6759 attrs->at_data_member_location = a;
6761 case DW_AT_decimal_scale:
6762 attrs->at_decimal_scale = a;
6764 case DW_AT_decimal_sign:
6765 attrs->at_decimal_sign = a;
6767 case DW_AT_default_value:
6768 attrs->at_default_value = a;
6770 case DW_AT_digit_count:
6771 attrs->at_digit_count = a;
6774 attrs->at_discr = a;
6776 case DW_AT_discr_list:
6777 attrs->at_discr_list = a;
6779 case DW_AT_discr_value:
6780 attrs->at_discr_value = a;
6782 case DW_AT_encoding:
6783 attrs->at_encoding = a;
6785 case DW_AT_endianity:
6786 attrs->at_endianity = a;
6788 case DW_AT_explicit:
6789 attrs->at_explicit = a;
6791 case DW_AT_is_optional:
6792 attrs->at_is_optional = a;
6794 case DW_AT_location:
6795 attrs->at_location = a;
6797 case DW_AT_lower_bound:
6798 attrs->at_lower_bound = a;
6801 attrs->at_mutable = a;
6803 case DW_AT_ordering:
6804 attrs->at_ordering = a;
6806 case DW_AT_picture_string:
6807 attrs->at_picture_string = a;
6809 case DW_AT_prototyped:
6810 attrs->at_prototyped = a;
6813 attrs->at_small = a;
6816 attrs->at_segment = a;
6818 case DW_AT_string_length:
6819 attrs->at_string_length = a;
6821 case DW_AT_threads_scaled:
6822 attrs->at_threads_scaled = a;
6824 case DW_AT_upper_bound:
6825 attrs->at_upper_bound = a;
6827 case DW_AT_use_location:
6828 attrs->at_use_location = a;
6830 case DW_AT_use_UTF8:
6831 attrs->at_use_UTF8 = a;
6833 case DW_AT_variable_parameter:
6834 attrs->at_variable_parameter = a;
6836 case DW_AT_virtuality:
6837 attrs->at_virtuality = a;
6839 case DW_AT_visibility:
6840 attrs->at_visibility = a;
6842 case DW_AT_vtable_elem_location:
6843 attrs->at_vtable_elem_location = a;
6851 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6854 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6858 struct checksum_attributes attrs;
6860 CHECKSUM_ULEB128 ('D');
6861 CHECKSUM_ULEB128 (die->die_tag);
6863 memset (&attrs, 0, sizeof (attrs));
6865 decl = get_AT_ref (die, DW_AT_specification);
6867 collect_checksum_attributes (&attrs, decl);
6868 collect_checksum_attributes (&attrs, die);
6870 CHECKSUM_ATTR (attrs.at_name);
6871 CHECKSUM_ATTR (attrs.at_accessibility);
6872 CHECKSUM_ATTR (attrs.at_address_class);
6873 CHECKSUM_ATTR (attrs.at_allocated);
6874 CHECKSUM_ATTR (attrs.at_artificial);
6875 CHECKSUM_ATTR (attrs.at_associated);
6876 CHECKSUM_ATTR (attrs.at_binary_scale);
6877 CHECKSUM_ATTR (attrs.at_bit_offset);
6878 CHECKSUM_ATTR (attrs.at_bit_size);
6879 CHECKSUM_ATTR (attrs.at_bit_stride);
6880 CHECKSUM_ATTR (attrs.at_byte_size);
6881 CHECKSUM_ATTR (attrs.at_byte_stride);
6882 CHECKSUM_ATTR (attrs.at_const_value);
6883 CHECKSUM_ATTR (attrs.at_containing_type);
6884 CHECKSUM_ATTR (attrs.at_count);
6885 CHECKSUM_ATTR (attrs.at_data_location);
6886 CHECKSUM_ATTR (attrs.at_data_member_location);
6887 CHECKSUM_ATTR (attrs.at_decimal_scale);
6888 CHECKSUM_ATTR (attrs.at_decimal_sign);
6889 CHECKSUM_ATTR (attrs.at_default_value);
6890 CHECKSUM_ATTR (attrs.at_digit_count);
6891 CHECKSUM_ATTR (attrs.at_discr);
6892 CHECKSUM_ATTR (attrs.at_discr_list);
6893 CHECKSUM_ATTR (attrs.at_discr_value);
6894 CHECKSUM_ATTR (attrs.at_encoding);
6895 CHECKSUM_ATTR (attrs.at_endianity);
6896 CHECKSUM_ATTR (attrs.at_explicit);
6897 CHECKSUM_ATTR (attrs.at_is_optional);
6898 CHECKSUM_ATTR (attrs.at_location);
6899 CHECKSUM_ATTR (attrs.at_lower_bound);
6900 CHECKSUM_ATTR (attrs.at_mutable);
6901 CHECKSUM_ATTR (attrs.at_ordering);
6902 CHECKSUM_ATTR (attrs.at_picture_string);
6903 CHECKSUM_ATTR (attrs.at_prototyped);
6904 CHECKSUM_ATTR (attrs.at_small);
6905 CHECKSUM_ATTR (attrs.at_segment);
6906 CHECKSUM_ATTR (attrs.at_string_length);
6907 CHECKSUM_ATTR (attrs.at_threads_scaled);
6908 CHECKSUM_ATTR (attrs.at_upper_bound);
6909 CHECKSUM_ATTR (attrs.at_use_location);
6910 CHECKSUM_ATTR (attrs.at_use_UTF8);
6911 CHECKSUM_ATTR (attrs.at_variable_parameter);
6912 CHECKSUM_ATTR (attrs.at_virtuality);
6913 CHECKSUM_ATTR (attrs.at_visibility);
6914 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
6915 CHECKSUM_ATTR (attrs.at_type);
6916 CHECKSUM_ATTR (attrs.at_friend);
6918 /* Checksum the child DIEs, except for nested types and member functions. */
6921 dw_attr_ref name_attr;
6924 name_attr = get_AT (c, DW_AT_name);
6925 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
6926 && name_attr != NULL)
6928 CHECKSUM_ULEB128 ('S');
6929 CHECKSUM_ULEB128 (c->die_tag);
6930 CHECKSUM_STRING (AT_string (name_attr));
6934 /* Mark this DIE so it gets processed when unmarking. */
6935 if (c->die_mark == 0)
6937 die_checksum_ordered (c, ctx, mark);
6939 } while (c != die->die_child);
6941 CHECKSUM_ULEB128 (0);
6945 #undef CHECKSUM_STRING
6946 #undef CHECKSUM_ATTR
6947 #undef CHECKSUM_LEB128
6948 #undef CHECKSUM_ULEB128
6950 /* Generate the type signature for DIE. This is computed by generating an
6951 MD5 checksum over the DIE's tag, its relevant attributes, and its
6952 children. Attributes that are references to other DIEs are processed
6953 by recursion, using the MARK field to prevent infinite recursion.
6954 If the DIE is nested inside a namespace or another type, we also
6955 need to include that context in the signature. The lower 64 bits
6956 of the resulting MD5 checksum comprise the signature. */
6959 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
6963 unsigned char checksum[16];
6967 name = get_AT_string (die, DW_AT_name);
6968 decl = get_AT_ref (die, DW_AT_specification);
6970 /* First, compute a signature for just the type name (and its surrounding
6971 context, if any. This is stored in the type unit DIE for link-time
6972 ODR (one-definition rule) checking. */
6974 if (is_cxx() && name != NULL)
6976 md5_init_ctx (&ctx);
6978 /* Checksum the names of surrounding namespaces and structures. */
6979 if (decl != NULL && decl->die_parent != NULL)
6980 checksum_die_context (decl->die_parent, &ctx);
6982 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
6983 md5_process_bytes (name, strlen (name) + 1, &ctx);
6984 md5_finish_ctx (&ctx, checksum);
6986 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
6989 /* Next, compute the complete type signature. */
6991 md5_init_ctx (&ctx);
6993 die->die_mark = mark;
6995 /* Checksum the names of surrounding namespaces and structures. */
6996 if (decl != NULL && decl->die_parent != NULL)
6997 checksum_die_context (decl->die_parent, &ctx);
6999 /* Checksum the DIE and its children. */
7000 die_checksum_ordered (die, &ctx, &mark);
7001 unmark_all_dies (die);
7002 md5_finish_ctx (&ctx, checksum);
7004 /* Store the signature in the type node and link the type DIE and the
7005 type node together. */
7006 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
7007 DWARF_TYPE_SIGNATURE_SIZE);
7008 die->die_id.die_type_node = type_node;
7009 type_node->type_die = die;
7011 /* If the DIE is a specification, link its declaration to the type node
7014 decl->die_id.die_type_node = type_node;
7017 /* Do the location expressions look same? */
7019 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7021 return loc1->dw_loc_opc == loc2->dw_loc_opc
7022 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7023 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7026 /* Do the values look the same? */
7028 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7030 dw_loc_descr_ref loc1, loc2;
7033 if (v1->val_class != v2->val_class)
7036 switch (v1->val_class)
7038 case dw_val_class_const:
7039 return v1->v.val_int == v2->v.val_int;
7040 case dw_val_class_unsigned_const:
7041 return v1->v.val_unsigned == v2->v.val_unsigned;
7042 case dw_val_class_const_double:
7043 return v1->v.val_double.high == v2->v.val_double.high
7044 && v1->v.val_double.low == v2->v.val_double.low;
7045 case dw_val_class_vec:
7046 if (v1->v.val_vec.length != v2->v.val_vec.length
7047 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7049 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7050 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7053 case dw_val_class_flag:
7054 return v1->v.val_flag == v2->v.val_flag;
7055 case dw_val_class_str:
7056 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7058 case dw_val_class_addr:
7059 r1 = v1->v.val_addr;
7060 r2 = v2->v.val_addr;
7061 if (GET_CODE (r1) != GET_CODE (r2))
7063 return !rtx_equal_p (r1, r2);
7065 case dw_val_class_offset:
7066 return v1->v.val_offset == v2->v.val_offset;
7068 case dw_val_class_loc:
7069 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7071 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7072 if (!same_loc_p (loc1, loc2, mark))
7074 return !loc1 && !loc2;
7076 case dw_val_class_die_ref:
7077 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7079 case dw_val_class_fde_ref:
7080 case dw_val_class_vms_delta:
7081 case dw_val_class_lbl_id:
7082 case dw_val_class_lineptr:
7083 case dw_val_class_macptr:
7086 case dw_val_class_file:
7087 return v1->v.val_file == v2->v.val_file;
7089 case dw_val_class_data8:
7090 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
7097 /* Do the attributes look the same? */
7100 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7102 if (at1->dw_attr != at2->dw_attr)
7105 /* We don't care that this was compiled with a different compiler
7106 snapshot; if the output is the same, that's what matters. */
7107 if (at1->dw_attr == DW_AT_producer)
7110 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7113 /* Do the dies look the same? */
7116 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7122 /* To avoid infinite recursion. */
7124 return die1->die_mark == die2->die_mark;
7125 die1->die_mark = die2->die_mark = ++(*mark);
7127 if (die1->die_tag != die2->die_tag)
7130 if (VEC_length (dw_attr_node, die1->die_attr)
7131 != VEC_length (dw_attr_node, die2->die_attr))
7134 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
7135 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7138 c1 = die1->die_child;
7139 c2 = die2->die_child;
7148 if (!same_die_p (c1, c2, mark))
7152 if (c1 == die1->die_child)
7154 if (c2 == die2->die_child)
7164 /* Do the dies look the same? Wrapper around same_die_p. */
7167 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7170 int ret = same_die_p (die1, die2, &mark);
7172 unmark_all_dies (die1);
7173 unmark_all_dies (die2);
7178 /* The prefix to attach to symbols on DIEs in the current comdat debug
7180 static char *comdat_symbol_id;
7182 /* The index of the current symbol within the current comdat CU. */
7183 static unsigned int comdat_symbol_number;
7185 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7186 children, and set comdat_symbol_id accordingly. */
7189 compute_section_prefix (dw_die_ref unit_die)
7191 const char *die_name = get_AT_string (unit_die, DW_AT_name);
7192 const char *base = die_name ? lbasename (die_name) : "anonymous";
7193 char *name = XALLOCAVEC (char, strlen (base) + 64);
7196 unsigned char checksum[16];
7199 /* Compute the checksum of the DIE, then append part of it as hex digits to
7200 the name filename of the unit. */
7202 md5_init_ctx (&ctx);
7204 die_checksum (unit_die, &ctx, &mark);
7205 unmark_all_dies (unit_die);
7206 md5_finish_ctx (&ctx, checksum);
7208 sprintf (name, "%s.", base);
7209 clean_symbol_name (name);
7211 p = name + strlen (name);
7212 for (i = 0; i < 4; i++)
7214 sprintf (p, "%.2x", checksum[i]);
7218 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
7219 comdat_symbol_number = 0;
7222 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7225 is_type_die (dw_die_ref die)
7227 switch (die->die_tag)
7229 case DW_TAG_array_type:
7230 case DW_TAG_class_type:
7231 case DW_TAG_interface_type:
7232 case DW_TAG_enumeration_type:
7233 case DW_TAG_pointer_type:
7234 case DW_TAG_reference_type:
7235 case DW_TAG_rvalue_reference_type:
7236 case DW_TAG_string_type:
7237 case DW_TAG_structure_type:
7238 case DW_TAG_subroutine_type:
7239 case DW_TAG_union_type:
7240 case DW_TAG_ptr_to_member_type:
7241 case DW_TAG_set_type:
7242 case DW_TAG_subrange_type:
7243 case DW_TAG_base_type:
7244 case DW_TAG_const_type:
7245 case DW_TAG_file_type:
7246 case DW_TAG_packed_type:
7247 case DW_TAG_volatile_type:
7248 case DW_TAG_typedef:
7255 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7256 Basically, we want to choose the bits that are likely to be shared between
7257 compilations (types) and leave out the bits that are specific to individual
7258 compilations (functions). */
7261 is_comdat_die (dw_die_ref c)
7263 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7264 we do for stabs. The advantage is a greater likelihood of sharing between
7265 objects that don't include headers in the same order (and therefore would
7266 put the base types in a different comdat). jason 8/28/00 */
7268 if (c->die_tag == DW_TAG_base_type)
7271 if (c->die_tag == DW_TAG_pointer_type
7272 || c->die_tag == DW_TAG_reference_type
7273 || c->die_tag == DW_TAG_rvalue_reference_type
7274 || c->die_tag == DW_TAG_const_type
7275 || c->die_tag == DW_TAG_volatile_type)
7277 dw_die_ref t = get_AT_ref (c, DW_AT_type);
7279 return t ? is_comdat_die (t) : 0;
7282 return is_type_die (c);
7285 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7286 compilation unit. */
7289 is_symbol_die (dw_die_ref c)
7291 return (is_type_die (c)
7292 || is_declaration_die (c)
7293 || c->die_tag == DW_TAG_namespace
7294 || c->die_tag == DW_TAG_module);
7297 /* Returns true iff C is a compile-unit DIE. */
7300 is_cu_die (dw_die_ref c)
7302 return c && c->die_tag == DW_TAG_compile_unit;
7306 gen_internal_sym (const char *prefix)
7310 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7311 return xstrdup (buf);
7314 /* Assign symbols to all worthy DIEs under DIE. */
7317 assign_symbol_names (dw_die_ref die)
7321 if (is_symbol_die (die))
7323 if (comdat_symbol_id)
7325 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7327 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7328 comdat_symbol_id, comdat_symbol_number++);
7329 die->die_id.die_symbol = xstrdup (p);
7332 die->die_id.die_symbol = gen_internal_sym ("LDIE");
7335 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7338 struct cu_hash_table_entry
7341 unsigned min_comdat_num, max_comdat_num;
7342 struct cu_hash_table_entry *next;
7345 /* Routines to manipulate hash table of CUs. */
7347 htab_cu_hash (const void *of)
7349 const struct cu_hash_table_entry *const entry =
7350 (const struct cu_hash_table_entry *) of;
7352 return htab_hash_string (entry->cu->die_id.die_symbol);
7356 htab_cu_eq (const void *of1, const void *of2)
7358 const struct cu_hash_table_entry *const entry1 =
7359 (const struct cu_hash_table_entry *) of1;
7360 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7362 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
7366 htab_cu_del (void *what)
7368 struct cu_hash_table_entry *next,
7369 *entry = (struct cu_hash_table_entry *) what;
7379 /* Check whether we have already seen this CU and set up SYM_NUM
7382 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
7384 struct cu_hash_table_entry dummy;
7385 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7387 dummy.max_comdat_num = 0;
7389 slot = (struct cu_hash_table_entry **)
7390 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
7394 for (; entry; last = entry, entry = entry->next)
7396 if (same_die_p_wrap (cu, entry->cu))
7402 *sym_num = entry->min_comdat_num;
7406 entry = XCNEW (struct cu_hash_table_entry);
7408 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7409 entry->next = *slot;
7415 /* Record SYM_NUM to record of CU in HTABLE. */
7417 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
7419 struct cu_hash_table_entry **slot, *entry;
7421 slot = (struct cu_hash_table_entry **)
7422 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
7426 entry->max_comdat_num = sym_num;
7429 /* Traverse the DIE (which is always comp_unit_die), and set up
7430 additional compilation units for each of the include files we see
7431 bracketed by BINCL/EINCL. */
7434 break_out_includes (dw_die_ref die)
7437 dw_die_ref unit = NULL;
7438 limbo_die_node *node, **pnode;
7439 htab_t cu_hash_table;
7443 dw_die_ref prev = c;
7445 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7446 || (unit && is_comdat_die (c)))
7448 dw_die_ref next = c->die_sib;
7450 /* This DIE is for a secondary CU; remove it from the main one. */
7451 remove_child_with_prev (c, prev);
7453 if (c->die_tag == DW_TAG_GNU_BINCL)
7454 unit = push_new_compile_unit (unit, c);
7455 else if (c->die_tag == DW_TAG_GNU_EINCL)
7456 unit = pop_compile_unit (unit);
7458 add_child_die (unit, c);
7460 if (c == die->die_child)
7463 } while (c != die->die_child);
7466 /* We can only use this in debugging, since the frontend doesn't check
7467 to make sure that we leave every include file we enter. */
7471 assign_symbol_names (die);
7472 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7473 for (node = limbo_die_list, pnode = &limbo_die_list;
7479 compute_section_prefix (node->die);
7480 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7481 &comdat_symbol_number);
7482 assign_symbol_names (node->die);
7484 *pnode = node->next;
7487 pnode = &node->next;
7488 record_comdat_symbol_number (node->die, cu_hash_table,
7489 comdat_symbol_number);
7492 htab_delete (cu_hash_table);
7495 /* Return non-zero if this DIE is a declaration. */
7498 is_declaration_die (dw_die_ref die)
7503 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7504 if (a->dw_attr == DW_AT_declaration)
7510 /* Return non-zero if this DIE is nested inside a subprogram. */
7513 is_nested_in_subprogram (dw_die_ref die)
7515 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
7519 return local_scope_p (decl);
7522 /* Return non-zero if this DIE contains a defining declaration of a
7526 contains_subprogram_definition (dw_die_ref die)
7530 if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
7532 FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
7536 /* Return non-zero if this is a type DIE that should be moved to a
7537 COMDAT .debug_types section. */
7540 should_move_die_to_comdat (dw_die_ref die)
7542 switch (die->die_tag)
7544 case DW_TAG_class_type:
7545 case DW_TAG_structure_type:
7546 case DW_TAG_enumeration_type:
7547 case DW_TAG_union_type:
7548 /* Don't move declarations, inlined instances, or types nested in a
7550 if (is_declaration_die (die)
7551 || get_AT (die, DW_AT_abstract_origin)
7552 || is_nested_in_subprogram (die))
7554 /* A type definition should never contain a subprogram definition. */
7555 gcc_assert (!contains_subprogram_definition (die));
7557 case DW_TAG_array_type:
7558 case DW_TAG_interface_type:
7559 case DW_TAG_pointer_type:
7560 case DW_TAG_reference_type:
7561 case DW_TAG_rvalue_reference_type:
7562 case DW_TAG_string_type:
7563 case DW_TAG_subroutine_type:
7564 case DW_TAG_ptr_to_member_type:
7565 case DW_TAG_set_type:
7566 case DW_TAG_subrange_type:
7567 case DW_TAG_base_type:
7568 case DW_TAG_const_type:
7569 case DW_TAG_file_type:
7570 case DW_TAG_packed_type:
7571 case DW_TAG_volatile_type:
7572 case DW_TAG_typedef:
7578 /* Make a clone of DIE. */
7581 clone_die (dw_die_ref die)
7587 clone = ggc_alloc_cleared_die_node ();
7588 clone->die_tag = die->die_tag;
7590 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7591 add_dwarf_attr (clone, a);
7596 /* Make a clone of the tree rooted at DIE. */
7599 clone_tree (dw_die_ref die)
7602 dw_die_ref clone = clone_die (die);
7604 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
7609 /* Make a clone of DIE as a declaration. */
7612 clone_as_declaration (dw_die_ref die)
7619 /* If the DIE is already a declaration, just clone it. */
7620 if (is_declaration_die (die))
7621 return clone_die (die);
7623 /* If the DIE is a specification, just clone its declaration DIE. */
7624 decl = get_AT_ref (die, DW_AT_specification);
7626 return clone_die (decl);
7628 clone = ggc_alloc_cleared_die_node ();
7629 clone->die_tag = die->die_tag;
7631 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7633 /* We don't want to copy over all attributes.
7634 For example we don't want DW_AT_byte_size because otherwise we will no
7635 longer have a declaration and GDB will treat it as a definition. */
7639 case DW_AT_artificial:
7640 case DW_AT_containing_type:
7641 case DW_AT_external:
7644 case DW_AT_virtuality:
7645 case DW_AT_linkage_name:
7646 case DW_AT_MIPS_linkage_name:
7647 add_dwarf_attr (clone, a);
7649 case DW_AT_byte_size:
7655 if (die->die_id.die_type_node)
7656 add_AT_die_ref (clone, DW_AT_signature, die);
7658 add_AT_flag (clone, DW_AT_declaration, 1);
7662 /* Copy the declaration context to the new compile unit DIE. This includes
7663 any surrounding namespace or type declarations. If the DIE has an
7664 AT_specification attribute, it also includes attributes and children
7665 attached to the specification. */
7668 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
7671 dw_die_ref new_decl;
7673 decl = get_AT_ref (die, DW_AT_specification);
7682 /* Copy the type node pointer from the new DIE to the original
7683 declaration DIE so we can forward references later. */
7684 decl->die_id.die_type_node = die->die_id.die_type_node;
7686 remove_AT (die, DW_AT_specification);
7688 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
7690 if (a->dw_attr != DW_AT_name
7691 && a->dw_attr != DW_AT_declaration
7692 && a->dw_attr != DW_AT_external)
7693 add_dwarf_attr (die, a);
7696 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
7699 if (decl->die_parent != NULL
7700 && decl->die_parent->die_tag != DW_TAG_compile_unit
7701 && decl->die_parent->die_tag != DW_TAG_type_unit)
7703 new_decl = copy_ancestor_tree (unit, decl, NULL);
7704 if (new_decl != NULL)
7706 remove_AT (new_decl, DW_AT_signature);
7707 add_AT_specification (die, new_decl);
7712 /* Generate the skeleton ancestor tree for the given NODE, then clone
7713 the DIE and add the clone into the tree. */
7716 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
7718 if (node->new_die != NULL)
7721 node->new_die = clone_as_declaration (node->old_die);
7723 if (node->parent != NULL)
7725 generate_skeleton_ancestor_tree (node->parent);
7726 add_child_die (node->parent->new_die, node->new_die);
7730 /* Generate a skeleton tree of DIEs containing any declarations that are
7731 found in the original tree. We traverse the tree looking for declaration
7732 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7735 generate_skeleton_bottom_up (skeleton_chain_node *parent)
7737 skeleton_chain_node node;
7740 dw_die_ref prev = NULL;
7741 dw_die_ref next = NULL;
7743 node.parent = parent;
7745 first = c = parent->old_die->die_child;
7749 if (prev == NULL || prev->die_sib == c)
7752 next = (c == first ? NULL : c->die_sib);
7754 node.new_die = NULL;
7755 if (is_declaration_die (c))
7757 /* Clone the existing DIE, move the original to the skeleton
7758 tree (which is in the main CU), and put the clone, with
7759 all the original's children, where the original came from. */
7760 dw_die_ref clone = clone_die (c);
7761 move_all_children (c, clone);
7763 replace_child (c, clone, prev);
7764 generate_skeleton_ancestor_tree (parent);
7765 add_child_die (parent->new_die, c);
7769 generate_skeleton_bottom_up (&node);
7770 } while (next != NULL);
7773 /* Wrapper function for generate_skeleton_bottom_up. */
7776 generate_skeleton (dw_die_ref die)
7778 skeleton_chain_node node;
7781 node.new_die = NULL;
7784 /* If this type definition is nested inside another type,
7785 always leave at least a declaration in its place. */
7786 if (die->die_parent != NULL && is_type_die (die->die_parent))
7787 node.new_die = clone_as_declaration (die);
7789 generate_skeleton_bottom_up (&node);
7790 return node.new_die;
7793 /* Remove the DIE from its parent, possibly replacing it with a cloned
7794 declaration. The original DIE will be moved to a new compile unit
7795 so that existing references to it follow it to the new location. If
7796 any of the original DIE's descendants is a declaration, we need to
7797 replace the original DIE with a skeleton tree and move the
7798 declarations back into the skeleton tree. */
7801 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
7803 dw_die_ref skeleton;
7805 skeleton = generate_skeleton (child);
7806 if (skeleton == NULL)
7807 remove_child_with_prev (child, prev);
7810 skeleton->die_id.die_type_node = child->die_id.die_type_node;
7811 replace_child (child, skeleton, prev);
7817 /* Traverse the DIE and set up additional .debug_types sections for each
7818 type worthy of being placed in a COMDAT section. */
7821 break_out_comdat_types (dw_die_ref die)
7825 dw_die_ref prev = NULL;
7826 dw_die_ref next = NULL;
7827 dw_die_ref unit = NULL;
7829 first = c = die->die_child;
7833 if (prev == NULL || prev->die_sib == c)
7836 next = (c == first ? NULL : c->die_sib);
7837 if (should_move_die_to_comdat (c))
7839 dw_die_ref replacement;
7840 comdat_type_node_ref type_node;
7842 /* Create a new type unit DIE as the root for the new tree, and
7843 add it to the list of comdat types. */
7844 unit = new_die (DW_TAG_type_unit, NULL, NULL);
7845 add_AT_unsigned (unit, DW_AT_language,
7846 get_AT_unsigned (comp_unit_die (), DW_AT_language));
7847 type_node = ggc_alloc_cleared_comdat_type_node ();
7848 type_node->root_die = unit;
7849 type_node->next = comdat_type_list;
7850 comdat_type_list = type_node;
7852 /* Generate the type signature. */
7853 generate_type_signature (c, type_node);
7855 /* Copy the declaration context, attributes, and children of the
7856 declaration into the new compile unit DIE. */
7857 copy_declaration_context (unit, c);
7859 /* Remove this DIE from the main CU. */
7860 replacement = remove_child_or_replace_with_skeleton (c, prev);
7862 /* Break out nested types into their own type units. */
7863 break_out_comdat_types (c);
7865 /* Add the DIE to the new compunit. */
7866 add_child_die (unit, c);
7868 if (replacement != NULL)
7871 else if (c->die_tag == DW_TAG_namespace
7872 || c->die_tag == DW_TAG_class_type
7873 || c->die_tag == DW_TAG_structure_type
7874 || c->die_tag == DW_TAG_union_type)
7876 /* Look for nested types that can be broken out. */
7877 break_out_comdat_types (c);
7879 } while (next != NULL);
7882 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7884 struct decl_table_entry
7890 /* Routines to manipulate hash table of copied declarations. */
7893 htab_decl_hash (const void *of)
7895 const struct decl_table_entry *const entry =
7896 (const struct decl_table_entry *) of;
7898 return htab_hash_pointer (entry->orig);
7902 htab_decl_eq (const void *of1, const void *of2)
7904 const struct decl_table_entry *const entry1 =
7905 (const struct decl_table_entry *) of1;
7906 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7908 return entry1->orig == entry2;
7912 htab_decl_del (void *what)
7914 struct decl_table_entry *entry = (struct decl_table_entry *) what;
7919 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7920 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7921 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7922 to check if the ancestor has already been copied into UNIT. */
7925 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7927 dw_die_ref parent = die->die_parent;
7928 dw_die_ref new_parent = unit;
7931 struct decl_table_entry *entry = NULL;
7935 /* Check if the entry has already been copied to UNIT. */
7936 slot = htab_find_slot_with_hash (decl_table, die,
7937 htab_hash_pointer (die), INSERT);
7938 if (*slot != HTAB_EMPTY_ENTRY)
7940 entry = (struct decl_table_entry *) *slot;
7944 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7945 entry = XCNEW (struct decl_table_entry);
7953 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
7956 if (parent->die_tag != DW_TAG_compile_unit
7957 && parent->die_tag != DW_TAG_type_unit)
7958 new_parent = copy_ancestor_tree (unit, parent, decl_table);
7961 copy = clone_as_declaration (die);
7962 add_child_die (new_parent, copy);
7964 if (decl_table != NULL)
7966 /* Record the pointer to the copy. */
7973 /* Walk the DIE and its children, looking for references to incomplete
7974 or trivial types that are unmarked (i.e., that are not in the current
7978 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
7984 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7986 if (AT_class (a) == dw_val_class_die_ref)
7988 dw_die_ref targ = AT_ref (a);
7989 comdat_type_node_ref type_node = targ->die_id.die_type_node;
7991 struct decl_table_entry *entry;
7993 if (targ->die_mark != 0 || type_node != NULL)
7996 slot = htab_find_slot_with_hash (decl_table, targ,
7997 htab_hash_pointer (targ), INSERT);
7999 if (*slot != HTAB_EMPTY_ENTRY)
8001 /* TARG has already been copied, so we just need to
8002 modify the reference to point to the copy. */
8003 entry = (struct decl_table_entry *) *slot;
8004 a->dw_attr_val.v.val_die_ref.die = entry->copy;
8008 dw_die_ref parent = unit;
8009 dw_die_ref copy = clone_tree (targ);
8011 /* Make sure the cloned tree is marked as part of the
8015 /* Record in DECL_TABLE that TARG has been copied.
8016 Need to do this now, before the recursive call,
8017 because DECL_TABLE may be expanded and SLOT
8018 would no longer be a valid pointer. */
8019 entry = XCNEW (struct decl_table_entry);
8024 /* If TARG has surrounding context, copy its ancestor tree
8025 into the new type unit. */
8026 if (targ->die_parent != NULL
8027 && targ->die_parent->die_tag != DW_TAG_compile_unit
8028 && targ->die_parent->die_tag != DW_TAG_type_unit)
8029 parent = copy_ancestor_tree (unit, targ->die_parent,
8032 add_child_die (parent, copy);
8033 a->dw_attr_val.v.val_die_ref.die = copy;
8035 /* Make sure the newly-copied DIE is walked. If it was
8036 installed in a previously-added context, it won't
8037 get visited otherwise. */
8040 /* Find the highest point of the newly-added tree,
8041 mark each node along the way, and walk from there. */
8042 parent->die_mark = 1;
8043 while (parent->die_parent
8044 && parent->die_parent->die_mark == 0)
8046 parent = parent->die_parent;
8047 parent->die_mark = 1;
8049 copy_decls_walk (unit, parent, decl_table);
8055 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
8058 /* Copy declarations for "unworthy" types into the new comdat section.
8059 Incomplete types, modified types, and certain other types aren't broken
8060 out into comdat sections of their own, so they don't have a signature,
8061 and we need to copy the declaration into the same section so that we
8062 don't have an external reference. */
8065 copy_decls_for_unworthy_types (dw_die_ref unit)
8070 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
8071 copy_decls_walk (unit, unit, decl_table);
8072 htab_delete (decl_table);
8076 /* Traverse the DIE and add a sibling attribute if it may have the
8077 effect of speeding up access to siblings. To save some space,
8078 avoid generating sibling attributes for DIE's without children. */
8081 add_sibling_attributes (dw_die_ref die)
8085 if (! die->die_child)
8088 if (die->die_parent && die != die->die_parent->die_child)
8089 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
8091 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
8094 /* Output all location lists for the DIE and its children. */
8097 output_location_lists (dw_die_ref die)
8103 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8104 if (AT_class (a) == dw_val_class_loc_list)
8105 output_loc_list (AT_loc_list (a));
8107 FOR_EACH_CHILD (die, c, output_location_lists (c));
8110 /* The format of each DIE (and its attribute value pairs) is encoded in an
8111 abbreviation table. This routine builds the abbreviation table and assigns
8112 a unique abbreviation id for each abbreviation entry. The children of each
8113 die are visited recursively. */
8116 build_abbrev_table (dw_die_ref die)
8118 unsigned long abbrev_id;
8119 unsigned int n_alloc;
8124 /* Scan the DIE references, and mark as external any that refer to
8125 DIEs from other CUs (i.e. those which are not marked). */
8126 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8127 if (AT_class (a) == dw_val_class_die_ref
8128 && AT_ref (a)->die_mark == 0)
8130 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
8131 set_AT_ref_external (a, 1);
8134 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8136 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8137 dw_attr_ref die_a, abbrev_a;
8141 if (abbrev->die_tag != die->die_tag)
8143 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
8146 if (VEC_length (dw_attr_node, abbrev->die_attr)
8147 != VEC_length (dw_attr_node, die->die_attr))
8150 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
8152 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
8153 if ((abbrev_a->dw_attr != die_a->dw_attr)
8154 || (value_format (abbrev_a) != value_format (die_a)))
8164 if (abbrev_id >= abbrev_die_table_in_use)
8166 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
8168 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
8169 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8172 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8173 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8174 abbrev_die_table_allocated = n_alloc;
8177 ++abbrev_die_table_in_use;
8178 abbrev_die_table[abbrev_id] = die;
8181 die->die_abbrev = abbrev_id;
8182 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
8185 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8188 constant_size (unsigned HOST_WIDE_INT value)
8195 log = floor_log2 (value);
8198 log = 1 << (floor_log2 (log) + 1);
8203 /* Return the size of a DIE as it is represented in the
8204 .debug_info section. */
8206 static unsigned long
8207 size_of_die (dw_die_ref die)
8209 unsigned long size = 0;
8213 size += size_of_uleb128 (die->die_abbrev);
8214 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8216 switch (AT_class (a))
8218 case dw_val_class_addr:
8219 size += DWARF2_ADDR_SIZE;
8221 case dw_val_class_offset:
8222 size += DWARF_OFFSET_SIZE;
8224 case dw_val_class_loc:
8226 unsigned long lsize = size_of_locs (AT_loc (a));
8229 if (dwarf_version >= 4)
8230 size += size_of_uleb128 (lsize);
8232 size += constant_size (lsize);
8236 case dw_val_class_loc_list:
8237 size += DWARF_OFFSET_SIZE;
8239 case dw_val_class_range_list:
8240 size += DWARF_OFFSET_SIZE;
8242 case dw_val_class_const:
8243 size += size_of_sleb128 (AT_int (a));
8245 case dw_val_class_unsigned_const:
8246 size += constant_size (AT_unsigned (a));
8248 case dw_val_class_const_double:
8249 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
8250 if (HOST_BITS_PER_WIDE_INT >= 64)
8253 case dw_val_class_vec:
8254 size += constant_size (a->dw_attr_val.v.val_vec.length
8255 * a->dw_attr_val.v.val_vec.elt_size)
8256 + a->dw_attr_val.v.val_vec.length
8257 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8259 case dw_val_class_flag:
8260 if (dwarf_version >= 4)
8261 /* Currently all add_AT_flag calls pass in 1 as last argument,
8262 so DW_FORM_flag_present can be used. If that ever changes,
8263 we'll need to use DW_FORM_flag and have some optimization
8264 in build_abbrev_table that will change those to
8265 DW_FORM_flag_present if it is set to 1 in all DIEs using
8266 the same abbrev entry. */
8267 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8271 case dw_val_class_die_ref:
8272 if (AT_ref_external (a))
8274 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8275 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8276 is sized by target address length, whereas in DWARF3
8277 it's always sized as an offset. */
8278 if (use_debug_types)
8279 size += DWARF_TYPE_SIGNATURE_SIZE;
8280 else if (dwarf_version == 2)
8281 size += DWARF2_ADDR_SIZE;
8283 size += DWARF_OFFSET_SIZE;
8286 size += DWARF_OFFSET_SIZE;
8288 case dw_val_class_fde_ref:
8289 size += DWARF_OFFSET_SIZE;
8291 case dw_val_class_lbl_id:
8292 size += DWARF2_ADDR_SIZE;
8294 case dw_val_class_lineptr:
8295 case dw_val_class_macptr:
8296 size += DWARF_OFFSET_SIZE;
8298 case dw_val_class_str:
8299 if (AT_string_form (a) == DW_FORM_strp)
8300 size += DWARF_OFFSET_SIZE;
8302 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8304 case dw_val_class_file:
8305 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8307 case dw_val_class_data8:
8310 case dw_val_class_vms_delta:
8311 size += DWARF_OFFSET_SIZE;
8321 /* Size the debugging information associated with a given DIE. Visits the
8322 DIE's children recursively. Updates the global variable next_die_offset, on
8323 each time through. Uses the current value of next_die_offset to update the
8324 die_offset field in each DIE. */
8327 calc_die_sizes (dw_die_ref die)
8331 gcc_assert (die->die_offset == 0
8332 || (unsigned long int) die->die_offset == next_die_offset);
8333 die->die_offset = next_die_offset;
8334 next_die_offset += size_of_die (die);
8336 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8338 if (die->die_child != NULL)
8339 /* Count the null byte used to terminate sibling lists. */
8340 next_die_offset += 1;
8343 /* Size just the base type children at the start of the CU.
8344 This is needed because build_abbrev needs to size locs
8345 and sizing of type based stack ops needs to know die_offset
8346 values for the base types. */
8349 calc_base_type_die_sizes (void)
8351 unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8353 dw_die_ref base_type;
8354 #if ENABLE_ASSERT_CHECKING
8355 dw_die_ref prev = comp_unit_die ()->die_child;
8358 die_offset += size_of_die (comp_unit_die ());
8359 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
8361 #if ENABLE_ASSERT_CHECKING
8362 gcc_assert (base_type->die_offset == 0
8363 && prev->die_sib == base_type
8364 && base_type->die_child == NULL
8365 && base_type->die_abbrev);
8368 base_type->die_offset = die_offset;
8369 die_offset += size_of_die (base_type);
8373 /* Set the marks for a die and its children. We do this so
8374 that we know whether or not a reference needs to use FORM_ref_addr; only
8375 DIEs in the same CU will be marked. We used to clear out the offset
8376 and use that as the flag, but ran into ordering problems. */
8379 mark_dies (dw_die_ref die)
8383 gcc_assert (!die->die_mark);
8386 FOR_EACH_CHILD (die, c, mark_dies (c));
8389 /* Clear the marks for a die and its children. */
8392 unmark_dies (dw_die_ref die)
8396 if (! use_debug_types)
8397 gcc_assert (die->die_mark);
8400 FOR_EACH_CHILD (die, c, unmark_dies (c));
8403 /* Clear the marks for a die, its children and referred dies. */
8406 unmark_all_dies (dw_die_ref die)
8416 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8418 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8419 if (AT_class (a) == dw_val_class_die_ref)
8420 unmark_all_dies (AT_ref (a));
8423 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8424 generated for the compilation unit. */
8426 static unsigned long
8427 size_of_pubnames (VEC (pubname_entry, gc) * names)
8433 size = DWARF_PUBNAMES_HEADER_SIZE;
8434 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
8435 if (names != pubtype_table
8436 || p->die->die_offset != 0
8437 || !flag_eliminate_unused_debug_types)
8438 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
8440 size += DWARF_OFFSET_SIZE;
8444 /* Return the size of the information in the .debug_aranges section. */
8446 static unsigned long
8447 size_of_aranges (void)
8451 size = DWARF_ARANGES_HEADER_SIZE;
8453 /* Count the address/length pair for this compilation unit. */
8454 if (text_section_used)
8455 size += 2 * DWARF2_ADDR_SIZE;
8456 if (cold_text_section_used)
8457 size += 2 * DWARF2_ADDR_SIZE;
8458 if (have_multiple_function_sections)
8460 unsigned fde_idx = 0;
8462 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
8464 dw_fde_ref fde = &fde_table[fde_idx];
8466 if (!fde->in_std_section)
8467 size += 2 * DWARF2_ADDR_SIZE;
8468 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
8469 size += 2 * DWARF2_ADDR_SIZE;
8473 /* Count the two zero words used to terminated the address range table. */
8474 size += 2 * DWARF2_ADDR_SIZE;
8478 /* Select the encoding of an attribute value. */
8480 static enum dwarf_form
8481 value_format (dw_attr_ref a)
8483 switch (a->dw_attr_val.val_class)
8485 case dw_val_class_addr:
8486 /* Only very few attributes allow DW_FORM_addr. */
8491 case DW_AT_entry_pc:
8492 case DW_AT_trampoline:
8493 return DW_FORM_addr;
8497 switch (DWARF2_ADDR_SIZE)
8500 return DW_FORM_data1;
8502 return DW_FORM_data2;
8504 return DW_FORM_data4;
8506 return DW_FORM_data8;
8510 case dw_val_class_range_list:
8511 case dw_val_class_loc_list:
8512 if (dwarf_version >= 4)
8513 return DW_FORM_sec_offset;
8515 case dw_val_class_vms_delta:
8516 case dw_val_class_offset:
8517 switch (DWARF_OFFSET_SIZE)
8520 return DW_FORM_data4;
8522 return DW_FORM_data8;
8526 case dw_val_class_loc:
8527 if (dwarf_version >= 4)
8528 return DW_FORM_exprloc;
8529 switch (constant_size (size_of_locs (AT_loc (a))))
8532 return DW_FORM_block1;
8534 return DW_FORM_block2;
8538 case dw_val_class_const:
8539 return DW_FORM_sdata;
8540 case dw_val_class_unsigned_const:
8541 switch (constant_size (AT_unsigned (a)))
8544 return DW_FORM_data1;
8546 return DW_FORM_data2;
8548 return DW_FORM_data4;
8550 return DW_FORM_data8;
8554 case dw_val_class_const_double:
8555 switch (HOST_BITS_PER_WIDE_INT)
8558 return DW_FORM_data2;
8560 return DW_FORM_data4;
8562 return DW_FORM_data8;
8565 return DW_FORM_block1;
8567 case dw_val_class_vec:
8568 switch (constant_size (a->dw_attr_val.v.val_vec.length
8569 * a->dw_attr_val.v.val_vec.elt_size))
8572 return DW_FORM_block1;
8574 return DW_FORM_block2;
8576 return DW_FORM_block4;
8580 case dw_val_class_flag:
8581 if (dwarf_version >= 4)
8583 /* Currently all add_AT_flag calls pass in 1 as last argument,
8584 so DW_FORM_flag_present can be used. If that ever changes,
8585 we'll need to use DW_FORM_flag and have some optimization
8586 in build_abbrev_table that will change those to
8587 DW_FORM_flag_present if it is set to 1 in all DIEs using
8588 the same abbrev entry. */
8589 gcc_assert (a->dw_attr_val.v.val_flag == 1);
8590 return DW_FORM_flag_present;
8592 return DW_FORM_flag;
8593 case dw_val_class_die_ref:
8594 if (AT_ref_external (a))
8595 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
8598 case dw_val_class_fde_ref:
8599 return DW_FORM_data;
8600 case dw_val_class_lbl_id:
8601 return DW_FORM_addr;
8602 case dw_val_class_lineptr:
8603 case dw_val_class_macptr:
8604 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
8605 case dw_val_class_str:
8606 return AT_string_form (a);
8607 case dw_val_class_file:
8608 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8611 return DW_FORM_data1;
8613 return DW_FORM_data2;
8615 return DW_FORM_data4;
8620 case dw_val_class_data8:
8621 return DW_FORM_data8;
8628 /* Output the encoding of an attribute value. */
8631 output_value_format (dw_attr_ref a)
8633 enum dwarf_form form = value_format (a);
8635 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8638 /* Output the .debug_abbrev section which defines the DIE abbreviation
8642 output_abbrev_section (void)
8644 unsigned long abbrev_id;
8646 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8648 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8652 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8653 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8654 dwarf_tag_name (abbrev->die_tag));
8656 if (abbrev->die_child != NULL)
8657 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8659 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8661 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8664 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8665 dwarf_attr_name (a_attr->dw_attr));
8666 output_value_format (a_attr);
8669 dw2_asm_output_data (1, 0, NULL);
8670 dw2_asm_output_data (1, 0, NULL);
8673 /* Terminate the table. */
8674 dw2_asm_output_data (1, 0, NULL);
8677 /* Output a symbol we can use to refer to this DIE from another CU. */
8680 output_die_symbol (dw_die_ref die)
8682 char *sym = die->die_id.die_symbol;
8687 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8688 /* We make these global, not weak; if the target doesn't support
8689 .linkonce, it doesn't support combining the sections, so debugging
8691 targetm.asm_out.globalize_label (asm_out_file, sym);
8693 ASM_OUTPUT_LABEL (asm_out_file, sym);
8696 /* Return a new location list, given the begin and end range, and the
8699 static inline dw_loc_list_ref
8700 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8701 const char *section)
8703 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
8705 retlist->begin = begin;
8707 retlist->expr = expr;
8708 retlist->section = section;
8713 /* Generate a new internal symbol for this location list node, if it
8714 hasn't got one yet. */
8717 gen_llsym (dw_loc_list_ref list)
8719 gcc_assert (!list->ll_symbol);
8720 list->ll_symbol = gen_internal_sym ("LLST");
8723 /* Output the location list given to us. */
8726 output_loc_list (dw_loc_list_ref list_head)
8728 dw_loc_list_ref curr = list_head;
8730 if (list_head->emitted)
8732 list_head->emitted = true;
8734 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8736 /* Walk the location list, and output each range + expression. */
8737 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8740 /* Don't output an entry that starts and ends at the same address. */
8741 if (strcmp (curr->begin, curr->end) == 0 && !curr->force)
8743 if (!have_multiple_function_sections)
8745 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8746 "Location list begin address (%s)",
8747 list_head->ll_symbol);
8748 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8749 "Location list end address (%s)",
8750 list_head->ll_symbol);
8754 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8755 "Location list begin address (%s)",
8756 list_head->ll_symbol);
8757 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8758 "Location list end address (%s)",
8759 list_head->ll_symbol);
8761 size = size_of_locs (curr->expr);
8763 /* Output the block length for this list of location operations. */
8764 gcc_assert (size <= 0xffff);
8765 dw2_asm_output_data (2, size, "%s", "Location expression size");
8767 output_loc_sequence (curr->expr, -1);
8770 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8771 "Location list terminator begin (%s)",
8772 list_head->ll_symbol);
8773 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8774 "Location list terminator end (%s)",
8775 list_head->ll_symbol);
8778 /* Output a type signature. */
8781 output_signature (const char *sig, const char *name)
8785 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8786 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
8789 /* Output the DIE and its attributes. Called recursively to generate
8790 the definitions of each child DIE. */
8793 output_die (dw_die_ref die)
8800 /* If someone in another CU might refer to us, set up a symbol for
8801 them to point to. */
8802 if (! use_debug_types && die->die_id.die_symbol)
8803 output_die_symbol (die);
8805 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
8806 (unsigned long)die->die_offset,
8807 dwarf_tag_name (die->die_tag));
8809 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8811 const char *name = dwarf_attr_name (a->dw_attr);
8813 switch (AT_class (a))
8815 case dw_val_class_addr:
8816 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8819 case dw_val_class_offset:
8820 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8824 case dw_val_class_range_list:
8826 char *p = strchr (ranges_section_label, '\0');
8828 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8829 a->dw_attr_val.v.val_offset);
8830 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8831 debug_ranges_section, "%s", name);
8836 case dw_val_class_loc:
8837 size = size_of_locs (AT_loc (a));
8839 /* Output the block length for this list of location operations. */
8840 if (dwarf_version >= 4)
8841 dw2_asm_output_data_uleb128 (size, "%s", name);
8843 dw2_asm_output_data (constant_size (size), size, "%s", name);
8845 output_loc_sequence (AT_loc (a), -1);
8848 case dw_val_class_const:
8849 /* ??? It would be slightly more efficient to use a scheme like is
8850 used for unsigned constants below, but gdb 4.x does not sign
8851 extend. Gdb 5.x does sign extend. */
8852 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8855 case dw_val_class_unsigned_const:
8856 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8857 AT_unsigned (a), "%s", name);
8860 case dw_val_class_const_double:
8862 unsigned HOST_WIDE_INT first, second;
8864 if (HOST_BITS_PER_WIDE_INT >= 64)
8865 dw2_asm_output_data (1,
8866 2 * HOST_BITS_PER_WIDE_INT
8867 / HOST_BITS_PER_CHAR,
8870 if (WORDS_BIG_ENDIAN)
8872 first = a->dw_attr_val.v.val_double.high;
8873 second = a->dw_attr_val.v.val_double.low;
8877 first = a->dw_attr_val.v.val_double.low;
8878 second = a->dw_attr_val.v.val_double.high;
8881 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8883 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8888 case dw_val_class_vec:
8890 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8891 unsigned int len = a->dw_attr_val.v.val_vec.length;
8895 dw2_asm_output_data (constant_size (len * elt_size),
8896 len * elt_size, "%s", name);
8897 if (elt_size > sizeof (HOST_WIDE_INT))
8902 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8905 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8906 "fp or vector constant word %u", i);
8910 case dw_val_class_flag:
8911 if (dwarf_version >= 4)
8913 /* Currently all add_AT_flag calls pass in 1 as last argument,
8914 so DW_FORM_flag_present can be used. If that ever changes,
8915 we'll need to use DW_FORM_flag and have some optimization
8916 in build_abbrev_table that will change those to
8917 DW_FORM_flag_present if it is set to 1 in all DIEs using
8918 the same abbrev entry. */
8919 gcc_assert (AT_flag (a) == 1);
8921 fprintf (asm_out_file, "\t\t\t%s %s\n",
8922 ASM_COMMENT_START, name);
8925 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8928 case dw_val_class_loc_list:
8930 char *sym = AT_loc_list (a)->ll_symbol;
8933 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8938 case dw_val_class_die_ref:
8939 if (AT_ref_external (a))
8941 if (use_debug_types)
8943 comdat_type_node_ref type_node =
8944 AT_ref (a)->die_id.die_type_node;
8946 gcc_assert (type_node);
8947 output_signature (type_node->signature, name);
8951 char *sym = AT_ref (a)->die_id.die_symbol;
8955 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8956 length, whereas in DWARF3 it's always sized as an
8958 if (dwarf_version == 2)
8959 size = DWARF2_ADDR_SIZE;
8961 size = DWARF_OFFSET_SIZE;
8962 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
8968 gcc_assert (AT_ref (a)->die_offset);
8969 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8974 case dw_val_class_fde_ref:
8978 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8979 a->dw_attr_val.v.val_fde_index * 2);
8980 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8985 case dw_val_class_vms_delta:
8986 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
8987 AT_vms_delta2 (a), AT_vms_delta1 (a),
8991 case dw_val_class_lbl_id:
8992 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8995 case dw_val_class_lineptr:
8996 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8997 debug_line_section, "%s", name);
9000 case dw_val_class_macptr:
9001 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9002 debug_macinfo_section, "%s", name);
9005 case dw_val_class_str:
9006 if (AT_string_form (a) == DW_FORM_strp)
9007 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
9008 a->dw_attr_val.v.val_str->label,
9010 "%s: \"%s\"", name, AT_string (a));
9012 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
9015 case dw_val_class_file:
9017 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
9019 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
9020 a->dw_attr_val.v.val_file->filename);
9024 case dw_val_class_data8:
9028 for (i = 0; i < 8; i++)
9029 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
9030 i == 0 ? "%s" : NULL, name);
9039 FOR_EACH_CHILD (die, c, output_die (c));
9041 /* Add null byte to terminate sibling list. */
9042 if (die->die_child != NULL)
9043 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9044 (unsigned long) die->die_offset);
9047 /* Output the compilation unit that appears at the beginning of the
9048 .debug_info section, and precedes the DIE descriptions. */
9051 output_compilation_unit_header (void)
9053 int ver = dwarf_version;
9055 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9056 dw2_asm_output_data (4, 0xffffffff,
9057 "Initial length escape value indicating 64-bit DWARF extension");
9058 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9059 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
9060 "Length of Compilation Unit Info");
9061 dw2_asm_output_data (2, ver, "DWARF version number");
9062 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
9063 debug_abbrev_section,
9064 "Offset Into Abbrev. Section");
9065 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9068 /* Output the compilation unit DIE and its children. */
9071 output_comp_unit (dw_die_ref die, int output_if_empty)
9073 const char *secname;
9076 /* Unless we are outputting main CU, we may throw away empty ones. */
9077 if (!output_if_empty && die->die_child == NULL)
9080 /* Even if there are no children of this DIE, we must output the information
9081 about the compilation unit. Otherwise, on an empty translation unit, we
9082 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9083 will then complain when examining the file. First mark all the DIEs in
9084 this CU so we know which get local refs. */
9087 build_abbrev_table (die);
9089 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9090 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9091 calc_die_sizes (die);
9093 oldsym = die->die_id.die_symbol;
9096 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
9098 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
9100 die->die_id.die_symbol = NULL;
9101 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9105 switch_to_section (debug_info_section);
9106 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9107 info_section_emitted = true;
9110 /* Output debugging information. */
9111 output_compilation_unit_header ();
9114 /* Leave the marks on the main CU, so we can check them in
9119 die->die_id.die_symbol = oldsym;
9123 /* Output a comdat type unit DIE and its children. */
9126 output_comdat_type_unit (comdat_type_node *node)
9128 const char *secname;
9131 #if defined (OBJECT_FORMAT_ELF)
9135 /* First mark all the DIEs in this CU so we know which get local refs. */
9136 mark_dies (node->root_die);
9138 build_abbrev_table (node->root_die);
9140 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9141 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
9142 calc_die_sizes (node->root_die);
9144 #if defined (OBJECT_FORMAT_ELF)
9145 secname = ".debug_types";
9146 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
9147 sprintf (tmp, "wt.");
9148 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9149 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
9150 comdat_key = get_identifier (tmp);
9151 targetm.asm_out.named_section (secname,
9152 SECTION_DEBUG | SECTION_LINKONCE,
9155 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
9156 sprintf (tmp, ".gnu.linkonce.wt.");
9157 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
9158 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
9160 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9163 /* Output debugging information. */
9164 output_compilation_unit_header ();
9165 output_signature (node->signature, "Type Signature");
9166 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
9167 "Offset to Type DIE");
9168 output_die (node->root_die);
9170 unmark_dies (node->root_die);
9173 /* Return the DWARF2/3 pubname associated with a decl. */
9176 dwarf2_name (tree decl, int scope)
9178 if (DECL_NAMELESS (decl))
9180 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
9183 /* Add a new entry to .debug_pubnames if appropriate. */
9186 add_pubname_string (const char *str, dw_die_ref die)
9188 if (targetm.want_debug_pub_sections)
9193 e.name = xstrdup (str);
9194 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
9199 add_pubname (tree decl, dw_die_ref die)
9201 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
9203 const char *name = dwarf2_name (decl, 1);
9205 add_pubname_string (name, die);
9209 /* Add a new entry to .debug_pubtypes if appropriate. */
9212 add_pubtype (tree decl, dw_die_ref die)
9216 if (!targetm.want_debug_pub_sections)
9220 if ((TREE_PUBLIC (decl)
9221 || is_cu_die (die->die_parent))
9222 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
9227 if (TYPE_NAME (decl))
9229 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
9230 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
9231 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
9232 && DECL_NAME (TYPE_NAME (decl)))
9233 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
9235 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
9240 e.name = dwarf2_name (decl, 1);
9242 e.name = xstrdup (e.name);
9245 /* If we don't have a name for the type, there's no point in adding
9247 if (e.name && e.name[0] != '\0')
9248 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
9252 /* Output the public names table used to speed up access to externally
9253 visible names; or the public types table used to find type definitions. */
9256 output_pubnames (VEC (pubname_entry, gc) * names)
9259 unsigned long pubnames_length = size_of_pubnames (names);
9262 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9263 dw2_asm_output_data (4, 0xffffffff,
9264 "Initial length escape value indicating 64-bit DWARF extension");
9265 if (names == pubname_table)
9266 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9267 "Length of Public Names Info");
9269 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9270 "Length of Public Type Names Info");
9271 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9272 dw2_asm_output_data (2, 2, "DWARF Version");
9273 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9275 "Offset of Compilation Unit Info");
9276 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
9277 "Compilation Unit Length");
9279 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
9281 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9282 if (names == pubname_table)
9283 gcc_assert (pub->die->die_mark);
9285 if (names != pubtype_table
9286 || pub->die->die_offset != 0
9287 || !flag_eliminate_unused_debug_types)
9289 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
9292 dw2_asm_output_nstring (pub->name, -1, "external name");
9296 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
9299 /* Output the information that goes into the .debug_aranges table.
9300 Namely, define the beginning and ending address range of the
9301 text section generated for this compilation unit. */
9304 output_aranges (unsigned long aranges_length)
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_data (DWARF_OFFSET_SIZE, aranges_length,
9312 "Length of Address Ranges Info");
9313 /* Version number for aranges is still 2, even in DWARF3. */
9314 dw2_asm_output_data (2, 2, "DWARF Version");
9315 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9317 "Offset of Compilation Unit Info");
9318 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
9319 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9321 /* We need to align to twice the pointer size here. */
9322 if (DWARF_ARANGES_PAD_SIZE)
9324 /* Pad using a 2 byte words so that padding is correct for any
9326 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9327 2 * DWARF2_ADDR_SIZE);
9328 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
9329 dw2_asm_output_data (2, 0, NULL);
9332 /* It is necessary not to output these entries if the sections were
9333 not used; if the sections were not used, the length will be 0 and
9334 the address may end up as 0 if the section is discarded by ld
9335 --gc-sections, leaving an invalid (0, 0) entry that can be
9336 confused with the terminator. */
9337 if (text_section_used)
9339 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
9340 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
9341 text_section_label, "Length");
9343 if (cold_text_section_used)
9345 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
9347 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
9348 cold_text_section_label, "Length");
9351 if (have_multiple_function_sections)
9353 unsigned fde_idx = 0;
9355 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
9357 dw_fde_ref fde = &fde_table[fde_idx];
9359 if (!fde->in_std_section)
9361 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
9363 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
9364 fde->dw_fde_begin, "Length");
9366 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
9368 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
9370 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
9371 fde->dw_fde_second_begin, "Length");
9376 /* Output the terminator words. */
9377 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9378 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9381 /* Add a new entry to .debug_ranges. Return the offset at which it
9385 add_ranges_num (int num)
9387 unsigned int in_use = ranges_table_in_use;
9389 if (in_use == ranges_table_allocated)
9391 ranges_table_allocated += RANGES_TABLE_INCREMENT;
9392 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
9393 ranges_table_allocated);
9394 memset (ranges_table + ranges_table_in_use, 0,
9395 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
9398 ranges_table[in_use].num = num;
9399 ranges_table_in_use = in_use + 1;
9401 return in_use * 2 * DWARF2_ADDR_SIZE;
9404 /* Add a new entry to .debug_ranges corresponding to a block, or a
9405 range terminator if BLOCK is NULL. */
9408 add_ranges (const_tree block)
9410 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
9413 /* Add a new entry to .debug_ranges corresponding to a pair of
9417 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
9420 unsigned int in_use = ranges_by_label_in_use;
9421 unsigned int offset;
9423 if (in_use == ranges_by_label_allocated)
9425 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
9426 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
9428 ranges_by_label_allocated);
9429 memset (ranges_by_label + ranges_by_label_in_use, 0,
9430 RANGES_TABLE_INCREMENT
9431 * sizeof (struct dw_ranges_by_label_struct));
9434 ranges_by_label[in_use].begin = begin;
9435 ranges_by_label[in_use].end = end;
9436 ranges_by_label_in_use = in_use + 1;
9438 offset = add_ranges_num (-(int)in_use - 1);
9441 add_AT_range_list (die, DW_AT_ranges, offset);
9447 output_ranges (void)
9450 static const char *const start_fmt = "Offset %#x";
9451 const char *fmt = start_fmt;
9453 for (i = 0; i < ranges_table_in_use; i++)
9455 int block_num = ranges_table[i].num;
9459 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9460 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9462 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9463 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9465 /* If all code is in the text section, then the compilation
9466 unit base address defaults to DW_AT_low_pc, which is the
9467 base of the text section. */
9468 if (!have_multiple_function_sections)
9470 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9472 fmt, i * 2 * DWARF2_ADDR_SIZE);
9473 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9474 text_section_label, NULL);
9477 /* Otherwise, the compilation unit base address is zero,
9478 which allows us to use absolute addresses, and not worry
9479 about whether the target supports cross-section
9483 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9484 fmt, i * 2 * DWARF2_ADDR_SIZE);
9485 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9491 /* Negative block_num stands for an index into ranges_by_label. */
9492 else if (block_num < 0)
9494 int lab_idx = - block_num - 1;
9496 if (!have_multiple_function_sections)
9500 /* If we ever use add_ranges_by_labels () for a single
9501 function section, all we have to do is to take out
9503 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9504 ranges_by_label[lab_idx].begin,
9506 fmt, i * 2 * DWARF2_ADDR_SIZE);
9507 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9508 ranges_by_label[lab_idx].end,
9509 text_section_label, NULL);
9514 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9515 ranges_by_label[lab_idx].begin,
9516 fmt, i * 2 * DWARF2_ADDR_SIZE);
9517 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9518 ranges_by_label[lab_idx].end,
9524 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9525 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9531 /* Data structure containing information about input files. */
9534 const char *path; /* Complete file name. */
9535 const char *fname; /* File name part. */
9536 int length; /* Length of entire string. */
9537 struct dwarf_file_data * file_idx; /* Index in input file table. */
9538 int dir_idx; /* Index in directory table. */
9541 /* Data structure containing information about directories with source
9545 const char *path; /* Path including directory name. */
9546 int length; /* Path length. */
9547 int prefix; /* Index of directory entry which is a prefix. */
9548 int count; /* Number of files in this directory. */
9549 int dir_idx; /* Index of directory used as base. */
9552 /* Callback function for file_info comparison. We sort by looking at
9553 the directories in the path. */
9556 file_info_cmp (const void *p1, const void *p2)
9558 const struct file_info *const s1 = (const struct file_info *) p1;
9559 const struct file_info *const s2 = (const struct file_info *) p2;
9560 const unsigned char *cp1;
9561 const unsigned char *cp2;
9563 /* Take care of file names without directories. We need to make sure that
9564 we return consistent values to qsort since some will get confused if
9565 we return the same value when identical operands are passed in opposite
9566 orders. So if neither has a directory, return 0 and otherwise return
9567 1 or -1 depending on which one has the directory. */
9568 if ((s1->path == s1->fname || s2->path == s2->fname))
9569 return (s2->path == s2->fname) - (s1->path == s1->fname);
9571 cp1 = (const unsigned char *) s1->path;
9572 cp2 = (const unsigned char *) s2->path;
9578 /* Reached the end of the first path? If so, handle like above. */
9579 if ((cp1 == (const unsigned char *) s1->fname)
9580 || (cp2 == (const unsigned char *) s2->fname))
9581 return ((cp2 == (const unsigned char *) s2->fname)
9582 - (cp1 == (const unsigned char *) s1->fname));
9584 /* Character of current path component the same? */
9585 else if (*cp1 != *cp2)
9590 struct file_name_acquire_data
9592 struct file_info *files;
9597 /* Traversal function for the hash table. */
9600 file_name_acquire (void ** slot, void *data)
9602 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9603 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9604 struct file_info *fi;
9607 gcc_assert (fnad->max_files >= d->emitted_number);
9609 if (! d->emitted_number)
9612 gcc_assert (fnad->max_files != fnad->used_files);
9614 fi = fnad->files + fnad->used_files++;
9616 /* Skip all leading "./". */
9618 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9621 /* Create a new array entry. */
9623 fi->length = strlen (f);
9626 /* Search for the file name part. */
9627 f = strrchr (f, DIR_SEPARATOR);
9628 #if defined (DIR_SEPARATOR_2)
9630 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9634 if (f == NULL || f < g)
9640 fi->fname = f == NULL ? fi->path : f + 1;
9644 /* Output the directory table and the file name table. We try to minimize
9645 the total amount of memory needed. A heuristic is used to avoid large
9646 slowdowns with many input files. */
9649 output_file_names (void)
9651 struct file_name_acquire_data fnad;
9653 struct file_info *files;
9654 struct dir_info *dirs;
9662 if (!last_emitted_file)
9664 dw2_asm_output_data (1, 0, "End directory table");
9665 dw2_asm_output_data (1, 0, "End file name table");
9669 numfiles = last_emitted_file->emitted_number;
9671 /* Allocate the various arrays we need. */
9672 files = XALLOCAVEC (struct file_info, numfiles);
9673 dirs = XALLOCAVEC (struct dir_info, numfiles);
9676 fnad.used_files = 0;
9677 fnad.max_files = numfiles;
9678 htab_traverse (file_table, file_name_acquire, &fnad);
9679 gcc_assert (fnad.used_files == fnad.max_files);
9681 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9683 /* Find all the different directories used. */
9684 dirs[0].path = files[0].path;
9685 dirs[0].length = files[0].fname - files[0].path;
9686 dirs[0].prefix = -1;
9688 dirs[0].dir_idx = 0;
9689 files[0].dir_idx = 0;
9692 for (i = 1; i < numfiles; i++)
9693 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9694 && memcmp (dirs[ndirs - 1].path, files[i].path,
9695 dirs[ndirs - 1].length) == 0)
9697 /* Same directory as last entry. */
9698 files[i].dir_idx = ndirs - 1;
9699 ++dirs[ndirs - 1].count;
9705 /* This is a new directory. */
9706 dirs[ndirs].path = files[i].path;
9707 dirs[ndirs].length = files[i].fname - files[i].path;
9708 dirs[ndirs].count = 1;
9709 dirs[ndirs].dir_idx = ndirs;
9710 files[i].dir_idx = ndirs;
9712 /* Search for a prefix. */
9713 dirs[ndirs].prefix = -1;
9714 for (j = 0; j < ndirs; j++)
9715 if (dirs[j].length < dirs[ndirs].length
9716 && dirs[j].length > 1
9717 && (dirs[ndirs].prefix == -1
9718 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9719 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9720 dirs[ndirs].prefix = j;
9725 /* Now to the actual work. We have to find a subset of the directories which
9726 allow expressing the file name using references to the directory table
9727 with the least amount of characters. We do not do an exhaustive search
9728 where we would have to check out every combination of every single
9729 possible prefix. Instead we use a heuristic which provides nearly optimal
9730 results in most cases and never is much off. */
9731 saved = XALLOCAVEC (int, ndirs);
9732 savehere = XALLOCAVEC (int, ndirs);
9734 memset (saved, '\0', ndirs * sizeof (saved[0]));
9735 for (i = 0; i < ndirs; i++)
9740 /* We can always save some space for the current directory. But this
9741 does not mean it will be enough to justify adding the directory. */
9742 savehere[i] = dirs[i].length;
9743 total = (savehere[i] - saved[i]) * dirs[i].count;
9745 for (j = i + 1; j < ndirs; j++)
9748 if (saved[j] < dirs[i].length)
9750 /* Determine whether the dirs[i] path is a prefix of the
9755 while (k != -1 && k != (int) i)
9760 /* Yes it is. We can possibly save some memory by
9761 writing the filenames in dirs[j] relative to
9763 savehere[j] = dirs[i].length;
9764 total += (savehere[j] - saved[j]) * dirs[j].count;
9769 /* Check whether we can save enough to justify adding the dirs[i]
9771 if (total > dirs[i].length + 1)
9773 /* It's worthwhile adding. */
9774 for (j = i; j < ndirs; j++)
9775 if (savehere[j] > 0)
9777 /* Remember how much we saved for this directory so far. */
9778 saved[j] = savehere[j];
9780 /* Remember the prefix directory. */
9781 dirs[j].dir_idx = i;
9786 /* Emit the directory name table. */
9787 idx_offset = dirs[0].length > 0 ? 1 : 0;
9788 for (i = 1 - idx_offset; i < ndirs; i++)
9789 dw2_asm_output_nstring (dirs[i].path,
9791 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9792 "Directory Entry: %#x", i + idx_offset);
9794 dw2_asm_output_data (1, 0, "End directory table");
9796 /* We have to emit them in the order of emitted_number since that's
9797 used in the debug info generation. To do this efficiently we
9798 generate a back-mapping of the indices first. */
9799 backmap = XALLOCAVEC (int, numfiles);
9800 for (i = 0; i < numfiles; i++)
9801 backmap[files[i].file_idx->emitted_number - 1] = i;
9803 /* Now write all the file names. */
9804 for (i = 0; i < numfiles; i++)
9806 int file_idx = backmap[i];
9807 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9809 #ifdef VMS_DEBUGGING_INFO
9810 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9812 /* Setting these fields can lead to debugger miscomparisons,
9813 but VMS Debug requires them to be set correctly. */
9818 int maxfilelen = strlen (files[file_idx].path)
9819 + dirs[dir_idx].length
9820 + MAX_VMS_VERSION_LEN + 1;
9821 char *filebuf = XALLOCAVEC (char, maxfilelen);
9823 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9824 snprintf (filebuf, maxfilelen, "%s;%d",
9825 files[file_idx].path + dirs[dir_idx].length, ver);
9827 dw2_asm_output_nstring
9828 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
9830 /* Include directory index. */
9831 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9833 /* Modification time. */
9834 dw2_asm_output_data_uleb128
9835 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9839 /* File length in bytes. */
9840 dw2_asm_output_data_uleb128
9841 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9845 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9846 "File Entry: %#x", (unsigned) i + 1);
9848 /* Include directory index. */
9849 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9851 /* Modification time. */
9852 dw2_asm_output_data_uleb128 (0, NULL);
9854 /* File length in bytes. */
9855 dw2_asm_output_data_uleb128 (0, NULL);
9856 #endif /* VMS_DEBUGGING_INFO */
9859 dw2_asm_output_data (1, 0, "End file name table");
9863 /* Output one line number table into the .debug_line section. */
9866 output_one_line_info_table (dw_line_info_table *table)
9868 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9869 unsigned int current_line = 1;
9870 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
9871 dw_line_info_entry *ent;
9874 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
9876 switch (ent->opcode)
9878 case LI_set_address:
9879 /* ??? Unfortunately, we have little choice here currently, and
9880 must always use the most general form. GCC does not know the
9881 address delta itself, so we can't use DW_LNS_advance_pc. Many
9882 ports do have length attributes which will give an upper bound
9883 on the address range. We could perhaps use length attributes
9884 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9885 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
9887 /* This can handle any delta. This takes
9888 4+DWARF2_ADDR_SIZE bytes. */
9889 dw2_asm_output_data (1, 0, "set address %s", line_label);
9890 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9891 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9892 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9896 if (ent->val == current_line)
9898 /* We still need to start a new row, so output a copy insn. */
9899 dw2_asm_output_data (1, DW_LNS_copy,
9900 "copy line %u", current_line);
9904 int line_offset = ent->val - current_line;
9905 int line_delta = line_offset - DWARF_LINE_BASE;
9907 current_line = ent->val;
9908 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9910 /* This can handle deltas from -10 to 234, using the current
9911 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9912 This takes 1 byte. */
9913 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9914 "line %u", current_line);
9918 /* This can handle any delta. This takes at least 4 bytes,
9919 depending on the value being encoded. */
9920 dw2_asm_output_data (1, DW_LNS_advance_line,
9921 "advance to line %u", current_line);
9922 dw2_asm_output_data_sleb128 (line_offset, NULL);
9923 dw2_asm_output_data (1, DW_LNS_copy, NULL);
9929 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
9930 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9934 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
9935 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
9938 case LI_negate_stmt:
9939 current_is_stmt = !current_is_stmt;
9940 dw2_asm_output_data (1, DW_LNS_negate_stmt,
9941 "is_stmt %d", current_is_stmt);
9944 case LI_set_prologue_end:
9945 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
9946 "set prologue end");
9949 case LI_set_epilogue_begin:
9950 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
9951 "set epilogue begin");
9954 case LI_set_discriminator:
9955 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
9956 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
9957 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
9958 dw2_asm_output_data_uleb128 (ent->val, NULL);
9963 /* Emit debug info for the address of the end of the table. */
9964 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
9965 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9966 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9967 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
9969 dw2_asm_output_data (1, 0, "end sequence");
9970 dw2_asm_output_data_uleb128 (1, NULL);
9971 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9974 /* Output the source line number correspondence information. This
9975 information goes into the .debug_line section. */
9978 output_line_info (void)
9980 char l1[20], l2[20], p1[20], p2[20];
9981 int ver = dwarf_version;
9982 bool saw_one = false;
9985 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9986 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9987 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9988 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9990 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9991 dw2_asm_output_data (4, 0xffffffff,
9992 "Initial length escape value indicating 64-bit DWARF extension");
9993 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9994 "Length of Source Line Info");
9995 ASM_OUTPUT_LABEL (asm_out_file, l1);
9997 dw2_asm_output_data (2, ver, "DWARF Version");
9998 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9999 ASM_OUTPUT_LABEL (asm_out_file, p1);
10001 /* Define the architecture-dependent minimum instruction length (in bytes).
10002 In this implementation of DWARF, this field is used for information
10003 purposes only. Since GCC generates assembly language, we have no
10004 a priori knowledge of how many instruction bytes are generated for each
10005 source line, and therefore can use only the DW_LNE_set_address and
10006 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10007 this as '1', which is "correct enough" for all architectures,
10008 and don't let the target override. */
10009 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10012 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
10013 "Maximum Operations Per Instruction");
10014 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
10015 "Default is_stmt_start flag");
10016 dw2_asm_output_data (1, DWARF_LINE_BASE,
10017 "Line Base Value (Special Opcodes)");
10018 dw2_asm_output_data (1, DWARF_LINE_RANGE,
10019 "Line Range Value (Special Opcodes)");
10020 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
10021 "Special Opcode Base");
10023 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
10028 case DW_LNS_advance_pc:
10029 case DW_LNS_advance_line:
10030 case DW_LNS_set_file:
10031 case DW_LNS_set_column:
10032 case DW_LNS_fixed_advance_pc:
10033 case DW_LNS_set_isa:
10041 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
10045 /* Write out the information about the files we use. */
10046 output_file_names ();
10047 ASM_OUTPUT_LABEL (asm_out_file, p2);
10049 if (separate_line_info)
10051 dw_line_info_table *table;
10054 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
10057 output_one_line_info_table (table);
10061 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
10063 output_one_line_info_table (cold_text_section_line_info);
10067 /* ??? Some Darwin linkers crash on a .debug_line section with no
10068 sequences. Further, merely a DW_LNE_end_sequence entry is not
10069 sufficient -- the address column must also be initialized.
10070 Make sure to output at least one set_address/end_sequence pair,
10071 choosing .text since that section is always present. */
10072 if (text_section_line_info->in_use || !saw_one)
10073 output_one_line_info_table (text_section_line_info);
10075 /* Output the marker for the end of the line number info. */
10076 ASM_OUTPUT_LABEL (asm_out_file, l2);
10079 /* Given a pointer to a tree node for some base type, return a pointer to
10080 a DIE that describes the given type.
10082 This routine must only be called for GCC type nodes that correspond to
10083 Dwarf base (fundamental) types. */
10086 base_type_die (tree type)
10088 dw_die_ref base_type_result;
10089 enum dwarf_type encoding;
10091 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
10094 /* If this is a subtype that should not be emitted as a subrange type,
10095 use the base type. See subrange_type_for_debug_p. */
10096 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
10097 type = TREE_TYPE (type);
10099 switch (TREE_CODE (type))
10102 if ((dwarf_version >= 4 || !dwarf_strict)
10103 && TYPE_NAME (type)
10104 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10105 && DECL_IS_BUILTIN (TYPE_NAME (type))
10106 && DECL_NAME (TYPE_NAME (type)))
10108 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
10109 if (strcmp (name, "char16_t") == 0
10110 || strcmp (name, "char32_t") == 0)
10112 encoding = DW_ATE_UTF;
10116 if (TYPE_STRING_FLAG (type))
10118 if (TYPE_UNSIGNED (type))
10119 encoding = DW_ATE_unsigned_char;
10121 encoding = DW_ATE_signed_char;
10123 else if (TYPE_UNSIGNED (type))
10124 encoding = DW_ATE_unsigned;
10126 encoding = DW_ATE_signed;
10130 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
10132 if (dwarf_version >= 3 || !dwarf_strict)
10133 encoding = DW_ATE_decimal_float;
10135 encoding = DW_ATE_lo_user;
10138 encoding = DW_ATE_float;
10141 case FIXED_POINT_TYPE:
10142 if (!(dwarf_version >= 3 || !dwarf_strict))
10143 encoding = DW_ATE_lo_user;
10144 else if (TYPE_UNSIGNED (type))
10145 encoding = DW_ATE_unsigned_fixed;
10147 encoding = DW_ATE_signed_fixed;
10150 /* Dwarf2 doesn't know anything about complex ints, so use
10151 a user defined type for it. */
10153 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
10154 encoding = DW_ATE_complex_float;
10156 encoding = DW_ATE_lo_user;
10160 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10161 encoding = DW_ATE_boolean;
10165 /* No other TREE_CODEs are Dwarf fundamental types. */
10166 gcc_unreachable ();
10169 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
10171 add_AT_unsigned (base_type_result, DW_AT_byte_size,
10172 int_size_in_bytes (type));
10173 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
10175 return base_type_result;
10178 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10179 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10182 is_base_type (tree type)
10184 switch (TREE_CODE (type))
10190 case FIXED_POINT_TYPE:
10198 case QUAL_UNION_TYPE:
10199 case ENUMERAL_TYPE:
10200 case FUNCTION_TYPE:
10203 case REFERENCE_TYPE:
10211 gcc_unreachable ();
10217 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10218 node, return the size in bits for the type if it is a constant, or else
10219 return the alignment for the type if the type's size is not constant, or
10220 else return BITS_PER_WORD if the type actually turns out to be an
10221 ERROR_MARK node. */
10223 static inline unsigned HOST_WIDE_INT
10224 simple_type_size_in_bits (const_tree type)
10226 if (TREE_CODE (type) == ERROR_MARK)
10227 return BITS_PER_WORD;
10228 else if (TYPE_SIZE (type) == NULL_TREE)
10230 else if (host_integerp (TYPE_SIZE (type), 1))
10231 return tree_low_cst (TYPE_SIZE (type), 1);
10233 return TYPE_ALIGN (type);
10236 /* Similarly, but return a double_int instead of UHWI. */
10238 static inline double_int
10239 double_int_type_size_in_bits (const_tree type)
10241 if (TREE_CODE (type) == ERROR_MARK)
10242 return uhwi_to_double_int (BITS_PER_WORD);
10243 else if (TYPE_SIZE (type) == NULL_TREE)
10244 return double_int_zero;
10245 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
10246 return tree_to_double_int (TYPE_SIZE (type));
10248 return uhwi_to_double_int (TYPE_ALIGN (type));
10251 /* Given a pointer to a tree node for a subrange type, return a pointer
10252 to a DIE that describes the given type. */
10255 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
10257 dw_die_ref subrange_die;
10258 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
10260 if (context_die == NULL)
10261 context_die = comp_unit_die ();
10263 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
10265 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
10267 /* The size of the subrange type and its base type do not match,
10268 so we need to generate a size attribute for the subrange type. */
10269 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
10273 add_bound_info (subrange_die, DW_AT_lower_bound, low);
10275 add_bound_info (subrange_die, DW_AT_upper_bound, high);
10277 return subrange_die;
10280 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10281 entry that chains various modifiers in front of the given type. */
10284 modified_type_die (tree type, int is_const_type, int is_volatile_type,
10285 dw_die_ref context_die)
10287 enum tree_code code = TREE_CODE (type);
10288 dw_die_ref mod_type_die;
10289 dw_die_ref sub_die = NULL;
10290 tree item_type = NULL;
10291 tree qualified_type;
10292 tree name, low, high;
10294 if (code == ERROR_MARK)
10297 /* See if we already have the appropriately qualified variant of
10300 = get_qualified_type (type,
10301 ((is_const_type ? TYPE_QUAL_CONST : 0)
10302 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
10304 if (qualified_type == sizetype
10305 && TYPE_NAME (qualified_type)
10306 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
10308 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
10310 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
10311 && TYPE_PRECISION (t)
10312 == TYPE_PRECISION (qualified_type)
10313 && TYPE_UNSIGNED (t)
10314 == TYPE_UNSIGNED (qualified_type));
10315 qualified_type = t;
10318 /* If we do, then we can just use its DIE, if it exists. */
10319 if (qualified_type)
10321 mod_type_die = lookup_type_die (qualified_type);
10323 return mod_type_die;
10326 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
10328 /* Handle C typedef types. */
10329 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
10330 && !DECL_ARTIFICIAL (name))
10332 tree dtype = TREE_TYPE (name);
10334 if (qualified_type == dtype)
10336 /* For a named type, use the typedef. */
10337 gen_type_die (qualified_type, context_die);
10338 return lookup_type_die (qualified_type);
10340 else if (is_const_type < TYPE_READONLY (dtype)
10341 || is_volatile_type < TYPE_VOLATILE (dtype)
10342 || (is_const_type <= TYPE_READONLY (dtype)
10343 && is_volatile_type <= TYPE_VOLATILE (dtype)
10344 && DECL_ORIGINAL_TYPE (name) != type))
10345 /* cv-unqualified version of named type. Just use the unnamed
10346 type to which it refers. */
10347 return modified_type_die (DECL_ORIGINAL_TYPE (name),
10348 is_const_type, is_volatile_type,
10350 /* Else cv-qualified version of named type; fall through. */
10354 /* If both is_const_type and is_volatile_type, prefer the path
10355 which leads to a qualified type. */
10356 && (!is_volatile_type
10357 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
10358 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
10360 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
10361 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
10363 else if (is_volatile_type)
10365 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
10366 sub_die = modified_type_die (type, is_const_type, 0, context_die);
10368 else if (code == POINTER_TYPE)
10370 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
10371 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10372 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10373 item_type = TREE_TYPE (type);
10374 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
10375 add_AT_unsigned (mod_type_die, DW_AT_address_class,
10376 TYPE_ADDR_SPACE (item_type));
10378 else if (code == REFERENCE_TYPE)
10380 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
10381 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
10384 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
10385 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10386 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10387 item_type = TREE_TYPE (type);
10388 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
10389 add_AT_unsigned (mod_type_die, DW_AT_address_class,
10390 TYPE_ADDR_SPACE (item_type));
10392 else if (code == INTEGER_TYPE
10393 && TREE_TYPE (type) != NULL_TREE
10394 && subrange_type_for_debug_p (type, &low, &high))
10396 mod_type_die = subrange_type_die (type, low, high, context_die);
10397 item_type = TREE_TYPE (type);
10399 else if (is_base_type (type))
10400 mod_type_die = base_type_die (type);
10403 gen_type_die (type, context_die);
10405 /* We have to get the type_main_variant here (and pass that to the
10406 `lookup_type_die' routine) because the ..._TYPE node we have
10407 might simply be a *copy* of some original type node (where the
10408 copy was created to help us keep track of typedef names) and
10409 that copy might have a different TYPE_UID from the original
10411 if (TREE_CODE (type) != VECTOR_TYPE)
10412 return lookup_type_die (type_main_variant (type));
10414 /* Vectors have the debugging information in the type,
10415 not the main variant. */
10416 return lookup_type_die (type);
10419 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10420 don't output a DW_TAG_typedef, since there isn't one in the
10421 user's program; just attach a DW_AT_name to the type.
10422 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10423 if the base type already has the same name. */
10425 && ((TREE_CODE (name) != TYPE_DECL
10426 && (qualified_type == TYPE_MAIN_VARIANT (type)
10427 || (!is_const_type && !is_volatile_type)))
10428 || (TREE_CODE (name) == TYPE_DECL
10429 && TREE_TYPE (name) == qualified_type
10430 && DECL_NAME (name))))
10432 if (TREE_CODE (name) == TYPE_DECL)
10433 /* Could just call add_name_and_src_coords_attributes here,
10434 but since this is a builtin type it doesn't have any
10435 useful source coordinates anyway. */
10436 name = DECL_NAME (name);
10437 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
10438 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
10439 if (TYPE_ARTIFICIAL (type))
10440 add_AT_flag (mod_type_die, DW_AT_artificial, 1);
10442 /* This probably indicates a bug. */
10443 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
10444 add_name_attribute (mod_type_die, "__unknown__");
10446 if (qualified_type)
10447 equate_type_number_to_die (qualified_type, mod_type_die);
10450 /* We must do this after the equate_type_number_to_die call, in case
10451 this is a recursive type. This ensures that the modified_type_die
10452 recursion will terminate even if the type is recursive. Recursive
10453 types are possible in Ada. */
10454 sub_die = modified_type_die (item_type,
10455 TYPE_READONLY (item_type),
10456 TYPE_VOLATILE (item_type),
10459 if (sub_die != NULL)
10460 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10462 return mod_type_die;
10465 /* Generate DIEs for the generic parameters of T.
10466 T must be either a generic type or a generic function.
10467 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10470 gen_generic_params_dies (tree t)
10474 dw_die_ref die = NULL;
10476 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
10480 die = lookup_type_die (t);
10481 else if (DECL_P (t))
10482 die = lookup_decl_die (t);
10486 parms = lang_hooks.get_innermost_generic_parms (t);
10488 /* T has no generic parameter. It means T is neither a generic type
10489 or function. End of story. */
10492 parms_num = TREE_VEC_LENGTH (parms);
10493 args = lang_hooks.get_innermost_generic_args (t);
10494 for (i = 0; i < parms_num; i++)
10496 tree parm, arg, arg_pack_elems;
10498 parm = TREE_VEC_ELT (parms, i);
10499 arg = TREE_VEC_ELT (args, i);
10500 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
10501 gcc_assert (parm && TREE_VALUE (parm) && arg);
10503 if (parm && TREE_VALUE (parm) && arg)
10505 /* If PARM represents a template parameter pack,
10506 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10507 by DW_TAG_template_*_parameter DIEs for the argument
10508 pack elements of ARG. Note that ARG would then be
10509 an argument pack. */
10510 if (arg_pack_elems)
10511 template_parameter_pack_die (TREE_VALUE (parm),
10515 generic_parameter_die (TREE_VALUE (parm), arg,
10516 true /* Emit DW_AT_name */, die);
10521 /* Create and return a DIE for PARM which should be
10522 the representation of a generic type parameter.
10523 For instance, in the C++ front end, PARM would be a template parameter.
10524 ARG is the argument to PARM.
10525 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10527 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10528 as a child node. */
10531 generic_parameter_die (tree parm, tree arg,
10533 dw_die_ref parent_die)
10535 dw_die_ref tmpl_die = NULL;
10536 const char *name = NULL;
10538 if (!parm || !DECL_NAME (parm) || !arg)
10541 /* We support non-type generic parameters and arguments,
10542 type generic parameters and arguments, as well as
10543 generic generic parameters (a.k.a. template template parameters in C++)
10545 if (TREE_CODE (parm) == PARM_DECL)
10546 /* PARM is a nontype generic parameter */
10547 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
10548 else if (TREE_CODE (parm) == TYPE_DECL)
10549 /* PARM is a type generic parameter. */
10550 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
10551 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10552 /* PARM is a generic generic parameter.
10553 Its DIE is a GNU extension. It shall have a
10554 DW_AT_name attribute to represent the name of the template template
10555 parameter, and a DW_AT_GNU_template_name attribute to represent the
10556 name of the template template argument. */
10557 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
10560 gcc_unreachable ();
10566 /* If PARM is a generic parameter pack, it means we are
10567 emitting debug info for a template argument pack element.
10568 In other terms, ARG is a template argument pack element.
10569 In that case, we don't emit any DW_AT_name attribute for
10573 name = IDENTIFIER_POINTER (DECL_NAME (parm));
10575 add_AT_string (tmpl_die, DW_AT_name, name);
10578 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10580 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10581 TMPL_DIE should have a child DW_AT_type attribute that is set
10582 to the type of the argument to PARM, which is ARG.
10583 If PARM is a type generic parameter, TMPL_DIE should have a
10584 child DW_AT_type that is set to ARG. */
10585 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
10586 add_type_attribute (tmpl_die, tmpl_type, 0,
10587 TREE_THIS_VOLATILE (tmpl_type),
10592 /* So TMPL_DIE is a DIE representing a
10593 a generic generic template parameter, a.k.a template template
10594 parameter in C++ and arg is a template. */
10596 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10597 to the name of the argument. */
10598 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
10600 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
10603 if (TREE_CODE (parm) == PARM_DECL)
10604 /* So PARM is a non-type generic parameter.
10605 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10606 attribute of TMPL_DIE which value represents the value
10608 We must be careful here:
10609 The value of ARG might reference some function decls.
10610 We might currently be emitting debug info for a generic
10611 type and types are emitted before function decls, we don't
10612 know if the function decls referenced by ARG will actually be
10613 emitted after cgraph computations.
10614 So must defer the generation of the DW_AT_const_value to
10615 after cgraph is ready. */
10616 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
10622 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10623 PARM_PACK must be a template parameter pack. The returned DIE
10624 will be child DIE of PARENT_DIE. */
10627 template_parameter_pack_die (tree parm_pack,
10628 tree parm_pack_args,
10629 dw_die_ref parent_die)
10634 gcc_assert (parent_die && parm_pack);
10636 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
10637 add_name_and_src_coords_attributes (die, parm_pack);
10638 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
10639 generic_parameter_die (parm_pack,
10640 TREE_VEC_ELT (parm_pack_args, j),
10641 false /* Don't emit DW_AT_name */,
10646 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10647 an enumerated type. */
10650 type_is_enum (const_tree type)
10652 return TREE_CODE (type) == ENUMERAL_TYPE;
10655 /* Return the DBX register number described by a given RTL node. */
10657 static unsigned int
10658 dbx_reg_number (const_rtx rtl)
10660 unsigned regno = REGNO (rtl);
10662 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10664 #ifdef LEAF_REG_REMAP
10665 if (current_function_uses_only_leaf_regs)
10667 int leaf_reg = LEAF_REG_REMAP (regno);
10668 if (leaf_reg != -1)
10669 regno = (unsigned) leaf_reg;
10673 return DBX_REGISTER_NUMBER (regno);
10676 /* Optionally add a DW_OP_piece term to a location description expression.
10677 DW_OP_piece is only added if the location description expression already
10678 doesn't end with DW_OP_piece. */
10681 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10683 dw_loc_descr_ref loc;
10685 if (*list_head != NULL)
10687 /* Find the end of the chain. */
10688 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10691 if (loc->dw_loc_opc != DW_OP_piece)
10692 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10696 /* Return a location descriptor that designates a machine register or
10697 zero if there is none. */
10699 static dw_loc_descr_ref
10700 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10704 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10707 /* We only use "frame base" when we're sure we're talking about the
10708 post-prologue local stack frame. We do this by *not* running
10709 register elimination until this point, and recognizing the special
10710 argument pointer and soft frame pointer rtx's.
10711 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10712 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
10713 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
10715 dw_loc_descr_ref result = NULL;
10717 if (dwarf_version >= 4 || !dwarf_strict)
10719 result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
10722 add_loc_descr (&result,
10723 new_loc_descr (DW_OP_stack_value, 0, 0));
10728 regs = targetm.dwarf_register_span (rtl);
10730 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10731 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10733 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10736 /* Return a location descriptor that designates a machine register for
10737 a given hard register number. */
10739 static dw_loc_descr_ref
10740 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10742 dw_loc_descr_ref reg_loc_descr;
10746 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10748 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10750 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10751 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10753 return reg_loc_descr;
10756 /* Given an RTL of a register, return a location descriptor that
10757 designates a value that spans more than one register. */
10759 static dw_loc_descr_ref
10760 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10761 enum var_init_status initialized)
10763 int nregs, size, i;
10765 dw_loc_descr_ref loc_result = NULL;
10768 #ifdef LEAF_REG_REMAP
10769 if (current_function_uses_only_leaf_regs)
10771 int leaf_reg = LEAF_REG_REMAP (reg);
10772 if (leaf_reg != -1)
10773 reg = (unsigned) leaf_reg;
10776 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10777 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10779 /* Simple, contiguous registers. */
10780 if (regs == NULL_RTX)
10782 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10787 dw_loc_descr_ref t;
10789 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10790 VAR_INIT_STATUS_INITIALIZED);
10791 add_loc_descr (&loc_result, t);
10792 add_loc_descr_op_piece (&loc_result, size);
10798 /* Now onto stupid register sets in non contiguous locations. */
10800 gcc_assert (GET_CODE (regs) == PARALLEL);
10802 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10805 for (i = 0; i < XVECLEN (regs, 0); ++i)
10807 dw_loc_descr_ref t;
10809 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10810 VAR_INIT_STATUS_INITIALIZED);
10811 add_loc_descr (&loc_result, t);
10812 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10813 add_loc_descr_op_piece (&loc_result, size);
10816 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10817 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10821 /* Return a location descriptor that designates a constant. */
10823 static dw_loc_descr_ref
10824 int_loc_descriptor (HOST_WIDE_INT i)
10826 enum dwarf_location_atom op;
10828 /* Pick the smallest representation of a constant, rather than just
10829 defaulting to the LEB encoding. */
10833 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10834 else if (i <= 0xff)
10835 op = DW_OP_const1u;
10836 else if (i <= 0xffff)
10837 op = DW_OP_const2u;
10838 else if (HOST_BITS_PER_WIDE_INT == 32
10839 || i <= 0xffffffff)
10840 op = DW_OP_const4u;
10847 op = DW_OP_const1s;
10848 else if (i >= -0x8000)
10849 op = DW_OP_const2s;
10850 else if (HOST_BITS_PER_WIDE_INT == 32
10851 || i >= -0x80000000)
10852 op = DW_OP_const4s;
10857 return new_loc_descr (op, i, 0);
10860 /* Return loc description representing "address" of integer value.
10861 This can appear only as toplevel expression. */
10863 static dw_loc_descr_ref
10864 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
10867 dw_loc_descr_ref loc_result = NULL;
10869 if (!(dwarf_version >= 4 || !dwarf_strict))
10876 else if (i <= 0xff)
10878 else if (i <= 0xffff)
10880 else if (HOST_BITS_PER_WIDE_INT == 32
10881 || i <= 0xffffffff)
10884 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
10890 else if (i >= -0x8000)
10892 else if (HOST_BITS_PER_WIDE_INT == 32
10893 || i >= -0x80000000)
10896 litsize = 1 + size_of_sleb128 (i);
10898 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10899 is more compact. For DW_OP_stack_value we need:
10900 litsize + 1 (DW_OP_stack_value)
10901 and for DW_OP_implicit_value:
10902 1 (DW_OP_implicit_value) + 1 (length) + size. */
10903 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
10905 loc_result = int_loc_descriptor (i);
10906 add_loc_descr (&loc_result,
10907 new_loc_descr (DW_OP_stack_value, 0, 0));
10911 loc_result = new_loc_descr (DW_OP_implicit_value,
10913 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
10914 loc_result->dw_loc_oprnd2.v.val_int = i;
10918 /* Return a location descriptor that designates a base+offset location. */
10920 static dw_loc_descr_ref
10921 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10922 enum var_init_status initialized)
10924 unsigned int regno;
10925 dw_loc_descr_ref result;
10926 dw_fde_ref fde = current_fde ();
10928 /* We only use "frame base" when we're sure we're talking about the
10929 post-prologue local stack frame. We do this by *not* running
10930 register elimination until this point, and recognizing the special
10931 argument pointer and soft frame pointer rtx's. */
10932 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10934 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10938 if (GET_CODE (elim) == PLUS)
10940 offset += INTVAL (XEXP (elim, 1));
10941 elim = XEXP (elim, 0);
10943 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10944 && (elim == hard_frame_pointer_rtx
10945 || elim == stack_pointer_rtx))
10946 || elim == (frame_pointer_needed
10947 ? hard_frame_pointer_rtx
10948 : stack_pointer_rtx));
10950 /* If drap register is used to align stack, use frame
10951 pointer + offset to access stack variables. If stack
10952 is aligned without drap, use stack pointer + offset to
10953 access stack variables. */
10954 if (crtl->stack_realign_tried
10955 && reg == frame_pointer_rtx)
10958 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10959 ? HARD_FRAME_POINTER_REGNUM
10961 return new_reg_loc_descr (base_reg, offset);
10964 gcc_assert (frame_pointer_fb_offset_valid);
10965 offset += frame_pointer_fb_offset;
10966 return new_loc_descr (DW_OP_fbreg, offset, 0);
10971 && (fde->drap_reg == REGNO (reg)
10972 || fde->vdrap_reg == REGNO (reg)))
10974 /* Use cfa+offset to represent the location of arguments passed
10975 on the stack when drap is used to align stack.
10976 Only do this when not optimizing, for optimized code var-tracking
10977 is supposed to track where the arguments live and the register
10978 used as vdrap or drap in some spot might be used for something
10979 else in other part of the routine. */
10980 return new_loc_descr (DW_OP_fbreg, offset, 0);
10983 regno = dbx_reg_number (reg);
10985 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10988 result = new_loc_descr (DW_OP_bregx, regno, offset);
10990 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10991 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10996 /* Return true if this RTL expression describes a base+offset calculation. */
10999 is_based_loc (const_rtx rtl)
11001 return (GET_CODE (rtl) == PLUS
11002 && ((REG_P (XEXP (rtl, 0))
11003 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
11004 && CONST_INT_P (XEXP (rtl, 1)))));
11007 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11010 static dw_loc_descr_ref
11011 tls_mem_loc_descriptor (rtx mem)
11014 dw_loc_descr_ref loc_result;
11016 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
11019 base = get_base_address (MEM_EXPR (mem));
11021 || TREE_CODE (base) != VAR_DECL
11022 || !DECL_THREAD_LOCAL_P (base))
11025 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
11026 if (loc_result == NULL)
11029 if (INTVAL (MEM_OFFSET (mem)))
11030 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
11035 /* Output debug info about reason why we failed to expand expression as dwarf
11039 expansion_failed (tree expr, rtx rtl, char const *reason)
11041 if (dump_file && (dump_flags & TDF_DETAILS))
11043 fprintf (dump_file, "Failed to expand as dwarf: ");
11045 print_generic_expr (dump_file, expr, dump_flags);
11048 fprintf (dump_file, "\n");
11049 print_rtl (dump_file, rtl);
11051 fprintf (dump_file, "\nReason: %s\n", reason);
11055 /* Helper function for const_ok_for_output, called either directly
11056 or via for_each_rtx. */
11059 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
11063 if (GET_CODE (rtl) == UNSPEC)
11065 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11066 we can't express it in the debug info. */
11067 #ifdef ENABLE_CHECKING
11068 /* Don't complain about TLS UNSPECs, those are just too hard to
11070 if (XVECLEN (rtl, 0) != 1
11071 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
11072 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
11073 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
11074 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
11075 inform (current_function_decl
11076 ? DECL_SOURCE_LOCATION (current_function_decl)
11077 : UNKNOWN_LOCATION,
11078 #if NUM_UNSPEC_VALUES > 0
11079 "non-delegitimized UNSPEC %s (%d) found in variable location",
11080 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
11081 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
11084 "non-delegitimized UNSPEC %d found in variable location",
11088 expansion_failed (NULL_TREE, rtl,
11089 "UNSPEC hasn't been delegitimized.\n");
11093 if (GET_CODE (rtl) != SYMBOL_REF)
11096 if (CONSTANT_POOL_ADDRESS_P (rtl))
11099 get_pool_constant_mark (rtl, &marked);
11100 /* If all references to this pool constant were optimized away,
11101 it was not output and thus we can't represent it. */
11104 expansion_failed (NULL_TREE, rtl,
11105 "Constant was removed from constant pool.\n");
11110 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11113 /* Avoid references to external symbols in debug info, on several targets
11114 the linker might even refuse to link when linking a shared library,
11115 and in many other cases the relocations for .debug_info/.debug_loc are
11116 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11117 to be defined within the same shared library or executable are fine. */
11118 if (SYMBOL_REF_EXTERNAL_P (rtl))
11120 tree decl = SYMBOL_REF_DECL (rtl);
11122 if (decl == NULL || !targetm.binds_local_p (decl))
11124 expansion_failed (NULL_TREE, rtl,
11125 "Symbol not defined in current TU.\n");
11133 /* Return true if constant RTL can be emitted in DW_OP_addr or
11134 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11135 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11138 const_ok_for_output (rtx rtl)
11140 if (GET_CODE (rtl) == SYMBOL_REF)
11141 return const_ok_for_output_1 (&rtl, NULL) == 0;
11143 if (GET_CODE (rtl) == CONST)
11144 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
11149 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11150 if possible, NULL otherwise. */
11153 base_type_for_mode (enum machine_mode mode, bool unsignedp)
11155 dw_die_ref type_die;
11156 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
11160 switch (TREE_CODE (type))
11168 type_die = lookup_type_die (type);
11170 type_die = modified_type_die (type, false, false, comp_unit_die ());
11171 if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
11176 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11177 type matching MODE, or, if MODE is narrower than or as wide as
11178 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11181 static dw_loc_descr_ref
11182 convert_descriptor_to_mode (enum machine_mode mode, dw_loc_descr_ref op)
11184 enum machine_mode outer_mode = mode;
11185 dw_die_ref type_die;
11186 dw_loc_descr_ref cvt;
11188 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
11190 add_loc_descr (&op, new_loc_descr (DW_OP_GNU_convert, 0, 0));
11193 type_die = base_type_for_mode (outer_mode, 1);
11194 if (type_die == NULL)
11196 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11197 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11198 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11199 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11200 add_loc_descr (&op, cvt);
11204 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11206 static dw_loc_descr_ref
11207 compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
11208 dw_loc_descr_ref op1)
11210 dw_loc_descr_ref ret = op0;
11211 add_loc_descr (&ret, op1);
11212 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11213 if (STORE_FLAG_VALUE != 1)
11215 add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
11216 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
11221 /* Return location descriptor for signed comparison OP RTL. */
11223 static dw_loc_descr_ref
11224 scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
11225 enum machine_mode mem_mode)
11227 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
11228 dw_loc_descr_ref op0, op1;
11231 if (op_mode == VOIDmode)
11232 op_mode = GET_MODE (XEXP (rtl, 1));
11233 if (op_mode == VOIDmode)
11237 && (GET_MODE_CLASS (op_mode) != MODE_INT
11238 || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
11241 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
11242 VAR_INIT_STATUS_INITIALIZED);
11243 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
11244 VAR_INIT_STATUS_INITIALIZED);
11246 if (op0 == NULL || op1 == NULL)
11249 if (GET_MODE_CLASS (op_mode) != MODE_INT
11250 || GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
11251 return compare_loc_descriptor (op, op0, op1);
11253 if (GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
11255 dw_die_ref type_die = base_type_for_mode (op_mode, 0);
11256 dw_loc_descr_ref cvt;
11258 if (type_die == NULL)
11260 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11261 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11262 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11263 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11264 add_loc_descr (&op0, cvt);
11265 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11266 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11267 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11268 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11269 add_loc_descr (&op1, cvt);
11270 return compare_loc_descriptor (op, op0, op1);
11273 shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
11274 /* For eq/ne, if the operands are known to be zero-extended,
11275 there is no need to do the fancy shifting up. */
11276 if (op == DW_OP_eq || op == DW_OP_ne)
11278 dw_loc_descr_ref last0, last1;
11279 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
11281 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
11283 /* deref_size zero extends, and for constants we can check
11284 whether they are zero extended or not. */
11285 if (((last0->dw_loc_opc == DW_OP_deref_size
11286 && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
11287 || (CONST_INT_P (XEXP (rtl, 0))
11288 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
11289 == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
11290 && ((last1->dw_loc_opc == DW_OP_deref_size
11291 && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
11292 || (CONST_INT_P (XEXP (rtl, 1))
11293 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
11294 == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
11295 return compare_loc_descriptor (op, op0, op1);
11297 add_loc_descr (&op0, int_loc_descriptor (shift));
11298 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11299 if (CONST_INT_P (XEXP (rtl, 1)))
11300 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
11303 add_loc_descr (&op1, int_loc_descriptor (shift));
11304 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11306 return compare_loc_descriptor (op, op0, op1);
11309 /* Return location descriptor for unsigned comparison OP RTL. */
11311 static dw_loc_descr_ref
11312 ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
11313 enum machine_mode mem_mode)
11315 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
11316 dw_loc_descr_ref op0, op1;
11318 if (op_mode == VOIDmode)
11319 op_mode = GET_MODE (XEXP (rtl, 1));
11320 if (op_mode == VOIDmode)
11322 if (GET_MODE_CLASS (op_mode) != MODE_INT)
11325 if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
11328 op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
11329 VAR_INIT_STATUS_INITIALIZED);
11330 op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
11331 VAR_INIT_STATUS_INITIALIZED);
11333 if (op0 == NULL || op1 == NULL)
11336 if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
11338 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
11339 dw_loc_descr_ref last0, last1;
11340 for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
11342 for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
11344 if (CONST_INT_P (XEXP (rtl, 0)))
11345 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
11346 /* deref_size zero extends, so no need to mask it again. */
11347 else if (last0->dw_loc_opc != DW_OP_deref_size
11348 || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
11350 add_loc_descr (&op0, int_loc_descriptor (mask));
11351 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11353 if (CONST_INT_P (XEXP (rtl, 1)))
11354 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
11355 /* deref_size zero extends, so no need to mask it again. */
11356 else if (last1->dw_loc_opc != DW_OP_deref_size
11357 || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
11359 add_loc_descr (&op1, int_loc_descriptor (mask));
11360 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11363 else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
11365 HOST_WIDE_INT bias = 1;
11366 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11367 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11368 if (CONST_INT_P (XEXP (rtl, 1)))
11369 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
11370 + INTVAL (XEXP (rtl, 1)));
11372 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
11375 return compare_loc_descriptor (op, op0, op1);
11378 /* Return location descriptor for {U,S}{MIN,MAX}. */
11380 static dw_loc_descr_ref
11381 minmax_loc_descriptor (rtx rtl, enum machine_mode mode,
11382 enum machine_mode mem_mode)
11384 enum dwarf_location_atom op;
11385 dw_loc_descr_ref op0, op1, ret;
11386 dw_loc_descr_ref bra_node, drop_node;
11389 && (GET_MODE_CLASS (mode) != MODE_INT
11390 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
11393 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11394 VAR_INIT_STATUS_INITIALIZED);
11395 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11396 VAR_INIT_STATUS_INITIALIZED);
11398 if (op0 == NULL || op1 == NULL)
11401 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
11402 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
11403 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
11404 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
11406 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11408 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
11409 add_loc_descr (&op0, int_loc_descriptor (mask));
11410 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11411 add_loc_descr (&op1, int_loc_descriptor (mask));
11412 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11414 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
11416 HOST_WIDE_INT bias = 1;
11417 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11418 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11419 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11422 else if (GET_MODE_CLASS (mode) == MODE_INT
11423 && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11425 int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode)) * BITS_PER_UNIT;
11426 add_loc_descr (&op0, int_loc_descriptor (shift));
11427 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11428 add_loc_descr (&op1, int_loc_descriptor (shift));
11429 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11431 else if (GET_MODE_CLASS (mode) == MODE_INT
11432 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11434 dw_die_ref type_die = base_type_for_mode (mode, 0);
11435 dw_loc_descr_ref cvt;
11436 if (type_die == NULL)
11438 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11439 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11440 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11441 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11442 add_loc_descr (&op0, cvt);
11443 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11444 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11445 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11446 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11447 add_loc_descr (&op1, cvt);
11450 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
11455 add_loc_descr (&ret, op1);
11456 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11457 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11458 add_loc_descr (&ret, bra_node);
11459 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11460 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
11461 add_loc_descr (&ret, drop_node);
11462 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11463 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
11464 if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
11465 && GET_MODE_CLASS (mode) == MODE_INT
11466 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
11467 ret = convert_descriptor_to_mode (mode, ret);
11471 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11472 but after converting arguments to type_die, afterwards
11473 convert back to unsigned. */
11475 static dw_loc_descr_ref
11476 typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
11477 enum machine_mode mode, enum machine_mode mem_mode)
11479 dw_loc_descr_ref cvt, op0, op1;
11481 if (type_die == NULL)
11483 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11484 VAR_INIT_STATUS_INITIALIZED);
11485 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
11486 VAR_INIT_STATUS_INITIALIZED);
11487 if (op0 == NULL || op1 == NULL)
11489 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11490 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11491 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11492 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11493 add_loc_descr (&op0, cvt);
11494 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11495 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11496 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
11497 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
11498 add_loc_descr (&op1, cvt);
11499 add_loc_descr (&op0, op1);
11500 add_loc_descr (&op0, new_loc_descr (op, 0, 0));
11501 return convert_descriptor_to_mode (mode, op0);
11504 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11505 const0 is DW_OP_lit0 or corresponding typed constant,
11506 const1 is DW_OP_lit1 or corresponding typed constant
11507 and constMSB is constant with just the MSB bit set
11509 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11510 L1: const0 DW_OP_swap
11511 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11512 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11517 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11518 L1: const0 DW_OP_swap
11519 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11520 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11525 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11526 L1: const1 DW_OP_swap
11527 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11528 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11532 static dw_loc_descr_ref
11533 clz_loc_descriptor (rtx rtl, enum machine_mode mode,
11534 enum machine_mode mem_mode)
11536 dw_loc_descr_ref op0, ret, tmp;
11537 HOST_WIDE_INT valv;
11538 dw_loc_descr_ref l1jump, l1label;
11539 dw_loc_descr_ref l2jump, l2label;
11540 dw_loc_descr_ref l3jump, l3label;
11541 dw_loc_descr_ref l4jump, l4label;
11544 if (GET_MODE_CLASS (mode) != MODE_INT
11545 || GET_MODE (XEXP (rtl, 0)) != mode
11546 || (GET_CODE (rtl) == CLZ
11547 && GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT))
11550 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11551 VAR_INIT_STATUS_INITIALIZED);
11555 if (GET_CODE (rtl) == CLZ)
11557 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11558 valv = GET_MODE_BITSIZE (mode);
11560 else if (GET_CODE (rtl) == FFS)
11562 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
11563 valv = GET_MODE_BITSIZE (mode);
11564 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11565 l1jump = new_loc_descr (DW_OP_bra, 0, 0);
11566 add_loc_descr (&ret, l1jump);
11567 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11568 tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
11569 VAR_INIT_STATUS_INITIALIZED);
11572 add_loc_descr (&ret, tmp);
11573 l4jump = new_loc_descr (DW_OP_skip, 0, 0);
11574 add_loc_descr (&ret, l4jump);
11575 l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
11576 ? const1_rtx : const0_rtx,
11578 VAR_INIT_STATUS_INITIALIZED);
11579 if (l1label == NULL)
11581 add_loc_descr (&ret, l1label);
11582 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11583 l2label = new_loc_descr (DW_OP_dup, 0, 0);
11584 add_loc_descr (&ret, l2label);
11585 if (GET_CODE (rtl) != CLZ)
11587 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
11588 msb = GEN_INT ((unsigned HOST_WIDE_INT) 1
11589 << (GET_MODE_BITSIZE (mode) - 1));
11591 msb = immed_double_const (0, (unsigned HOST_WIDE_INT) 1
11592 << (GET_MODE_BITSIZE (mode)
11593 - HOST_BITS_PER_WIDE_INT - 1), mode);
11594 if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
11595 tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11596 ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
11597 ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
11599 tmp = mem_loc_descriptor (msb, mode, mem_mode,
11600 VAR_INIT_STATUS_INITIALIZED);
11603 add_loc_descr (&ret, tmp);
11604 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11605 l3jump = new_loc_descr (DW_OP_bra, 0, 0);
11606 add_loc_descr (&ret, l3jump);
11607 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11608 VAR_INIT_STATUS_INITIALIZED);
11611 add_loc_descr (&ret, tmp);
11612 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
11613 ? DW_OP_shl : DW_OP_shr, 0, 0));
11614 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11615 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
11616 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11617 l2jump = new_loc_descr (DW_OP_skip, 0, 0);
11618 add_loc_descr (&ret, l2jump);
11619 l3label = new_loc_descr (DW_OP_drop, 0, 0);
11620 add_loc_descr (&ret, l3label);
11621 l4label = new_loc_descr (DW_OP_nop, 0, 0);
11622 add_loc_descr (&ret, l4label);
11623 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11624 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11625 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11626 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11627 l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11628 l3jump->dw_loc_oprnd1.v.val_loc = l3label;
11629 l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11630 l4jump->dw_loc_oprnd1.v.val_loc = l4label;
11634 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11635 const1 is DW_OP_lit1 or corresponding typed constant):
11637 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11638 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11642 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11643 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11646 static dw_loc_descr_ref
11647 popcount_loc_descriptor (rtx rtl, enum machine_mode mode,
11648 enum machine_mode mem_mode)
11650 dw_loc_descr_ref op0, ret, tmp;
11651 dw_loc_descr_ref l1jump, l1label;
11652 dw_loc_descr_ref l2jump, l2label;
11654 if (GET_MODE_CLASS (mode) != MODE_INT
11655 || GET_MODE (XEXP (rtl, 0)) != mode)
11658 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11659 VAR_INIT_STATUS_INITIALIZED);
11663 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11664 VAR_INIT_STATUS_INITIALIZED);
11667 add_loc_descr (&ret, tmp);
11668 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11669 l1label = new_loc_descr (DW_OP_dup, 0, 0);
11670 add_loc_descr (&ret, l1label);
11671 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11672 add_loc_descr (&ret, l2jump);
11673 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11674 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11675 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11676 VAR_INIT_STATUS_INITIALIZED);
11679 add_loc_descr (&ret, tmp);
11680 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11681 add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
11682 ? DW_OP_plus : DW_OP_xor, 0, 0));
11683 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11684 tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
11685 VAR_INIT_STATUS_INITIALIZED);
11686 add_loc_descr (&ret, tmp);
11687 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11688 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11689 add_loc_descr (&ret, l1jump);
11690 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11691 add_loc_descr (&ret, l2label);
11692 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11693 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11694 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11695 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11699 /* BSWAP (constS is initial shift count, either 56 or 24):
11701 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11702 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11703 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11704 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11705 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11707 static dw_loc_descr_ref
11708 bswap_loc_descriptor (rtx rtl, enum machine_mode mode,
11709 enum machine_mode mem_mode)
11711 dw_loc_descr_ref op0, ret, tmp;
11712 dw_loc_descr_ref l1jump, l1label;
11713 dw_loc_descr_ref l2jump, l2label;
11715 if (GET_MODE_CLASS (mode) != MODE_INT
11716 || BITS_PER_UNIT != 8
11717 || (GET_MODE_BITSIZE (mode) != 32
11718 && GET_MODE_BITSIZE (mode) != 64))
11721 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11722 VAR_INIT_STATUS_INITIALIZED);
11727 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11729 VAR_INIT_STATUS_INITIALIZED);
11732 add_loc_descr (&ret, tmp);
11733 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11734 VAR_INIT_STATUS_INITIALIZED);
11737 add_loc_descr (&ret, tmp);
11738 l1label = new_loc_descr (DW_OP_pick, 2, 0);
11739 add_loc_descr (&ret, l1label);
11740 tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
11742 VAR_INIT_STATUS_INITIALIZED);
11743 add_loc_descr (&ret, tmp);
11744 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
11745 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11746 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11747 tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
11748 VAR_INIT_STATUS_INITIALIZED);
11751 add_loc_descr (&ret, tmp);
11752 add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
11753 add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
11754 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11755 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11756 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11757 add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
11758 tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
11759 VAR_INIT_STATUS_INITIALIZED);
11760 add_loc_descr (&ret, tmp);
11761 add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
11762 l2jump = new_loc_descr (DW_OP_bra, 0, 0);
11763 add_loc_descr (&ret, l2jump);
11764 tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
11765 VAR_INIT_STATUS_INITIALIZED);
11766 add_loc_descr (&ret, tmp);
11767 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
11768 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11769 l1jump = new_loc_descr (DW_OP_skip, 0, 0);
11770 add_loc_descr (&ret, l1jump);
11771 l2label = new_loc_descr (DW_OP_drop, 0, 0);
11772 add_loc_descr (&ret, l2label);
11773 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11774 add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
11775 l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11776 l1jump->dw_loc_oprnd1.v.val_loc = l1label;
11777 l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
11778 l2jump->dw_loc_oprnd1.v.val_loc = l2label;
11782 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11783 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11784 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11785 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11787 ROTATERT is similar:
11788 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11789 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11790 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11792 static dw_loc_descr_ref
11793 rotate_loc_descriptor (rtx rtl, enum machine_mode mode,
11794 enum machine_mode mem_mode)
11796 rtx rtlop1 = XEXP (rtl, 1);
11797 dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
11800 if (GET_MODE_CLASS (mode) != MODE_INT)
11803 if (GET_MODE (rtlop1) != VOIDmode
11804 && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode))
11805 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
11806 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
11807 VAR_INIT_STATUS_INITIALIZED);
11808 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
11809 VAR_INIT_STATUS_INITIALIZED);
11810 if (op0 == NULL || op1 == NULL)
11812 if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
11813 for (i = 0; i < 2; i++)
11815 if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
11816 mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
11818 VAR_INIT_STATUS_INITIALIZED);
11819 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
11820 mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
11822 : HOST_BITS_PER_WIDE_INT == 64
11823 ? DW_OP_const8u : DW_OP_constu,
11824 GET_MODE_MASK (mode), 0);
11827 if (mask[i] == NULL)
11829 add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
11832 add_loc_descr (&ret, op1);
11833 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11834 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
11835 if (GET_CODE (rtl) == ROTATERT)
11837 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11838 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11839 GET_MODE_BITSIZE (mode), 0));
11841 add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
11842 if (mask[0] != NULL)
11843 add_loc_descr (&ret, mask[0]);
11844 add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
11845 if (mask[1] != NULL)
11847 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11848 add_loc_descr (&ret, mask[1]);
11849 add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
11851 if (GET_CODE (rtl) == ROTATE)
11853 add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
11854 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
11855 GET_MODE_BITSIZE (mode), 0));
11857 add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
11858 add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
11862 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11863 for DEBUG_PARAMETER_REF RTL. */
11865 static dw_loc_descr_ref
11866 parameter_ref_descriptor (rtx rtl)
11868 dw_loc_descr_ref ret;
11873 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
11874 ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
11875 ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
11878 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
11879 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
11880 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
11884 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
11885 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
11890 /* Helper function to get mode of MEM's address. */
11893 get_address_mode (rtx mem)
11895 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
11896 if (mode != VOIDmode)
11898 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
11901 /* The following routine converts the RTL for a variable or parameter
11902 (resident in memory) into an equivalent Dwarf representation of a
11903 mechanism for getting the address of that same variable onto the top of a
11904 hypothetical "address evaluation" stack.
11906 When creating memory location descriptors, we are effectively transforming
11907 the RTL for a memory-resident object into its Dwarf postfix expression
11908 equivalent. This routine recursively descends an RTL tree, turning
11909 it into Dwarf postfix code as it goes.
11911 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11913 MEM_MODE is the mode of the memory reference, needed to handle some
11914 autoincrement addressing modes.
11916 Return 0 if we can't represent the location. */
11919 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11920 enum machine_mode mem_mode,
11921 enum var_init_status initialized)
11923 dw_loc_descr_ref mem_loc_result = NULL;
11924 enum dwarf_location_atom op;
11925 dw_loc_descr_ref op0, op1;
11927 if (mode == VOIDmode)
11928 mode = GET_MODE (rtl);
11930 /* Note that for a dynamically sized array, the location we will generate a
11931 description of here will be the lowest numbered location which is
11932 actually within the array. That's *not* necessarily the same as the
11933 zeroth element of the array. */
11935 rtl = targetm.delegitimize_address (rtl);
11937 if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
11940 switch (GET_CODE (rtl))
11945 return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
11948 /* The case of a subreg may arise when we have a local (register)
11949 variable or a formal (register) parameter which doesn't quite fill
11950 up an entire register. For now, just assume that it is
11951 legitimate to make the Dwarf info refer to the whole register which
11952 contains the given subreg. */
11953 if (!subreg_lowpart_p (rtl))
11955 if (GET_MODE_CLASS (mode) == MODE_INT
11956 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
11957 && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
11958 #ifdef POINTERS_EXTEND_UNSIGNED
11959 || (mode == Pmode && mem_mode != VOIDmode)
11962 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
11964 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11965 GET_MODE (SUBREG_REG (rtl)),
11966 mem_mode, initialized);
11971 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11973 if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
11974 && (GET_MODE_CLASS (mode) != MODE_INT
11975 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
11979 dw_die_ref type_die;
11980 dw_loc_descr_ref cvt;
11982 mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
11983 GET_MODE (SUBREG_REG (rtl)),
11984 mem_mode, initialized);
11985 if (mem_loc_result == NULL)
11987 type_die = base_type_for_mode (mode,
11988 GET_MODE_CLASS (mode) == MODE_INT);
11989 if (type_die == NULL)
11991 mem_loc_result = NULL;
11994 if (GET_MODE_SIZE (mode)
11995 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
11996 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
11998 cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
11999 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12000 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12001 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12002 add_loc_descr (&mem_loc_result, cvt);
12007 if (GET_MODE_CLASS (mode) != MODE_INT
12008 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12009 #ifdef POINTERS_EXTEND_UNSIGNED
12010 && (mode != Pmode || mem_mode == VOIDmode)
12014 dw_die_ref type_die;
12018 if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
12020 type_die = base_type_for_mode (mode,
12021 GET_MODE_CLASS (mode) == MODE_INT);
12022 if (type_die == NULL)
12024 mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
12025 dbx_reg_number (rtl), 0);
12026 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
12027 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
12028 mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
12031 /* Whenever a register number forms a part of the description of the
12032 method for calculating the (dynamic) address of a memory resident
12033 object, DWARF rules require the register number be referred to as
12034 a "base register". This distinction is not based in any way upon
12035 what category of register the hardware believes the given register
12036 belongs to. This is strictly DWARF terminology we're dealing with
12037 here. Note that in cases where the location of a memory-resident
12038 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12039 OP_CONST (0)) the actual DWARF location descriptor that we generate
12040 may just be OP_BASEREG (basereg). This may look deceptively like
12041 the object in question was allocated to a register (rather than in
12042 memory) so DWARF consumers need to be aware of the subtle
12043 distinction between OP_REG and OP_BASEREG. */
12044 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
12045 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
12046 else if (stack_realign_drap
12048 && crtl->args.internal_arg_pointer == rtl
12049 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
12051 /* If RTL is internal_arg_pointer, which has been optimized
12052 out, use DRAP instead. */
12053 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
12054 VAR_INIT_STATUS_INITIALIZED);
12060 if (GET_MODE_CLASS (mode) != MODE_INT)
12062 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12063 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12066 else if (GET_CODE (rtl) == ZERO_EXTEND
12067 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12068 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
12069 < HOST_BITS_PER_WIDE_INT
12070 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12071 to expand zero extend as two shifts instead of
12073 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= 4)
12075 enum machine_mode imode = GET_MODE (XEXP (rtl, 0));
12076 mem_loc_result = op0;
12077 add_loc_descr (&mem_loc_result,
12078 int_loc_descriptor (GET_MODE_MASK (imode)));
12079 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
12081 else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
12083 int shift = DWARF2_ADDR_SIZE
12084 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
12085 shift *= BITS_PER_UNIT;
12086 if (GET_CODE (rtl) == SIGN_EXTEND)
12090 mem_loc_result = op0;
12091 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
12092 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
12093 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
12094 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12096 else if (!dwarf_strict)
12098 dw_die_ref type_die1, type_die2;
12099 dw_loc_descr_ref cvt;
12101 type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12102 GET_CODE (rtl) == ZERO_EXTEND);
12103 if (type_die1 == NULL)
12105 type_die2 = base_type_for_mode (mode, 1);
12106 if (type_die2 == NULL)
12108 mem_loc_result = op0;
12109 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12110 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12111 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
12112 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12113 add_loc_descr (&mem_loc_result, cvt);
12114 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12115 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12116 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
12117 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12118 add_loc_descr (&mem_loc_result, cvt);
12123 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
12124 get_address_mode (rtl), mode,
12125 VAR_INIT_STATUS_INITIALIZED);
12126 if (mem_loc_result == NULL)
12127 mem_loc_result = tls_mem_loc_descriptor (rtl);
12128 if (mem_loc_result != 0)
12130 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12131 || GET_MODE_CLASS (mode) != MODE_INT)
12133 dw_die_ref type_die;
12134 dw_loc_descr_ref deref;
12139 = base_type_for_mode (mode, GET_MODE_CLASS (mode) == MODE_INT);
12140 if (type_die == NULL)
12142 deref = new_loc_descr (DW_OP_GNU_deref_type,
12143 GET_MODE_SIZE (mode), 0);
12144 deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
12145 deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
12146 deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
12147 add_loc_descr (&mem_loc_result, deref);
12149 else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
12150 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
12152 add_loc_descr (&mem_loc_result,
12153 new_loc_descr (DW_OP_deref_size,
12154 GET_MODE_SIZE (mode), 0));
12158 rtx new_rtl = avoid_constant_pool_reference (rtl);
12159 if (new_rtl != rtl)
12160 return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized);
12165 return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
12168 /* Some ports can transform a symbol ref into a label ref, because
12169 the symbol ref is too far away and has to be dumped into a constant
12173 if (GET_MODE_CLASS (mode) != MODE_INT
12174 || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
12175 #ifdef POINTERS_EXTEND_UNSIGNED
12176 && (mode != Pmode || mem_mode == VOIDmode)
12180 if (GET_CODE (rtl) == SYMBOL_REF
12181 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
12183 dw_loc_descr_ref temp;
12185 /* If this is not defined, we have no way to emit the data. */
12186 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
12189 /* We used to emit DW_OP_addr here, but that's wrong, since
12190 DW_OP_addr should be relocated by the debug info consumer,
12191 while DW_OP_GNU_push_tls_address operand should not. */
12192 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
12193 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
12194 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
12195 temp->dw_loc_oprnd1.v.val_addr = rtl;
12196 temp->dtprel = true;
12198 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
12199 add_loc_descr (&mem_loc_result, temp);
12204 if (!const_ok_for_output (rtl))
12208 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
12209 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
12210 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
12211 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12217 case DEBUG_IMPLICIT_PTR:
12218 expansion_failed (NULL_TREE, rtl,
12219 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12225 if (REG_P (ENTRY_VALUE_EXP (rtl)))
12227 if (GET_MODE_CLASS (mode) != MODE_INT
12228 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12229 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
12230 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12233 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
12234 VAR_INIT_STATUS_INITIALIZED);
12236 else if (MEM_P (ENTRY_VALUE_EXP (rtl))
12237 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
12239 op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
12240 VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12241 if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
12245 gcc_unreachable ();
12248 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
12249 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
12250 mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
12253 case DEBUG_PARAMETER_REF:
12254 mem_loc_result = parameter_ref_descriptor (rtl);
12258 /* Extract the PLUS expression nested inside and fall into
12259 PLUS code below. */
12260 rtl = XEXP (rtl, 1);
12265 /* Turn these into a PLUS expression and fall into the PLUS code
12267 rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
12268 GEN_INT (GET_CODE (rtl) == PRE_INC
12269 ? GET_MODE_UNIT_SIZE (mem_mode)
12270 : -GET_MODE_UNIT_SIZE (mem_mode)));
12272 /* ... fall through ... */
12276 if (is_based_loc (rtl)
12277 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12278 && GET_MODE_CLASS (mode) == MODE_INT)
12279 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
12280 INTVAL (XEXP (rtl, 1)),
12281 VAR_INIT_STATUS_INITIALIZED);
12284 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12285 VAR_INIT_STATUS_INITIALIZED);
12286 if (mem_loc_result == 0)
12289 if (CONST_INT_P (XEXP (rtl, 1))
12290 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
12291 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
12294 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12295 VAR_INIT_STATUS_INITIALIZED);
12298 add_loc_descr (&mem_loc_result, op1);
12299 add_loc_descr (&mem_loc_result,
12300 new_loc_descr (DW_OP_plus, 0, 0));
12305 /* If a pseudo-reg is optimized away, it is possible for it to
12306 be replaced with a MEM containing a multiply or shift. */
12317 && GET_MODE_CLASS (mode) == MODE_INT
12318 && GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
12320 mem_loc_result = typed_binop (DW_OP_div, rtl,
12321 base_type_for_mode (mode, 0),
12345 if (GET_MODE_CLASS (mode) != MODE_INT)
12347 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12348 VAR_INIT_STATUS_INITIALIZED);
12350 rtx rtlop1 = XEXP (rtl, 1);
12351 if (GET_MODE (rtlop1) != VOIDmode
12352 && GET_MODE_BITSIZE (GET_MODE (rtlop1))
12353 < GET_MODE_BITSIZE (mode))
12354 rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
12355 op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
12356 VAR_INIT_STATUS_INITIALIZED);
12359 if (op0 == 0 || op1 == 0)
12362 mem_loc_result = op0;
12363 add_loc_descr (&mem_loc_result, op1);
12364 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12380 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12381 VAR_INIT_STATUS_INITIALIZED);
12382 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12383 VAR_INIT_STATUS_INITIALIZED);
12385 if (op0 == 0 || op1 == 0)
12388 mem_loc_result = op0;
12389 add_loc_descr (&mem_loc_result, op1);
12390 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12394 if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE && !dwarf_strict)
12396 mem_loc_result = typed_binop (DW_OP_mod, rtl,
12397 base_type_for_mode (mode, 0),
12402 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12403 VAR_INIT_STATUS_INITIALIZED);
12404 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12405 VAR_INIT_STATUS_INITIALIZED);
12407 if (op0 == 0 || op1 == 0)
12410 mem_loc_result = op0;
12411 add_loc_descr (&mem_loc_result, op1);
12412 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
12413 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
12414 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
12415 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
12416 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
12420 if (!dwarf_strict && GET_MODE_CLASS (mode) == MODE_INT)
12422 if (GET_MODE_CLASS (mode) > DWARF2_ADDR_SIZE)
12427 mem_loc_result = typed_binop (DW_OP_div, rtl,
12428 base_type_for_mode (mode, 1),
12446 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
12447 VAR_INIT_STATUS_INITIALIZED);
12452 mem_loc_result = op0;
12453 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12457 if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12458 #ifdef POINTERS_EXTEND_UNSIGNED
12460 && mem_mode != VOIDmode
12461 && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
12465 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
12469 && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
12470 || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
12472 dw_die_ref type_die = base_type_for_mode (mode, 1);
12473 if (type_die == NULL)
12475 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
12477 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12478 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12479 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
12480 if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
12481 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
12484 mem_loc_result->dw_loc_oprnd2.val_class
12485 = dw_val_class_const_double;
12486 mem_loc_result->dw_loc_oprnd2.v.val_double
12487 = shwi_to_double_int (INTVAL (rtl));
12495 dw_die_ref type_die;
12497 /* Note that a CONST_DOUBLE rtx could represent either an integer
12498 or a floating-point constant. A CONST_DOUBLE is used whenever
12499 the constant requires more than one word in order to be
12500 adequately represented. We output CONST_DOUBLEs as blocks. */
12501 if (mode == VOIDmode
12502 || (GET_MODE (rtl) == VOIDmode
12503 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
12505 type_die = base_type_for_mode (mode,
12506 GET_MODE_CLASS (mode) == MODE_INT);
12507 if (type_die == NULL)
12509 mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
12510 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12511 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12512 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
12513 if (SCALAR_FLOAT_MODE_P (mode))
12515 unsigned int length = GET_MODE_SIZE (mode);
12516 unsigned char *array
12517 = (unsigned char*) ggc_alloc_atomic (length);
12519 insert_float (rtl, array);
12520 mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12521 mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
12522 mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
12523 mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12527 mem_loc_result->dw_loc_oprnd2.val_class
12528 = dw_val_class_const_double;
12529 mem_loc_result->dw_loc_oprnd2.v.val_double
12530 = rtx_to_double_int (rtl);
12536 mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
12540 mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12544 mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12548 mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12552 mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12556 mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
12560 mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
12564 mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
12568 mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
12572 mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
12577 if (GET_MODE_CLASS (mode) != MODE_INT)
12582 mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
12587 if (CONST_INT_P (XEXP (rtl, 1))
12588 && CONST_INT_P (XEXP (rtl, 2))
12589 && ((unsigned) INTVAL (XEXP (rtl, 1))
12590 + (unsigned) INTVAL (XEXP (rtl, 2))
12591 <= GET_MODE_BITSIZE (mode))
12592 && GET_MODE_CLASS (mode) == MODE_INT
12593 && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
12594 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
12597 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12598 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12601 if (GET_CODE (rtl) == SIGN_EXTRACT)
12605 mem_loc_result = op0;
12606 size = INTVAL (XEXP (rtl, 1));
12607 shift = INTVAL (XEXP (rtl, 2));
12608 if (BITS_BIG_ENDIAN)
12609 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
12611 if (shift + size != (int) DWARF2_ADDR_SIZE)
12613 add_loc_descr (&mem_loc_result,
12614 int_loc_descriptor (DWARF2_ADDR_SIZE
12616 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
12618 if (size != (int) DWARF2_ADDR_SIZE)
12620 add_loc_descr (&mem_loc_result,
12621 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
12622 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
12629 dw_loc_descr_ref op2, bra_node, drop_node;
12630 op0 = mem_loc_descriptor (XEXP (rtl, 0),
12631 GET_MODE (XEXP (rtl, 0)) == VOIDmode
12632 ? word_mode : GET_MODE (XEXP (rtl, 0)),
12633 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12634 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
12635 VAR_INIT_STATUS_INITIALIZED);
12636 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
12637 VAR_INIT_STATUS_INITIALIZED);
12638 if (op0 == NULL || op1 == NULL || op2 == NULL)
12641 mem_loc_result = op1;
12642 add_loc_descr (&mem_loc_result, op2);
12643 add_loc_descr (&mem_loc_result, op0);
12644 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12645 add_loc_descr (&mem_loc_result, bra_node);
12646 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
12647 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
12648 add_loc_descr (&mem_loc_result, drop_node);
12649 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12650 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
12655 case FLOAT_TRUNCATE:
12657 case UNSIGNED_FLOAT:
12662 dw_die_ref type_die;
12663 dw_loc_descr_ref cvt;
12665 op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
12666 mem_mode, VAR_INIT_STATUS_INITIALIZED);
12669 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
12670 && (GET_CODE (rtl) == FLOAT
12671 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
12672 <= DWARF2_ADDR_SIZE))
12674 type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
12675 GET_CODE (rtl) == UNSIGNED_FLOAT);
12676 if (type_die == NULL)
12678 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12679 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12680 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12681 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12682 add_loc_descr (&op0, cvt);
12684 type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
12685 if (type_die == NULL)
12687 cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
12688 cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12689 cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
12690 cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
12691 add_loc_descr (&op0, cvt);
12692 if (GET_MODE_CLASS (mode) == MODE_INT
12693 && (GET_CODE (rtl) == FIX
12694 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
12696 op0 = convert_descriptor_to_mode (mode, op0);
12700 mem_loc_result = op0;
12707 mem_loc_result = clz_loc_descriptor (rtl, mode, mem_mode);
12712 mem_loc_result = popcount_loc_descriptor (rtl, mode, mem_mode);
12716 mem_loc_result = bswap_loc_descriptor (rtl, mode, mem_mode);
12721 mem_loc_result = rotate_loc_descriptor (rtl, mode, mem_mode);
12726 /* In theory, we could implement the above. */
12727 /* DWARF cannot represent the unsigned compare operations
12752 case FRACT_CONVERT:
12753 case UNSIGNED_FRACT_CONVERT:
12755 case UNSIGNED_SAT_FRACT:
12761 case VEC_DUPLICATE:
12765 case STRICT_LOW_PART:
12769 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12770 can't express it in the debug info. This can happen e.g. with some
12775 resolve_one_addr (&rtl, NULL);
12779 #ifdef ENABLE_CHECKING
12780 print_rtl (stderr, rtl);
12781 gcc_unreachable ();
12787 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12788 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12790 return mem_loc_result;
12793 /* Return a descriptor that describes the concatenation of two locations.
12794 This is typically a complex variable. */
12796 static dw_loc_descr_ref
12797 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
12799 dw_loc_descr_ref cc_loc_result = NULL;
12800 dw_loc_descr_ref x0_ref
12801 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12802 dw_loc_descr_ref x1_ref
12803 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12805 if (x0_ref == 0 || x1_ref == 0)
12808 cc_loc_result = x0_ref;
12809 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
12811 add_loc_descr (&cc_loc_result, x1_ref);
12812 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
12814 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
12815 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12817 return cc_loc_result;
12820 /* Return a descriptor that describes the concatenation of N
12823 static dw_loc_descr_ref
12824 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
12827 dw_loc_descr_ref cc_loc_result = NULL;
12828 unsigned int n = XVECLEN (concatn, 0);
12830 for (i = 0; i < n; ++i)
12832 dw_loc_descr_ref ref;
12833 rtx x = XVECEXP (concatn, 0, i);
12835 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
12839 add_loc_descr (&cc_loc_result, ref);
12840 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
12843 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
12844 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
12846 return cc_loc_result;
12849 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12850 for DEBUG_IMPLICIT_PTR RTL. */
12852 static dw_loc_descr_ref
12853 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
12855 dw_loc_descr_ref ret;
12860 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
12861 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
12862 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
12863 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
12864 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
12865 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
12868 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
12869 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
12870 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
12874 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
12875 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
12880 /* Output a proper Dwarf location descriptor for a variable or parameter
12881 which is either allocated in a register or in a memory location. For a
12882 register, we just generate an OP_REG and the register number. For a
12883 memory location we provide a Dwarf postfix expression describing how to
12884 generate the (dynamic) address of the object onto the address stack.
12886 MODE is mode of the decl if this loc_descriptor is going to be used in
12887 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12888 allowed, VOIDmode otherwise.
12890 If we don't know how to describe it, return 0. */
12892 static dw_loc_descr_ref
12893 loc_descriptor (rtx rtl, enum machine_mode mode,
12894 enum var_init_status initialized)
12896 dw_loc_descr_ref loc_result = NULL;
12898 switch (GET_CODE (rtl))
12901 /* The case of a subreg may arise when we have a local (register)
12902 variable or a formal (register) parameter which doesn't quite fill
12903 up an entire register. For now, just assume that it is
12904 legitimate to make the Dwarf info refer to the whole register which
12905 contains the given subreg. */
12906 if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
12907 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
12913 loc_result = reg_loc_descriptor (rtl, initialized);
12917 loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
12918 GET_MODE (rtl), initialized);
12919 if (loc_result == NULL)
12920 loc_result = tls_mem_loc_descriptor (rtl);
12921 if (loc_result == NULL)
12923 rtx new_rtl = avoid_constant_pool_reference (rtl);
12924 if (new_rtl != rtl)
12925 loc_result = loc_descriptor (new_rtl, mode, initialized);
12930 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
12935 loc_result = concatn_loc_descriptor (rtl, initialized);
12940 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
12942 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
12943 if (GET_CODE (loc) == EXPR_LIST)
12944 loc = XEXP (loc, 0);
12945 loc_result = loc_descriptor (loc, mode, initialized);
12949 rtl = XEXP (rtl, 1);
12954 rtvec par_elems = XVEC (rtl, 0);
12955 int num_elem = GET_NUM_ELEM (par_elems);
12956 enum machine_mode mode;
12959 /* Create the first one, so we have something to add to. */
12960 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
12961 VOIDmode, initialized);
12962 if (loc_result == NULL)
12964 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
12965 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12966 for (i = 1; i < num_elem; i++)
12968 dw_loc_descr_ref temp;
12970 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
12971 VOIDmode, initialized);
12974 add_loc_descr (&loc_result, temp);
12975 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
12976 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
12982 if (mode != VOIDmode && mode != BLKmode)
12983 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
12988 if (mode == VOIDmode)
12989 mode = GET_MODE (rtl);
12991 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12993 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
12995 /* Note that a CONST_DOUBLE rtx could represent either an integer
12996 or a floating-point constant. A CONST_DOUBLE is used whenever
12997 the constant requires more than one word in order to be
12998 adequately represented. We output CONST_DOUBLEs as blocks. */
12999 loc_result = new_loc_descr (DW_OP_implicit_value,
13000 GET_MODE_SIZE (mode), 0);
13001 if (SCALAR_FLOAT_MODE_P (mode))
13003 unsigned int length = GET_MODE_SIZE (mode);
13004 unsigned char *array
13005 = (unsigned char*) ggc_alloc_atomic (length);
13007 insert_float (rtl, array);
13008 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13009 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
13010 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
13011 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13015 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
13016 loc_result->dw_loc_oprnd2.v.val_double
13017 = rtx_to_double_int (rtl);
13023 if (mode == VOIDmode)
13024 mode = GET_MODE (rtl);
13026 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
13028 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
13029 unsigned int length = CONST_VECTOR_NUNITS (rtl);
13030 unsigned char *array = (unsigned char *)
13031 ggc_alloc_atomic (length * elt_size);
13035 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
13036 switch (GET_MODE_CLASS (mode))
13038 case MODE_VECTOR_INT:
13039 for (i = 0, p = array; i < length; i++, p += elt_size)
13041 rtx elt = CONST_VECTOR_ELT (rtl, i);
13042 double_int val = rtx_to_double_int (elt);
13044 if (elt_size <= sizeof (HOST_WIDE_INT))
13045 insert_int (double_int_to_shwi (val), elt_size, p);
13048 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
13049 insert_double (val, p);
13054 case MODE_VECTOR_FLOAT:
13055 for (i = 0, p = array; i < length; i++, p += elt_size)
13057 rtx elt = CONST_VECTOR_ELT (rtl, i);
13058 insert_float (elt, p);
13063 gcc_unreachable ();
13066 loc_result = new_loc_descr (DW_OP_implicit_value,
13067 length * elt_size, 0);
13068 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
13069 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
13070 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
13071 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
13076 if (mode == VOIDmode
13077 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
13078 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
13079 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
13081 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
13086 if (!const_ok_for_output (rtl))
13089 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
13090 && (dwarf_version >= 4 || !dwarf_strict))
13092 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13093 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13094 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13095 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
13096 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13100 case DEBUG_IMPLICIT_PTR:
13101 loc_result = implicit_ptr_descriptor (rtl, 0);
13105 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
13106 && CONST_INT_P (XEXP (rtl, 1)))
13109 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
13115 if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
13116 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
13117 && dwarf_version >= 4)
13118 || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
13120 /* Value expression. */
13121 loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
13123 add_loc_descr (&loc_result,
13124 new_loc_descr (DW_OP_stack_value, 0, 0));
13132 /* We need to figure out what section we should use as the base for the
13133 address ranges where a given location is valid.
13134 1. If this particular DECL has a section associated with it, use that.
13135 2. If this function has a section associated with it, use that.
13136 3. Otherwise, use the text section.
13137 XXX: If you split a variable across multiple sections, we won't notice. */
13139 static const char *
13140 secname_for_decl (const_tree decl)
13142 const char *secname;
13144 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
13146 tree sectree = DECL_SECTION_NAME (decl);
13147 secname = TREE_STRING_POINTER (sectree);
13149 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
13151 tree sectree = DECL_SECTION_NAME (current_function_decl);
13152 secname = TREE_STRING_POINTER (sectree);
13154 else if (cfun && in_cold_section_p)
13155 secname = crtl->subsections.cold_section_label;
13157 secname = text_section_label;
13162 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13165 decl_by_reference_p (tree decl)
13167 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
13168 || TREE_CODE (decl) == VAR_DECL)
13169 && DECL_BY_REFERENCE (decl));
13172 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13175 static dw_loc_descr_ref
13176 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
13177 enum var_init_status initialized)
13179 int have_address = 0;
13180 dw_loc_descr_ref descr;
13181 enum machine_mode mode;
13183 if (want_address != 2)
13185 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
13187 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
13189 varloc = PAT_VAR_LOCATION_LOC (varloc);
13190 if (GET_CODE (varloc) == EXPR_LIST)
13191 varloc = XEXP (varloc, 0);
13192 mode = GET_MODE (varloc);
13193 if (MEM_P (varloc))
13195 rtx addr = XEXP (varloc, 0);
13196 descr = mem_loc_descriptor (addr, get_address_mode (varloc),
13197 mode, initialized);
13202 rtx x = avoid_constant_pool_reference (varloc);
13204 descr = mem_loc_descriptor (x, mode, VOIDmode,
13209 descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
13216 if (GET_CODE (varloc) == VAR_LOCATION)
13217 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
13219 mode = DECL_MODE (loc);
13220 descr = loc_descriptor (varloc, mode, initialized);
13227 if (want_address == 2 && !have_address
13228 && (dwarf_version >= 4 || !dwarf_strict))
13230 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
13232 expansion_failed (loc, NULL_RTX,
13233 "DWARF address size mismatch");
13236 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
13239 /* Show if we can't fill the request for an address. */
13240 if (want_address && !have_address)
13242 expansion_failed (loc, NULL_RTX,
13243 "Want address and only have value");
13247 /* If we've got an address and don't want one, dereference. */
13248 if (!want_address && have_address)
13250 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
13251 enum dwarf_location_atom op;
13253 if (size > DWARF2_ADDR_SIZE || size == -1)
13255 expansion_failed (loc, NULL_RTX,
13256 "DWARF address size mismatch");
13259 else if (size == DWARF2_ADDR_SIZE)
13262 op = DW_OP_deref_size;
13264 add_loc_descr (&descr, new_loc_descr (op, size, 0));
13270 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13271 if it is not possible. */
13273 static dw_loc_descr_ref
13274 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
13276 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
13277 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
13278 else if (dwarf_version >= 3 || !dwarf_strict)
13279 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
13284 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13285 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13287 static dw_loc_descr_ref
13288 dw_sra_loc_expr (tree decl, rtx loc)
13291 unsigned int padsize = 0;
13292 dw_loc_descr_ref descr, *descr_tail;
13293 unsigned HOST_WIDE_INT decl_size;
13295 enum var_init_status initialized;
13297 if (DECL_SIZE (decl) == NULL
13298 || !host_integerp (DECL_SIZE (decl), 1))
13301 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
13303 descr_tail = &descr;
13305 for (p = loc; p; p = XEXP (p, 1))
13307 unsigned int bitsize = decl_piece_bitsize (p);
13308 rtx loc_note = *decl_piece_varloc_ptr (p);
13309 dw_loc_descr_ref cur_descr;
13310 dw_loc_descr_ref *tail, last = NULL;
13311 unsigned int opsize = 0;
13313 if (loc_note == NULL_RTX
13314 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
13316 padsize += bitsize;
13319 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
13320 varloc = NOTE_VAR_LOCATION (loc_note);
13321 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
13322 if (cur_descr == NULL)
13324 padsize += bitsize;
13328 /* Check that cur_descr either doesn't use
13329 DW_OP_*piece operations, or their sum is equal
13330 to bitsize. Otherwise we can't embed it. */
13331 for (tail = &cur_descr; *tail != NULL;
13332 tail = &(*tail)->dw_loc_next)
13333 if ((*tail)->dw_loc_opc == DW_OP_piece)
13335 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
13339 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
13341 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
13345 if (last != NULL && opsize != bitsize)
13347 padsize += bitsize;
13351 /* If there is a hole, add DW_OP_*piece after empty DWARF
13352 expression, which means that those bits are optimized out. */
13355 if (padsize > decl_size)
13357 decl_size -= padsize;
13358 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
13359 if (*descr_tail == NULL)
13361 descr_tail = &(*descr_tail)->dw_loc_next;
13364 *descr_tail = cur_descr;
13366 if (bitsize > decl_size)
13368 decl_size -= bitsize;
13371 HOST_WIDE_INT offset = 0;
13372 if (GET_CODE (varloc) == VAR_LOCATION
13373 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
13375 varloc = PAT_VAR_LOCATION_LOC (varloc);
13376 if (GET_CODE (varloc) == EXPR_LIST)
13377 varloc = XEXP (varloc, 0);
13381 if (GET_CODE (varloc) == CONST
13382 || GET_CODE (varloc) == SIGN_EXTEND
13383 || GET_CODE (varloc) == ZERO_EXTEND)
13384 varloc = XEXP (varloc, 0);
13385 else if (GET_CODE (varloc) == SUBREG)
13386 varloc = SUBREG_REG (varloc);
13391 /* DW_OP_bit_size offset should be zero for register
13392 or implicit location descriptions and empty location
13393 descriptions, but for memory addresses needs big endian
13395 if (MEM_P (varloc))
13397 unsigned HOST_WIDE_INT memsize
13398 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
13399 if (memsize != bitsize)
13401 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
13402 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
13404 if (memsize < bitsize)
13406 if (BITS_BIG_ENDIAN)
13407 offset = memsize - bitsize;
13411 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
13412 if (*descr_tail == NULL)
13414 descr_tail = &(*descr_tail)->dw_loc_next;
13418 /* If there were any non-empty expressions, add padding till the end of
13420 if (descr != NULL && decl_size != 0)
13422 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
13423 if (*descr_tail == NULL)
13429 /* Return the dwarf representation of the location list LOC_LIST of
13430 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13433 static dw_loc_list_ref
13434 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
13436 const char *endname, *secname;
13438 enum var_init_status initialized;
13439 struct var_loc_node *node;
13440 dw_loc_descr_ref descr;
13441 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13442 dw_loc_list_ref list = NULL;
13443 dw_loc_list_ref *listp = &list;
13445 /* Now that we know what section we are using for a base,
13446 actually construct the list of locations.
13447 The first location information is what is passed to the
13448 function that creates the location list, and the remaining
13449 locations just get added on to that list.
13450 Note that we only know the start address for a location
13451 (IE location changes), so to build the range, we use
13452 the range [current location start, next location start].
13453 This means we have to special case the last node, and generate
13454 a range of [last location start, end of function label]. */
13456 secname = secname_for_decl (decl);
13458 for (node = loc_list->first; node; node = node->next)
13459 if (GET_CODE (node->loc) == EXPR_LIST
13460 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
13462 if (GET_CODE (node->loc) == EXPR_LIST)
13464 /* This requires DW_OP_{,bit_}piece, which is not usable
13465 inside DWARF expressions. */
13466 if (want_address != 2)
13468 descr = dw_sra_loc_expr (decl, node->loc);
13474 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
13475 varloc = NOTE_VAR_LOCATION (node->loc);
13476 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
13480 bool range_across_switch = false;
13481 /* If section switch happens in between node->label
13482 and node->next->label (or end of function) and
13483 we can't emit it as a single entry list,
13484 emit two ranges, first one ending at the end
13485 of first partition and second one starting at the
13486 beginning of second partition. */
13487 if (node == loc_list->last_before_switch
13488 && (node != loc_list->first || loc_list->first->next)
13489 && current_function_decl)
13491 endname = current_fde ()->dw_fde_end;
13492 range_across_switch = true;
13494 /* The variable has a location between NODE->LABEL and
13495 NODE->NEXT->LABEL. */
13496 else if (node->next)
13497 endname = node->next->label;
13498 /* If the variable has a location at the last label
13499 it keeps its location until the end of function. */
13500 else if (!current_function_decl)
13501 endname = text_end_label;
13504 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13505 current_function_funcdef_no);
13506 endname = ggc_strdup (label_id);
13509 *listp = new_loc_list (descr, node->label, endname, secname);
13510 if (TREE_CODE (decl) == PARM_DECL
13511 && node == loc_list->first
13512 && GET_CODE (node->loc) == NOTE
13513 && strcmp (node->label, endname) == 0)
13514 (*listp)->force = true;
13515 listp = &(*listp)->dw_loc_next;
13517 if (range_across_switch)
13519 if (GET_CODE (node->loc) == EXPR_LIST)
13520 descr = dw_sra_loc_expr (decl, node->loc);
13523 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
13524 varloc = NOTE_VAR_LOCATION (node->loc);
13525 descr = dw_loc_list_1 (decl, varloc, want_address,
13528 gcc_assert (descr);
13529 /* The variable has a location between NODE->LABEL and
13530 NODE->NEXT->LABEL. */
13532 endname = node->next->label;
13534 endname = current_fde ()->dw_fde_second_end;
13535 *listp = new_loc_list (descr,
13536 current_fde ()->dw_fde_second_begin,
13538 listp = &(*listp)->dw_loc_next;
13543 /* Try to avoid the overhead of a location list emitting a location
13544 expression instead, but only if we didn't have more than one
13545 location entry in the first place. If some entries were not
13546 representable, we don't want to pretend a single entry that was
13547 applies to the entire scope in which the variable is
13549 if (list && loc_list->first->next)
13555 /* Return if the loc_list has only single element and thus can be represented
13556 as location description. */
13559 single_element_loc_list_p (dw_loc_list_ref list)
13561 gcc_assert (!list->dw_loc_next || list->ll_symbol);
13562 return !list->ll_symbol;
13565 /* To each location in list LIST add loc descr REF. */
13568 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
13570 dw_loc_descr_ref copy;
13571 add_loc_descr (&list->expr, ref);
13572 list = list->dw_loc_next;
13575 copy = ggc_alloc_dw_loc_descr_node ();
13576 memcpy (copy, ref, sizeof (dw_loc_descr_node));
13577 add_loc_descr (&list->expr, copy);
13578 while (copy->dw_loc_next)
13580 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
13581 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
13582 copy->dw_loc_next = new_copy;
13585 list = list->dw_loc_next;
13589 /* Given two lists RET and LIST
13590 produce location list that is result of adding expression in LIST
13591 to expression in RET on each possition in program.
13592 Might be destructive on both RET and LIST.
13594 TODO: We handle only simple cases of RET or LIST having at most one
13595 element. General case would inolve sorting the lists in program order
13596 and merging them that will need some additional work.
13597 Adding that will improve quality of debug info especially for SRA-ed
13601 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
13610 if (!list->dw_loc_next)
13612 add_loc_descr_to_each (*ret, list->expr);
13615 if (!(*ret)->dw_loc_next)
13617 add_loc_descr_to_each (list, (*ret)->expr);
13621 expansion_failed (NULL_TREE, NULL_RTX,
13622 "Don't know how to merge two non-trivial"
13623 " location lists.\n");
13628 /* LOC is constant expression. Try a luck, look it up in constant
13629 pool and return its loc_descr of its address. */
13631 static dw_loc_descr_ref
13632 cst_pool_loc_descr (tree loc)
13634 /* Get an RTL for this, if something has been emitted. */
13635 rtx rtl = lookup_constant_def (loc);
13637 if (!rtl || !MEM_P (rtl))
13642 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
13644 /* TODO: We might get more coverage if we was actually delaying expansion
13645 of all expressions till end of compilation when constant pools are fully
13647 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
13649 expansion_failed (loc, NULL_RTX,
13650 "CST value in contant pool but not marked.");
13653 return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
13654 GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
13657 /* Return dw_loc_list representing address of addr_expr LOC
13658 by looking for innder INDIRECT_REF expression and turing it
13659 into simple arithmetics. */
13661 static dw_loc_list_ref
13662 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
13665 HOST_WIDE_INT bitsize, bitpos, bytepos;
13666 enum machine_mode mode;
13668 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13669 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13671 obj = get_inner_reference (TREE_OPERAND (loc, 0),
13672 &bitsize, &bitpos, &offset, &mode,
13673 &unsignedp, &volatilep, false);
13675 if (bitpos % BITS_PER_UNIT)
13677 expansion_failed (loc, NULL_RTX, "bitfield access");
13680 if (!INDIRECT_REF_P (obj))
13682 expansion_failed (obj,
13683 NULL_RTX, "no indirect ref in inner refrence");
13686 if (!offset && !bitpos)
13687 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
13689 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
13690 && (dwarf_version >= 4 || !dwarf_strict))
13692 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
13697 /* Variable offset. */
13698 list_ret1 = loc_list_from_tree (offset, 0);
13699 if (list_ret1 == 0)
13701 add_loc_list (&list_ret, list_ret1);
13704 add_loc_descr_to_each (list_ret,
13705 new_loc_descr (DW_OP_plus, 0, 0));
13707 bytepos = bitpos / BITS_PER_UNIT;
13709 add_loc_descr_to_each (list_ret,
13710 new_loc_descr (DW_OP_plus_uconst,
13712 else if (bytepos < 0)
13713 loc_list_plus_const (list_ret, bytepos);
13714 add_loc_descr_to_each (list_ret,
13715 new_loc_descr (DW_OP_stack_value, 0, 0));
13721 /* Generate Dwarf location list representing LOC.
13722 If WANT_ADDRESS is false, expression computing LOC will be computed
13723 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13724 if WANT_ADDRESS is 2, expression computing address useable in location
13725 will be returned (i.e. DW_OP_reg can be used
13726 to refer to register values). */
13728 static dw_loc_list_ref
13729 loc_list_from_tree (tree loc, int want_address)
13731 dw_loc_descr_ref ret = NULL, ret1 = NULL;
13732 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
13733 int have_address = 0;
13734 enum dwarf_location_atom op;
13736 /* ??? Most of the time we do not take proper care for sign/zero
13737 extending the values properly. Hopefully this won't be a real
13740 switch (TREE_CODE (loc))
13743 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
13746 case PLACEHOLDER_EXPR:
13747 /* This case involves extracting fields from an object to determine the
13748 position of other fields. We don't try to encode this here. The
13749 only user of this is Ada, which encodes the needed information using
13750 the names of types. */
13751 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
13755 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
13756 /* There are no opcodes for these operations. */
13759 case PREINCREMENT_EXPR:
13760 case PREDECREMENT_EXPR:
13761 case POSTINCREMENT_EXPR:
13762 case POSTDECREMENT_EXPR:
13763 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
13764 /* There are no opcodes for these operations. */
13768 /* If we already want an address, see if there is INDIRECT_REF inside
13769 e.g. for &this->field. */
13772 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
13773 (loc, want_address == 2);
13776 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
13777 && (ret = cst_pool_loc_descr (loc)))
13780 /* Otherwise, process the argument and look for the address. */
13781 if (!list_ret && !ret)
13782 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
13786 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
13792 if (DECL_THREAD_LOCAL_P (loc))
13795 enum dwarf_location_atom first_op;
13796 enum dwarf_location_atom second_op;
13797 bool dtprel = false;
13799 if (targetm.have_tls)
13801 /* If this is not defined, we have no way to emit the
13803 if (!targetm.asm_out.output_dwarf_dtprel)
13806 /* The way DW_OP_GNU_push_tls_address is specified, we
13807 can only look up addresses of objects in the current
13808 module. We used DW_OP_addr as first op, but that's
13809 wrong, because DW_OP_addr is relocated by the debug
13810 info consumer, while DW_OP_GNU_push_tls_address
13811 operand shouldn't be. */
13812 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
13814 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
13816 second_op = DW_OP_GNU_push_tls_address;
13820 if (!targetm.emutls.debug_form_tls_address
13821 || !(dwarf_version >= 3 || !dwarf_strict))
13823 /* We stuffed the control variable into the DECL_VALUE_EXPR
13824 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13825 no longer appear in gimple code. We used the control
13826 variable in specific so that we could pick it up here. */
13827 loc = DECL_VALUE_EXPR (loc);
13828 first_op = DW_OP_addr;
13829 second_op = DW_OP_form_tls_address;
13832 rtl = rtl_for_decl_location (loc);
13833 if (rtl == NULL_RTX)
13838 rtl = XEXP (rtl, 0);
13839 if (! CONSTANT_P (rtl))
13842 ret = new_loc_descr (first_op, 0, 0);
13843 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13844 ret->dw_loc_oprnd1.v.val_addr = rtl;
13845 ret->dtprel = dtprel;
13847 ret1 = new_loc_descr (second_op, 0, 0);
13848 add_loc_descr (&ret, ret1);
13857 if (DECL_HAS_VALUE_EXPR_P (loc))
13858 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
13862 case FUNCTION_DECL:
13865 var_loc_list *loc_list = lookup_decl_loc (loc);
13867 if (loc_list && loc_list->first)
13869 list_ret = dw_loc_list (loc_list, loc, want_address);
13870 have_address = want_address != 0;
13873 rtl = rtl_for_decl_location (loc);
13874 if (rtl == NULL_RTX)
13876 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
13879 else if (CONST_INT_P (rtl))
13881 HOST_WIDE_INT val = INTVAL (rtl);
13882 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
13883 val &= GET_MODE_MASK (DECL_MODE (loc));
13884 ret = int_loc_descriptor (val);
13886 else if (GET_CODE (rtl) == CONST_STRING)
13888 expansion_failed (loc, NULL_RTX, "CONST_STRING");
13891 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
13893 ret = new_loc_descr (DW_OP_addr, 0, 0);
13894 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
13895 ret->dw_loc_oprnd1.v.val_addr = rtl;
13899 enum machine_mode mode, mem_mode;
13901 /* Certain constructs can only be represented at top-level. */
13902 if (want_address == 2)
13904 ret = loc_descriptor (rtl, VOIDmode,
13905 VAR_INIT_STATUS_INITIALIZED);
13910 mode = GET_MODE (rtl);
13911 mem_mode = VOIDmode;
13915 mode = get_address_mode (rtl);
13916 rtl = XEXP (rtl, 0);
13919 ret = mem_loc_descriptor (rtl, mode, mem_mode,
13920 VAR_INIT_STATUS_INITIALIZED);
13923 expansion_failed (loc, rtl,
13924 "failed to produce loc descriptor for rtl");
13931 if (!integer_zerop (TREE_OPERAND (loc, 1)))
13935 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
13939 case COMPOUND_EXPR:
13940 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
13943 case VIEW_CONVERT_EXPR:
13946 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
13948 case COMPONENT_REF:
13949 case BIT_FIELD_REF:
13951 case ARRAY_RANGE_REF:
13952 case REALPART_EXPR:
13953 case IMAGPART_EXPR:
13956 HOST_WIDE_INT bitsize, bitpos, bytepos;
13957 enum machine_mode mode;
13959 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
13961 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
13962 &unsignedp, &volatilep, false);
13964 gcc_assert (obj != loc);
13966 list_ret = loc_list_from_tree (obj,
13968 && !bitpos && !offset ? 2 : 1);
13969 /* TODO: We can extract value of the small expression via shifting even
13970 for nonzero bitpos. */
13973 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
13975 expansion_failed (loc, NULL_RTX,
13976 "bitfield access");
13980 if (offset != NULL_TREE)
13982 /* Variable offset. */
13983 list_ret1 = loc_list_from_tree (offset, 0);
13984 if (list_ret1 == 0)
13986 add_loc_list (&list_ret, list_ret1);
13989 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
13992 bytepos = bitpos / BITS_PER_UNIT;
13994 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
13995 else if (bytepos < 0)
13996 loc_list_plus_const (list_ret, bytepos);
14003 if ((want_address || !host_integerp (loc, 0))
14004 && (ret = cst_pool_loc_descr (loc)))
14006 else if (want_address == 2
14007 && host_integerp (loc, 0)
14008 && (ret = address_of_int_loc_descriptor
14009 (int_size_in_bytes (TREE_TYPE (loc)),
14010 tree_low_cst (loc, 0))))
14012 else if (host_integerp (loc, 0))
14013 ret = int_loc_descriptor (tree_low_cst (loc, 0));
14016 expansion_failed (loc, NULL_RTX,
14017 "Integer operand is not host integer");
14026 if ((ret = cst_pool_loc_descr (loc)))
14029 /* We can construct small constants here using int_loc_descriptor. */
14030 expansion_failed (loc, NULL_RTX,
14031 "constructor or constant not in constant pool");
14034 case TRUTH_AND_EXPR:
14035 case TRUTH_ANDIF_EXPR:
14040 case TRUTH_XOR_EXPR:
14045 case TRUTH_OR_EXPR:
14046 case TRUTH_ORIF_EXPR:
14051 case FLOOR_DIV_EXPR:
14052 case CEIL_DIV_EXPR:
14053 case ROUND_DIV_EXPR:
14054 case TRUNC_DIV_EXPR:
14055 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
14064 case FLOOR_MOD_EXPR:
14065 case CEIL_MOD_EXPR:
14066 case ROUND_MOD_EXPR:
14067 case TRUNC_MOD_EXPR:
14068 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
14073 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
14074 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
14075 if (list_ret == 0 || list_ret1 == 0)
14078 add_loc_list (&list_ret, list_ret1);
14081 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
14082 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
14083 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
14084 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
14085 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
14097 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
14100 case POINTER_PLUS_EXPR:
14102 if (host_integerp (TREE_OPERAND (loc, 1), 0))
14104 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
14108 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
14116 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14123 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14130 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14137 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
14152 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
14153 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
14154 if (list_ret == 0 || list_ret1 == 0)
14157 add_loc_list (&list_ret, list_ret1);
14160 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
14163 case TRUTH_NOT_EXPR:
14177 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
14181 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
14187 const enum tree_code code =
14188 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
14190 loc = build3 (COND_EXPR, TREE_TYPE (loc),
14191 build2 (code, integer_type_node,
14192 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
14193 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
14196 /* ... fall through ... */
14200 dw_loc_descr_ref lhs
14201 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
14202 dw_loc_list_ref rhs
14203 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
14204 dw_loc_descr_ref bra_node, jump_node, tmp;
14206 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
14207 if (list_ret == 0 || lhs == 0 || rhs == 0)
14210 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14211 add_loc_descr_to_each (list_ret, bra_node);
14213 add_loc_list (&list_ret, rhs);
14214 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
14215 add_loc_descr_to_each (list_ret, jump_node);
14217 add_loc_descr_to_each (list_ret, lhs);
14218 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14219 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
14221 /* ??? Need a node to point the skip at. Use a nop. */
14222 tmp = new_loc_descr (DW_OP_nop, 0, 0);
14223 add_loc_descr_to_each (list_ret, tmp);
14224 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14225 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
14229 case FIX_TRUNC_EXPR:
14233 /* Leave front-end specific codes as simply unknown. This comes
14234 up, for instance, with the C STMT_EXPR. */
14235 if ((unsigned int) TREE_CODE (loc)
14236 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
14238 expansion_failed (loc, NULL_RTX,
14239 "language specific tree node");
14243 #ifdef ENABLE_CHECKING
14244 /* Otherwise this is a generic code; we should just lists all of
14245 these explicitly. We forgot one. */
14246 gcc_unreachable ();
14248 /* In a release build, we want to degrade gracefully: better to
14249 generate incomplete debugging information than to crash. */
14254 if (!ret && !list_ret)
14257 if (want_address == 2 && !have_address
14258 && (dwarf_version >= 4 || !dwarf_strict))
14260 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14262 expansion_failed (loc, NULL_RTX,
14263 "DWARF address size mismatch");
14267 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
14269 add_loc_descr_to_each (list_ret,
14270 new_loc_descr (DW_OP_stack_value, 0, 0));
14273 /* Show if we can't fill the request for an address. */
14274 if (want_address && !have_address)
14276 expansion_failed (loc, NULL_RTX,
14277 "Want address and only have value");
14281 gcc_assert (!ret || !list_ret);
14283 /* If we've got an address and don't want one, dereference. */
14284 if (!want_address && have_address)
14286 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14288 if (size > DWARF2_ADDR_SIZE || size == -1)
14290 expansion_failed (loc, NULL_RTX,
14291 "DWARF address size mismatch");
14294 else if (size == DWARF2_ADDR_SIZE)
14297 op = DW_OP_deref_size;
14300 add_loc_descr (&ret, new_loc_descr (op, size, 0));
14302 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
14305 list_ret = new_loc_list (ret, NULL, NULL, NULL);
14310 /* Same as above but return only single location expression. */
14311 static dw_loc_descr_ref
14312 loc_descriptor_from_tree (tree loc, int want_address)
14314 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
14317 if (ret->dw_loc_next)
14319 expansion_failed (loc, NULL_RTX,
14320 "Location list where only loc descriptor needed");
14326 /* Given a value, round it up to the lowest multiple of `boundary'
14327 which is not less than the value itself. */
14329 static inline HOST_WIDE_INT
14330 ceiling (HOST_WIDE_INT value, unsigned int boundary)
14332 return (((value + boundary - 1) / boundary) * boundary);
14335 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14336 pointer to the declared type for the relevant field variable, or return
14337 `integer_type_node' if the given node turns out to be an
14338 ERROR_MARK node. */
14341 field_type (const_tree decl)
14345 if (TREE_CODE (decl) == ERROR_MARK)
14346 return integer_type_node;
14348 type = DECL_BIT_FIELD_TYPE (decl);
14349 if (type == NULL_TREE)
14350 type = TREE_TYPE (decl);
14355 /* Given a pointer to a tree node, return the alignment in bits for
14356 it, or else return BITS_PER_WORD if the node actually turns out to
14357 be an ERROR_MARK node. */
14359 static inline unsigned
14360 simple_type_align_in_bits (const_tree type)
14362 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
14365 static inline unsigned
14366 simple_decl_align_in_bits (const_tree decl)
14368 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
14371 /* Return the result of rounding T up to ALIGN. */
14373 static inline double_int
14374 round_up_to_align (double_int t, unsigned int align)
14376 double_int alignd = uhwi_to_double_int (align);
14377 t = double_int_add (t, alignd);
14378 t = double_int_add (t, double_int_minus_one);
14379 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
14380 t = double_int_mul (t, alignd);
14384 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14385 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14386 or return 0 if we are unable to determine what that offset is, either
14387 because the argument turns out to be a pointer to an ERROR_MARK node, or
14388 because the offset is actually variable. (We can't handle the latter case
14391 static HOST_WIDE_INT
14392 field_byte_offset (const_tree decl)
14394 double_int object_offset_in_bits;
14395 double_int object_offset_in_bytes;
14396 double_int bitpos_int;
14398 if (TREE_CODE (decl) == ERROR_MARK)
14401 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
14403 /* We cannot yet cope with fields whose positions are variable, so
14404 for now, when we see such things, we simply return 0. Someday, we may
14405 be able to handle such cases, but it will be damn difficult. */
14406 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
14409 bitpos_int = tree_to_double_int (bit_position (decl));
14411 #ifdef PCC_BITFIELD_TYPE_MATTERS
14412 if (PCC_BITFIELD_TYPE_MATTERS)
14415 tree field_size_tree;
14416 double_int deepest_bitpos;
14417 double_int field_size_in_bits;
14418 unsigned int type_align_in_bits;
14419 unsigned int decl_align_in_bits;
14420 double_int type_size_in_bits;
14422 type = field_type (decl);
14423 type_size_in_bits = double_int_type_size_in_bits (type);
14424 type_align_in_bits = simple_type_align_in_bits (type);
14426 field_size_tree = DECL_SIZE (decl);
14428 /* The size could be unspecified if there was an error, or for
14429 a flexible array member. */
14430 if (!field_size_tree)
14431 field_size_tree = bitsize_zero_node;
14433 /* If the size of the field is not constant, use the type size. */
14434 if (TREE_CODE (field_size_tree) == INTEGER_CST)
14435 field_size_in_bits = tree_to_double_int (field_size_tree);
14437 field_size_in_bits = type_size_in_bits;
14439 decl_align_in_bits = simple_decl_align_in_bits (decl);
14441 /* The GCC front-end doesn't make any attempt to keep track of the
14442 starting bit offset (relative to the start of the containing
14443 structure type) of the hypothetical "containing object" for a
14444 bit-field. Thus, when computing the byte offset value for the
14445 start of the "containing object" of a bit-field, we must deduce
14446 this information on our own. This can be rather tricky to do in
14447 some cases. For example, handling the following structure type
14448 definition when compiling for an i386/i486 target (which only
14449 aligns long long's to 32-bit boundaries) can be very tricky:
14451 struct S { int field1; long long field2:31; };
14453 Fortunately, there is a simple rule-of-thumb which can be used
14454 in such cases. When compiling for an i386/i486, GCC will
14455 allocate 8 bytes for the structure shown above. It decides to
14456 do this based upon one simple rule for bit-field allocation.
14457 GCC allocates each "containing object" for each bit-field at
14458 the first (i.e. lowest addressed) legitimate alignment boundary
14459 (based upon the required minimum alignment for the declared
14460 type of the field) which it can possibly use, subject to the
14461 condition that there is still enough available space remaining
14462 in the containing object (when allocated at the selected point)
14463 to fully accommodate all of the bits of the bit-field itself.
14465 This simple rule makes it obvious why GCC allocates 8 bytes for
14466 each object of the structure type shown above. When looking
14467 for a place to allocate the "containing object" for `field2',
14468 the compiler simply tries to allocate a 64-bit "containing
14469 object" at each successive 32-bit boundary (starting at zero)
14470 until it finds a place to allocate that 64- bit field such that
14471 at least 31 contiguous (and previously unallocated) bits remain
14472 within that selected 64 bit field. (As it turns out, for the
14473 example above, the compiler finds it is OK to allocate the
14474 "containing object" 64-bit field at bit-offset zero within the
14477 Here we attempt to work backwards from the limited set of facts
14478 we're given, and we try to deduce from those facts, where GCC
14479 must have believed that the containing object started (within
14480 the structure type). The value we deduce is then used (by the
14481 callers of this routine) to generate DW_AT_location and
14482 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14483 the case of DW_AT_location, regular fields as well). */
14485 /* Figure out the bit-distance from the start of the structure to
14486 the "deepest" bit of the bit-field. */
14487 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
14489 /* This is the tricky part. Use some fancy footwork to deduce
14490 where the lowest addressed bit of the containing object must
14492 object_offset_in_bits
14493 = double_int_sub (deepest_bitpos, type_size_in_bits);
14495 /* Round up to type_align by default. This works best for
14497 object_offset_in_bits
14498 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
14500 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
14502 object_offset_in_bits
14503 = double_int_sub (deepest_bitpos, type_size_in_bits);
14505 /* Round up to decl_align instead. */
14506 object_offset_in_bits
14507 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
14511 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14512 object_offset_in_bits = bitpos_int;
14514 object_offset_in_bytes
14515 = double_int_div (object_offset_in_bits,
14516 uhwi_to_double_int (BITS_PER_UNIT), true,
14518 return double_int_to_shwi (object_offset_in_bytes);
14521 /* The following routines define various Dwarf attributes and any data
14522 associated with them. */
14524 /* Add a location description attribute value to a DIE.
14526 This emits location attributes suitable for whole variables and
14527 whole parameters. Note that the location attributes for struct fields are
14528 generated by the routine `data_member_location_attribute' below. */
14531 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
14532 dw_loc_list_ref descr)
14536 if (single_element_loc_list_p (descr))
14537 add_AT_loc (die, attr_kind, descr->expr);
14539 add_AT_loc_list (die, attr_kind, descr);
14542 /* Add DW_AT_accessibility attribute to DIE if needed. */
14545 add_accessibility_attribute (dw_die_ref die, tree decl)
14547 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14548 children, otherwise the default is DW_ACCESS_public. In DWARF2
14549 the default has always been DW_ACCESS_public. */
14550 if (TREE_PROTECTED (decl))
14551 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14552 else if (TREE_PRIVATE (decl))
14554 if (dwarf_version == 2
14555 || die->die_parent == NULL
14556 || die->die_parent->die_tag != DW_TAG_class_type)
14557 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
14559 else if (dwarf_version > 2
14561 && die->die_parent->die_tag == DW_TAG_class_type)
14562 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14565 /* Attach the specialized form of location attribute used for data members of
14566 struct and union types. In the special case of a FIELD_DECL node which
14567 represents a bit-field, the "offset" part of this special location
14568 descriptor must indicate the distance in bytes from the lowest-addressed
14569 byte of the containing struct or union type to the lowest-addressed byte of
14570 the "containing object" for the bit-field. (See the `field_byte_offset'
14573 For any given bit-field, the "containing object" is a hypothetical object
14574 (of some integral or enum type) within which the given bit-field lives. The
14575 type of this hypothetical "containing object" is always the same as the
14576 declared type of the individual bit-field itself (for GCC anyway... the
14577 DWARF spec doesn't actually mandate this). Note that it is the size (in
14578 bytes) of the hypothetical "containing object" which will be given in the
14579 DW_AT_byte_size attribute for this bit-field. (See the
14580 `byte_size_attribute' function below.) It is also used when calculating the
14581 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14582 function below.) */
14585 add_data_member_location_attribute (dw_die_ref die, tree decl)
14587 HOST_WIDE_INT offset;
14588 dw_loc_descr_ref loc_descr = 0;
14590 if (TREE_CODE (decl) == TREE_BINFO)
14592 /* We're working on the TAG_inheritance for a base class. */
14593 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
14595 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14596 aren't at a fixed offset from all (sub)objects of the same
14597 type. We need to extract the appropriate offset from our
14598 vtable. The following dwarf expression means
14600 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14602 This is specific to the V3 ABI, of course. */
14604 dw_loc_descr_ref tmp;
14606 /* Make a copy of the object address. */
14607 tmp = new_loc_descr (DW_OP_dup, 0, 0);
14608 add_loc_descr (&loc_descr, tmp);
14610 /* Extract the vtable address. */
14611 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14612 add_loc_descr (&loc_descr, tmp);
14614 /* Calculate the address of the offset. */
14615 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
14616 gcc_assert (offset < 0);
14618 tmp = int_loc_descriptor (-offset);
14619 add_loc_descr (&loc_descr, tmp);
14620 tmp = new_loc_descr (DW_OP_minus, 0, 0);
14621 add_loc_descr (&loc_descr, tmp);
14623 /* Extract the offset. */
14624 tmp = new_loc_descr (DW_OP_deref, 0, 0);
14625 add_loc_descr (&loc_descr, tmp);
14627 /* Add it to the object address. */
14628 tmp = new_loc_descr (DW_OP_plus, 0, 0);
14629 add_loc_descr (&loc_descr, tmp);
14632 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
14635 offset = field_byte_offset (decl);
14639 if (dwarf_version > 2)
14641 /* Don't need to output a location expression, just the constant. */
14643 add_AT_int (die, DW_AT_data_member_location, offset);
14645 add_AT_unsigned (die, DW_AT_data_member_location, offset);
14650 enum dwarf_location_atom op;
14652 /* The DWARF2 standard says that we should assume that the structure
14653 address is already on the stack, so we can specify a structure
14654 field address by using DW_OP_plus_uconst. */
14656 #ifdef MIPS_DEBUGGING_INFO
14657 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
14658 operator correctly. It works only if we leave the offset on the
14662 op = DW_OP_plus_uconst;
14665 loc_descr = new_loc_descr (op, offset, 0);
14669 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
14672 /* Writes integer values to dw_vec_const array. */
14675 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
14679 *dest++ = val & 0xff;
14685 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14687 static HOST_WIDE_INT
14688 extract_int (const unsigned char *src, unsigned int size)
14690 HOST_WIDE_INT val = 0;
14696 val |= *--src & 0xff;
14702 /* Writes double_int values to dw_vec_const array. */
14705 insert_double (double_int val, unsigned char *dest)
14707 unsigned char *p0 = dest;
14708 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
14710 if (WORDS_BIG_ENDIAN)
14716 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
14717 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
14720 /* Writes floating point values to dw_vec_const array. */
14723 insert_float (const_rtx rtl, unsigned char *array)
14725 REAL_VALUE_TYPE rv;
14729 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
14730 real_to_target (val, &rv, GET_MODE (rtl));
14732 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14733 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
14735 insert_int (val[i], 4, array);
14740 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14741 does not have a "location" either in memory or in a register. These
14742 things can arise in GNU C when a constant is passed as an actual parameter
14743 to an inlined function. They can also arise in C++ where declared
14744 constants do not necessarily get memory "homes". */
14747 add_const_value_attribute (dw_die_ref die, rtx rtl)
14749 switch (GET_CODE (rtl))
14753 HOST_WIDE_INT val = INTVAL (rtl);
14756 add_AT_int (die, DW_AT_const_value, val);
14758 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
14763 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14764 floating-point constant. A CONST_DOUBLE is used whenever the
14765 constant requires more than one word in order to be adequately
14768 enum machine_mode mode = GET_MODE (rtl);
14770 if (SCALAR_FLOAT_MODE_P (mode))
14772 unsigned int length = GET_MODE_SIZE (mode);
14773 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
14775 insert_float (rtl, array);
14776 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
14779 add_AT_double (die, DW_AT_const_value,
14780 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
14786 enum machine_mode mode = GET_MODE (rtl);
14787 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
14788 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14789 unsigned char *array = (unsigned char *) ggc_alloc_atomic
14790 (length * elt_size);
14794 switch (GET_MODE_CLASS (mode))
14796 case MODE_VECTOR_INT:
14797 for (i = 0, p = array; i < length; i++, p += elt_size)
14799 rtx elt = CONST_VECTOR_ELT (rtl, i);
14800 double_int val = rtx_to_double_int (elt);
14802 if (elt_size <= sizeof (HOST_WIDE_INT))
14803 insert_int (double_int_to_shwi (val), elt_size, p);
14806 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14807 insert_double (val, p);
14812 case MODE_VECTOR_FLOAT:
14813 for (i = 0, p = array; i < length; i++, p += elt_size)
14815 rtx elt = CONST_VECTOR_ELT (rtl, i);
14816 insert_float (elt, p);
14821 gcc_unreachable ();
14824 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
14829 if (dwarf_version >= 4 || !dwarf_strict)
14831 dw_loc_descr_ref loc_result;
14832 resolve_one_addr (&rtl, NULL);
14834 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14835 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14836 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14837 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14838 add_AT_loc (die, DW_AT_location, loc_result);
14839 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14845 if (CONSTANT_P (XEXP (rtl, 0)))
14846 return add_const_value_attribute (die, XEXP (rtl, 0));
14849 if (!const_ok_for_output (rtl))
14852 if (dwarf_version >= 4 || !dwarf_strict)
14857 /* In cases where an inlined instance of an inline function is passed
14858 the address of an `auto' variable (which is local to the caller) we
14859 can get a situation where the DECL_RTL of the artificial local
14860 variable (for the inlining) which acts as a stand-in for the
14861 corresponding formal parameter (of the inline function) will look
14862 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14863 exactly a compile-time constant expression, but it isn't the address
14864 of the (artificial) local variable either. Rather, it represents the
14865 *value* which the artificial local variable always has during its
14866 lifetime. We currently have no way to represent such quasi-constant
14867 values in Dwarf, so for now we just punt and generate nothing. */
14875 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
14876 && MEM_READONLY_P (rtl)
14877 && GET_MODE (rtl) == BLKmode)
14879 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
14885 /* No other kinds of rtx should be possible here. */
14886 gcc_unreachable ();
14891 /* Determine whether the evaluation of EXPR references any variables
14892 or functions which aren't otherwise used (and therefore may not be
14895 reference_to_unused (tree * tp, int * walk_subtrees,
14896 void * data ATTRIBUTE_UNUSED)
14898 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
14899 *walk_subtrees = 0;
14901 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
14902 && ! TREE_ASM_WRITTEN (*tp))
14904 /* ??? The C++ FE emits debug information for using decls, so
14905 putting gcc_unreachable here falls over. See PR31899. For now
14906 be conservative. */
14907 else if (!cgraph_global_info_ready
14908 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
14910 else if (TREE_CODE (*tp) == VAR_DECL)
14912 struct varpool_node *node = varpool_get_node (*tp);
14913 if (!node || !node->needed)
14916 else if (TREE_CODE (*tp) == FUNCTION_DECL
14917 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
14919 /* The call graph machinery must have finished analyzing,
14920 optimizing and gimplifying the CU by now.
14921 So if *TP has no call graph node associated
14922 to it, it means *TP will not be emitted. */
14923 if (!cgraph_get_node (*tp))
14926 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
14932 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14933 for use in a later add_const_value_attribute call. */
14936 rtl_for_decl_init (tree init, tree type)
14938 rtx rtl = NULL_RTX;
14942 /* If a variable is initialized with a string constant without embedded
14943 zeros, build CONST_STRING. */
14944 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
14946 tree enttype = TREE_TYPE (type);
14947 tree domain = TYPE_DOMAIN (type);
14948 enum machine_mode mode = TYPE_MODE (enttype);
14950 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
14952 && integer_zerop (TYPE_MIN_VALUE (domain))
14953 && compare_tree_int (TYPE_MAX_VALUE (domain),
14954 TREE_STRING_LENGTH (init) - 1) == 0
14955 && ((size_t) TREE_STRING_LENGTH (init)
14956 == strlen (TREE_STRING_POINTER (init)) + 1))
14958 rtl = gen_rtx_CONST_STRING (VOIDmode,
14959 ggc_strdup (TREE_STRING_POINTER (init)));
14960 rtl = gen_rtx_MEM (BLKmode, rtl);
14961 MEM_READONLY_P (rtl) = 1;
14964 /* Other aggregates, and complex values, could be represented using
14966 else if (AGGREGATE_TYPE_P (type)
14967 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
14968 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
14969 || TREE_CODE (type) == COMPLEX_TYPE)
14971 /* Vectors only work if their mode is supported by the target.
14972 FIXME: generic vectors ought to work too. */
14973 else if (TREE_CODE (type) == VECTOR_TYPE
14974 && !VECTOR_MODE_P (TYPE_MODE (type)))
14976 /* If the initializer is something that we know will expand into an
14977 immediate RTL constant, expand it now. We must be careful not to
14978 reference variables which won't be output. */
14979 else if (initializer_constant_valid_p (init, type)
14980 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
14982 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14984 if (TREE_CODE (type) == VECTOR_TYPE)
14985 switch (TREE_CODE (init))
14990 if (TREE_CONSTANT (init))
14992 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
14993 bool constant_p = true;
14995 unsigned HOST_WIDE_INT ix;
14997 /* Even when ctor is constant, it might contain non-*_CST
14998 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14999 belong into VECTOR_CST nodes. */
15000 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
15001 if (!CONSTANT_CLASS_P (value))
15003 constant_p = false;
15009 init = build_vector_from_ctor (type, elts);
15019 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
15021 /* If expand_expr returns a MEM, it wasn't immediate. */
15022 gcc_assert (!rtl || !MEM_P (rtl));
15028 /* Generate RTL for the variable DECL to represent its location. */
15031 rtl_for_decl_location (tree decl)
15035 /* Here we have to decide where we are going to say the parameter "lives"
15036 (as far as the debugger is concerned). We only have a couple of
15037 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15039 DECL_RTL normally indicates where the parameter lives during most of the
15040 activation of the function. If optimization is enabled however, this
15041 could be either NULL or else a pseudo-reg. Both of those cases indicate
15042 that the parameter doesn't really live anywhere (as far as the code
15043 generation parts of GCC are concerned) during most of the function's
15044 activation. That will happen (for example) if the parameter is never
15045 referenced within the function.
15047 We could just generate a location descriptor here for all non-NULL
15048 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15049 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15050 where DECL_RTL is NULL or is a pseudo-reg.
15052 Note however that we can only get away with using DECL_INCOMING_RTL as
15053 a backup substitute for DECL_RTL in certain limited cases. In cases
15054 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15055 we can be sure that the parameter was passed using the same type as it is
15056 declared to have within the function, and that its DECL_INCOMING_RTL
15057 points us to a place where a value of that type is passed.
15059 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15060 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15061 because in these cases DECL_INCOMING_RTL points us to a value of some
15062 type which is *different* from the type of the parameter itself. Thus,
15063 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15064 such cases, the debugger would end up (for example) trying to fetch a
15065 `float' from a place which actually contains the first part of a
15066 `double'. That would lead to really incorrect and confusing
15067 output at debug-time.
15069 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15070 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15071 are a couple of exceptions however. On little-endian machines we can
15072 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15073 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15074 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15075 when (on a little-endian machine) a non-prototyped function has a
15076 parameter declared to be of type `short' or `char'. In such cases,
15077 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15078 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15079 passed `int' value. If the debugger then uses that address to fetch
15080 a `short' or a `char' (on a little-endian machine) the result will be
15081 the correct data, so we allow for such exceptional cases below.
15083 Note that our goal here is to describe the place where the given formal
15084 parameter lives during most of the function's activation (i.e. between the
15085 end of the prologue and the start of the epilogue). We'll do that as best
15086 as we can. Note however that if the given formal parameter is modified
15087 sometime during the execution of the function, then a stack backtrace (at
15088 debug-time) will show the function as having been called with the *new*
15089 value rather than the value which was originally passed in. This happens
15090 rarely enough that it is not a major problem, but it *is* a problem, and
15091 I'd like to fix it.
15093 A future version of dwarf2out.c may generate two additional attributes for
15094 any given DW_TAG_formal_parameter DIE which will describe the "passed
15095 type" and the "passed location" for the given formal parameter in addition
15096 to the attributes we now generate to indicate the "declared type" and the
15097 "active location" for each parameter. This additional set of attributes
15098 could be used by debuggers for stack backtraces. Separately, note that
15099 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15100 This happens (for example) for inlined-instances of inline function formal
15101 parameters which are never referenced. This really shouldn't be
15102 happening. All PARM_DECL nodes should get valid non-NULL
15103 DECL_INCOMING_RTL values. FIXME. */
15105 /* Use DECL_RTL as the "location" unless we find something better. */
15106 rtl = DECL_RTL_IF_SET (decl);
15108 /* When generating abstract instances, ignore everything except
15109 constants, symbols living in memory, and symbols living in
15110 fixed registers. */
15111 if (! reload_completed)
15114 && (CONSTANT_P (rtl)
15116 && CONSTANT_P (XEXP (rtl, 0)))
15118 && TREE_CODE (decl) == VAR_DECL
15119 && TREE_STATIC (decl))))
15121 rtl = targetm.delegitimize_address (rtl);
15126 else if (TREE_CODE (decl) == PARM_DECL)
15128 if (rtl == NULL_RTX
15129 || is_pseudo_reg (rtl)
15131 && is_pseudo_reg (XEXP (rtl, 0))
15132 && DECL_INCOMING_RTL (decl)
15133 && MEM_P (DECL_INCOMING_RTL (decl))
15134 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
15136 tree declared_type = TREE_TYPE (decl);
15137 tree passed_type = DECL_ARG_TYPE (decl);
15138 enum machine_mode dmode = TYPE_MODE (declared_type);
15139 enum machine_mode pmode = TYPE_MODE (passed_type);
15141 /* This decl represents a formal parameter which was optimized out.
15142 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15143 all cases where (rtl == NULL_RTX) just below. */
15144 if (dmode == pmode)
15145 rtl = DECL_INCOMING_RTL (decl);
15146 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
15147 && SCALAR_INT_MODE_P (dmode)
15148 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
15149 && DECL_INCOMING_RTL (decl))
15151 rtx inc = DECL_INCOMING_RTL (decl);
15154 else if (MEM_P (inc))
15156 if (BYTES_BIG_ENDIAN)
15157 rtl = adjust_address_nv (inc, dmode,
15158 GET_MODE_SIZE (pmode)
15159 - GET_MODE_SIZE (dmode));
15166 /* If the parm was passed in registers, but lives on the stack, then
15167 make a big endian correction if the mode of the type of the
15168 parameter is not the same as the mode of the rtl. */
15169 /* ??? This is the same series of checks that are made in dbxout.c before
15170 we reach the big endian correction code there. It isn't clear if all
15171 of these checks are necessary here, but keeping them all is the safe
15173 else if (MEM_P (rtl)
15174 && XEXP (rtl, 0) != const0_rtx
15175 && ! CONSTANT_P (XEXP (rtl, 0))
15176 /* Not passed in memory. */
15177 && !MEM_P (DECL_INCOMING_RTL (decl))
15178 /* Not passed by invisible reference. */
15179 && (!REG_P (XEXP (rtl, 0))
15180 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
15181 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
15182 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15183 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
15186 /* Big endian correction check. */
15187 && BYTES_BIG_ENDIAN
15188 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
15189 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
15192 int offset = (UNITS_PER_WORD
15193 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
15195 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
15196 plus_constant (XEXP (rtl, 0), offset));
15199 else if (TREE_CODE (decl) == VAR_DECL
15202 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
15203 && BYTES_BIG_ENDIAN)
15205 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
15206 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
15208 /* If a variable is declared "register" yet is smaller than
15209 a register, then if we store the variable to memory, it
15210 looks like we're storing a register-sized value, when in
15211 fact we are not. We need to adjust the offset of the
15212 storage location to reflect the actual value's bytes,
15213 else gdb will not be able to display it. */
15215 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
15216 plus_constant (XEXP (rtl, 0), rsize-dsize));
15219 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15220 and will have been substituted directly into all expressions that use it.
15221 C does not have such a concept, but C++ and other languages do. */
15222 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
15223 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
15226 rtl = targetm.delegitimize_address (rtl);
15228 /* If we don't look past the constant pool, we risk emitting a
15229 reference to a constant pool entry that isn't referenced from
15230 code, and thus is not emitted. */
15232 rtl = avoid_constant_pool_reference (rtl);
15234 /* Try harder to get a rtl. If this symbol ends up not being emitted
15235 in the current CU, resolve_addr will remove the expression referencing
15237 if (rtl == NULL_RTX
15238 && TREE_CODE (decl) == VAR_DECL
15239 && !DECL_EXTERNAL (decl)
15240 && TREE_STATIC (decl)
15241 && DECL_NAME (decl)
15242 && !DECL_HARD_REGISTER (decl)
15243 && DECL_MODE (decl) != VOIDmode)
15245 rtl = make_decl_rtl_for_debug (decl);
15247 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
15248 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
15255 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15256 returned. If so, the decl for the COMMON block is returned, and the
15257 value is the offset into the common block for the symbol. */
15260 fortran_common (tree decl, HOST_WIDE_INT *value)
15262 tree val_expr, cvar;
15263 enum machine_mode mode;
15264 HOST_WIDE_INT bitsize, bitpos;
15266 int volatilep = 0, unsignedp = 0;
15268 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15269 it does not have a value (the offset into the common area), or if it
15270 is thread local (as opposed to global) then it isn't common, and shouldn't
15271 be handled as such. */
15272 if (TREE_CODE (decl) != VAR_DECL
15273 || !TREE_STATIC (decl)
15274 || !DECL_HAS_VALUE_EXPR_P (decl)
15278 val_expr = DECL_VALUE_EXPR (decl);
15279 if (TREE_CODE (val_expr) != COMPONENT_REF)
15282 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
15283 &mode, &unsignedp, &volatilep, true);
15285 if (cvar == NULL_TREE
15286 || TREE_CODE (cvar) != VAR_DECL
15287 || DECL_ARTIFICIAL (cvar)
15288 || !TREE_PUBLIC (cvar))
15292 if (offset != NULL)
15294 if (!host_integerp (offset, 0))
15296 *value = tree_low_cst (offset, 0);
15299 *value += bitpos / BITS_PER_UNIT;
15304 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15305 data attribute for a variable or a parameter. We generate the
15306 DW_AT_const_value attribute only in those cases where the given variable
15307 or parameter does not have a true "location" either in memory or in a
15308 register. This can happen (for example) when a constant is passed as an
15309 actual argument in a call to an inline function. (It's possible that
15310 these things can crop up in other ways also.) Note that one type of
15311 constant value which can be passed into an inlined function is a constant
15312 pointer. This can happen for example if an actual argument in an inlined
15313 function call evaluates to a compile-time constant address.
15315 CACHE_P is true if it is worth caching the location list for DECL,
15316 so that future calls can reuse it rather than regenerate it from scratch.
15317 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15318 since we will need to refer to them each time the function is inlined. */
15321 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
15322 enum dwarf_attribute attr)
15325 dw_loc_list_ref list;
15326 var_loc_list *loc_list;
15327 cached_dw_loc_list *cache;
15330 if (TREE_CODE (decl) == ERROR_MARK)
15333 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
15334 || TREE_CODE (decl) == RESULT_DECL);
15336 /* Try to get some constant RTL for this decl, and use that as the value of
15339 rtl = rtl_for_decl_location (decl);
15340 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
15341 && add_const_value_attribute (die, rtl))
15344 /* See if we have single element location list that is equivalent to
15345 a constant value. That way we are better to use add_const_value_attribute
15346 rather than expanding constant value equivalent. */
15347 loc_list = lookup_decl_loc (decl);
15350 && loc_list->first->next == NULL
15351 && NOTE_P (loc_list->first->loc)
15352 && NOTE_VAR_LOCATION (loc_list->first->loc)
15353 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
15355 struct var_loc_node *node;
15357 node = loc_list->first;
15358 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
15359 if (GET_CODE (rtl) == EXPR_LIST)
15360 rtl = XEXP (rtl, 0);
15361 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
15362 && add_const_value_attribute (die, rtl))
15365 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15366 list several times. See if we've already cached the contents. */
15368 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
15372 cache = (cached_dw_loc_list *)
15373 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
15375 list = cache->loc_list;
15379 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
15380 /* It is usually worth caching this result if the decl is from
15381 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15382 if (cache_p && list && list->dw_loc_next)
15384 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
15385 DECL_UID (decl), INSERT);
15386 cache = ggc_alloc_cleared_cached_dw_loc_list ();
15387 cache->decl_id = DECL_UID (decl);
15388 cache->loc_list = list;
15394 add_AT_location_description (die, attr, list);
15397 /* None of that worked, so it must not really have a location;
15398 try adding a constant value attribute from the DECL_INITIAL. */
15399 return tree_add_const_value_attribute_for_decl (die, decl);
15402 /* Add VARIABLE and DIE into deferred locations list. */
15405 defer_location (tree variable, dw_die_ref die)
15407 deferred_locations entry;
15408 entry.variable = variable;
15410 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
15413 /* Helper function for tree_add_const_value_attribute. Natively encode
15414 initializer INIT into an array. Return true if successful. */
15417 native_encode_initializer (tree init, unsigned char *array, int size)
15421 if (init == NULL_TREE)
15425 switch (TREE_CODE (init))
15428 type = TREE_TYPE (init);
15429 if (TREE_CODE (type) == ARRAY_TYPE)
15431 tree enttype = TREE_TYPE (type);
15432 enum machine_mode mode = TYPE_MODE (enttype);
15434 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
15436 if (int_size_in_bytes (type) != size)
15438 if (size > TREE_STRING_LENGTH (init))
15440 memcpy (array, TREE_STRING_POINTER (init),
15441 TREE_STRING_LENGTH (init));
15442 memset (array + TREE_STRING_LENGTH (init),
15443 '\0', size - TREE_STRING_LENGTH (init));
15446 memcpy (array, TREE_STRING_POINTER (init), size);
15451 type = TREE_TYPE (init);
15452 if (int_size_in_bytes (type) != size)
15454 if (TREE_CODE (type) == ARRAY_TYPE)
15456 HOST_WIDE_INT min_index;
15457 unsigned HOST_WIDE_INT cnt;
15458 int curpos = 0, fieldsize;
15459 constructor_elt *ce;
15461 if (TYPE_DOMAIN (type) == NULL_TREE
15462 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
15465 fieldsize = int_size_in_bytes (TREE_TYPE (type));
15466 if (fieldsize <= 0)
15469 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
15470 memset (array, '\0', size);
15471 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
15473 tree val = ce->value;
15474 tree index = ce->index;
15476 if (index && TREE_CODE (index) == RANGE_EXPR)
15477 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
15480 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
15485 if (!native_encode_initializer (val, array + pos, fieldsize))
15488 curpos = pos + fieldsize;
15489 if (index && TREE_CODE (index) == RANGE_EXPR)
15491 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
15492 - tree_low_cst (TREE_OPERAND (index, 0), 0);
15493 while (count-- > 0)
15496 memcpy (array + curpos, array + pos, fieldsize);
15497 curpos += fieldsize;
15500 gcc_assert (curpos <= size);
15504 else if (TREE_CODE (type) == RECORD_TYPE
15505 || TREE_CODE (type) == UNION_TYPE)
15507 tree field = NULL_TREE;
15508 unsigned HOST_WIDE_INT cnt;
15509 constructor_elt *ce;
15511 if (int_size_in_bytes (type) != size)
15514 if (TREE_CODE (type) == RECORD_TYPE)
15515 field = TYPE_FIELDS (type);
15517 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
15519 tree val = ce->value;
15520 int pos, fieldsize;
15522 if (ce->index != 0)
15528 if (field == NULL_TREE || DECL_BIT_FIELD (field))
15531 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
15532 && TYPE_DOMAIN (TREE_TYPE (field))
15533 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
15535 else if (DECL_SIZE_UNIT (field) == NULL_TREE
15536 || !host_integerp (DECL_SIZE_UNIT (field), 0))
15538 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
15539 pos = int_byte_position (field);
15540 gcc_assert (pos + fieldsize <= size);
15542 && !native_encode_initializer (val, array + pos, fieldsize))
15548 case VIEW_CONVERT_EXPR:
15549 case NON_LVALUE_EXPR:
15550 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
15552 return native_encode_expr (init, array, size) == size;
15556 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15557 attribute is the const value T. */
15560 tree_add_const_value_attribute (dw_die_ref die, tree t)
15563 tree type = TREE_TYPE (t);
15566 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
15570 gcc_assert (!DECL_P (init));
15572 rtl = rtl_for_decl_init (init, type);
15574 return add_const_value_attribute (die, rtl);
15575 /* If the host and target are sane, try harder. */
15576 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
15577 && initializer_constant_valid_p (init, type))
15579 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
15580 if (size > 0 && (int) size == size)
15582 unsigned char *array = (unsigned char *)
15583 ggc_alloc_cleared_atomic (size);
15585 if (native_encode_initializer (init, array, size))
15587 add_AT_vec (die, DW_AT_const_value, size, 1, array);
15595 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15596 attribute is the const value of T, where T is an integral constant
15597 variable with static storage duration
15598 (so it can't be a PARM_DECL or a RESULT_DECL). */
15601 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
15605 || (TREE_CODE (decl) != VAR_DECL
15606 && TREE_CODE (decl) != CONST_DECL)
15607 || (TREE_CODE (decl) == VAR_DECL
15608 && !TREE_STATIC (decl)))
15611 if (TREE_READONLY (decl)
15612 && ! TREE_THIS_VOLATILE (decl)
15613 && DECL_INITIAL (decl))
15618 /* Don't add DW_AT_const_value if abstract origin already has one. */
15619 if (get_AT (var_die, DW_AT_const_value))
15622 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
15625 /* Convert the CFI instructions for the current function into a
15626 location list. This is used for DW_AT_frame_base when we targeting
15627 a dwarf2 consumer that does not support the dwarf3
15628 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15631 static dw_loc_list_ref
15632 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
15636 dw_loc_list_ref list, *list_tail;
15638 dw_cfa_location last_cfa, next_cfa;
15639 const char *start_label, *last_label, *section;
15640 dw_cfa_location remember;
15642 fde = current_fde ();
15643 gcc_assert (fde != NULL);
15645 section = secname_for_decl (current_function_decl);
15649 memset (&next_cfa, 0, sizeof (next_cfa));
15650 next_cfa.reg = INVALID_REGNUM;
15651 remember = next_cfa;
15653 start_label = fde->dw_fde_begin;
15655 /* ??? Bald assumption that the CIE opcode list does not contain
15656 advance opcodes. */
15657 FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
15658 lookup_cfa_1 (cfi, &next_cfa, &remember);
15660 last_cfa = next_cfa;
15661 last_label = start_label;
15663 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
15665 /* If the first partition contained no CFI adjustments, the
15666 CIE opcodes apply to the whole first partition. */
15667 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15668 fde->dw_fde_begin, fde->dw_fde_end, section);
15669 list_tail =&(*list_tail)->dw_loc_next;
15670 start_label = last_label = fde->dw_fde_second_begin;
15673 FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
15675 switch (cfi->dw_cfi_opc)
15677 case DW_CFA_set_loc:
15678 case DW_CFA_advance_loc1:
15679 case DW_CFA_advance_loc2:
15680 case DW_CFA_advance_loc4:
15681 if (!cfa_equal_p (&last_cfa, &next_cfa))
15683 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15684 start_label, last_label, section);
15686 list_tail = &(*list_tail)->dw_loc_next;
15687 last_cfa = next_cfa;
15688 start_label = last_label;
15690 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
15693 case DW_CFA_advance_loc:
15694 /* The encoding is complex enough that we should never emit this. */
15695 gcc_unreachable ();
15698 lookup_cfa_1 (cfi, &next_cfa, &remember);
15701 if (ix + 1 == fde->dw_fde_switch_cfi_index)
15703 if (!cfa_equal_p (&last_cfa, &next_cfa))
15705 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15706 start_label, last_label, section);
15708 list_tail = &(*list_tail)->dw_loc_next;
15709 last_cfa = next_cfa;
15710 start_label = last_label;
15712 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15713 start_label, fde->dw_fde_end, section);
15714 list_tail = &(*list_tail)->dw_loc_next;
15715 start_label = last_label = fde->dw_fde_second_begin;
15719 if (!cfa_equal_p (&last_cfa, &next_cfa))
15721 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
15722 start_label, last_label, section);
15723 list_tail = &(*list_tail)->dw_loc_next;
15724 start_label = last_label;
15727 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
15729 fde->dw_fde_second_begin
15730 ? fde->dw_fde_second_end : fde->dw_fde_end,
15733 if (list && list->dw_loc_next)
15739 /* Compute a displacement from the "steady-state frame pointer" to the
15740 frame base (often the same as the CFA), and store it in
15741 frame_pointer_fb_offset. OFFSET is added to the displacement
15742 before the latter is negated. */
15745 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
15749 #ifdef FRAME_POINTER_CFA_OFFSET
15750 reg = frame_pointer_rtx;
15751 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
15753 reg = arg_pointer_rtx;
15754 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
15757 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
15758 if (GET_CODE (elim) == PLUS)
15760 offset += INTVAL (XEXP (elim, 1));
15761 elim = XEXP (elim, 0);
15764 frame_pointer_fb_offset = -offset;
15766 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15767 in which to eliminate. This is because it's stack pointer isn't
15768 directly accessible as a register within the ISA. To work around
15769 this, assume that while we cannot provide a proper value for
15770 frame_pointer_fb_offset, we won't need one either. */
15771 frame_pointer_fb_offset_valid
15772 = ((SUPPORTS_STACK_ALIGNMENT
15773 && (elim == hard_frame_pointer_rtx
15774 || elim == stack_pointer_rtx))
15775 || elim == (frame_pointer_needed
15776 ? hard_frame_pointer_rtx
15777 : stack_pointer_rtx));
15780 /* Generate a DW_AT_name attribute given some string value to be included as
15781 the value of the attribute. */
15784 add_name_attribute (dw_die_ref die, const char *name_string)
15786 if (name_string != NULL && *name_string != 0)
15788 if (demangle_name_func)
15789 name_string = (*demangle_name_func) (name_string);
15791 add_AT_string (die, DW_AT_name, name_string);
15795 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15796 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15797 of TYPE accordingly.
15799 ??? This is a temporary measure until after we're able to generate
15800 regular DWARF for the complex Ada type system. */
15803 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
15804 dw_die_ref context_die)
15807 dw_die_ref dtype_die;
15809 if (!lang_hooks.types.descriptive_type)
15812 dtype = lang_hooks.types.descriptive_type (type);
15816 dtype_die = lookup_type_die (dtype);
15819 gen_type_die (dtype, context_die);
15820 dtype_die = lookup_type_die (dtype);
15821 gcc_assert (dtype_die);
15824 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
15827 /* Generate a DW_AT_comp_dir attribute for DIE. */
15830 add_comp_dir_attribute (dw_die_ref die)
15832 const char *wd = get_src_pwd ();
15838 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
15842 wdlen = strlen (wd);
15843 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
15845 wd1 [wdlen] = DIR_SEPARATOR;
15846 wd1 [wdlen + 1] = 0;
15850 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
15853 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15857 lower_bound_default (void)
15859 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
15864 case DW_LANG_C_plus_plus:
15866 case DW_LANG_ObjC_plus_plus:
15869 case DW_LANG_Fortran77:
15870 case DW_LANG_Fortran90:
15871 case DW_LANG_Fortran95:
15875 case DW_LANG_Python:
15876 return dwarf_version >= 4 ? 0 : -1;
15877 case DW_LANG_Ada95:
15878 case DW_LANG_Ada83:
15879 case DW_LANG_Cobol74:
15880 case DW_LANG_Cobol85:
15881 case DW_LANG_Pascal83:
15882 case DW_LANG_Modula2:
15884 return dwarf_version >= 4 ? 1 : -1;
15890 /* Given a tree node describing an array bound (either lower or upper) output
15891 a representation for that bound. */
15894 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
15896 switch (TREE_CODE (bound))
15901 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15904 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
15907 /* Use the default if possible. */
15908 if (bound_attr == DW_AT_lower_bound
15909 && host_integerp (bound, 0)
15910 && (dflt = lower_bound_default ()) != -1
15911 && tree_low_cst (bound, 0) == dflt)
15914 /* Otherwise represent the bound as an unsigned value with the
15915 precision of its type. The precision and signedness of the
15916 type will be necessary to re-interpret it unambiguously. */
15917 else if (prec < HOST_BITS_PER_WIDE_INT)
15919 unsigned HOST_WIDE_INT mask
15920 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
15921 add_AT_unsigned (subrange_die, bound_attr,
15922 TREE_INT_CST_LOW (bound) & mask);
15924 else if (prec == HOST_BITS_PER_WIDE_INT
15925 || TREE_INT_CST_HIGH (bound) == 0)
15926 add_AT_unsigned (subrange_die, bound_attr,
15927 TREE_INT_CST_LOW (bound));
15929 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
15930 TREE_INT_CST_LOW (bound));
15935 case VIEW_CONVERT_EXPR:
15936 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
15946 dw_die_ref decl_die = lookup_decl_die (bound);
15948 /* ??? Can this happen, or should the variable have been bound
15949 first? Probably it can, since I imagine that we try to create
15950 the types of parameters in the order in which they exist in
15951 the list, and won't have created a forward reference to a
15952 later parameter. */
15953 if (decl_die != NULL)
15955 add_AT_die_ref (subrange_die, bound_attr, decl_die);
15963 /* Otherwise try to create a stack operation procedure to
15964 evaluate the value of the array bound. */
15966 dw_die_ref ctx, decl_die;
15967 dw_loc_list_ref list;
15969 list = loc_list_from_tree (bound, 2);
15970 if (list == NULL || single_element_loc_list_p (list))
15972 /* If DW_AT_*bound is not a reference nor constant, it is
15973 a DWARF expression rather than location description.
15974 For that loc_list_from_tree (bound, 0) is needed.
15975 If that fails to give a single element list,
15976 fall back to outputting this as a reference anyway. */
15977 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
15978 if (list2 && single_element_loc_list_p (list2))
15980 add_AT_loc (subrange_die, bound_attr, list2->expr);
15987 if (current_function_decl == 0)
15988 ctx = comp_unit_die ();
15990 ctx = lookup_decl_die (current_function_decl);
15992 decl_die = new_die (DW_TAG_variable, ctx, bound);
15993 add_AT_flag (decl_die, DW_AT_artificial, 1);
15994 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
15995 add_AT_location_description (decl_die, DW_AT_location, list);
15996 add_AT_die_ref (subrange_die, bound_attr, decl_die);
16002 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16003 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16004 Note that the block of subscript information for an array type also
16005 includes information about the element type of the given array type. */
16008 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
16010 unsigned dimension_number;
16012 dw_die_ref subrange_die;
16014 for (dimension_number = 0;
16015 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
16016 type = TREE_TYPE (type), dimension_number++)
16018 tree domain = TYPE_DOMAIN (type);
16020 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
16023 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16024 and (in GNU C only) variable bounds. Handle all three forms
16026 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
16029 /* We have an array type with specified bounds. */
16030 lower = TYPE_MIN_VALUE (domain);
16031 upper = TYPE_MAX_VALUE (domain);
16033 /* Define the index type. */
16034 if (TREE_TYPE (domain))
16036 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16037 TREE_TYPE field. We can't emit debug info for this
16038 because it is an unnamed integral type. */
16039 if (TREE_CODE (domain) == INTEGER_TYPE
16040 && TYPE_NAME (domain) == NULL_TREE
16041 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
16042 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
16045 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
16049 /* ??? If upper is NULL, the array has unspecified length,
16050 but it does have a lower bound. This happens with Fortran
16052 Since the debugger is definitely going to need to know N
16053 to produce useful results, go ahead and output the lower
16054 bound solo, and hope the debugger can cope. */
16056 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
16058 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
16061 /* Otherwise we have an array type with an unspecified length. The
16062 DWARF-2 spec does not say how to handle this; let's just leave out the
16068 add_byte_size_attribute (dw_die_ref die, tree tree_node)
16072 switch (TREE_CODE (tree_node))
16077 case ENUMERAL_TYPE:
16080 case QUAL_UNION_TYPE:
16081 size = int_size_in_bytes (tree_node);
16084 /* For a data member of a struct or union, the DW_AT_byte_size is
16085 generally given as the number of bytes normally allocated for an
16086 object of the *declared* type of the member itself. This is true
16087 even for bit-fields. */
16088 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
16091 gcc_unreachable ();
16094 /* Note that `size' might be -1 when we get to this point. If it is, that
16095 indicates that the byte size of the entity in question is variable. We
16096 have no good way of expressing this fact in Dwarf at the present time,
16097 so just let the -1 pass on through. */
16098 add_AT_unsigned (die, DW_AT_byte_size, size);
16101 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16102 which specifies the distance in bits from the highest order bit of the
16103 "containing object" for the bit-field to the highest order bit of the
16106 For any given bit-field, the "containing object" is a hypothetical object
16107 (of some integral or enum type) within which the given bit-field lives. The
16108 type of this hypothetical "containing object" is always the same as the
16109 declared type of the individual bit-field itself. The determination of the
16110 exact location of the "containing object" for a bit-field is rather
16111 complicated. It's handled by the `field_byte_offset' function (above).
16113 Note that it is the size (in bytes) of the hypothetical "containing object"
16114 which will be given in the DW_AT_byte_size attribute for this bit-field.
16115 (See `byte_size_attribute' above). */
16118 add_bit_offset_attribute (dw_die_ref die, tree decl)
16120 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
16121 tree type = DECL_BIT_FIELD_TYPE (decl);
16122 HOST_WIDE_INT bitpos_int;
16123 HOST_WIDE_INT highest_order_object_bit_offset;
16124 HOST_WIDE_INT highest_order_field_bit_offset;
16125 HOST_WIDE_INT bit_offset;
16127 /* Must be a field and a bit field. */
16128 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
16130 /* We can't yet handle bit-fields whose offsets are variable, so if we
16131 encounter such things, just return without generating any attribute
16132 whatsoever. Likewise for variable or too large size. */
16133 if (! host_integerp (bit_position (decl), 0)
16134 || ! host_integerp (DECL_SIZE (decl), 1))
16137 bitpos_int = int_bit_position (decl);
16139 /* Note that the bit offset is always the distance (in bits) from the
16140 highest-order bit of the "containing object" to the highest-order bit of
16141 the bit-field itself. Since the "high-order end" of any object or field
16142 is different on big-endian and little-endian machines, the computation
16143 below must take account of these differences. */
16144 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
16145 highest_order_field_bit_offset = bitpos_int;
16147 if (! BYTES_BIG_ENDIAN)
16149 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
16150 highest_order_object_bit_offset += simple_type_size_in_bits (type);
16154 = (! BYTES_BIG_ENDIAN
16155 ? highest_order_object_bit_offset - highest_order_field_bit_offset
16156 : highest_order_field_bit_offset - highest_order_object_bit_offset);
16158 if (bit_offset < 0)
16159 add_AT_int (die, DW_AT_bit_offset, bit_offset);
16161 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
16164 /* For a FIELD_DECL node which represents a bit field, output an attribute
16165 which specifies the length in bits of the given field. */
16168 add_bit_size_attribute (dw_die_ref die, tree decl)
16170 /* Must be a field and a bit field. */
16171 gcc_assert (TREE_CODE (decl) == FIELD_DECL
16172 && DECL_BIT_FIELD_TYPE (decl));
16174 if (host_integerp (DECL_SIZE (decl), 1))
16175 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
16178 /* If the compiled language is ANSI C, then add a 'prototyped'
16179 attribute, if arg types are given for the parameters of a function. */
16182 add_prototyped_attribute (dw_die_ref die, tree func_type)
16184 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
16185 && prototype_p (func_type))
16186 add_AT_flag (die, DW_AT_prototyped, 1);
16189 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16190 by looking in either the type declaration or object declaration
16193 static inline dw_die_ref
16194 add_abstract_origin_attribute (dw_die_ref die, tree origin)
16196 dw_die_ref origin_die = NULL;
16198 if (TREE_CODE (origin) != FUNCTION_DECL)
16200 /* We may have gotten separated from the block for the inlined
16201 function, if we're in an exception handler or some such; make
16202 sure that the abstract function has been written out.
16204 Doing this for nested functions is wrong, however; functions are
16205 distinct units, and our context might not even be inline. */
16209 fn = TYPE_STUB_DECL (fn);
16211 fn = decl_function_context (fn);
16213 dwarf2out_abstract_function (fn);
16216 if (DECL_P (origin))
16217 origin_die = lookup_decl_die (origin);
16218 else if (TYPE_P (origin))
16219 origin_die = lookup_type_die (origin);
16221 /* XXX: Functions that are never lowered don't always have correct block
16222 trees (in the case of java, they simply have no block tree, in some other
16223 languages). For these functions, there is nothing we can really do to
16224 output correct debug info for inlined functions in all cases. Rather
16225 than die, we'll just produce deficient debug info now, in that we will
16226 have variables without a proper abstract origin. In the future, when all
16227 functions are lowered, we should re-add a gcc_assert (origin_die)
16231 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
16235 /* We do not currently support the pure_virtual attribute. */
16238 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
16240 if (DECL_VINDEX (func_decl))
16242 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
16244 if (host_integerp (DECL_VINDEX (func_decl), 0))
16245 add_AT_loc (die, DW_AT_vtable_elem_location,
16246 new_loc_descr (DW_OP_constu,
16247 tree_low_cst (DECL_VINDEX (func_decl), 0),
16250 /* GNU extension: Record what type this method came from originally. */
16251 if (debug_info_level > DINFO_LEVEL_TERSE
16252 && DECL_CONTEXT (func_decl))
16253 add_AT_die_ref (die, DW_AT_containing_type,
16254 lookup_type_die (DECL_CONTEXT (func_decl)));
16258 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16259 given decl. This used to be a vendor extension until after DWARF 4
16260 standardized it. */
16263 add_linkage_attr (dw_die_ref die, tree decl)
16265 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
16267 /* Mimic what assemble_name_raw does with a leading '*'. */
16268 if (name[0] == '*')
16271 if (dwarf_version >= 4)
16272 add_AT_string (die, DW_AT_linkage_name, name);
16274 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
16277 /* Add source coordinate attributes for the given decl. */
16280 add_src_coords_attributes (dw_die_ref die, tree decl)
16282 expanded_location s;
16284 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
16286 s = expand_location (DECL_SOURCE_LOCATION (decl));
16287 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
16288 add_AT_unsigned (die, DW_AT_decl_line, s.line);
16291 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16294 add_linkage_name (dw_die_ref die, tree decl)
16296 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
16297 && TREE_PUBLIC (decl)
16298 && !DECL_ABSTRACT (decl)
16299 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
16300 && die->die_tag != DW_TAG_member)
16302 /* Defer until we have an assembler name set. */
16303 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
16305 limbo_die_node *asm_name;
16307 asm_name = ggc_alloc_cleared_limbo_die_node ();
16308 asm_name->die = die;
16309 asm_name->created_for = decl;
16310 asm_name->next = deferred_asm_name;
16311 deferred_asm_name = asm_name;
16313 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
16314 add_linkage_attr (die, decl);
16318 /* Add a DW_AT_name attribute and source coordinate attribute for the
16319 given decl, but only if it actually has a name. */
16322 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
16326 decl_name = DECL_NAME (decl);
16327 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
16329 const char *name = dwarf2_name (decl, 0);
16331 add_name_attribute (die, name);
16332 if (! DECL_ARTIFICIAL (decl))
16333 add_src_coords_attributes (die, decl);
16335 add_linkage_name (die, decl);
16338 #ifdef VMS_DEBUGGING_INFO
16339 /* Get the function's name, as described by its RTL. This may be different
16340 from the DECL_NAME name used in the source file. */
16341 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
16343 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
16344 XEXP (DECL_RTL (decl), 0));
16345 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
16347 #endif /* VMS_DEBUGGING_INFO */
16350 #ifdef VMS_DEBUGGING_INFO
16351 /* Output the debug main pointer die for VMS */
16354 dwarf2out_vms_debug_main_pointer (void)
16356 char label[MAX_ARTIFICIAL_LABEL_BYTES];
16359 /* Allocate the VMS debug main subprogram die. */
16360 die = ggc_alloc_cleared_die_node ();
16361 die->die_tag = DW_TAG_subprogram;
16362 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
16363 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
16364 current_function_funcdef_no);
16365 add_AT_lbl_id (die, DW_AT_entry_pc, label);
16367 /* Make it the first child of comp_unit_die (). */
16368 die->die_parent = comp_unit_die ();
16369 if (comp_unit_die ()->die_child)
16371 die->die_sib = comp_unit_die ()->die_child->die_sib;
16372 comp_unit_die ()->die_child->die_sib = die;
16376 die->die_sib = die;
16377 comp_unit_die ()->die_child = die;
16380 #endif /* VMS_DEBUGGING_INFO */
16382 /* Push a new declaration scope. */
16385 push_decl_scope (tree scope)
16387 VEC_safe_push (tree, gc, decl_scope_table, scope);
16390 /* Pop a declaration scope. */
16393 pop_decl_scope (void)
16395 VEC_pop (tree, decl_scope_table);
16398 /* Return the DIE for the scope that immediately contains this type.
16399 Non-named types get global scope. Named types nested in other
16400 types get their containing scope if it's open, or global scope
16401 otherwise. All other types (i.e. function-local named types) get
16402 the current active scope. */
16405 scope_die_for (tree t, dw_die_ref context_die)
16407 dw_die_ref scope_die = NULL;
16408 tree containing_scope;
16411 /* Non-types always go in the current scope. */
16412 gcc_assert (TYPE_P (t));
16414 containing_scope = TYPE_CONTEXT (t);
16416 /* Use the containing namespace if it was passed in (for a declaration). */
16417 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
16419 if (context_die == lookup_decl_die (containing_scope))
16422 containing_scope = NULL_TREE;
16425 /* Ignore function type "scopes" from the C frontend. They mean that
16426 a tagged type is local to a parmlist of a function declarator, but
16427 that isn't useful to DWARF. */
16428 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
16429 containing_scope = NULL_TREE;
16431 if (SCOPE_FILE_SCOPE_P (containing_scope))
16432 scope_die = comp_unit_die ();
16433 else if (TYPE_P (containing_scope))
16435 /* For types, we can just look up the appropriate DIE. But
16436 first we check to see if we're in the middle of emitting it
16437 so we know where the new DIE should go. */
16438 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
16439 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
16444 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
16445 || TREE_ASM_WRITTEN (containing_scope));
16446 /*We are not in the middle of emitting the type
16447 CONTAINING_SCOPE. Let's see if it's emitted already. */
16448 scope_die = lookup_type_die (containing_scope);
16450 /* If none of the current dies are suitable, we get file scope. */
16451 if (scope_die == NULL)
16452 scope_die = comp_unit_die ();
16455 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
16458 scope_die = context_die;
16463 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16466 local_scope_p (dw_die_ref context_die)
16468 for (; context_die; context_die = context_die->die_parent)
16469 if (context_die->die_tag == DW_TAG_inlined_subroutine
16470 || context_die->die_tag == DW_TAG_subprogram)
16476 /* Returns nonzero if CONTEXT_DIE is a class. */
16479 class_scope_p (dw_die_ref context_die)
16481 return (context_die
16482 && (context_die->die_tag == DW_TAG_structure_type
16483 || context_die->die_tag == DW_TAG_class_type
16484 || context_die->die_tag == DW_TAG_interface_type
16485 || context_die->die_tag == DW_TAG_union_type));
16488 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16489 whether or not to treat a DIE in this context as a declaration. */
16492 class_or_namespace_scope_p (dw_die_ref context_die)
16494 return (class_scope_p (context_die)
16495 || (context_die && context_die->die_tag == DW_TAG_namespace));
16498 /* Many forms of DIEs require a "type description" attribute. This
16499 routine locates the proper "type descriptor" die for the type given
16500 by 'type', and adds a DW_AT_type attribute below the given die. */
16503 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
16504 int decl_volatile, dw_die_ref context_die)
16506 enum tree_code code = TREE_CODE (type);
16507 dw_die_ref type_die = NULL;
16509 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16510 or fixed-point type, use the inner type. This is because we have no
16511 support for unnamed types in base_type_die. This can happen if this is
16512 an Ada subrange type. Correct solution is emit a subrange type die. */
16513 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
16514 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
16515 type = TREE_TYPE (type), code = TREE_CODE (type);
16517 if (code == ERROR_MARK
16518 /* Handle a special case. For functions whose return type is void, we
16519 generate *no* type attribute. (Note that no object may have type
16520 `void', so this only applies to function return types). */
16521 || code == VOID_TYPE)
16524 type_die = modified_type_die (type,
16525 decl_const || TYPE_READONLY (type),
16526 decl_volatile || TYPE_VOLATILE (type),
16529 if (type_die != NULL)
16530 add_AT_die_ref (object_die, DW_AT_type, type_die);
16533 /* Given an object die, add the calling convention attribute for the
16534 function call type. */
16536 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
16538 enum dwarf_calling_convention value = DW_CC_normal;
16540 value = ((enum dwarf_calling_convention)
16541 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
16544 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
16546 /* DWARF 2 doesn't provide a way to identify a program's source-level
16547 entry point. DW_AT_calling_convention attributes are only meant
16548 to describe functions' calling conventions. However, lacking a
16549 better way to signal the Fortran main program, we used this for
16550 a long time, following existing custom. Now, DWARF 4 has
16551 DW_AT_main_subprogram, which we add below, but some tools still
16552 rely on the old way, which we thus keep. */
16553 value = DW_CC_program;
16555 if (dwarf_version >= 4 || !dwarf_strict)
16556 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
16559 /* Only add the attribute if the backend requests it, and
16560 is not DW_CC_normal. */
16561 if (value && (value != DW_CC_normal))
16562 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
16565 /* Given a tree pointer to a struct, class, union, or enum type node, return
16566 a pointer to the (string) tag name for the given type, or zero if the type
16567 was declared without a tag. */
16569 static const char *
16570 type_tag (const_tree type)
16572 const char *name = 0;
16574 if (TYPE_NAME (type) != 0)
16578 /* Find the IDENTIFIER_NODE for the type name. */
16579 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
16580 && !TYPE_NAMELESS (type))
16581 t = TYPE_NAME (type);
16583 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16584 a TYPE_DECL node, regardless of whether or not a `typedef' was
16586 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16587 && ! DECL_IGNORED_P (TYPE_NAME (type)))
16589 /* We want to be extra verbose. Don't call dwarf_name if
16590 DECL_NAME isn't set. The default hook for decl_printable_name
16591 doesn't like that, and in this context it's correct to return
16592 0, instead of "<anonymous>" or the like. */
16593 if (DECL_NAME (TYPE_NAME (type))
16594 && !DECL_NAMELESS (TYPE_NAME (type)))
16595 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
16598 /* Now get the name as a string, or invent one. */
16599 if (!name && t != 0)
16600 name = IDENTIFIER_POINTER (t);
16603 return (name == 0 || *name == '\0') ? 0 : name;
16606 /* Return the type associated with a data member, make a special check
16607 for bit field types. */
16610 member_declared_type (const_tree member)
16612 return (DECL_BIT_FIELD_TYPE (member)
16613 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
16616 /* Get the decl's label, as described by its RTL. This may be different
16617 from the DECL_NAME name used in the source file. */
16620 static const char *
16621 decl_start_label (tree decl)
16624 const char *fnname;
16626 x = DECL_RTL (decl);
16627 gcc_assert (MEM_P (x));
16630 gcc_assert (GET_CODE (x) == SYMBOL_REF);
16632 fnname = XSTR (x, 0);
16637 /* These routines generate the internal representation of the DIE's for
16638 the compilation unit. Debugging information is collected by walking
16639 the declaration trees passed in from dwarf2out_decl(). */
16642 gen_array_type_die (tree type, dw_die_ref context_die)
16644 dw_die_ref scope_die = scope_die_for (type, context_die);
16645 dw_die_ref array_die;
16647 /* GNU compilers represent multidimensional array types as sequences of one
16648 dimensional array types whose element types are themselves array types.
16649 We sometimes squish that down to a single array_type DIE with multiple
16650 subscripts in the Dwarf debugging info. The draft Dwarf specification
16651 say that we are allowed to do this kind of compression in C, because
16652 there is no difference between an array of arrays and a multidimensional
16653 array. We don't do this for Ada to remain as close as possible to the
16654 actual representation, which is especially important against the language
16655 flexibilty wrt arrays of variable size. */
16657 bool collapse_nested_arrays = !is_ada ();
16660 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16661 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16662 if (TYPE_STRING_FLAG (type)
16663 && TREE_CODE (type) == ARRAY_TYPE
16665 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
16667 HOST_WIDE_INT size;
16669 array_die = new_die (DW_TAG_string_type, scope_die, type);
16670 add_name_attribute (array_die, type_tag (type));
16671 equate_type_number_to_die (type, array_die);
16672 size = int_size_in_bytes (type);
16674 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16675 else if (TYPE_DOMAIN (type) != NULL_TREE
16676 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
16677 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
16679 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
16680 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
16682 size = int_size_in_bytes (TREE_TYPE (szdecl));
16683 if (loc && size > 0)
16685 add_AT_location_description (array_die, DW_AT_string_length, loc);
16686 if (size != DWARF2_ADDR_SIZE)
16687 add_AT_unsigned (array_die, DW_AT_byte_size, size);
16693 /* ??? The SGI dwarf reader fails for array of array of enum types
16694 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
16695 array type comes before the outer array type. We thus call gen_type_die
16696 before we new_die and must prevent nested array types collapsing for this
16699 #ifdef MIPS_DEBUGGING_INFO
16700 gen_type_die (TREE_TYPE (type), context_die);
16701 collapse_nested_arrays = false;
16704 array_die = new_die (DW_TAG_array_type, scope_die, type);
16705 add_name_attribute (array_die, type_tag (type));
16706 add_gnat_descriptive_type_attribute (array_die, type, context_die);
16707 if (TYPE_ARTIFICIAL (type))
16708 add_AT_flag (array_die, DW_AT_artificial, 1);
16709 equate_type_number_to_die (type, array_die);
16711 if (TREE_CODE (type) == VECTOR_TYPE)
16712 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
16714 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16716 && TREE_CODE (type) == ARRAY_TYPE
16717 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
16718 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
16719 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16722 /* We default the array ordering. SDB will probably do
16723 the right things even if DW_AT_ordering is not present. It's not even
16724 an issue until we start to get into multidimensional arrays anyway. If
16725 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16726 then we'll have to put the DW_AT_ordering attribute back in. (But if
16727 and when we find out that we need to put these in, we will only do so
16728 for multidimensional arrays. */
16729 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
16732 #ifdef MIPS_DEBUGGING_INFO
16733 /* The SGI compilers handle arrays of unknown bound by setting
16734 AT_declaration and not emitting any subrange DIEs. */
16735 if (TREE_CODE (type) == ARRAY_TYPE
16736 && ! TYPE_DOMAIN (type))
16737 add_AT_flag (array_die, DW_AT_declaration, 1);
16740 if (TREE_CODE (type) == VECTOR_TYPE)
16742 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16743 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
16744 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
16745 add_bound_info (subrange_die, DW_AT_upper_bound,
16746 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
16749 add_subscript_info (array_die, type, collapse_nested_arrays);
16751 /* Add representation of the type of the elements of this array type and
16752 emit the corresponding DIE if we haven't done it already. */
16753 element_type = TREE_TYPE (type);
16754 if (collapse_nested_arrays)
16755 while (TREE_CODE (element_type) == ARRAY_TYPE)
16757 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
16759 element_type = TREE_TYPE (element_type);
16762 #ifndef MIPS_DEBUGGING_INFO
16763 gen_type_die (element_type, context_die);
16766 add_type_attribute (array_die, element_type, 0, 0, context_die);
16768 if (get_AT (array_die, DW_AT_name))
16769 add_pubtype (type, array_die);
16772 static dw_loc_descr_ref
16773 descr_info_loc (tree val, tree base_decl)
16775 HOST_WIDE_INT size;
16776 dw_loc_descr_ref loc, loc2;
16777 enum dwarf_location_atom op;
16779 if (val == base_decl)
16780 return new_loc_descr (DW_OP_push_object_address, 0, 0);
16782 switch (TREE_CODE (val))
16785 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16787 return loc_descriptor_from_tree (val, 0);
16789 if (host_integerp (val, 0))
16790 return int_loc_descriptor (tree_low_cst (val, 0));
16793 size = int_size_in_bytes (TREE_TYPE (val));
16796 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16799 if (size == DWARF2_ADDR_SIZE)
16800 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
16802 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
16804 case POINTER_PLUS_EXPR:
16806 if (host_integerp (TREE_OPERAND (val, 1), 1)
16807 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
16810 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16813 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
16819 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
16822 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
16825 add_loc_descr (&loc, loc2);
16826 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
16848 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
16849 tree val, tree base_decl)
16851 dw_loc_descr_ref loc;
16853 if (host_integerp (val, 0))
16855 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
16859 loc = descr_info_loc (val, base_decl);
16863 add_AT_loc (die, attr, loc);
16866 /* This routine generates DIE for array with hidden descriptor, details
16867 are filled into *info by a langhook. */
16870 gen_descr_array_type_die (tree type, struct array_descr_info *info,
16871 dw_die_ref context_die)
16873 dw_die_ref scope_die = scope_die_for (type, context_die);
16874 dw_die_ref array_die;
16877 array_die = new_die (DW_TAG_array_type, scope_die, type);
16878 add_name_attribute (array_die, type_tag (type));
16879 equate_type_number_to_die (type, array_die);
16881 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16883 && info->ndimensions >= 2)
16884 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
16886 if (info->data_location)
16887 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
16889 if (info->associated)
16890 add_descr_info_field (array_die, DW_AT_associated, info->associated,
16892 if (info->allocated)
16893 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
16896 for (dim = 0; dim < info->ndimensions; dim++)
16898 dw_die_ref subrange_die
16899 = new_die (DW_TAG_subrange_type, array_die, NULL);
16901 if (info->dimen[dim].lower_bound)
16903 /* If it is the default value, omit it. */
16906 if (host_integerp (info->dimen[dim].lower_bound, 0)
16907 && (dflt = lower_bound_default ()) != -1
16908 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
16911 add_descr_info_field (subrange_die, DW_AT_lower_bound,
16912 info->dimen[dim].lower_bound,
16915 if (info->dimen[dim].upper_bound)
16916 add_descr_info_field (subrange_die, DW_AT_upper_bound,
16917 info->dimen[dim].upper_bound,
16919 if (info->dimen[dim].stride)
16920 add_descr_info_field (subrange_die, DW_AT_byte_stride,
16921 info->dimen[dim].stride,
16925 gen_type_die (info->element_type, context_die);
16926 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
16928 if (get_AT (array_die, DW_AT_name))
16929 add_pubtype (type, array_die);
16934 gen_entry_point_die (tree decl, dw_die_ref context_die)
16936 tree origin = decl_ultimate_origin (decl);
16937 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
16939 if (origin != NULL)
16940 add_abstract_origin_attribute (decl_die, origin);
16943 add_name_and_src_coords_attributes (decl_die, decl);
16944 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
16945 0, 0, context_die);
16948 if (DECL_ABSTRACT (decl))
16949 equate_decl_number_to_die (decl, decl_die);
16951 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
16955 /* Walk through the list of incomplete types again, trying once more to
16956 emit full debugging info for them. */
16959 retry_incomplete_types (void)
16963 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
16964 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
16965 DINFO_USAGE_DIR_USE))
16966 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
16969 /* Determine what tag to use for a record type. */
16971 static enum dwarf_tag
16972 record_type_tag (tree type)
16974 if (! lang_hooks.types.classify_record)
16975 return DW_TAG_structure_type;
16977 switch (lang_hooks.types.classify_record (type))
16979 case RECORD_IS_STRUCT:
16980 return DW_TAG_structure_type;
16982 case RECORD_IS_CLASS:
16983 return DW_TAG_class_type;
16985 case RECORD_IS_INTERFACE:
16986 if (dwarf_version >= 3 || !dwarf_strict)
16987 return DW_TAG_interface_type;
16988 return DW_TAG_structure_type;
16991 gcc_unreachable ();
16995 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16996 include all of the information about the enumeration values also. Each
16997 enumerated type name/value is listed as a child of the enumerated type
17001 gen_enumeration_type_die (tree type, dw_die_ref context_die)
17003 dw_die_ref type_die = lookup_type_die (type);
17005 if (type_die == NULL)
17007 type_die = new_die (DW_TAG_enumeration_type,
17008 scope_die_for (type, context_die), type);
17009 equate_type_number_to_die (type, type_die);
17010 add_name_attribute (type_die, type_tag (type));
17011 add_gnat_descriptive_type_attribute (type_die, type, context_die);
17012 if (TYPE_ARTIFICIAL (type))
17013 add_AT_flag (type_die, DW_AT_artificial, 1);
17014 if (dwarf_version >= 4 || !dwarf_strict)
17016 if (ENUM_IS_SCOPED (type))
17017 add_AT_flag (type_die, DW_AT_enum_class, 1);
17018 if (ENUM_IS_OPAQUE (type))
17019 add_AT_flag (type_die, DW_AT_declaration, 1);
17022 else if (! TYPE_SIZE (type))
17025 remove_AT (type_die, DW_AT_declaration);
17027 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17028 given enum type is incomplete, do not generate the DW_AT_byte_size
17029 attribute or the DW_AT_element_list attribute. */
17030 if (TYPE_SIZE (type))
17034 TREE_ASM_WRITTEN (type) = 1;
17035 add_byte_size_attribute (type_die, type);
17036 if (TYPE_STUB_DECL (type) != NULL_TREE)
17038 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
17039 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
17042 /* If the first reference to this type was as the return type of an
17043 inline function, then it may not have a parent. Fix this now. */
17044 if (type_die->die_parent == NULL)
17045 add_child_die (scope_die_for (type, context_die), type_die);
17047 for (link = TYPE_VALUES (type);
17048 link != NULL; link = TREE_CHAIN (link))
17050 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
17051 tree value = TREE_VALUE (link);
17053 add_name_attribute (enum_die,
17054 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
17056 if (TREE_CODE (value) == CONST_DECL)
17057 value = DECL_INITIAL (value);
17059 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
17060 /* DWARF2 does not provide a way of indicating whether or
17061 not enumeration constants are signed or unsigned. GDB
17062 always assumes the values are signed, so we output all
17063 values as if they were signed. That means that
17064 enumeration constants with very large unsigned values
17065 will appear to have negative values in the debugger. */
17066 add_AT_int (enum_die, DW_AT_const_value,
17067 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
17071 add_AT_flag (type_die, DW_AT_declaration, 1);
17073 if (get_AT (type_die, DW_AT_name))
17074 add_pubtype (type, type_die);
17079 /* Generate a DIE to represent either a real live formal parameter decl or to
17080 represent just the type of some formal parameter position in some function
17083 Note that this routine is a bit unusual because its argument may be a
17084 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17085 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17086 node. If it's the former then this function is being called to output a
17087 DIE to represent a formal parameter object (or some inlining thereof). If
17088 it's the latter, then this function is only being called to output a
17089 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17090 argument type of some subprogram type.
17091 If EMIT_NAME_P is true, name and source coordinate attributes
17095 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
17096 dw_die_ref context_die)
17098 tree node_or_origin = node ? node : origin;
17099 tree ultimate_origin;
17100 dw_die_ref parm_die
17101 = new_die (DW_TAG_formal_parameter, context_die, node);
17103 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
17105 case tcc_declaration:
17106 ultimate_origin = decl_ultimate_origin (node_or_origin);
17107 if (node || ultimate_origin)
17108 origin = ultimate_origin;
17109 if (origin != NULL)
17110 add_abstract_origin_attribute (parm_die, origin);
17111 else if (emit_name_p)
17112 add_name_and_src_coords_attributes (parm_die, node);
17114 || (! DECL_ABSTRACT (node_or_origin)
17115 && variably_modified_type_p (TREE_TYPE (node_or_origin),
17116 decl_function_context
17117 (node_or_origin))))
17119 tree type = TREE_TYPE (node_or_origin);
17120 if (decl_by_reference_p (node_or_origin))
17121 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
17124 add_type_attribute (parm_die, type,
17125 TREE_READONLY (node_or_origin),
17126 TREE_THIS_VOLATILE (node_or_origin),
17129 if (origin == NULL && DECL_ARTIFICIAL (node))
17130 add_AT_flag (parm_die, DW_AT_artificial, 1);
17132 if (node && node != origin)
17133 equate_decl_number_to_die (node, parm_die);
17134 if (! DECL_ABSTRACT (node_or_origin))
17135 add_location_or_const_value_attribute (parm_die, node_or_origin,
17136 node == NULL, DW_AT_location);
17141 /* We were called with some kind of a ..._TYPE node. */
17142 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
17146 gcc_unreachable ();
17152 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17153 children DW_TAG_formal_parameter DIEs representing the arguments of the
17156 PARM_PACK must be a function parameter pack.
17157 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17158 must point to the subsequent arguments of the function PACK_ARG belongs to.
17159 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17160 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17161 following the last one for which a DIE was generated. */
17164 gen_formal_parameter_pack_die (tree parm_pack,
17166 dw_die_ref subr_die,
17170 dw_die_ref parm_pack_die;
17172 gcc_assert (parm_pack
17173 && lang_hooks.function_parameter_pack_p (parm_pack)
17176 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
17177 add_src_coords_attributes (parm_pack_die, parm_pack);
17179 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
17181 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
17184 gen_formal_parameter_die (arg, NULL,
17185 false /* Don't emit name attribute. */,
17190 return parm_pack_die;
17193 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17194 at the end of an (ANSI prototyped) formal parameters list. */
17197 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
17199 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
17202 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17203 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17204 parameters as specified in some function type specification (except for
17205 those which appear as part of a function *definition*). */
17208 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
17211 tree formal_type = NULL;
17212 tree first_parm_type;
17215 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
17217 arg = DECL_ARGUMENTS (function_or_method_type);
17218 function_or_method_type = TREE_TYPE (function_or_method_type);
17223 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
17225 /* Make our first pass over the list of formal parameter types and output a
17226 DW_TAG_formal_parameter DIE for each one. */
17227 for (link = first_parm_type; link; )
17229 dw_die_ref parm_die;
17231 formal_type = TREE_VALUE (link);
17232 if (formal_type == void_type_node)
17235 /* Output a (nameless) DIE to represent the formal parameter itself. */
17236 parm_die = gen_formal_parameter_die (formal_type, NULL,
17237 true /* Emit name attribute. */,
17239 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
17240 && link == first_parm_type)
17242 add_AT_flag (parm_die, DW_AT_artificial, 1);
17243 if (dwarf_version >= 3 || !dwarf_strict)
17244 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
17246 else if (arg && DECL_ARTIFICIAL (arg))
17247 add_AT_flag (parm_die, DW_AT_artificial, 1);
17249 link = TREE_CHAIN (link);
17251 arg = DECL_CHAIN (arg);
17254 /* If this function type has an ellipsis, add a
17255 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17256 if (formal_type != void_type_node)
17257 gen_unspecified_parameters_die (function_or_method_type, context_die);
17259 /* Make our second (and final) pass over the list of formal parameter types
17260 and output DIEs to represent those types (as necessary). */
17261 for (link = TYPE_ARG_TYPES (function_or_method_type);
17262 link && TREE_VALUE (link);
17263 link = TREE_CHAIN (link))
17264 gen_type_die (TREE_VALUE (link), context_die);
17267 /* We want to generate the DIE for TYPE so that we can generate the
17268 die for MEMBER, which has been defined; we will need to refer back
17269 to the member declaration nested within TYPE. If we're trying to
17270 generate minimal debug info for TYPE, processing TYPE won't do the
17271 trick; we need to attach the member declaration by hand. */
17274 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
17276 gen_type_die (type, context_die);
17278 /* If we're trying to avoid duplicate debug info, we may not have
17279 emitted the member decl for this function. Emit it now. */
17280 if (TYPE_STUB_DECL (type)
17281 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
17282 && ! lookup_decl_die (member))
17284 dw_die_ref type_die;
17285 gcc_assert (!decl_ultimate_origin (member));
17287 push_decl_scope (type);
17288 type_die = lookup_type_die_strip_naming_typedef (type);
17289 if (TREE_CODE (member) == FUNCTION_DECL)
17290 gen_subprogram_die (member, type_die);
17291 else if (TREE_CODE (member) == FIELD_DECL)
17293 /* Ignore the nameless fields that are used to skip bits but handle
17294 C++ anonymous unions and structs. */
17295 if (DECL_NAME (member) != NULL_TREE
17296 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
17297 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
17299 gen_type_die (member_declared_type (member), type_die);
17300 gen_field_die (member, type_die);
17304 gen_variable_die (member, NULL_TREE, type_die);
17310 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17311 may later generate inlined and/or out-of-line instances of. */
17314 dwarf2out_abstract_function (tree decl)
17316 dw_die_ref old_die;
17320 htab_t old_decl_loc_table;
17321 htab_t old_cached_dw_loc_list_table;
17322 int old_call_site_count, old_tail_call_site_count;
17323 struct call_arg_loc_node *old_call_arg_locations;
17325 /* Make sure we have the actual abstract inline, not a clone. */
17326 decl = DECL_ORIGIN (decl);
17328 old_die = lookup_decl_die (decl);
17329 if (old_die && get_AT (old_die, DW_AT_inline))
17330 /* We've already generated the abstract instance. */
17333 /* We can be called while recursively when seeing block defining inlined subroutine
17334 DIE. Be sure to not clobber the outer location table nor use it or we would
17335 get locations in abstract instantces. */
17336 old_decl_loc_table = decl_loc_table;
17337 decl_loc_table = NULL;
17338 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
17339 cached_dw_loc_list_table = NULL;
17340 old_call_arg_locations = call_arg_locations;
17341 call_arg_locations = NULL;
17342 old_call_site_count = call_site_count;
17343 call_site_count = -1;
17344 old_tail_call_site_count = tail_call_site_count;
17345 tail_call_site_count = -1;
17347 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17348 we don't get confused by DECL_ABSTRACT. */
17349 if (debug_info_level > DINFO_LEVEL_TERSE)
17351 context = decl_class_context (decl);
17353 gen_type_die_for_member
17354 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
17357 /* Pretend we've just finished compiling this function. */
17358 save_fn = current_function_decl;
17359 current_function_decl = decl;
17360 push_cfun (DECL_STRUCT_FUNCTION (decl));
17362 was_abstract = DECL_ABSTRACT (decl);
17363 set_decl_abstract_flags (decl, 1);
17364 dwarf2out_decl (decl);
17365 if (! was_abstract)
17366 set_decl_abstract_flags (decl, 0);
17368 current_function_decl = save_fn;
17369 decl_loc_table = old_decl_loc_table;
17370 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
17371 call_arg_locations = old_call_arg_locations;
17372 call_site_count = old_call_site_count;
17373 tail_call_site_count = old_tail_call_site_count;
17377 /* Helper function of premark_used_types() which gets called through
17380 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17381 marked as unused by prune_unused_types. */
17384 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
17389 type = (tree) *slot;
17390 die = lookup_type_die (type);
17392 die->die_perennial_p = 1;
17396 /* Helper function of premark_types_used_by_global_vars which gets called
17397 through htab_traverse.
17399 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17400 marked as unused by prune_unused_types. The DIE of the type is marked
17401 only if the global variable using the type will actually be emitted. */
17404 premark_types_used_by_global_vars_helper (void **slot,
17405 void *data ATTRIBUTE_UNUSED)
17407 struct types_used_by_vars_entry *entry;
17410 entry = (struct types_used_by_vars_entry *) *slot;
17411 gcc_assert (entry->type != NULL
17412 && entry->var_decl != NULL);
17413 die = lookup_type_die (entry->type);
17416 /* Ask cgraph if the global variable really is to be emitted.
17417 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17418 struct varpool_node *node = varpool_get_node (entry->var_decl);
17419 if (node && node->needed)
17421 die->die_perennial_p = 1;
17422 /* Keep the parent DIEs as well. */
17423 while ((die = die->die_parent) && die->die_perennial_p == 0)
17424 die->die_perennial_p = 1;
17430 /* Mark all members of used_types_hash as perennial. */
17433 premark_used_types (void)
17435 if (cfun && cfun->used_types_hash)
17436 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
17439 /* Mark all members of types_used_by_vars_entry as perennial. */
17442 premark_types_used_by_global_vars (void)
17444 if (types_used_by_vars_hash)
17445 htab_traverse (types_used_by_vars_hash,
17446 premark_types_used_by_global_vars_helper, NULL);
17449 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17450 for CA_LOC call arg loc node. */
17453 gen_call_site_die (tree decl, dw_die_ref subr_die,
17454 struct call_arg_loc_node *ca_loc)
17456 dw_die_ref stmt_die = NULL, die;
17457 tree block = ca_loc->block;
17460 && block != DECL_INITIAL (decl)
17461 && TREE_CODE (block) == BLOCK)
17463 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
17464 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
17467 block = BLOCK_SUPERCONTEXT (block);
17469 if (stmt_die == NULL)
17470 stmt_die = subr_die;
17471 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
17472 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
17473 if (ca_loc->tail_call_p)
17474 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
17475 if (ca_loc->symbol_ref)
17477 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
17479 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
17481 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
17486 /* Generate a DIE to represent a declared function (either file-scope or
17490 gen_subprogram_die (tree decl, dw_die_ref context_die)
17492 tree origin = decl_ultimate_origin (decl);
17493 dw_die_ref subr_die;
17495 dw_die_ref old_die = lookup_decl_die (decl);
17496 int declaration = (current_function_decl != decl
17497 || class_or_namespace_scope_p (context_die));
17499 premark_used_types ();
17501 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17502 started to generate the abstract instance of an inline, decided to output
17503 its containing class, and proceeded to emit the declaration of the inline
17504 from the member list for the class. If so, DECLARATION takes priority;
17505 we'll get back to the abstract instance when done with the class. */
17507 /* The class-scope declaration DIE must be the primary DIE. */
17508 if (origin && declaration && class_or_namespace_scope_p (context_die))
17511 gcc_assert (!old_die);
17514 /* Now that the C++ front end lazily declares artificial member fns, we
17515 might need to retrofit the declaration into its class. */
17516 if (!declaration && !origin && !old_die
17517 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
17518 && !class_or_namespace_scope_p (context_die)
17519 && debug_info_level > DINFO_LEVEL_TERSE)
17520 old_die = force_decl_die (decl);
17522 if (origin != NULL)
17524 gcc_assert (!declaration || local_scope_p (context_die));
17526 /* Fixup die_parent for the abstract instance of a nested
17527 inline function. */
17528 if (old_die && old_die->die_parent == NULL)
17529 add_child_die (context_die, old_die);
17531 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17532 add_abstract_origin_attribute (subr_die, origin);
17533 /* This is where the actual code for a cloned function is.
17534 Let's emit linkage name attribute for it. This helps
17535 debuggers to e.g, set breakpoints into
17536 constructors/destructors when the user asks "break
17538 add_linkage_name (subr_die, decl);
17542 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17543 struct dwarf_file_data * file_index = lookup_filename (s.file);
17545 if (!get_AT_flag (old_die, DW_AT_declaration)
17546 /* We can have a normal definition following an inline one in the
17547 case of redefinition of GNU C extern inlines.
17548 It seems reasonable to use AT_specification in this case. */
17549 && !get_AT (old_die, DW_AT_inline))
17551 /* Detect and ignore this case, where we are trying to output
17552 something we have already output. */
17556 /* If the definition comes from the same place as the declaration,
17557 maybe use the old DIE. We always want the DIE for this function
17558 that has the *_pc attributes to be under comp_unit_die so the
17559 debugger can find it. We also need to do this for abstract
17560 instances of inlines, since the spec requires the out-of-line copy
17561 to have the same parent. For local class methods, this doesn't
17562 apply; we just use the old DIE. */
17563 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
17564 && (DECL_ARTIFICIAL (decl)
17565 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
17566 && (get_AT_unsigned (old_die, DW_AT_decl_line)
17567 == (unsigned) s.line))))
17569 subr_die = old_die;
17571 /* Clear out the declaration attribute and the formal parameters.
17572 Do not remove all children, because it is possible that this
17573 declaration die was forced using force_decl_die(). In such
17574 cases die that forced declaration die (e.g. TAG_imported_module)
17575 is one of the children that we do not want to remove. */
17576 remove_AT (subr_die, DW_AT_declaration);
17577 remove_AT (subr_die, DW_AT_object_pointer);
17578 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
17582 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17583 add_AT_specification (subr_die, old_die);
17584 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
17585 add_AT_file (subr_die, DW_AT_decl_file, file_index);
17586 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
17587 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
17592 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
17594 if (TREE_PUBLIC (decl))
17595 add_AT_flag (subr_die, DW_AT_external, 1);
17597 add_name_and_src_coords_attributes (subr_die, decl);
17598 if (debug_info_level > DINFO_LEVEL_TERSE)
17600 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
17601 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
17602 0, 0, context_die);
17605 add_pure_or_virtual_attribute (subr_die, decl);
17606 if (DECL_ARTIFICIAL (decl))
17607 add_AT_flag (subr_die, DW_AT_artificial, 1);
17609 add_accessibility_attribute (subr_die, decl);
17614 if (!old_die || !get_AT (old_die, DW_AT_inline))
17616 add_AT_flag (subr_die, DW_AT_declaration, 1);
17618 /* If this is an explicit function declaration then generate
17619 a DW_AT_explicit attribute. */
17620 if (lang_hooks.decls.function_decl_explicit_p (decl)
17621 && (dwarf_version >= 3 || !dwarf_strict))
17622 add_AT_flag (subr_die, DW_AT_explicit, 1);
17624 /* The first time we see a member function, it is in the context of
17625 the class to which it belongs. We make sure of this by emitting
17626 the class first. The next time is the definition, which is
17627 handled above. The two may come from the same source text.
17629 Note that force_decl_die() forces function declaration die. It is
17630 later reused to represent definition. */
17631 equate_decl_number_to_die (decl, subr_die);
17634 else if (DECL_ABSTRACT (decl))
17636 if (DECL_DECLARED_INLINE_P (decl))
17638 if (cgraph_function_possibly_inlined_p (decl))
17639 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
17641 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
17645 if (cgraph_function_possibly_inlined_p (decl))
17646 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
17648 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
17651 if (DECL_DECLARED_INLINE_P (decl)
17652 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
17653 add_AT_flag (subr_die, DW_AT_artificial, 1);
17655 equate_decl_number_to_die (decl, subr_die);
17657 else if (!DECL_EXTERNAL (decl))
17659 HOST_WIDE_INT cfa_fb_offset;
17661 if (!old_die || !get_AT (old_die, DW_AT_inline))
17662 equate_decl_number_to_die (decl, subr_die);
17664 if (!flag_reorder_blocks_and_partition)
17666 dw_fde_ref fde = &fde_table[current_funcdef_fde];
17667 if (fde->dw_fde_begin)
17669 /* We have already generated the labels. */
17670 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17671 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17675 /* Create start/end labels and add the range. */
17676 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
17677 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
17678 current_function_funcdef_no);
17679 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
17680 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
17681 current_function_funcdef_no);
17682 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
17685 #if VMS_DEBUGGING_INFO
17686 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17687 Section 2.3 Prologue and Epilogue Attributes:
17688 When a breakpoint is set on entry to a function, it is generally
17689 desirable for execution to be suspended, not on the very first
17690 instruction of the function, but rather at a point after the
17691 function's frame has been set up, after any language defined local
17692 declaration processing has been completed, and before execution of
17693 the first statement of the function begins. Debuggers generally
17694 cannot properly determine where this point is. Similarly for a
17695 breakpoint set on exit from a function. The prologue and epilogue
17696 attributes allow a compiler to communicate the location(s) to use. */
17699 if (fde->dw_fde_vms_end_prologue)
17700 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
17701 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
17703 if (fde->dw_fde_vms_begin_epilogue)
17704 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
17705 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
17709 add_pubname (decl, subr_die);
17712 { /* Generate pubnames entries for the split function code
17714 dw_fde_ref fde = &fde_table[current_funcdef_fde];
17716 if (fde->dw_fde_second_begin)
17718 if (dwarf_version >= 3 || !dwarf_strict)
17720 /* We should use ranges for non-contiguous code section
17721 addresses. Use the actual code range for the initial
17722 section, since the HOT/COLD labels might precede an
17723 alignment offset. */
17724 bool range_list_added = false;
17725 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
17726 fde->dw_fde_end, &range_list_added);
17727 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
17728 fde->dw_fde_second_end,
17729 &range_list_added);
17730 add_pubname (decl, subr_die);
17731 if (range_list_added)
17736 /* There is no real support in DW2 for this .. so we make
17737 a work-around. First, emit the pub name for the segment
17738 containing the function label. Then make and emit a
17739 simplified subprogram DIE for the second segment with the
17740 name pre-fixed by __hot/cold_sect_of_. We use the same
17741 linkage name for the second die so that gdb will find both
17742 sections when given "b foo". */
17743 const char *name = NULL;
17744 tree decl_name = DECL_NAME (decl);
17745 dw_die_ref seg_die;
17747 /* Do the 'primary' section. */
17748 add_AT_lbl_id (subr_die, DW_AT_low_pc,
17749 fde->dw_fde_begin);
17750 add_AT_lbl_id (subr_die, DW_AT_high_pc,
17753 add_pubname (decl, subr_die);
17755 /* Build a minimal DIE for the secondary section. */
17756 seg_die = new_die (DW_TAG_subprogram,
17757 subr_die->die_parent, decl);
17759 if (TREE_PUBLIC (decl))
17760 add_AT_flag (seg_die, DW_AT_external, 1);
17762 if (decl_name != NULL
17763 && IDENTIFIER_POINTER (decl_name) != NULL)
17765 name = dwarf2_name (decl, 1);
17766 if (! DECL_ARTIFICIAL (decl))
17767 add_src_coords_attributes (seg_die, decl);
17769 add_linkage_name (seg_die, decl);
17771 gcc_assert (name != NULL);
17772 add_pure_or_virtual_attribute (seg_die, decl);
17773 if (DECL_ARTIFICIAL (decl))
17774 add_AT_flag (seg_die, DW_AT_artificial, 1);
17776 name = concat ("__second_sect_of_", name, NULL);
17777 add_AT_lbl_id (seg_die, DW_AT_low_pc,
17778 fde->dw_fde_second_begin);
17779 add_AT_lbl_id (seg_die, DW_AT_high_pc,
17780 fde->dw_fde_second_end);
17781 add_name_attribute (seg_die, name);
17782 add_pubname_string (name, seg_die);
17787 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
17788 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
17789 add_pubname (decl, subr_die);
17793 #ifdef MIPS_DEBUGGING_INFO
17794 /* Add a reference to the FDE for this routine. */
17795 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
17798 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
17800 /* We define the "frame base" as the function's CFA. This is more
17801 convenient for several reasons: (1) It's stable across the prologue
17802 and epilogue, which makes it better than just a frame pointer,
17803 (2) With dwarf3, there exists a one-byte encoding that allows us
17804 to reference the .debug_frame data by proxy, but failing that,
17805 (3) We can at least reuse the code inspection and interpretation
17806 code that determines the CFA position at various points in the
17808 if (dwarf_version >= 3)
17810 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
17811 add_AT_loc (subr_die, DW_AT_frame_base, op);
17815 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
17816 if (list->dw_loc_next)
17817 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
17819 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
17822 /* Compute a displacement from the "steady-state frame pointer" to
17823 the CFA. The former is what all stack slots and argument slots
17824 will reference in the rtl; the later is what we've told the
17825 debugger about. We'll need to adjust all frame_base references
17826 by this displacement. */
17827 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
17829 if (cfun->static_chain_decl)
17830 add_AT_location_description (subr_die, DW_AT_static_link,
17831 loc_list_from_tree (cfun->static_chain_decl, 2));
17834 /* Generate child dies for template paramaters. */
17835 if (debug_info_level > DINFO_LEVEL_TERSE)
17836 gen_generic_params_dies (decl);
17838 /* Now output descriptions of the arguments for this function. This gets
17839 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17840 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17841 `...' at the end of the formal parameter list. In order to find out if
17842 there was a trailing ellipsis or not, we must instead look at the type
17843 associated with the FUNCTION_DECL. This will be a node of type
17844 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17845 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17846 an ellipsis at the end. */
17848 /* In the case where we are describing a mere function declaration, all we
17849 need to do here (and all we *can* do here) is to describe the *types* of
17850 its formal parameters. */
17851 if (debug_info_level <= DINFO_LEVEL_TERSE)
17853 else if (declaration)
17854 gen_formal_types_die (decl, subr_die);
17857 /* Generate DIEs to represent all known formal parameters. */
17858 tree parm = DECL_ARGUMENTS (decl);
17859 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
17860 tree generic_decl_parm = generic_decl
17861 ? DECL_ARGUMENTS (generic_decl)
17864 /* Now we want to walk the list of parameters of the function and
17865 emit their relevant DIEs.
17867 We consider the case of DECL being an instance of a generic function
17868 as well as it being a normal function.
17870 If DECL is an instance of a generic function we walk the
17871 parameters of the generic function declaration _and_ the parameters of
17872 DECL itself. This is useful because we want to emit specific DIEs for
17873 function parameter packs and those are declared as part of the
17874 generic function declaration. In that particular case,
17875 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17876 That DIE has children DIEs representing the set of arguments
17877 of the pack. Note that the set of pack arguments can be empty.
17878 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17881 Otherwise, we just consider the parameters of DECL. */
17882 while (generic_decl_parm || parm)
17884 if (generic_decl_parm
17885 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
17886 gen_formal_parameter_pack_die (generic_decl_parm,
17891 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
17893 if (parm == DECL_ARGUMENTS (decl)
17894 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
17896 && (dwarf_version >= 3 || !dwarf_strict))
17897 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
17899 parm = DECL_CHAIN (parm);
17902 if (generic_decl_parm)
17903 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
17906 /* Decide whether we need an unspecified_parameters DIE at the end.
17907 There are 2 more cases to do this for: 1) the ansi ... declaration -
17908 this is detectable when the end of the arg list is not a
17909 void_type_node 2) an unprototyped function declaration (not a
17910 definition). This just means that we have no info about the
17911 parameters at all. */
17912 if (prototype_p (TREE_TYPE (decl)))
17914 /* This is the prototyped case, check for.... */
17915 if (stdarg_p (TREE_TYPE (decl)))
17916 gen_unspecified_parameters_die (decl, subr_die);
17918 else if (DECL_INITIAL (decl) == NULL_TREE)
17919 gen_unspecified_parameters_die (decl, subr_die);
17922 /* Output Dwarf info for all of the stuff within the body of the function
17923 (if it has one - it may be just a declaration). */
17924 outer_scope = DECL_INITIAL (decl);
17926 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17927 a function. This BLOCK actually represents the outermost binding contour
17928 for the function, i.e. the contour in which the function's formal
17929 parameters and labels get declared. Curiously, it appears that the front
17930 end doesn't actually put the PARM_DECL nodes for the current function onto
17931 the BLOCK_VARS list for this outer scope, but are strung off of the
17932 DECL_ARGUMENTS list for the function instead.
17934 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17935 the LABEL_DECL nodes for the function however, and we output DWARF info
17936 for those in decls_for_scope. Just within the `outer_scope' there will be
17937 a BLOCK node representing the function's outermost pair of curly braces,
17938 and any blocks used for the base and member initializers of a C++
17939 constructor function. */
17940 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
17942 int call_site_note_count = 0;
17943 int tail_call_site_note_count = 0;
17945 /* Emit a DW_TAG_variable DIE for a named return value. */
17946 if (DECL_NAME (DECL_RESULT (decl)))
17947 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
17949 current_function_has_inlines = 0;
17950 decls_for_scope (outer_scope, subr_die, 0);
17952 if (call_arg_locations && !dwarf_strict)
17954 struct call_arg_loc_node *ca_loc;
17955 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
17957 dw_die_ref die = NULL;
17958 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
17961 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
17962 arg; arg = next_arg)
17964 dw_loc_descr_ref reg, val;
17965 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
17966 dw_die_ref cdie, tdie = NULL;
17968 next_arg = XEXP (arg, 1);
17969 if (REG_P (XEXP (XEXP (arg, 0), 0))
17971 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
17972 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
17973 && REGNO (XEXP (XEXP (arg, 0), 0))
17974 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
17975 next_arg = XEXP (next_arg, 1);
17976 if (mode == VOIDmode)
17978 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
17979 if (mode == VOIDmode)
17980 mode = GET_MODE (XEXP (arg, 0));
17982 if (mode == VOIDmode || mode == BLKmode)
17984 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
17986 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17987 tloc = XEXP (XEXP (arg, 0), 1);
17990 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
17991 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
17993 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
17994 tlocc = XEXP (XEXP (arg, 0), 1);
17998 if (REG_P (XEXP (XEXP (arg, 0), 0)))
17999 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
18000 VAR_INIT_STATUS_INITIALIZED);
18001 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
18003 rtx mem = XEXP (XEXP (arg, 0), 0);
18004 reg = mem_loc_descriptor (XEXP (mem, 0),
18005 get_address_mode (mem),
18007 VAR_INIT_STATUS_INITIALIZED);
18009 else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
18010 == DEBUG_PARAMETER_REF)
18013 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
18014 tdie = lookup_decl_die (tdecl);
18021 && GET_CODE (XEXP (XEXP (arg, 0), 0))
18022 != DEBUG_PARAMETER_REF)
18024 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
18026 VAR_INIT_STATUS_INITIALIZED);
18030 die = gen_call_site_die (decl, subr_die, ca_loc);
18031 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
18034 add_AT_loc (cdie, DW_AT_location, reg);
18035 else if (tdie != NULL)
18036 add_AT_die_ref (cdie, DW_AT_abstract_origin, tdie);
18037 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
18038 if (next_arg != XEXP (arg, 1))
18040 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
18041 if (mode == VOIDmode)
18042 mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
18043 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
18046 VAR_INIT_STATUS_INITIALIZED);
18048 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
18052 && (ca_loc->symbol_ref || tloc))
18053 die = gen_call_site_die (decl, subr_die, ca_loc);
18054 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
18056 dw_loc_descr_ref tval = NULL;
18058 if (tloc != NULL_RTX)
18059 tval = mem_loc_descriptor (tloc,
18060 GET_MODE (tloc) == VOIDmode
18061 ? Pmode : GET_MODE (tloc),
18063 VAR_INIT_STATUS_INITIALIZED);
18065 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
18066 else if (tlocc != NULL_RTX)
18068 tval = mem_loc_descriptor (tlocc,
18069 GET_MODE (tlocc) == VOIDmode
18070 ? Pmode : GET_MODE (tlocc),
18072 VAR_INIT_STATUS_INITIALIZED);
18074 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
18080 call_site_note_count++;
18081 if (ca_loc->tail_call_p)
18082 tail_call_site_note_count++;
18086 call_arg_locations = NULL;
18087 call_arg_loc_last = NULL;
18088 if (tail_call_site_count >= 0
18089 && tail_call_site_count == tail_call_site_note_count
18092 if (call_site_count >= 0
18093 && call_site_count == call_site_note_count)
18094 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
18096 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
18098 call_site_count = -1;
18099 tail_call_site_count = -1;
18101 /* Add the calling convention attribute if requested. */
18102 add_calling_convention_attribute (subr_die, decl);
18106 /* Returns a hash value for X (which really is a die_struct). */
18109 common_block_die_table_hash (const void *x)
18111 const_dw_die_ref d = (const_dw_die_ref) x;
18112 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
18115 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18116 as decl_id and die_parent of die_struct Y. */
18119 common_block_die_table_eq (const void *x, const void *y)
18121 const_dw_die_ref d = (const_dw_die_ref) x;
18122 const_dw_die_ref e = (const_dw_die_ref) y;
18123 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
18126 /* Generate a DIE to represent a declared data object.
18127 Either DECL or ORIGIN must be non-null. */
18130 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
18134 tree decl_or_origin = decl ? decl : origin;
18135 tree ultimate_origin;
18136 dw_die_ref var_die;
18137 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
18138 dw_die_ref origin_die;
18139 bool declaration = (DECL_EXTERNAL (decl_or_origin)
18140 || class_or_namespace_scope_p (context_die));
18141 bool specialization_p = false;
18143 ultimate_origin = decl_ultimate_origin (decl_or_origin);
18144 if (decl || ultimate_origin)
18145 origin = ultimate_origin;
18146 com_decl = fortran_common (decl_or_origin, &off);
18148 /* Symbol in common gets emitted as a child of the common block, in the form
18149 of a data member. */
18152 dw_die_ref com_die;
18153 dw_loc_list_ref loc;
18154 die_node com_die_arg;
18156 var_die = lookup_decl_die (decl_or_origin);
18159 if (get_AT (var_die, DW_AT_location) == NULL)
18161 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
18166 /* Optimize the common case. */
18167 if (single_element_loc_list_p (loc)
18168 && loc->expr->dw_loc_opc == DW_OP_addr
18169 && loc->expr->dw_loc_next == NULL
18170 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
18172 loc->expr->dw_loc_oprnd1.v.val_addr
18173 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
18175 loc_list_plus_const (loc, off);
18177 add_AT_location_description (var_die, DW_AT_location, loc);
18178 remove_AT (var_die, DW_AT_declaration);
18184 if (common_block_die_table == NULL)
18185 common_block_die_table
18186 = htab_create_ggc (10, common_block_die_table_hash,
18187 common_block_die_table_eq, NULL);
18189 com_die_arg.decl_id = DECL_UID (com_decl);
18190 com_die_arg.die_parent = context_die;
18191 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
18192 loc = loc_list_from_tree (com_decl, 2);
18193 if (com_die == NULL)
18196 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
18199 com_die = new_die (DW_TAG_common_block, context_die, decl);
18200 add_name_and_src_coords_attributes (com_die, com_decl);
18203 add_AT_location_description (com_die, DW_AT_location, loc);
18204 /* Avoid sharing the same loc descriptor between
18205 DW_TAG_common_block and DW_TAG_variable. */
18206 loc = loc_list_from_tree (com_decl, 2);
18208 else if (DECL_EXTERNAL (decl))
18209 add_AT_flag (com_die, DW_AT_declaration, 1);
18210 add_pubname_string (cnam, com_die); /* ??? needed? */
18211 com_die->decl_id = DECL_UID (com_decl);
18212 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
18213 *slot = (void *) com_die;
18215 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
18217 add_AT_location_description (com_die, DW_AT_location, loc);
18218 loc = loc_list_from_tree (com_decl, 2);
18219 remove_AT (com_die, DW_AT_declaration);
18221 var_die = new_die (DW_TAG_variable, com_die, decl);
18222 add_name_and_src_coords_attributes (var_die, decl);
18223 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
18224 TREE_THIS_VOLATILE (decl), context_die);
18225 add_AT_flag (var_die, DW_AT_external, 1);
18230 /* Optimize the common case. */
18231 if (single_element_loc_list_p (loc)
18232 && loc->expr->dw_loc_opc == DW_OP_addr
18233 && loc->expr->dw_loc_next == NULL
18234 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
18235 loc->expr->dw_loc_oprnd1.v.val_addr
18236 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
18238 loc_list_plus_const (loc, off);
18240 add_AT_location_description (var_die, DW_AT_location, loc);
18242 else if (DECL_EXTERNAL (decl))
18243 add_AT_flag (var_die, DW_AT_declaration, 1);
18244 equate_decl_number_to_die (decl, var_die);
18248 /* If the compiler emitted a definition for the DECL declaration
18249 and if we already emitted a DIE for it, don't emit a second
18250 DIE for it again. Allow re-declarations of DECLs that are
18251 inside functions, though. */
18252 if (old_die && declaration && !local_scope_p (context_die))
18255 /* For static data members, the declaration in the class is supposed
18256 to have DW_TAG_member tag; the specification should still be
18257 DW_TAG_variable referencing the DW_TAG_member DIE. */
18258 if (declaration && class_scope_p (context_die))
18259 var_die = new_die (DW_TAG_member, context_die, decl);
18261 var_die = new_die (DW_TAG_variable, context_die, decl);
18264 if (origin != NULL)
18265 origin_die = add_abstract_origin_attribute (var_die, origin);
18267 /* Loop unrolling can create multiple blocks that refer to the same
18268 static variable, so we must test for the DW_AT_declaration flag.
18270 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18271 copy decls and set the DECL_ABSTRACT flag on them instead of
18274 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18276 ??? The declare_in_namespace support causes us to get two DIEs for one
18277 variable, both of which are declarations. We want to avoid considering
18278 one to be a specification, so we must test that this DIE is not a
18280 else if (old_die && TREE_STATIC (decl) && ! declaration
18281 && get_AT_flag (old_die, DW_AT_declaration) == 1)
18283 /* This is a definition of a C++ class level static. */
18284 add_AT_specification (var_die, old_die);
18285 specialization_p = true;
18286 if (DECL_NAME (decl))
18288 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
18289 struct dwarf_file_data * file_index = lookup_filename (s.file);
18291 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
18292 add_AT_file (var_die, DW_AT_decl_file, file_index);
18294 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
18295 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
18297 if (old_die->die_tag == DW_TAG_member)
18298 add_linkage_name (var_die, decl);
18302 add_name_and_src_coords_attributes (var_die, decl);
18304 if ((origin == NULL && !specialization_p)
18306 && !DECL_ABSTRACT (decl_or_origin)
18307 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
18308 decl_function_context
18309 (decl_or_origin))))
18311 tree type = TREE_TYPE (decl_or_origin);
18313 if (decl_by_reference_p (decl_or_origin))
18314 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
18316 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
18317 TREE_THIS_VOLATILE (decl_or_origin), context_die);
18320 if (origin == NULL && !specialization_p)
18322 if (TREE_PUBLIC (decl))
18323 add_AT_flag (var_die, DW_AT_external, 1);
18325 if (DECL_ARTIFICIAL (decl))
18326 add_AT_flag (var_die, DW_AT_artificial, 1);
18328 add_accessibility_attribute (var_die, decl);
18332 add_AT_flag (var_die, DW_AT_declaration, 1);
18334 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
18335 equate_decl_number_to_die (decl, var_die);
18338 && (! DECL_ABSTRACT (decl_or_origin)
18339 /* Local static vars are shared between all clones/inlines,
18340 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18342 || (TREE_CODE (decl_or_origin) == VAR_DECL
18343 && TREE_STATIC (decl_or_origin)
18344 && DECL_RTL_SET_P (decl_or_origin)))
18345 /* When abstract origin already has DW_AT_location attribute, no need
18346 to add it again. */
18347 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
18349 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
18350 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
18351 defer_location (decl_or_origin, var_die);
18353 add_location_or_const_value_attribute (var_die, decl_or_origin,
18354 decl == NULL, DW_AT_location);
18355 add_pubname (decl_or_origin, var_die);
18358 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
18361 /* Generate a DIE to represent a named constant. */
18364 gen_const_die (tree decl, dw_die_ref context_die)
18366 dw_die_ref const_die;
18367 tree type = TREE_TYPE (decl);
18369 const_die = new_die (DW_TAG_constant, context_die, decl);
18370 add_name_and_src_coords_attributes (const_die, decl);
18371 add_type_attribute (const_die, type, 1, 0, context_die);
18372 if (TREE_PUBLIC (decl))
18373 add_AT_flag (const_die, DW_AT_external, 1);
18374 if (DECL_ARTIFICIAL (decl))
18375 add_AT_flag (const_die, DW_AT_artificial, 1);
18376 tree_add_const_value_attribute_for_decl (const_die, decl);
18379 /* Generate a DIE to represent a label identifier. */
18382 gen_label_die (tree decl, dw_die_ref context_die)
18384 tree origin = decl_ultimate_origin (decl);
18385 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
18387 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18389 if (origin != NULL)
18390 add_abstract_origin_attribute (lbl_die, origin);
18392 add_name_and_src_coords_attributes (lbl_die, decl);
18394 if (DECL_ABSTRACT (decl))
18395 equate_decl_number_to_die (decl, lbl_die);
18398 insn = DECL_RTL_IF_SET (decl);
18400 /* Deleted labels are programmer specified labels which have been
18401 eliminated because of various optimizations. We still emit them
18402 here so that it is possible to put breakpoints on them. */
18406 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
18408 /* When optimization is enabled (via -O) some parts of the compiler
18409 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18410 represent source-level labels which were explicitly declared by
18411 the user. This really shouldn't be happening though, so catch
18412 it if it ever does happen. */
18413 gcc_assert (!INSN_DELETED_P (insn));
18415 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
18416 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
18421 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18422 attributes to the DIE for a block STMT, to describe where the inlined
18423 function was called from. This is similar to add_src_coords_attributes. */
18426 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
18428 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
18430 if (dwarf_version >= 3 || !dwarf_strict)
18432 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
18433 add_AT_unsigned (die, DW_AT_call_line, s.line);
18438 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18439 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18442 add_high_low_attributes (tree stmt, dw_die_ref die)
18444 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18446 if (BLOCK_FRAGMENT_CHAIN (stmt)
18447 && (dwarf_version >= 3 || !dwarf_strict))
18451 if (inlined_function_outer_scope_p (stmt))
18453 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
18454 BLOCK_NUMBER (stmt));
18455 add_AT_lbl_id (die, DW_AT_entry_pc, label);
18458 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
18460 chain = BLOCK_FRAGMENT_CHAIN (stmt);
18463 add_ranges (chain);
18464 chain = BLOCK_FRAGMENT_CHAIN (chain);
18471 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
18472 BLOCK_NUMBER (stmt));
18473 add_AT_lbl_id (die, DW_AT_low_pc, label);
18474 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
18475 BLOCK_NUMBER (stmt));
18476 add_AT_lbl_id (die, DW_AT_high_pc, label);
18480 /* Generate a DIE for a lexical block. */
18483 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
18485 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
18487 if (call_arg_locations)
18489 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
18490 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
18491 BLOCK_NUMBER (stmt) + 1);
18492 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
18495 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
18496 add_high_low_attributes (stmt, stmt_die);
18498 decls_for_scope (stmt, stmt_die, depth);
18501 /* Generate a DIE for an inlined subprogram. */
18504 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
18508 /* The instance of function that is effectively being inlined shall not
18510 gcc_assert (! BLOCK_ABSTRACT (stmt));
18512 decl = block_ultimate_origin (stmt);
18514 /* Emit info for the abstract instance first, if we haven't yet. We
18515 must emit this even if the block is abstract, otherwise when we
18516 emit the block below (or elsewhere), we may end up trying to emit
18517 a die whose origin die hasn't been emitted, and crashing. */
18518 dwarf2out_abstract_function (decl);
18520 if (! BLOCK_ABSTRACT (stmt))
18522 dw_die_ref subr_die
18523 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
18525 if (call_arg_locations)
18527 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
18528 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
18529 BLOCK_NUMBER (stmt) + 1);
18530 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
18532 add_abstract_origin_attribute (subr_die, decl);
18533 if (TREE_ASM_WRITTEN (stmt))
18534 add_high_low_attributes (stmt, subr_die);
18535 add_call_src_coords_attributes (stmt, subr_die);
18537 decls_for_scope (stmt, subr_die, depth);
18538 current_function_has_inlines = 1;
18542 /* Generate a DIE for a field in a record, or structure. */
18545 gen_field_die (tree decl, dw_die_ref context_die)
18547 dw_die_ref decl_die;
18549 if (TREE_TYPE (decl) == error_mark_node)
18552 decl_die = new_die (DW_TAG_member, context_die, decl);
18553 add_name_and_src_coords_attributes (decl_die, decl);
18554 add_type_attribute (decl_die, member_declared_type (decl),
18555 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
18558 if (DECL_BIT_FIELD_TYPE (decl))
18560 add_byte_size_attribute (decl_die, decl);
18561 add_bit_size_attribute (decl_die, decl);
18562 add_bit_offset_attribute (decl_die, decl);
18565 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
18566 add_data_member_location_attribute (decl_die, decl);
18568 if (DECL_ARTIFICIAL (decl))
18569 add_AT_flag (decl_die, DW_AT_artificial, 1);
18571 add_accessibility_attribute (decl_die, decl);
18573 /* Equate decl number to die, so that we can look up this decl later on. */
18574 equate_decl_number_to_die (decl, decl_die);
18578 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18579 Use modified_type_die instead.
18580 We keep this code here just in case these types of DIEs may be needed to
18581 represent certain things in other languages (e.g. Pascal) someday. */
18584 gen_pointer_type_die (tree type, dw_die_ref context_die)
18587 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
18589 equate_type_number_to_die (type, ptr_die);
18590 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18591 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18594 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18595 Use modified_type_die instead.
18596 We keep this code here just in case these types of DIEs may be needed to
18597 represent certain things in other languages (e.g. Pascal) someday. */
18600 gen_reference_type_die (tree type, dw_die_ref context_die)
18602 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
18604 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
18605 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
18607 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
18609 equate_type_number_to_die (type, ref_die);
18610 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
18611 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
18615 /* Generate a DIE for a pointer to a member type. */
18618 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
18621 = new_die (DW_TAG_ptr_to_member_type,
18622 scope_die_for (type, context_die), type);
18624 equate_type_number_to_die (type, ptr_die);
18625 add_AT_die_ref (ptr_die, DW_AT_containing_type,
18626 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
18627 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
18630 /* Generate the DIE for the compilation unit. */
18633 gen_compile_unit_die (const char *filename)
18636 char producer[250];
18637 const char *language_string = lang_hooks.name;
18640 die = new_die (DW_TAG_compile_unit, NULL, NULL);
18644 add_name_attribute (die, filename);
18645 /* Don't add cwd for <built-in>. */
18646 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
18647 add_comp_dir_attribute (die);
18650 sprintf (producer, "%s %s", language_string, version_string);
18652 #ifdef MIPS_DEBUGGING_INFO
18653 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
18654 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
18655 not appear in the producer string, the debugger reaches the conclusion
18656 that the object file is stripped and has no debugging information.
18657 To get the MIPS/SGI debugger to believe that there is debugging
18658 information in the object file, we add a -g to the producer string. */
18659 if (debug_info_level > DINFO_LEVEL_TERSE)
18660 strcat (producer, " -g");
18663 add_AT_string (die, DW_AT_producer, producer);
18665 /* If our producer is LTO try to figure out a common language to use
18666 from the global list of translation units. */
18667 if (strcmp (language_string, "GNU GIMPLE") == 0)
18671 const char *common_lang = NULL;
18673 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
18675 if (!TRANSLATION_UNIT_LANGUAGE (t))
18678 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
18679 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
18681 else if (strncmp (common_lang, "GNU C", 5) == 0
18682 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
18683 /* Mixing C and C++ is ok, use C++ in that case. */
18684 common_lang = "GNU C++";
18687 /* Fall back to C. */
18688 common_lang = NULL;
18694 language_string = common_lang;
18697 language = DW_LANG_C89;
18698 if (strcmp (language_string, "GNU C++") == 0)
18699 language = DW_LANG_C_plus_plus;
18700 else if (strcmp (language_string, "GNU F77") == 0)
18701 language = DW_LANG_Fortran77;
18702 else if (strcmp (language_string, "GNU Pascal") == 0)
18703 language = DW_LANG_Pascal83;
18704 else if (dwarf_version >= 3 || !dwarf_strict)
18706 if (strcmp (language_string, "GNU Ada") == 0)
18707 language = DW_LANG_Ada95;
18708 else if (strcmp (language_string, "GNU Fortran") == 0)
18709 language = DW_LANG_Fortran95;
18710 else if (strcmp (language_string, "GNU Java") == 0)
18711 language = DW_LANG_Java;
18712 else if (strcmp (language_string, "GNU Objective-C") == 0)
18713 language = DW_LANG_ObjC;
18714 else if (strcmp (language_string, "GNU Objective-C++") == 0)
18715 language = DW_LANG_ObjC_plus_plus;
18718 add_AT_unsigned (die, DW_AT_language, language);
18722 case DW_LANG_Fortran77:
18723 case DW_LANG_Fortran90:
18724 case DW_LANG_Fortran95:
18725 /* Fortran has case insensitive identifiers and the front-end
18726 lowercases everything. */
18727 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
18730 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18736 /* Generate the DIE for a base class. */
18739 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
18741 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
18743 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
18744 add_data_member_location_attribute (die, binfo);
18746 if (BINFO_VIRTUAL_P (binfo))
18747 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
18749 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18750 children, otherwise the default is DW_ACCESS_public. In DWARF2
18751 the default has always been DW_ACCESS_private. */
18752 if (access == access_public_node)
18754 if (dwarf_version == 2
18755 || context_die->die_tag == DW_TAG_class_type)
18756 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
18758 else if (access == access_protected_node)
18759 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
18760 else if (dwarf_version > 2
18761 && context_die->die_tag != DW_TAG_class_type)
18762 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
18765 /* Generate a DIE for a class member. */
18768 gen_member_die (tree type, dw_die_ref context_die)
18771 tree binfo = TYPE_BINFO (type);
18774 /* If this is not an incomplete type, output descriptions of each of its
18775 members. Note that as we output the DIEs necessary to represent the
18776 members of this record or union type, we will also be trying to output
18777 DIEs to represent the *types* of those members. However the `type'
18778 function (above) will specifically avoid generating type DIEs for member
18779 types *within* the list of member DIEs for this (containing) type except
18780 for those types (of members) which are explicitly marked as also being
18781 members of this (containing) type themselves. The g++ front- end can
18782 force any given type to be treated as a member of some other (containing)
18783 type by setting the TYPE_CONTEXT of the given (member) type to point to
18784 the TREE node representing the appropriate (containing) type. */
18786 /* First output info about the base classes. */
18789 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
18793 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
18794 gen_inheritance_die (base,
18795 (accesses ? VEC_index (tree, accesses, i)
18796 : access_public_node), context_die);
18799 /* Now output info about the data members and type members. */
18800 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
18802 /* If we thought we were generating minimal debug info for TYPE
18803 and then changed our minds, some of the member declarations
18804 may have already been defined. Don't define them again, but
18805 do put them in the right order. */
18807 child = lookup_decl_die (member);
18809 splice_child_die (context_die, child);
18811 gen_decl_die (member, NULL, context_die);
18814 /* Now output info about the function members (if any). */
18815 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
18817 /* Don't include clones in the member list. */
18818 if (DECL_ABSTRACT_ORIGIN (member))
18821 child = lookup_decl_die (member);
18823 splice_child_die (context_die, child);
18825 gen_decl_die (member, NULL, context_die);
18829 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
18830 is set, we pretend that the type was never defined, so we only get the
18831 member DIEs needed by later specification DIEs. */
18834 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
18835 enum debug_info_usage usage)
18837 dw_die_ref type_die = lookup_type_die (type);
18838 dw_die_ref scope_die = 0;
18840 int complete = (TYPE_SIZE (type)
18841 && (! TYPE_STUB_DECL (type)
18842 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
18843 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
18844 complete = complete && should_emit_struct_debug (type, usage);
18846 if (type_die && ! complete)
18849 if (TYPE_CONTEXT (type) != NULL_TREE
18850 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
18851 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
18854 scope_die = scope_die_for (type, context_die);
18856 if (! type_die || (nested && is_cu_die (scope_die)))
18857 /* First occurrence of type or toplevel definition of nested class. */
18859 dw_die_ref old_die = type_die;
18861 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
18862 ? record_type_tag (type) : DW_TAG_union_type,
18864 equate_type_number_to_die (type, type_die);
18866 add_AT_specification (type_die, old_die);
18869 add_name_attribute (type_die, type_tag (type));
18870 add_gnat_descriptive_type_attribute (type_die, type, context_die);
18871 if (TYPE_ARTIFICIAL (type))
18872 add_AT_flag (type_die, DW_AT_artificial, 1);
18876 remove_AT (type_die, DW_AT_declaration);
18878 /* Generate child dies for template paramaters. */
18879 if (debug_info_level > DINFO_LEVEL_TERSE
18880 && COMPLETE_TYPE_P (type))
18881 schedule_generic_params_dies_gen (type);
18883 /* If this type has been completed, then give it a byte_size attribute and
18884 then give a list of members. */
18885 if (complete && !ns_decl)
18887 /* Prevent infinite recursion in cases where the type of some member of
18888 this type is expressed in terms of this type itself. */
18889 TREE_ASM_WRITTEN (type) = 1;
18890 add_byte_size_attribute (type_die, type);
18891 if (TYPE_STUB_DECL (type) != NULL_TREE)
18893 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18894 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18897 /* If the first reference to this type was as the return type of an
18898 inline function, then it may not have a parent. Fix this now. */
18899 if (type_die->die_parent == NULL)
18900 add_child_die (scope_die, type_die);
18902 push_decl_scope (type);
18903 gen_member_die (type, type_die);
18906 /* GNU extension: Record what type our vtable lives in. */
18907 if (TYPE_VFIELD (type))
18909 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
18911 gen_type_die (vtype, context_die);
18912 add_AT_die_ref (type_die, DW_AT_containing_type,
18913 lookup_type_die (vtype));
18918 add_AT_flag (type_die, DW_AT_declaration, 1);
18920 /* We don't need to do this for function-local types. */
18921 if (TYPE_STUB_DECL (type)
18922 && ! decl_function_context (TYPE_STUB_DECL (type)))
18923 VEC_safe_push (tree, gc, incomplete_types, type);
18926 if (get_AT (type_die, DW_AT_name))
18927 add_pubtype (type, type_die);
18930 /* Generate a DIE for a subroutine _type_. */
18933 gen_subroutine_type_die (tree type, dw_die_ref context_die)
18935 tree return_type = TREE_TYPE (type);
18936 dw_die_ref subr_die
18937 = new_die (DW_TAG_subroutine_type,
18938 scope_die_for (type, context_die), type);
18940 equate_type_number_to_die (type, subr_die);
18941 add_prototyped_attribute (subr_die, type);
18942 add_type_attribute (subr_die, return_type, 0, 0, context_die);
18943 gen_formal_types_die (type, subr_die);
18945 if (get_AT (subr_die, DW_AT_name))
18946 add_pubtype (type, subr_die);
18949 /* Generate a DIE for a type definition. */
18952 gen_typedef_die (tree decl, dw_die_ref context_die)
18954 dw_die_ref type_die;
18957 if (TREE_ASM_WRITTEN (decl))
18960 TREE_ASM_WRITTEN (decl) = 1;
18961 type_die = new_die (DW_TAG_typedef, context_die, decl);
18962 origin = decl_ultimate_origin (decl);
18963 if (origin != NULL)
18964 add_abstract_origin_attribute (type_die, origin);
18969 add_name_and_src_coords_attributes (type_die, decl);
18970 if (DECL_ORIGINAL_TYPE (decl))
18972 type = DECL_ORIGINAL_TYPE (decl);
18974 gcc_assert (type != TREE_TYPE (decl));
18975 equate_type_number_to_die (TREE_TYPE (decl), type_die);
18979 type = TREE_TYPE (decl);
18981 if (is_naming_typedef_decl (TYPE_NAME (type)))
18983 /* Here, we are in the case of decl being a typedef naming
18984 an anonymous type, e.g:
18985 typedef struct {...} foo;
18986 In that case TREE_TYPE (decl) is not a typedef variant
18987 type and TYPE_NAME of the anonymous type is set to the
18988 TYPE_DECL of the typedef. This construct is emitted by
18991 TYPE is the anonymous struct named by the typedef
18992 DECL. As we need the DW_AT_type attribute of the
18993 DW_TAG_typedef to point to the DIE of TYPE, let's
18994 generate that DIE right away. add_type_attribute
18995 called below will then pick (via lookup_type_die) that
18996 anonymous struct DIE. */
18997 if (!TREE_ASM_WRITTEN (type))
18998 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
19000 /* This is a GNU Extension. We are adding a
19001 DW_AT_linkage_name attribute to the DIE of the
19002 anonymous struct TYPE. The value of that attribute
19003 is the name of the typedef decl naming the anonymous
19004 struct. This greatly eases the work of consumers of
19005 this debug info. */
19006 add_linkage_attr (lookup_type_die (type), decl);
19010 add_type_attribute (type_die, type, TREE_READONLY (decl),
19011 TREE_THIS_VOLATILE (decl), context_die);
19013 if (is_naming_typedef_decl (decl))
19014 /* We want that all subsequent calls to lookup_type_die with
19015 TYPE in argument yield the DW_TAG_typedef we have just
19017 equate_type_number_to_die (type, type_die);
19019 add_accessibility_attribute (type_die, decl);
19022 if (DECL_ABSTRACT (decl))
19023 equate_decl_number_to_die (decl, type_die);
19025 if (get_AT (type_die, DW_AT_name))
19026 add_pubtype (decl, type_die);
19029 /* Generate a DIE for a struct, class, enum or union type. */
19032 gen_tagged_type_die (tree type,
19033 dw_die_ref context_die,
19034 enum debug_info_usage usage)
19038 if (type == NULL_TREE
19039 || !is_tagged_type (type))
19042 /* If this is a nested type whose containing class hasn't been written
19043 out yet, writing it out will cover this one, too. This does not apply
19044 to instantiations of member class templates; they need to be added to
19045 the containing class as they are generated. FIXME: This hurts the
19046 idea of combining type decls from multiple TUs, since we can't predict
19047 what set of template instantiations we'll get. */
19048 if (TYPE_CONTEXT (type)
19049 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
19050 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
19052 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
19054 if (TREE_ASM_WRITTEN (type))
19057 /* If that failed, attach ourselves to the stub. */
19058 push_decl_scope (TYPE_CONTEXT (type));
19059 context_die = lookup_type_die (TYPE_CONTEXT (type));
19062 else if (TYPE_CONTEXT (type) != NULL_TREE
19063 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
19065 /* If this type is local to a function that hasn't been written
19066 out yet, use a NULL context for now; it will be fixed up in
19067 decls_for_scope. */
19068 context_die = lookup_decl_die (TYPE_CONTEXT (type));
19069 /* A declaration DIE doesn't count; nested types need to go in the
19071 if (context_die && is_declaration_die (context_die))
19072 context_die = NULL;
19077 context_die = declare_in_namespace (type, context_die);
19081 if (TREE_CODE (type) == ENUMERAL_TYPE)
19083 /* This might have been written out by the call to
19084 declare_in_namespace. */
19085 if (!TREE_ASM_WRITTEN (type))
19086 gen_enumeration_type_die (type, context_die);
19089 gen_struct_or_union_type_die (type, context_die, usage);
19094 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19095 it up if it is ever completed. gen_*_type_die will set it for us
19096 when appropriate. */
19099 /* Generate a type description DIE. */
19102 gen_type_die_with_usage (tree type, dw_die_ref context_die,
19103 enum debug_info_usage usage)
19105 struct array_descr_info info;
19107 if (type == NULL_TREE || type == error_mark_node)
19110 if (TYPE_NAME (type) != NULL_TREE
19111 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
19112 && is_redundant_typedef (TYPE_NAME (type))
19113 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
19114 /* The DECL of this type is a typedef we don't want to emit debug
19115 info for but we want debug info for its underlying typedef.
19116 This can happen for e.g, the injected-class-name of a C++
19118 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
19120 /* If TYPE is a typedef type variant, let's generate debug info
19121 for the parent typedef which TYPE is a type of. */
19122 if (typedef_variant_p (type))
19124 if (TREE_ASM_WRITTEN (type))
19127 /* Prevent broken recursion; we can't hand off to the same type. */
19128 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
19130 /* Use the DIE of the containing namespace as the parent DIE of
19131 the type description DIE we want to generate. */
19132 if (DECL_CONTEXT (TYPE_NAME (type))
19133 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
19134 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
19136 TREE_ASM_WRITTEN (type) = 1;
19138 gen_decl_die (TYPE_NAME (type), NULL, context_die);
19142 /* If type is an anonymous tagged type named by a typedef, let's
19143 generate debug info for the typedef. */
19144 if (is_naming_typedef_decl (TYPE_NAME (type)))
19146 /* Use the DIE of the containing namespace as the parent DIE of
19147 the type description DIE we want to generate. */
19148 if (DECL_CONTEXT (TYPE_NAME (type))
19149 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
19150 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
19152 gen_decl_die (TYPE_NAME (type), NULL, context_die);
19156 /* If this is an array type with hidden descriptor, handle it first. */
19157 if (!TREE_ASM_WRITTEN (type)
19158 && lang_hooks.types.get_array_descr_info
19159 && lang_hooks.types.get_array_descr_info (type, &info)
19160 && (dwarf_version >= 3 || !dwarf_strict))
19162 gen_descr_array_type_die (type, &info, context_die);
19163 TREE_ASM_WRITTEN (type) = 1;
19167 /* We are going to output a DIE to represent the unqualified version
19168 of this type (i.e. without any const or volatile qualifiers) so
19169 get the main variant (i.e. the unqualified version) of this type
19170 now. (Vectors are special because the debugging info is in the
19171 cloned type itself). */
19172 if (TREE_CODE (type) != VECTOR_TYPE)
19173 type = type_main_variant (type);
19175 if (TREE_ASM_WRITTEN (type))
19178 switch (TREE_CODE (type))
19184 case REFERENCE_TYPE:
19185 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19186 ensures that the gen_type_die recursion will terminate even if the
19187 type is recursive. Recursive types are possible in Ada. */
19188 /* ??? We could perhaps do this for all types before the switch
19190 TREE_ASM_WRITTEN (type) = 1;
19192 /* For these types, all that is required is that we output a DIE (or a
19193 set of DIEs) to represent the "basis" type. */
19194 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19195 DINFO_USAGE_IND_USE);
19199 /* This code is used for C++ pointer-to-data-member types.
19200 Output a description of the relevant class type. */
19201 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
19202 DINFO_USAGE_IND_USE);
19204 /* Output a description of the type of the object pointed to. */
19205 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19206 DINFO_USAGE_IND_USE);
19208 /* Now output a DIE to represent this pointer-to-data-member type
19210 gen_ptr_to_mbr_type_die (type, context_die);
19213 case FUNCTION_TYPE:
19214 /* Force out return type (in case it wasn't forced out already). */
19215 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19216 DINFO_USAGE_DIR_USE);
19217 gen_subroutine_type_die (type, context_die);
19221 /* Force out return type (in case it wasn't forced out already). */
19222 gen_type_die_with_usage (TREE_TYPE (type), context_die,
19223 DINFO_USAGE_DIR_USE);
19224 gen_subroutine_type_die (type, context_die);
19228 gen_array_type_die (type, context_die);
19232 gen_array_type_die (type, context_die);
19235 case ENUMERAL_TYPE:
19238 case QUAL_UNION_TYPE:
19239 gen_tagged_type_die (type, context_die, usage);
19245 case FIXED_POINT_TYPE:
19248 /* No DIEs needed for fundamental types. */
19253 /* Just use DW_TAG_unspecified_type. */
19255 dw_die_ref type_die = lookup_type_die (type);
19256 if (type_die == NULL)
19258 tree name = TYPE_NAME (type);
19259 if (TREE_CODE (name) == TYPE_DECL)
19260 name = DECL_NAME (name);
19261 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
19262 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
19263 equate_type_number_to_die (type, type_die);
19269 gcc_unreachable ();
19272 TREE_ASM_WRITTEN (type) = 1;
19276 gen_type_die (tree type, dw_die_ref context_die)
19278 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
19281 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19282 things which are local to the given block. */
19285 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
19287 int must_output_die = 0;
19290 /* Ignore blocks that are NULL. */
19291 if (stmt == NULL_TREE)
19294 inlined_func = inlined_function_outer_scope_p (stmt);
19296 /* If the block is one fragment of a non-contiguous block, do not
19297 process the variables, since they will have been done by the
19298 origin block. Do process subblocks. */
19299 if (BLOCK_FRAGMENT_ORIGIN (stmt))
19303 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
19304 gen_block_die (sub, context_die, depth + 1);
19309 /* Determine if we need to output any Dwarf DIEs at all to represent this
19312 /* The outer scopes for inlinings *must* always be represented. We
19313 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19314 must_output_die = 1;
19317 /* Determine if this block directly contains any "significant"
19318 local declarations which we will need to output DIEs for. */
19319 if (debug_info_level > DINFO_LEVEL_TERSE)
19320 /* We are not in terse mode so *any* local declaration counts
19321 as being a "significant" one. */
19322 must_output_die = ((BLOCK_VARS (stmt) != NULL
19323 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
19324 && (TREE_USED (stmt)
19325 || TREE_ASM_WRITTEN (stmt)
19326 || BLOCK_ABSTRACT (stmt)));
19327 else if ((TREE_USED (stmt)
19328 || TREE_ASM_WRITTEN (stmt)
19329 || BLOCK_ABSTRACT (stmt))
19330 && !dwarf2out_ignore_block (stmt))
19331 must_output_die = 1;
19334 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19335 DIE for any block which contains no significant local declarations at
19336 all. Rather, in such cases we just call `decls_for_scope' so that any
19337 needed Dwarf info for any sub-blocks will get properly generated. Note
19338 that in terse mode, our definition of what constitutes a "significant"
19339 local declaration gets restricted to include only inlined function
19340 instances and local (nested) function definitions. */
19341 if (must_output_die)
19345 /* If STMT block is abstract, that means we have been called
19346 indirectly from dwarf2out_abstract_function.
19347 That function rightfully marks the descendent blocks (of
19348 the abstract function it is dealing with) as being abstract,
19349 precisely to prevent us from emitting any
19350 DW_TAG_inlined_subroutine DIE as a descendent
19351 of an abstract function instance. So in that case, we should
19352 not call gen_inlined_subroutine_die.
19354 Later though, when cgraph asks dwarf2out to emit info
19355 for the concrete instance of the function decl into which
19356 the concrete instance of STMT got inlined, the later will lead
19357 to the generation of a DW_TAG_inlined_subroutine DIE. */
19358 if (! BLOCK_ABSTRACT (stmt))
19359 gen_inlined_subroutine_die (stmt, context_die, depth);
19362 gen_lexical_block_die (stmt, context_die, depth);
19365 decls_for_scope (stmt, context_die, depth);
19368 /* Process variable DECL (or variable with origin ORIGIN) within
19369 block STMT and add it to CONTEXT_DIE. */
19371 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
19374 tree decl_or_origin = decl ? decl : origin;
19376 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
19377 die = lookup_decl_die (decl_or_origin);
19378 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
19379 && TYPE_DECL_IS_STUB (decl_or_origin))
19380 die = lookup_type_die (TREE_TYPE (decl_or_origin));
19384 if (die != NULL && die->die_parent == NULL)
19385 add_child_die (context_die, die);
19386 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
19387 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
19388 stmt, context_die);
19390 gen_decl_die (decl, origin, context_die);
19393 /* Generate all of the decls declared within a given scope and (recursively)
19394 all of its sub-blocks. */
19397 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
19403 /* Ignore NULL blocks. */
19404 if (stmt == NULL_TREE)
19407 /* Output the DIEs to represent all of the data objects and typedefs
19408 declared directly within this block but not within any nested
19409 sub-blocks. Also, nested function and tag DIEs have been
19410 generated with a parent of NULL; fix that up now. */
19411 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
19412 process_scope_var (stmt, decl, NULL_TREE, context_die);
19413 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
19414 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
19417 /* If we're at -g1, we're not interested in subblocks. */
19418 if (debug_info_level <= DINFO_LEVEL_TERSE)
19421 /* Output the DIEs to represent all sub-blocks (and the items declared
19422 therein) of this block. */
19423 for (subblocks = BLOCK_SUBBLOCKS (stmt);
19425 subblocks = BLOCK_CHAIN (subblocks))
19426 gen_block_die (subblocks, context_die, depth + 1);
19429 /* Is this a typedef we can avoid emitting? */
19432 is_redundant_typedef (const_tree decl)
19434 if (TYPE_DECL_IS_STUB (decl))
19437 if (DECL_ARTIFICIAL (decl)
19438 && DECL_CONTEXT (decl)
19439 && is_tagged_type (DECL_CONTEXT (decl))
19440 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
19441 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
19442 /* Also ignore the artificial member typedef for the class name. */
19448 /* Return TRUE if TYPE is a typedef that names a type for linkage
19449 purposes. This kind of typedefs is produced by the C++ FE for
19452 typedef struct {...} foo;
19454 In that case, there is no typedef variant type produced for foo.
19455 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19459 is_naming_typedef_decl (const_tree decl)
19461 if (decl == NULL_TREE
19462 || TREE_CODE (decl) != TYPE_DECL
19463 || !is_tagged_type (TREE_TYPE (decl))
19464 || DECL_IS_BUILTIN (decl)
19465 || is_redundant_typedef (decl)
19466 /* It looks like Ada produces TYPE_DECLs that are very similar
19467 to C++ naming typedefs but that have different
19468 semantics. Let's be specific to c++ for now. */
19472 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
19473 && TYPE_NAME (TREE_TYPE (decl)) == decl
19474 && (TYPE_STUB_DECL (TREE_TYPE (decl))
19475 != TYPE_NAME (TREE_TYPE (decl))));
19478 /* Returns the DIE for a context. */
19480 static inline dw_die_ref
19481 get_context_die (tree context)
19485 /* Find die that represents this context. */
19486 if (TYPE_P (context))
19488 context = TYPE_MAIN_VARIANT (context);
19489 return strip_naming_typedef (context, force_type_die (context));
19492 return force_decl_die (context);
19494 return comp_unit_die ();
19497 /* Returns the DIE for decl. A DIE will always be returned. */
19500 force_decl_die (tree decl)
19502 dw_die_ref decl_die;
19503 unsigned saved_external_flag;
19504 tree save_fn = NULL_TREE;
19505 decl_die = lookup_decl_die (decl);
19508 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
19510 decl_die = lookup_decl_die (decl);
19514 switch (TREE_CODE (decl))
19516 case FUNCTION_DECL:
19517 /* Clear current_function_decl, so that gen_subprogram_die thinks
19518 that this is a declaration. At this point, we just want to force
19519 declaration die. */
19520 save_fn = current_function_decl;
19521 current_function_decl = NULL_TREE;
19522 gen_subprogram_die (decl, context_die);
19523 current_function_decl = save_fn;
19527 /* Set external flag to force declaration die. Restore it after
19528 gen_decl_die() call. */
19529 saved_external_flag = DECL_EXTERNAL (decl);
19530 DECL_EXTERNAL (decl) = 1;
19531 gen_decl_die (decl, NULL, context_die);
19532 DECL_EXTERNAL (decl) = saved_external_flag;
19535 case NAMESPACE_DECL:
19536 if (dwarf_version >= 3 || !dwarf_strict)
19537 dwarf2out_decl (decl);
19539 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19540 decl_die = comp_unit_die ();
19543 case TRANSLATION_UNIT_DECL:
19544 decl_die = comp_unit_die ();
19548 gcc_unreachable ();
19551 /* We should be able to find the DIE now. */
19553 decl_die = lookup_decl_die (decl);
19554 gcc_assert (decl_die);
19560 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19561 always returned. */
19564 force_type_die (tree type)
19566 dw_die_ref type_die;
19568 type_die = lookup_type_die (type);
19571 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
19573 type_die = modified_type_die (type, TYPE_READONLY (type),
19574 TYPE_VOLATILE (type), context_die);
19575 gcc_assert (type_die);
19580 /* Force out any required namespaces to be able to output DECL,
19581 and return the new context_die for it, if it's changed. */
19584 setup_namespace_context (tree thing, dw_die_ref context_die)
19586 tree context = (DECL_P (thing)
19587 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
19588 if (context && TREE_CODE (context) == NAMESPACE_DECL)
19589 /* Force out the namespace. */
19590 context_die = force_decl_die (context);
19592 return context_die;
19595 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19596 type) within its namespace, if appropriate.
19598 For compatibility with older debuggers, namespace DIEs only contain
19599 declarations; all definitions are emitted at CU scope. */
19602 declare_in_namespace (tree thing, dw_die_ref context_die)
19604 dw_die_ref ns_context;
19606 if (debug_info_level <= DINFO_LEVEL_TERSE)
19607 return context_die;
19609 /* If this decl is from an inlined function, then don't try to emit it in its
19610 namespace, as we will get confused. It would have already been emitted
19611 when the abstract instance of the inline function was emitted anyways. */
19612 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
19613 return context_die;
19615 ns_context = setup_namespace_context (thing, context_die);
19617 if (ns_context != context_die)
19621 if (DECL_P (thing))
19622 gen_decl_die (thing, NULL, ns_context);
19624 gen_type_die (thing, ns_context);
19626 return context_die;
19629 /* Generate a DIE for a namespace or namespace alias. */
19632 gen_namespace_die (tree decl, dw_die_ref context_die)
19634 dw_die_ref namespace_die;
19636 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19637 they are an alias of. */
19638 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
19640 /* Output a real namespace or module. */
19641 context_die = setup_namespace_context (decl, comp_unit_die ());
19642 namespace_die = new_die (is_fortran ()
19643 ? DW_TAG_module : DW_TAG_namespace,
19644 context_die, decl);
19645 /* For Fortran modules defined in different CU don't add src coords. */
19646 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
19648 const char *name = dwarf2_name (decl, 0);
19650 add_name_attribute (namespace_die, name);
19653 add_name_and_src_coords_attributes (namespace_die, decl);
19654 if (DECL_EXTERNAL (decl))
19655 add_AT_flag (namespace_die, DW_AT_declaration, 1);
19656 equate_decl_number_to_die (decl, namespace_die);
19660 /* Output a namespace alias. */
19662 /* Force out the namespace we are an alias of, if necessary. */
19663 dw_die_ref origin_die
19664 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
19666 if (DECL_FILE_SCOPE_P (decl)
19667 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
19668 context_die = setup_namespace_context (decl, comp_unit_die ());
19669 /* Now create the namespace alias DIE. */
19670 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
19671 add_name_and_src_coords_attributes (namespace_die, decl);
19672 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
19673 equate_decl_number_to_die (decl, namespace_die);
19677 /* Generate Dwarf debug information for a decl described by DECL.
19678 The return value is currently only meaningful for PARM_DECLs,
19679 for all other decls it returns NULL. */
19682 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
19684 tree decl_or_origin = decl ? decl : origin;
19685 tree class_origin = NULL, ultimate_origin;
19687 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
19690 switch (TREE_CODE (decl_or_origin))
19696 if (!is_fortran () && !is_ada ())
19698 /* The individual enumerators of an enum type get output when we output
19699 the Dwarf representation of the relevant enum type itself. */
19703 /* Emit its type. */
19704 gen_type_die (TREE_TYPE (decl), context_die);
19706 /* And its containing namespace. */
19707 context_die = declare_in_namespace (decl, context_die);
19709 gen_const_die (decl, context_die);
19712 case FUNCTION_DECL:
19713 /* Don't output any DIEs to represent mere function declarations,
19714 unless they are class members or explicit block externs. */
19715 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
19716 && DECL_FILE_SCOPE_P (decl_or_origin)
19717 && (current_function_decl == NULL_TREE
19718 || DECL_ARTIFICIAL (decl_or_origin)))
19723 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19724 on local redeclarations of global functions. That seems broken. */
19725 if (current_function_decl != decl)
19726 /* This is only a declaration. */;
19729 /* If we're emitting a clone, emit info for the abstract instance. */
19730 if (origin || DECL_ORIGIN (decl) != decl)
19731 dwarf2out_abstract_function (origin
19732 ? DECL_ORIGIN (origin)
19733 : DECL_ABSTRACT_ORIGIN (decl));
19735 /* If we're emitting an out-of-line copy of an inline function,
19736 emit info for the abstract instance and set up to refer to it. */
19737 else if (cgraph_function_possibly_inlined_p (decl)
19738 && ! DECL_ABSTRACT (decl)
19739 && ! class_or_namespace_scope_p (context_die)
19740 /* dwarf2out_abstract_function won't emit a die if this is just
19741 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19742 that case, because that works only if we have a die. */
19743 && DECL_INITIAL (decl) != NULL_TREE)
19745 dwarf2out_abstract_function (decl);
19746 set_decl_origin_self (decl);
19749 /* Otherwise we're emitting the primary DIE for this decl. */
19750 else if (debug_info_level > DINFO_LEVEL_TERSE)
19752 /* Before we describe the FUNCTION_DECL itself, make sure that we
19753 have its containing type. */
19755 origin = decl_class_context (decl);
19756 if (origin != NULL_TREE)
19757 gen_type_die (origin, context_die);
19759 /* And its return type. */
19760 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
19762 /* And its virtual context. */
19763 if (DECL_VINDEX (decl) != NULL_TREE)
19764 gen_type_die (DECL_CONTEXT (decl), context_die);
19766 /* Make sure we have a member DIE for decl. */
19767 if (origin != NULL_TREE)
19768 gen_type_die_for_member (origin, decl, context_die);
19770 /* And its containing namespace. */
19771 context_die = declare_in_namespace (decl, context_die);
19774 /* Now output a DIE to represent the function itself. */
19776 gen_subprogram_die (decl, context_die);
19780 /* If we are in terse mode, don't generate any DIEs to represent any
19781 actual typedefs. */
19782 if (debug_info_level <= DINFO_LEVEL_TERSE)
19785 /* In the special case of a TYPE_DECL node representing the declaration
19786 of some type tag, if the given TYPE_DECL is marked as having been
19787 instantiated from some other (original) TYPE_DECL node (e.g. one which
19788 was generated within the original definition of an inline function) we
19789 used to generate a special (abbreviated) DW_TAG_structure_type,
19790 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19791 should be actually referencing those DIEs, as variable DIEs with that
19792 type would be emitted already in the abstract origin, so it was always
19793 removed during unused type prunning. Don't add anything in this
19795 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
19798 if (is_redundant_typedef (decl))
19799 gen_type_die (TREE_TYPE (decl), context_die);
19801 /* Output a DIE to represent the typedef itself. */
19802 gen_typedef_die (decl, context_die);
19806 if (debug_info_level >= DINFO_LEVEL_NORMAL)
19807 gen_label_die (decl, context_die);
19812 /* If we are in terse mode, don't generate any DIEs to represent any
19813 variable declarations or definitions. */
19814 if (debug_info_level <= DINFO_LEVEL_TERSE)
19817 /* Output any DIEs that are needed to specify the type of this data
19819 if (decl_by_reference_p (decl_or_origin))
19820 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19822 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19824 /* And its containing type. */
19825 class_origin = decl_class_context (decl_or_origin);
19826 if (class_origin != NULL_TREE)
19827 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
19829 /* And its containing namespace. */
19830 context_die = declare_in_namespace (decl_or_origin, context_die);
19832 /* Now output the DIE to represent the data object itself. This gets
19833 complicated because of the possibility that the VAR_DECL really
19834 represents an inlined instance of a formal parameter for an inline
19836 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19837 if (ultimate_origin != NULL_TREE
19838 && TREE_CODE (ultimate_origin) == PARM_DECL)
19839 gen_formal_parameter_die (decl, origin,
19840 true /* Emit name attribute. */,
19843 gen_variable_die (decl, origin, context_die);
19847 /* Ignore the nameless fields that are used to skip bits but handle C++
19848 anonymous unions and structs. */
19849 if (DECL_NAME (decl) != NULL_TREE
19850 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
19851 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
19853 gen_type_die (member_declared_type (decl), context_die);
19854 gen_field_die (decl, context_die);
19859 if (DECL_BY_REFERENCE (decl_or_origin))
19860 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
19862 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
19863 return gen_formal_parameter_die (decl, origin,
19864 true /* Emit name attribute. */,
19867 case NAMESPACE_DECL:
19868 case IMPORTED_DECL:
19869 if (dwarf_version >= 3 || !dwarf_strict)
19870 gen_namespace_die (decl, context_die);
19874 /* Probably some frontend-internal decl. Assume we don't care. */
19875 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
19882 /* Output debug information for global decl DECL. Called from toplev.c after
19883 compilation proper has finished. */
19886 dwarf2out_global_decl (tree decl)
19888 /* Output DWARF2 information for file-scope tentative data object
19889 declarations, file-scope (extern) function declarations (which
19890 had no corresponding body) and file-scope tagged type declarations
19891 and definitions which have not yet been forced out. */
19892 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
19893 dwarf2out_decl (decl);
19896 /* Output debug information for type decl DECL. Called from toplev.c
19897 and from language front ends (to record built-in types). */
19899 dwarf2out_type_decl (tree decl, int local)
19902 dwarf2out_decl (decl);
19905 /* Output debug information for imported module or decl DECL.
19906 NAME is non-NULL name in the lexical block if the decl has been renamed.
19907 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
19908 that DECL belongs to.
19909 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
19911 dwarf2out_imported_module_or_decl_1 (tree decl,
19913 tree lexical_block,
19914 dw_die_ref lexical_block_die)
19916 expanded_location xloc;
19917 dw_die_ref imported_die = NULL;
19918 dw_die_ref at_import_die;
19920 if (TREE_CODE (decl) == IMPORTED_DECL)
19922 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
19923 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
19927 xloc = expand_location (input_location);
19929 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
19931 at_import_die = force_type_die (TREE_TYPE (decl));
19932 /* For namespace N { typedef void T; } using N::T; base_type_die
19933 returns NULL, but DW_TAG_imported_declaration requires
19934 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
19935 if (!at_import_die)
19937 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
19938 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
19939 at_import_die = lookup_type_die (TREE_TYPE (decl));
19940 gcc_assert (at_import_die);
19945 at_import_die = lookup_decl_die (decl);
19946 if (!at_import_die)
19948 /* If we're trying to avoid duplicate debug info, we may not have
19949 emitted the member decl for this field. Emit it now. */
19950 if (TREE_CODE (decl) == FIELD_DECL)
19952 tree type = DECL_CONTEXT (decl);
19954 if (TYPE_CONTEXT (type)
19955 && TYPE_P (TYPE_CONTEXT (type))
19956 && !should_emit_struct_debug (TYPE_CONTEXT (type),
19957 DINFO_USAGE_DIR_USE))
19959 gen_type_die_for_member (type, decl,
19960 get_context_die (TYPE_CONTEXT (type)));
19962 at_import_die = force_decl_die (decl);
19966 if (TREE_CODE (decl) == NAMESPACE_DECL)
19968 if (dwarf_version >= 3 || !dwarf_strict)
19969 imported_die = new_die (DW_TAG_imported_module,
19976 imported_die = new_die (DW_TAG_imported_declaration,
19980 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
19981 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
19983 add_AT_string (imported_die, DW_AT_name,
19984 IDENTIFIER_POINTER (name));
19985 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
19988 /* Output debug information for imported module or decl DECL.
19989 NAME is non-NULL name in context if the decl has been renamed.
19990 CHILD is true if decl is one of the renamed decls as part of
19991 importing whole module. */
19994 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
19997 /* dw_die_ref at_import_die; */
19998 dw_die_ref scope_die;
20000 if (debug_info_level <= DINFO_LEVEL_TERSE)
20005 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20006 We need decl DIE for reference and scope die. First, get DIE for the decl
20009 /* Get the scope die for decl context. Use comp_unit_die for global module
20010 or decl. If die is not found for non globals, force new die. */
20012 && TYPE_P (context)
20013 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
20016 if (!(dwarf_version >= 3 || !dwarf_strict))
20019 scope_die = get_context_die (context);
20023 gcc_assert (scope_die->die_child);
20024 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
20025 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
20026 scope_die = scope_die->die_child;
20029 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20030 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
20034 /* Write the debugging output for DECL. */
20037 dwarf2out_decl (tree decl)
20039 dw_die_ref context_die = comp_unit_die ();
20041 switch (TREE_CODE (decl))
20046 case FUNCTION_DECL:
20047 /* What we would really like to do here is to filter out all mere
20048 file-scope declarations of file-scope functions which are never
20049 referenced later within this translation unit (and keep all of ones
20050 that *are* referenced later on) but we aren't clairvoyant, so we have
20051 no idea which functions will be referenced in the future (i.e. later
20052 on within the current translation unit). So here we just ignore all
20053 file-scope function declarations which are not also definitions. If
20054 and when the debugger needs to know something about these functions,
20055 it will have to hunt around and find the DWARF information associated
20056 with the definition of the function.
20058 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20059 nodes represent definitions and which ones represent mere
20060 declarations. We have to check DECL_INITIAL instead. That's because
20061 the C front-end supports some weird semantics for "extern inline"
20062 function definitions. These can get inlined within the current
20063 translation unit (and thus, we need to generate Dwarf info for their
20064 abstract instances so that the Dwarf info for the concrete inlined
20065 instances can have something to refer to) but the compiler never
20066 generates any out-of-lines instances of such things (despite the fact
20067 that they *are* definitions).
20069 The important point is that the C front-end marks these "extern
20070 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20071 them anyway. Note that the C++ front-end also plays some similar games
20072 for inline function definitions appearing within include files which
20073 also contain `#pragma interface' pragmas. */
20074 if (DECL_INITIAL (decl) == NULL_TREE)
20077 /* If we're a nested function, initially use a parent of NULL; if we're
20078 a plain function, this will be fixed up in decls_for_scope. If
20079 we're a method, it will be ignored, since we already have a DIE. */
20080 if (decl_function_context (decl)
20081 /* But if we're in terse mode, we don't care about scope. */
20082 && debug_info_level > DINFO_LEVEL_TERSE)
20083 context_die = NULL;
20087 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20088 declaration and if the declaration was never even referenced from
20089 within this entire compilation unit. We suppress these DIEs in
20090 order to save space in the .debug section (by eliminating entries
20091 which are probably useless). Note that we must not suppress
20092 block-local extern declarations (whether used or not) because that
20093 would screw-up the debugger's name lookup mechanism and cause it to
20094 miss things which really ought to be in scope at a given point. */
20095 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
20098 /* For local statics lookup proper context die. */
20099 if (TREE_STATIC (decl) && decl_function_context (decl))
20100 context_die = lookup_decl_die (DECL_CONTEXT (decl));
20102 /* If we are in terse mode, don't generate any DIEs to represent any
20103 variable declarations or definitions. */
20104 if (debug_info_level <= DINFO_LEVEL_TERSE)
20109 if (debug_info_level <= DINFO_LEVEL_TERSE)
20111 if (!is_fortran () && !is_ada ())
20113 if (TREE_STATIC (decl) && decl_function_context (decl))
20114 context_die = lookup_decl_die (DECL_CONTEXT (decl));
20117 case NAMESPACE_DECL:
20118 case IMPORTED_DECL:
20119 if (debug_info_level <= DINFO_LEVEL_TERSE)
20121 if (lookup_decl_die (decl) != NULL)
20126 /* Don't emit stubs for types unless they are needed by other DIEs. */
20127 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
20130 /* Don't bother trying to generate any DIEs to represent any of the
20131 normal built-in types for the language we are compiling. */
20132 if (DECL_IS_BUILTIN (decl))
20135 /* If we are in terse mode, don't generate any DIEs for types. */
20136 if (debug_info_level <= DINFO_LEVEL_TERSE)
20139 /* If we're a function-scope tag, initially use a parent of NULL;
20140 this will be fixed up in decls_for_scope. */
20141 if (decl_function_context (decl))
20142 context_die = NULL;
20150 gen_decl_die (decl, NULL, context_die);
20153 /* Write the debugging output for DECL. */
20156 dwarf2out_function_decl (tree decl)
20158 dwarf2out_decl (decl);
20159 call_arg_locations = NULL;
20160 call_arg_loc_last = NULL;
20161 call_site_count = -1;
20162 tail_call_site_count = -1;
20163 VEC_free (dw_die_ref, heap, block_map);
20164 htab_empty (decl_loc_table);
20165 htab_empty (cached_dw_loc_list_table);
20168 /* Output a marker (i.e. a label) for the beginning of the generated code for
20169 a lexical block. */
20172 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
20173 unsigned int blocknum)
20175 switch_to_section (current_function_section ());
20176 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
20179 /* Output a marker (i.e. a label) for the end of the generated code for a
20183 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
20185 switch_to_section (current_function_section ());
20186 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
20189 /* Returns nonzero if it is appropriate not to emit any debugging
20190 information for BLOCK, because it doesn't contain any instructions.
20192 Don't allow this for blocks with nested functions or local classes
20193 as we would end up with orphans, and in the presence of scheduling
20194 we may end up calling them anyway. */
20197 dwarf2out_ignore_block (const_tree block)
20202 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
20203 if (TREE_CODE (decl) == FUNCTION_DECL
20204 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
20206 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
20208 decl = BLOCK_NONLOCALIZED_VAR (block, i);
20209 if (TREE_CODE (decl) == FUNCTION_DECL
20210 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
20217 /* Hash table routines for file_hash. */
20220 file_table_eq (const void *p1_p, const void *p2_p)
20222 const struct dwarf_file_data *const p1 =
20223 (const struct dwarf_file_data *) p1_p;
20224 const char *const p2 = (const char *) p2_p;
20225 return filename_cmp (p1->filename, p2) == 0;
20229 file_table_hash (const void *p_p)
20231 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
20232 return htab_hash_string (p->filename);
20235 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20236 dwarf2out.c) and return its "index". The index of each (known) filename is
20237 just a unique number which is associated with only that one filename. We
20238 need such numbers for the sake of generating labels (in the .debug_sfnames
20239 section) and references to those files numbers (in the .debug_srcinfo
20240 and.debug_macinfo sections). If the filename given as an argument is not
20241 found in our current list, add it to the list and assign it the next
20242 available unique index number. In order to speed up searches, we remember
20243 the index of the filename was looked up last. This handles the majority of
20246 static struct dwarf_file_data *
20247 lookup_filename (const char *file_name)
20250 struct dwarf_file_data * created;
20252 /* Check to see if the file name that was searched on the previous
20253 call matches this file name. If so, return the index. */
20254 if (file_table_last_lookup
20255 && (file_name == file_table_last_lookup->filename
20256 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
20257 return file_table_last_lookup;
20259 /* Didn't match the previous lookup, search the table. */
20260 slot = htab_find_slot_with_hash (file_table, file_name,
20261 htab_hash_string (file_name), INSERT);
20263 return (struct dwarf_file_data *) *slot;
20265 created = ggc_alloc_dwarf_file_data ();
20266 created->filename = file_name;
20267 created->emitted_number = 0;
20272 /* If the assembler will construct the file table, then translate the compiler
20273 internal file table number into the assembler file table number, and emit
20274 a .file directive if we haven't already emitted one yet. The file table
20275 numbers are different because we prune debug info for unused variables and
20276 types, which may include filenames. */
20279 maybe_emit_file (struct dwarf_file_data * fd)
20281 if (! fd->emitted_number)
20283 if (last_emitted_file)
20284 fd->emitted_number = last_emitted_file->emitted_number + 1;
20286 fd->emitted_number = 1;
20287 last_emitted_file = fd;
20289 if (DWARF2_ASM_LINE_DEBUG_INFO)
20291 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
20292 output_quoted_string (asm_out_file,
20293 remap_debug_filename (fd->filename));
20294 fputc ('\n', asm_out_file);
20298 return fd->emitted_number;
20301 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20302 That generation should happen after function debug info has been
20303 generated. The value of the attribute is the constant value of ARG. */
20306 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
20308 die_arg_entry entry;
20313 if (!tmpl_value_parm_die_table)
20314 tmpl_value_parm_die_table
20315 = VEC_alloc (die_arg_entry, gc, 32);
20319 VEC_safe_push (die_arg_entry, gc,
20320 tmpl_value_parm_die_table,
20324 /* Return TRUE if T is an instance of generic type, FALSE
20328 generic_type_p (tree t)
20330 if (t == NULL_TREE || !TYPE_P (t))
20332 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
20335 /* Schedule the generation of the generic parameter dies for the
20336 instance of generic type T. The proper generation itself is later
20337 done by gen_scheduled_generic_parms_dies. */
20340 schedule_generic_params_dies_gen (tree t)
20342 if (!generic_type_p (t))
20345 if (generic_type_instances == NULL)
20346 generic_type_instances = VEC_alloc (tree, gc, 256);
20348 VEC_safe_push (tree, gc, generic_type_instances, t);
20351 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20352 by append_entry_to_tmpl_value_parm_die_table. This function must
20353 be called after function DIEs have been generated. */
20356 gen_remaining_tmpl_value_param_die_attribute (void)
20358 if (tmpl_value_parm_die_table)
20363 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
20364 tree_add_const_value_attribute (e->die, e->arg);
20368 /* Generate generic parameters DIEs for instances of generic types
20369 that have been previously scheduled by
20370 schedule_generic_params_dies_gen. This function must be called
20371 after all the types of the CU have been laid out. */
20374 gen_scheduled_generic_parms_dies (void)
20379 if (generic_type_instances == NULL)
20382 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
20383 gen_generic_params_dies (t);
20387 /* Replace DW_AT_name for the decl with name. */
20390 dwarf2out_set_name (tree decl, tree name)
20396 die = TYPE_SYMTAB_DIE (decl);
20400 dname = dwarf2_name (name, 0);
20404 attr = get_AT (die, DW_AT_name);
20407 struct indirect_string_node *node;
20409 node = find_AT_string (dname);
20410 /* replace the string. */
20411 attr->dw_attr_val.v.val_str = node;
20415 add_name_attribute (die, dname);
20418 /* Called by the final INSN scan whenever we see a var location. We
20419 use it to drop labels in the right places, and throw the location in
20420 our lookup table. */
20423 dwarf2out_var_location (rtx loc_note)
20425 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
20426 struct var_loc_node *newloc;
20428 static const char *last_label;
20429 static const char *last_postcall_label;
20430 static bool last_in_cold_section_p;
20434 if (!NOTE_P (loc_note))
20436 if (CALL_P (loc_note))
20439 if (SIBLING_CALL_P (loc_note))
20440 tail_call_site_count++;
20445 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
20446 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
20449 next_real = next_real_insn (loc_note);
20451 /* If there are no instructions which would be affected by this note,
20452 don't do anything. */
20454 && next_real == NULL_RTX
20455 && !NOTE_DURING_CALL_P (loc_note))
20458 if (next_real == NULL_RTX)
20459 next_real = get_last_insn ();
20461 /* If there were any real insns between note we processed last time
20462 and this note (or if it is the first note), clear
20463 last_{,postcall_}label so that they are not reused this time. */
20464 if (last_var_location_insn == NULL_RTX
20465 || last_var_location_insn != next_real
20466 || last_in_cold_section_p != in_cold_section_p)
20469 last_postcall_label = NULL;
20474 decl = NOTE_VAR_LOCATION_DECL (loc_note);
20475 newloc = add_var_loc_to_decl (decl, loc_note,
20476 NOTE_DURING_CALL_P (loc_note)
20477 ? last_postcall_label : last_label);
20478 if (newloc == NULL)
20487 /* If there were no real insns between note we processed last time
20488 and this note, use the label we emitted last time. Otherwise
20489 create a new label and emit it. */
20490 if (last_label == NULL)
20492 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
20493 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
20495 last_label = ggc_strdup (loclabel);
20500 struct call_arg_loc_node *ca_loc
20501 = ggc_alloc_cleared_call_arg_loc_node ();
20502 rtx prev = prev_real_insn (loc_note), x;
20503 ca_loc->call_arg_loc_note = loc_note;
20504 ca_loc->next = NULL;
20505 ca_loc->label = last_label;
20508 || (NONJUMP_INSN_P (prev)
20509 && GET_CODE (PATTERN (prev)) == SEQUENCE
20510 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
20511 if (!CALL_P (prev))
20512 prev = XVECEXP (PATTERN (prev), 0, 0);
20513 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
20514 x = PATTERN (prev);
20515 if (GET_CODE (x) == PARALLEL)
20516 x = XVECEXP (x, 0, 0);
20517 if (GET_CODE (x) == SET)
20519 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
20521 x = XEXP (XEXP (x, 0), 0);
20522 if (GET_CODE (x) == SYMBOL_REF
20523 && SYMBOL_REF_DECL (x)
20524 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
20525 ca_loc->symbol_ref = x;
20527 ca_loc->block = insn_scope (prev);
20528 if (call_arg_locations)
20529 call_arg_loc_last->next = ca_loc;
20531 call_arg_locations = ca_loc;
20532 call_arg_loc_last = ca_loc;
20534 else if (!NOTE_DURING_CALL_P (loc_note))
20535 newloc->label = last_label;
20538 if (!last_postcall_label)
20540 sprintf (loclabel, "%s-1", last_label);
20541 last_postcall_label = ggc_strdup (loclabel);
20543 newloc->label = last_postcall_label;
20546 last_var_location_insn = next_real;
20547 last_in_cold_section_p = in_cold_section_p;
20550 /* Note in one location list that text section has changed. */
20553 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
20555 var_loc_list *list = (var_loc_list *) *slot;
20557 list->last_before_switch
20558 = list->last->next ? list->last->next : list->last;
20562 /* Note in all location lists that text section has changed. */
20565 var_location_switch_text_section (void)
20567 if (decl_loc_table == NULL)
20570 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
20573 /* Create a new line number table. */
20575 static dw_line_info_table *
20576 new_line_info_table (void)
20578 dw_line_info_table *table;
20580 table = ggc_alloc_cleared_dw_line_info_table_struct ();
20581 table->file_num = 1;
20582 table->line_num = 1;
20583 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
20588 /* Lookup the "current" table into which we emit line info, so
20589 that we don't have to do it for every source line. */
20592 set_cur_line_info_table (section *sec)
20594 dw_line_info_table *table;
20596 if (sec == text_section)
20597 table = text_section_line_info;
20598 else if (sec == cold_text_section)
20600 table = cold_text_section_line_info;
20603 cold_text_section_line_info = table = new_line_info_table ();
20604 table->end_label = cold_end_label;
20609 const char *end_label;
20611 if (flag_reorder_blocks_and_partition)
20613 if (in_cold_section_p)
20614 end_label = crtl->subsections.cold_section_end_label;
20616 end_label = crtl->subsections.hot_section_end_label;
20620 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20621 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
20622 current_function_funcdef_no);
20623 end_label = ggc_strdup (label);
20626 table = new_line_info_table ();
20627 table->end_label = end_label;
20629 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
20632 cur_line_info_table = table;
20636 /* We need to reset the locations at the beginning of each
20637 function. We can't do this in the end_function hook, because the
20638 declarations that use the locations won't have been output when
20639 that hook is called. Also compute have_multiple_function_sections here. */
20642 dwarf2out_begin_function (tree fun)
20644 section *sec = function_section (fun);
20646 if (sec != text_section)
20647 have_multiple_function_sections = true;
20649 if (flag_reorder_blocks_and_partition && !cold_text_section)
20651 gcc_assert (current_function_decl == fun);
20652 cold_text_section = unlikely_text_section ();
20653 switch_to_section (cold_text_section);
20654 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
20655 switch_to_section (sec);
20658 dwarf2out_note_section_used ();
20659 call_site_count = 0;
20660 tail_call_site_count = 0;
20662 set_cur_line_info_table (sec);
20665 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20668 push_dw_line_info_entry (dw_line_info_table *table,
20669 enum dw_line_info_opcode opcode, unsigned int val)
20671 dw_line_info_entry e;
20674 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
20677 /* Output a label to mark the beginning of a source code line entry
20678 and record information relating to this source line, in
20679 'line_info_table' for later output of the .debug_line section. */
20680 /* ??? The discriminator parameter ought to be unsigned. */
20683 dwarf2out_source_line (unsigned int line, const char *filename,
20684 int discriminator, bool is_stmt)
20686 unsigned int file_num;
20687 dw_line_info_table *table;
20689 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
20692 /* The discriminator column was added in dwarf4. Simplify the below
20693 by simply removing it if we're not supposed to output it. */
20694 if (dwarf_version < 4 && dwarf_strict)
20697 table = cur_line_info_table;
20698 file_num = maybe_emit_file (lookup_filename (filename));
20700 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20701 the debugger has used the second (possibly duplicate) line number
20702 at the beginning of the function to mark the end of the prologue.
20703 We could eliminate any other duplicates within the function. For
20704 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20705 that second line number entry. */
20706 /* Recall that this end-of-prologue indication is *not* the same thing
20707 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20708 to which the hook corresponds, follows the last insn that was
20709 emitted by gen_prologue. What we need is to preceed the first insn
20710 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20711 insn that corresponds to something the user wrote. These may be
20712 very different locations once scheduling is enabled. */
20714 if (0 && file_num == table->file_num
20715 && line == table->line_num
20716 && discriminator == table->discrim_num
20717 && is_stmt == table->is_stmt)
20720 switch_to_section (current_function_section ());
20722 /* If requested, emit something human-readable. */
20723 if (flag_debug_asm)
20724 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
20726 if (DWARF2_ASM_LINE_DEBUG_INFO)
20728 /* Emit the .loc directive understood by GNU as. */
20729 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
20730 if (is_stmt != table->is_stmt)
20731 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
20732 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
20733 fprintf (asm_out_file, " discriminator %d", discriminator);
20734 fputc ('\n', asm_out_file);
20738 unsigned int label_num = ++line_info_label_num;
20740 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
20742 push_dw_line_info_entry (table, LI_set_address, label_num);
20743 if (file_num != table->file_num)
20744 push_dw_line_info_entry (table, LI_set_file, file_num);
20745 if (discriminator != table->discrim_num)
20746 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
20747 if (is_stmt != table->is_stmt)
20748 push_dw_line_info_entry (table, LI_negate_stmt, 0);
20749 push_dw_line_info_entry (table, LI_set_line, line);
20752 table->file_num = file_num;
20753 table->line_num = line;
20754 table->discrim_num = discriminator;
20755 table->is_stmt = is_stmt;
20756 table->in_use = true;
20759 /* Record the beginning of a new source file. */
20762 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
20764 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20766 /* Record the beginning of the file for break_out_includes. */
20767 dw_die_ref bincl_die;
20769 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
20770 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
20773 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20776 e.code = DW_MACINFO_start_file;
20778 e.info = xstrdup (filename);
20779 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20783 /* Record the end of a source file. */
20786 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
20788 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
20789 /* Record the end of the file for break_out_includes. */
20790 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
20792 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20795 e.code = DW_MACINFO_end_file;
20798 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20802 /* Called from debug_define in toplev.c. The `buffer' parameter contains
20803 the tail part of the directive line, i.e. the part which is past the
20804 initial whitespace, #, whitespace, directive-name, whitespace part. */
20807 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
20808 const char *buffer ATTRIBUTE_UNUSED)
20810 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20813 e.code = DW_MACINFO_define;
20815 e.info = xstrdup (buffer);;
20816 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20820 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
20821 the tail part of the directive line, i.e. the part which is past the
20822 initial whitespace, #, whitespace, directive-name, whitespace part. */
20825 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
20826 const char *buffer ATTRIBUTE_UNUSED)
20828 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20831 e.code = DW_MACINFO_undef;
20833 e.info = xstrdup (buffer);;
20834 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
20839 output_macinfo (void)
20842 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
20843 macinfo_entry *ref;
20848 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
20852 case DW_MACINFO_start_file:
20854 int file_num = maybe_emit_file (lookup_filename (ref->info));
20855 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
20856 dw2_asm_output_data_uleb128
20857 (ref->lineno, "Included from line number %lu",
20858 (unsigned long)ref->lineno);
20859 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
20862 case DW_MACINFO_end_file:
20863 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
20865 case DW_MACINFO_define:
20866 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
20867 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20868 (unsigned long)ref->lineno);
20869 dw2_asm_output_nstring (ref->info, -1, "The macro");
20871 case DW_MACINFO_undef:
20872 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
20873 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
20874 (unsigned long)ref->lineno);
20875 dw2_asm_output_nstring (ref->info, -1, "The macro");
20878 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
20879 ASM_COMMENT_START, (unsigned long)ref->code);
20885 /* Set up for Dwarf output at the start of compilation. */
20888 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
20890 /* Allocate the file_table. */
20891 file_table = htab_create_ggc (50, file_table_hash,
20892 file_table_eq, NULL);
20894 /* Allocate the decl_die_table. */
20895 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
20896 decl_die_table_eq, NULL);
20898 /* Allocate the decl_loc_table. */
20899 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
20900 decl_loc_table_eq, NULL);
20902 /* Allocate the cached_dw_loc_list_table. */
20903 cached_dw_loc_list_table
20904 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
20905 cached_dw_loc_list_table_eq, NULL);
20907 /* Allocate the initial hunk of the decl_scope_table. */
20908 decl_scope_table = VEC_alloc (tree, gc, 256);
20910 /* Allocate the initial hunk of the abbrev_die_table. */
20911 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
20912 (ABBREV_DIE_TABLE_INCREMENT);
20913 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
20914 /* Zero-th entry is allocated, but unused. */
20915 abbrev_die_table_in_use = 1;
20917 /* Allocate the pubtypes and pubnames vectors. */
20918 pubname_table = VEC_alloc (pubname_entry, gc, 32);
20919 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
20921 incomplete_types = VEC_alloc (tree, gc, 64);
20923 used_rtx_array = VEC_alloc (rtx, gc, 32);
20925 debug_info_section = get_section (DEBUG_INFO_SECTION,
20926 SECTION_DEBUG, NULL);
20927 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
20928 SECTION_DEBUG, NULL);
20929 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
20930 SECTION_DEBUG, NULL);
20931 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
20932 SECTION_DEBUG, NULL);
20933 debug_line_section = get_section (DEBUG_LINE_SECTION,
20934 SECTION_DEBUG, NULL);
20935 debug_loc_section = get_section (DEBUG_LOC_SECTION,
20936 SECTION_DEBUG, NULL);
20937 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
20938 SECTION_DEBUG, NULL);
20939 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
20940 SECTION_DEBUG, NULL);
20941 debug_str_section = get_section (DEBUG_STR_SECTION,
20942 DEBUG_STR_SECTION_FLAGS, NULL);
20943 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
20944 SECTION_DEBUG, NULL);
20945 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
20946 SECTION_DEBUG, NULL);
20948 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
20949 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
20950 DEBUG_ABBREV_SECTION_LABEL, 0);
20951 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
20952 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
20953 COLD_TEXT_SECTION_LABEL, 0);
20954 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
20956 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
20957 DEBUG_INFO_SECTION_LABEL, 0);
20958 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
20959 DEBUG_LINE_SECTION_LABEL, 0);
20960 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
20961 DEBUG_RANGES_SECTION_LABEL, 0);
20962 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
20963 DEBUG_MACINFO_SECTION_LABEL, 0);
20965 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
20966 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
20968 switch_to_section (text_section);
20969 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
20971 /* Make sure the line number table for .text always exists. */
20972 text_section_line_info = new_line_info_table ();
20973 text_section_line_info->end_label = text_end_label;
20976 /* Called before cgraph_optimize starts outputtting functions, variables
20977 and toplevel asms into assembly. */
20980 dwarf2out_assembly_start (void)
20982 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
20983 && dwarf2out_do_cfi_asm ()
20984 && (!(flag_unwind_tables || flag_exceptions)
20985 || targetm_common.except_unwind_info (&global_options) != UI_DWARF2))
20986 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
20989 /* A helper function for dwarf2out_finish called through
20990 htab_traverse. Emit one queued .debug_str string. */
20993 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
20995 struct indirect_string_node *node = (struct indirect_string_node *) *h;
20997 if (node->form == DW_FORM_strp)
20999 switch_to_section (debug_str_section);
21000 ASM_OUTPUT_LABEL (asm_out_file, node->label);
21001 assemble_string (node->str, strlen (node->str) + 1);
21007 #if ENABLE_ASSERT_CHECKING
21008 /* Verify that all marks are clear. */
21011 verify_marks_clear (dw_die_ref die)
21015 gcc_assert (! die->die_mark);
21016 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
21018 #endif /* ENABLE_ASSERT_CHECKING */
21020 /* Clear the marks for a die and its children.
21021 Be cool if the mark isn't set. */
21024 prune_unmark_dies (dw_die_ref die)
21030 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
21033 /* Given DIE that we're marking as used, find any other dies
21034 it references as attributes and mark them as used. */
21037 prune_unused_types_walk_attribs (dw_die_ref die)
21042 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21044 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
21046 /* A reference to another DIE.
21047 Make sure that it will get emitted.
21048 If it was broken out into a comdat group, don't follow it. */
21049 if (! use_debug_types
21050 || a->dw_attr == DW_AT_specification
21051 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
21052 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
21054 /* Set the string's refcount to 0 so that prune_unused_types_mark
21055 accounts properly for it. */
21056 if (AT_class (a) == dw_val_class_str)
21057 a->dw_attr_val.v.val_str->refcount = 0;
21061 /* Mark the generic parameters and arguments children DIEs of DIE. */
21064 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
21068 if (die == NULL || die->die_child == NULL)
21070 c = die->die_child;
21073 switch (c->die_tag)
21075 case DW_TAG_template_type_param:
21076 case DW_TAG_template_value_param:
21077 case DW_TAG_GNU_template_template_param:
21078 case DW_TAG_GNU_template_parameter_pack:
21079 prune_unused_types_mark (c, 1);
21085 } while (c && c != die->die_child);
21088 /* Mark DIE as being used. If DOKIDS is true, then walk down
21089 to DIE's children. */
21092 prune_unused_types_mark (dw_die_ref die, int dokids)
21096 if (die->die_mark == 0)
21098 /* We haven't done this node yet. Mark it as used. */
21100 /* If this is the DIE of a generic type instantiation,
21101 mark the children DIEs that describe its generic parms and
21103 prune_unused_types_mark_generic_parms_dies (die);
21105 /* We also have to mark its parents as used.
21106 (But we don't want to mark our parents' kids due to this.) */
21107 if (die->die_parent)
21108 prune_unused_types_mark (die->die_parent, 0);
21110 /* Mark any referenced nodes. */
21111 prune_unused_types_walk_attribs (die);
21113 /* If this node is a specification,
21114 also mark the definition, if it exists. */
21115 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
21116 prune_unused_types_mark (die->die_definition, 1);
21119 if (dokids && die->die_mark != 2)
21121 /* We need to walk the children, but haven't done so yet.
21122 Remember that we've walked the kids. */
21125 /* If this is an array type, we need to make sure our
21126 kids get marked, even if they're types. If we're
21127 breaking out types into comdat sections, do this
21128 for all type definitions. */
21129 if (die->die_tag == DW_TAG_array_type
21130 || (use_debug_types
21131 && is_type_die (die) && ! is_declaration_die (die)))
21132 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
21134 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21138 /* For local classes, look if any static member functions were emitted
21139 and if so, mark them. */
21142 prune_unused_types_walk_local_classes (dw_die_ref die)
21146 if (die->die_mark == 2)
21149 switch (die->die_tag)
21151 case DW_TAG_structure_type:
21152 case DW_TAG_union_type:
21153 case DW_TAG_class_type:
21156 case DW_TAG_subprogram:
21157 if (!get_AT_flag (die, DW_AT_declaration)
21158 || die->die_definition != NULL)
21159 prune_unused_types_mark (die, 1);
21166 /* Mark children. */
21167 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
21170 /* Walk the tree DIE and mark types that we actually use. */
21173 prune_unused_types_walk (dw_die_ref die)
21177 /* Don't do anything if this node is already marked and
21178 children have been marked as well. */
21179 if (die->die_mark == 2)
21182 switch (die->die_tag)
21184 case DW_TAG_structure_type:
21185 case DW_TAG_union_type:
21186 case DW_TAG_class_type:
21187 if (die->die_perennial_p)
21190 for (c = die->die_parent; c; c = c->die_parent)
21191 if (c->die_tag == DW_TAG_subprogram)
21194 /* Finding used static member functions inside of classes
21195 is needed just for local classes, because for other classes
21196 static member function DIEs with DW_AT_specification
21197 are emitted outside of the DW_TAG_*_type. If we ever change
21198 it, we'd need to call this even for non-local classes. */
21200 prune_unused_types_walk_local_classes (die);
21202 /* It's a type node --- don't mark it. */
21205 case DW_TAG_const_type:
21206 case DW_TAG_packed_type:
21207 case DW_TAG_pointer_type:
21208 case DW_TAG_reference_type:
21209 case DW_TAG_rvalue_reference_type:
21210 case DW_TAG_volatile_type:
21211 case DW_TAG_typedef:
21212 case DW_TAG_array_type:
21213 case DW_TAG_interface_type:
21214 case DW_TAG_friend:
21215 case DW_TAG_variant_part:
21216 case DW_TAG_enumeration_type:
21217 case DW_TAG_subroutine_type:
21218 case DW_TAG_string_type:
21219 case DW_TAG_set_type:
21220 case DW_TAG_subrange_type:
21221 case DW_TAG_ptr_to_member_type:
21222 case DW_TAG_file_type:
21223 if (die->die_perennial_p)
21226 /* It's a type node --- don't mark it. */
21230 /* Mark everything else. */
21234 if (die->die_mark == 0)
21238 /* Now, mark any dies referenced from here. */
21239 prune_unused_types_walk_attribs (die);
21244 /* Mark children. */
21245 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
21248 /* Increment the string counts on strings referred to from DIE's
21252 prune_unused_types_update_strings (dw_die_ref die)
21257 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21258 if (AT_class (a) == dw_val_class_str)
21260 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
21262 /* Avoid unnecessarily putting strings that are used less than
21263 twice in the hash table. */
21265 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
21268 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
21269 htab_hash_string (s->str),
21271 gcc_assert (*slot == NULL);
21277 /* Remove from the tree DIE any dies that aren't marked. */
21280 prune_unused_types_prune (dw_die_ref die)
21284 gcc_assert (die->die_mark);
21285 prune_unused_types_update_strings (die);
21287 if (! die->die_child)
21290 c = die->die_child;
21292 dw_die_ref prev = c;
21293 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
21294 if (c == die->die_child)
21296 /* No marked children between 'prev' and the end of the list. */
21298 /* No marked children at all. */
21299 die->die_child = NULL;
21302 prev->die_sib = c->die_sib;
21303 die->die_child = prev;
21308 if (c != prev->die_sib)
21310 prune_unused_types_prune (c);
21311 } while (c != die->die_child);
21314 /* Remove dies representing declarations that we never use. */
21317 prune_unused_types (void)
21320 limbo_die_node *node;
21321 comdat_type_node *ctnode;
21323 dw_die_ref base_type;
21325 #if ENABLE_ASSERT_CHECKING
21326 /* All the marks should already be clear. */
21327 verify_marks_clear (comp_unit_die ());
21328 for (node = limbo_die_list; node; node = node->next)
21329 verify_marks_clear (node->die);
21330 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21331 verify_marks_clear (ctnode->root_die);
21332 #endif /* ENABLE_ASSERT_CHECKING */
21334 /* Mark types that are used in global variables. */
21335 premark_types_used_by_global_vars ();
21337 /* Set the mark on nodes that are actually used. */
21338 prune_unused_types_walk (comp_unit_die ());
21339 for (node = limbo_die_list; node; node = node->next)
21340 prune_unused_types_walk (node->die);
21341 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21343 prune_unused_types_walk (ctnode->root_die);
21344 prune_unused_types_mark (ctnode->type_die, 1);
21347 /* Also set the mark on nodes referenced from the
21349 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
21350 prune_unused_types_mark (pub->die, 1);
21351 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21352 prune_unused_types_mark (base_type, 1);
21354 if (debug_str_hash)
21355 htab_empty (debug_str_hash);
21356 prune_unused_types_prune (comp_unit_die ());
21357 for (node = limbo_die_list; node; node = node->next)
21358 prune_unused_types_prune (node->die);
21359 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21360 prune_unused_types_prune (ctnode->root_die);
21362 /* Leave the marks clear. */
21363 prune_unmark_dies (comp_unit_die ());
21364 for (node = limbo_die_list; node; node = node->next)
21365 prune_unmark_dies (node->die);
21366 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
21367 prune_unmark_dies (ctnode->root_die);
21370 /* Set the parameter to true if there are any relative pathnames in
21373 file_table_relative_p (void ** slot, void *param)
21375 bool *p = (bool *) param;
21376 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
21377 if (!IS_ABSOLUTE_PATH (d->filename))
21385 /* Routines to manipulate hash table of comdat type units. */
21388 htab_ct_hash (const void *of)
21391 const comdat_type_node *const type_node = (const comdat_type_node *) of;
21393 memcpy (&h, type_node->signature, sizeof (h));
21398 htab_ct_eq (const void *of1, const void *of2)
21400 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
21401 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
21403 return (! memcmp (type_node_1->signature, type_node_2->signature,
21404 DWARF_TYPE_SIGNATURE_SIZE));
21407 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
21408 to the location it would have been added, should we know its
21409 DECL_ASSEMBLER_NAME when we added other attributes. This will
21410 probably improve compactness of debug info, removing equivalent
21411 abbrevs, and hide any differences caused by deferring the
21412 computation of the assembler name, triggered by e.g. PCH. */
21415 move_linkage_attr (dw_die_ref die)
21417 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
21418 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
21420 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
21421 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
21425 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
21427 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
21431 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
21433 VEC_pop (dw_attr_node, die->die_attr);
21434 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
21438 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
21439 referenced from typed stack ops and count how often they are used. */
21442 mark_base_types (dw_loc_descr_ref loc)
21444 dw_die_ref base_type = NULL;
21446 for (; loc; loc = loc->dw_loc_next)
21448 switch (loc->dw_loc_opc)
21450 case DW_OP_GNU_regval_type:
21451 case DW_OP_GNU_deref_type:
21452 base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
21454 case DW_OP_GNU_convert:
21455 case DW_OP_GNU_reinterpret:
21456 if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
21459 case DW_OP_GNU_const_type:
21460 base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
21462 case DW_OP_GNU_entry_value:
21463 mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
21468 gcc_assert (base_type->die_parent == comp_unit_die ());
21469 if (base_type->die_mark)
21470 base_type->die_mark++;
21473 VEC_safe_push (dw_die_ref, heap, base_types, base_type);
21474 base_type->die_mark = 1;
21479 /* Comparison function for sorting marked base types. */
21482 base_type_cmp (const void *x, const void *y)
21484 dw_die_ref dx = *(const dw_die_ref *) x;
21485 dw_die_ref dy = *(const dw_die_ref *) y;
21486 unsigned int byte_size1, byte_size2;
21487 unsigned int encoding1, encoding2;
21488 if (dx->die_mark > dy->die_mark)
21490 if (dx->die_mark < dy->die_mark)
21492 byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
21493 byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
21494 if (byte_size1 < byte_size2)
21496 if (byte_size1 > byte_size2)
21498 encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
21499 encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
21500 if (encoding1 < encoding2)
21502 if (encoding1 > encoding2)
21507 /* Move base types marked by mark_base_types as early as possible
21508 in the CU, sorted by decreasing usage count both to make the
21509 uleb128 references as small as possible and to make sure they
21510 will have die_offset already computed by calc_die_sizes when
21511 sizes of typed stack loc ops is computed. */
21514 move_marked_base_types (void)
21517 dw_die_ref base_type, die, c;
21519 if (VEC_empty (dw_die_ref, base_types))
21522 /* Sort by decreasing usage count, they will be added again in that
21524 VEC_qsort (dw_die_ref, base_types, base_type_cmp);
21525 die = comp_unit_die ();
21526 c = die->die_child;
21529 dw_die_ref prev = c;
21531 while (c->die_mark)
21533 remove_child_with_prev (c, prev);
21534 /* As base types got marked, there must be at least
21535 one node other than DW_TAG_base_type. */
21536 gcc_assert (c != c->die_sib);
21540 while (c != die->die_child);
21541 gcc_assert (die->die_child);
21542 c = die->die_child;
21543 for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
21545 base_type->die_mark = 0;
21546 base_type->die_sib = c->die_sib;
21547 c->die_sib = base_type;
21552 /* Helper function for resolve_addr, attempt to resolve
21553 one CONST_STRING, return non-zero if not successful. Similarly verify that
21554 SYMBOL_REFs refer to variables emitted in the current CU. */
21557 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
21561 if (GET_CODE (rtl) == CONST_STRING)
21563 size_t len = strlen (XSTR (rtl, 0)) + 1;
21564 tree t = build_string (len, XSTR (rtl, 0));
21565 tree tlen = size_int (len - 1);
21567 = build_array_type (char_type_node, build_index_type (tlen));
21568 rtl = lookup_constant_def (t);
21569 if (!rtl || !MEM_P (rtl))
21571 rtl = XEXP (rtl, 0);
21572 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
21577 if (GET_CODE (rtl) == SYMBOL_REF
21578 && SYMBOL_REF_DECL (rtl))
21580 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
21582 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
21585 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
21589 if (GET_CODE (rtl) == CONST
21590 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
21596 /* Helper function for resolve_addr, handle one location
21597 expression, return false if at least one CONST_STRING or SYMBOL_REF in
21598 the location list couldn't be resolved. */
21601 resolve_addr_in_expr (dw_loc_descr_ref loc)
21603 dw_loc_descr_ref keep = NULL;
21604 for (; loc; loc = loc->dw_loc_next)
21605 switch (loc->dw_loc_opc)
21608 if (resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21611 case DW_OP_const4u:
21612 case DW_OP_const8u:
21614 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
21617 case DW_OP_implicit_value:
21618 if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
21619 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL))
21622 case DW_OP_GNU_implicit_pointer:
21623 case DW_OP_GNU_parameter_ref:
21624 if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
21627 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
21630 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
21631 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
21632 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
21635 case DW_OP_GNU_const_type:
21636 case DW_OP_GNU_regval_type:
21637 case DW_OP_GNU_deref_type:
21638 case DW_OP_GNU_convert:
21639 case DW_OP_GNU_reinterpret:
21640 while (loc->dw_loc_next
21641 && loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert)
21643 dw_die_ref base1, base2;
21644 unsigned enc1, enc2, size1, size2;
21645 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21646 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21647 base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
21648 else if (loc->dw_loc_oprnd1.val_class
21649 == dw_val_class_unsigned_const)
21652 base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
21653 if (loc->dw_loc_next->dw_loc_oprnd1.val_class
21654 == dw_val_class_unsigned_const)
21656 base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
21657 gcc_assert (base1->die_tag == DW_TAG_base_type
21658 && base2->die_tag == DW_TAG_base_type);
21659 enc1 = get_AT_unsigned (base1, DW_AT_encoding);
21660 enc2 = get_AT_unsigned (base2, DW_AT_encoding);
21661 size1 = get_AT_unsigned (base1, DW_AT_byte_size);
21662 size2 = get_AT_unsigned (base2, DW_AT_byte_size);
21664 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
21665 && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
21669 /* Optimize away next DW_OP_GNU_convert after
21670 adjusting LOC's base type die reference. */
21671 if (loc->dw_loc_opc == DW_OP_GNU_regval_type
21672 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
21673 loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
21675 loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
21676 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
21679 /* Don't change integer DW_OP_GNU_convert after e.g. floating
21680 point typed stack entry. */
21681 else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
21682 keep = loc->dw_loc_next;
21692 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
21693 an address in .rodata section if the string literal is emitted there,
21694 or remove the containing location list or replace DW_AT_const_value
21695 with DW_AT_location and empty location expression, if it isn't found
21696 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
21697 to something that has been emitted in the current CU. */
21700 resolve_addr (dw_die_ref die)
21704 dw_loc_list_ref *curr, *start, loc;
21707 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
21708 switch (AT_class (a))
21710 case dw_val_class_loc_list:
21711 start = curr = AT_loc_list_ptr (a);
21714 /* The same list can be referenced more than once. See if we have
21715 already recorded the result from a previous pass. */
21717 *curr = loc->dw_loc_next;
21718 else if (!loc->resolved_addr)
21720 /* As things stand, we do not expect or allow one die to
21721 reference a suffix of another die's location list chain.
21722 References must be identical or completely separate.
21723 There is therefore no need to cache the result of this
21724 pass on any list other than the first; doing so
21725 would lead to unnecessary writes. */
21728 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
21729 if (!resolve_addr_in_expr ((*curr)->expr))
21731 dw_loc_list_ref next = (*curr)->dw_loc_next;
21732 if (next && (*curr)->ll_symbol)
21734 gcc_assert (!next->ll_symbol);
21735 next->ll_symbol = (*curr)->ll_symbol;
21741 mark_base_types ((*curr)->expr);
21742 curr = &(*curr)->dw_loc_next;
21746 loc->resolved_addr = 1;
21750 loc->dw_loc_next = *start;
21755 remove_AT (die, a->dw_attr);
21759 case dw_val_class_loc:
21760 if (!resolve_addr_in_expr (AT_loc (a)))
21762 remove_AT (die, a->dw_attr);
21766 mark_base_types (AT_loc (a));
21768 case dw_val_class_addr:
21769 if (a->dw_attr == DW_AT_const_value
21770 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
21772 remove_AT (die, a->dw_attr);
21775 if (die->die_tag == DW_TAG_GNU_call_site
21776 && a->dw_attr == DW_AT_abstract_origin)
21778 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
21779 dw_die_ref tdie = lookup_decl_die (tdecl);
21781 && DECL_EXTERNAL (tdecl)
21782 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
21784 force_decl_die (tdecl);
21785 tdie = lookup_decl_die (tdecl);
21789 a->dw_attr_val.val_class = dw_val_class_die_ref;
21790 a->dw_attr_val.v.val_die_ref.die = tdie;
21791 a->dw_attr_val.v.val_die_ref.external = 0;
21795 remove_AT (die, a->dw_attr);
21804 FOR_EACH_CHILD (die, c, resolve_addr (c));
21807 /* Helper routines for optimize_location_lists.
21808 This pass tries to share identical local lists in .debug_loc
21811 /* Iteratively hash operands of LOC opcode. */
21813 static inline hashval_t
21814 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
21816 dw_val_ref val1 = &loc->dw_loc_oprnd1;
21817 dw_val_ref val2 = &loc->dw_loc_oprnd2;
21819 switch (loc->dw_loc_opc)
21821 case DW_OP_const4u:
21822 case DW_OP_const8u:
21826 case DW_OP_const1u:
21827 case DW_OP_const1s:
21828 case DW_OP_const2u:
21829 case DW_OP_const2s:
21830 case DW_OP_const4s:
21831 case DW_OP_const8s:
21835 case DW_OP_plus_uconst:
21871 case DW_OP_deref_size:
21872 case DW_OP_xderef_size:
21873 hash = iterative_hash_object (val1->v.val_int, hash);
21880 gcc_assert (val1->val_class == dw_val_class_loc);
21881 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
21882 hash = iterative_hash_object (offset, hash);
21885 case DW_OP_implicit_value:
21886 hash = iterative_hash_object (val1->v.val_unsigned, hash);
21887 switch (val2->val_class)
21889 case dw_val_class_const:
21890 hash = iterative_hash_object (val2->v.val_int, hash);
21892 case dw_val_class_vec:
21894 unsigned int elt_size = val2->v.val_vec.elt_size;
21895 unsigned int len = val2->v.val_vec.length;
21897 hash = iterative_hash_object (elt_size, hash);
21898 hash = iterative_hash_object (len, hash);
21899 hash = iterative_hash (val2->v.val_vec.array,
21900 len * elt_size, hash);
21903 case dw_val_class_const_double:
21904 hash = iterative_hash_object (val2->v.val_double.low, hash);
21905 hash = iterative_hash_object (val2->v.val_double.high, hash);
21907 case dw_val_class_addr:
21908 hash = iterative_hash_rtx (val2->v.val_addr, hash);
21911 gcc_unreachable ();
21915 case DW_OP_bit_piece:
21916 hash = iterative_hash_object (val1->v.val_int, hash);
21917 hash = iterative_hash_object (val2->v.val_int, hash);
21923 unsigned char dtprel = 0xd1;
21924 hash = iterative_hash_object (dtprel, hash);
21926 hash = iterative_hash_rtx (val1->v.val_addr, hash);
21928 case DW_OP_GNU_implicit_pointer:
21929 hash = iterative_hash_object (val2->v.val_int, hash);
21931 case DW_OP_GNU_entry_value:
21932 hash = hash_loc_operands (val1->v.val_loc, hash);
21934 case DW_OP_GNU_regval_type:
21935 case DW_OP_GNU_deref_type:
21937 unsigned int byte_size
21938 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
21939 unsigned int encoding
21940 = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
21941 hash = iterative_hash_object (val1->v.val_int, hash);
21942 hash = iterative_hash_object (byte_size, hash);
21943 hash = iterative_hash_object (encoding, hash);
21946 case DW_OP_GNU_convert:
21947 case DW_OP_GNU_reinterpret:
21948 if (val1->val_class == dw_val_class_unsigned_const)
21950 hash = iterative_hash_object (val1->v.val_unsigned, hash);
21954 case DW_OP_GNU_const_type:
21956 unsigned int byte_size
21957 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
21958 unsigned int encoding
21959 = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
21960 hash = iterative_hash_object (byte_size, hash);
21961 hash = iterative_hash_object (encoding, hash);
21962 if (loc->dw_loc_opc != DW_OP_GNU_const_type)
21964 hash = iterative_hash_object (val2->val_class, hash);
21965 switch (val2->val_class)
21967 case dw_val_class_const:
21968 hash = iterative_hash_object (val2->v.val_int, hash);
21970 case dw_val_class_vec:
21972 unsigned int elt_size = val2->v.val_vec.elt_size;
21973 unsigned int len = val2->v.val_vec.length;
21975 hash = iterative_hash_object (elt_size, hash);
21976 hash = iterative_hash_object (len, hash);
21977 hash = iterative_hash (val2->v.val_vec.array,
21978 len * elt_size, hash);
21981 case dw_val_class_const_double:
21982 hash = iterative_hash_object (val2->v.val_double.low, hash);
21983 hash = iterative_hash_object (val2->v.val_double.high, hash);
21986 gcc_unreachable ();
21992 /* Other codes have no operands. */
21998 /* Iteratively hash the whole DWARF location expression LOC. */
22000 static inline hashval_t
22001 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
22003 dw_loc_descr_ref l;
22004 bool sizes_computed = false;
22005 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22006 size_of_locs (loc);
22008 for (l = loc; l != NULL; l = l->dw_loc_next)
22010 enum dwarf_location_atom opc = l->dw_loc_opc;
22011 hash = iterative_hash_object (opc, hash);
22012 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
22014 size_of_locs (loc);
22015 sizes_computed = true;
22017 hash = hash_loc_operands (l, hash);
22022 /* Compute hash of the whole location list LIST_HEAD. */
22025 hash_loc_list (dw_loc_list_ref list_head)
22027 dw_loc_list_ref curr = list_head;
22028 hashval_t hash = 0;
22030 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
22032 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
22033 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
22035 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
22037 hash = hash_locs (curr->expr, hash);
22039 list_head->hash = hash;
22042 /* Return true if X and Y opcodes have the same operands. */
22045 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
22047 dw_val_ref valx1 = &x->dw_loc_oprnd1;
22048 dw_val_ref valx2 = &x->dw_loc_oprnd2;
22049 dw_val_ref valy1 = &y->dw_loc_oprnd1;
22050 dw_val_ref valy2 = &y->dw_loc_oprnd2;
22052 switch (x->dw_loc_opc)
22054 case DW_OP_const4u:
22055 case DW_OP_const8u:
22059 case DW_OP_const1u:
22060 case DW_OP_const1s:
22061 case DW_OP_const2u:
22062 case DW_OP_const2s:
22063 case DW_OP_const4s:
22064 case DW_OP_const8s:
22068 case DW_OP_plus_uconst:
22104 case DW_OP_deref_size:
22105 case DW_OP_xderef_size:
22106 return valx1->v.val_int == valy1->v.val_int;
22109 gcc_assert (valx1->val_class == dw_val_class_loc
22110 && valy1->val_class == dw_val_class_loc
22111 && x->dw_loc_addr == y->dw_loc_addr);
22112 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
22113 case DW_OP_implicit_value:
22114 if (valx1->v.val_unsigned != valy1->v.val_unsigned
22115 || valx2->val_class != valy2->val_class)
22117 switch (valx2->val_class)
22119 case dw_val_class_const:
22120 return valx2->v.val_int == valy2->v.val_int;
22121 case dw_val_class_vec:
22122 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22123 && valx2->v.val_vec.length == valy2->v.val_vec.length
22124 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22125 valx2->v.val_vec.elt_size
22126 * valx2->v.val_vec.length) == 0;
22127 case dw_val_class_const_double:
22128 return valx2->v.val_double.low == valy2->v.val_double.low
22129 && valx2->v.val_double.high == valy2->v.val_double.high;
22130 case dw_val_class_addr:
22131 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
22133 gcc_unreachable ();
22136 case DW_OP_bit_piece:
22137 return valx1->v.val_int == valy1->v.val_int
22138 && valx2->v.val_int == valy2->v.val_int;
22141 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
22142 case DW_OP_GNU_implicit_pointer:
22143 return valx1->val_class == dw_val_class_die_ref
22144 && valx1->val_class == valy1->val_class
22145 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
22146 && valx2->v.val_int == valy2->v.val_int;
22147 case DW_OP_GNU_entry_value:
22148 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
22149 case DW_OP_GNU_const_type:
22150 if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
22151 || valx2->val_class != valy2->val_class)
22153 switch (valx2->val_class)
22155 case dw_val_class_const:
22156 return valx2->v.val_int == valy2->v.val_int;
22157 case dw_val_class_vec:
22158 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22159 && valx2->v.val_vec.length == valy2->v.val_vec.length
22160 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22161 valx2->v.val_vec.elt_size
22162 * valx2->v.val_vec.length) == 0;
22163 case dw_val_class_const_double:
22164 return valx2->v.val_double.low == valy2->v.val_double.low
22165 && valx2->v.val_double.high == valy2->v.val_double.high;
22167 gcc_unreachable ();
22169 case DW_OP_GNU_regval_type:
22170 case DW_OP_GNU_deref_type:
22171 return valx1->v.val_int == valy1->v.val_int
22172 && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
22173 case DW_OP_GNU_convert:
22174 case DW_OP_GNU_reinterpret:
22175 if (valx1->val_class != valy1->val_class)
22177 if (valx1->val_class == dw_val_class_unsigned_const)
22178 return valx1->v.val_unsigned == valy1->v.val_unsigned;
22179 return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
22180 case DW_OP_GNU_parameter_ref:
22181 return valx1->val_class == dw_val_class_die_ref
22182 && valx1->val_class == valy1->val_class
22183 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
22185 /* Other codes have no operands. */
22190 /* Return true if DWARF location expressions X and Y are the same. */
22193 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
22195 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
22196 if (x->dw_loc_opc != y->dw_loc_opc
22197 || x->dtprel != y->dtprel
22198 || !compare_loc_operands (x, y))
22200 return x == NULL && y == NULL;
22203 /* Return precomputed hash of location list X. */
22206 loc_list_hash (const void *x)
22208 return ((const struct dw_loc_list_struct *) x)->hash;
22211 /* Return 1 if location lists X and Y are the same. */
22214 loc_list_eq (const void *x, const void *y)
22216 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
22217 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
22220 if (a->hash != b->hash)
22222 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
22223 if (strcmp (a->begin, b->begin) != 0
22224 || strcmp (a->end, b->end) != 0
22225 || (a->section == NULL) != (b->section == NULL)
22226 || (a->section && strcmp (a->section, b->section) != 0)
22227 || !compare_locs (a->expr, b->expr))
22229 return a == NULL && b == NULL;
22232 /* Recursively optimize location lists referenced from DIE
22233 children and share them whenever possible. */
22236 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
22243 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22244 if (AT_class (a) == dw_val_class_loc_list)
22246 dw_loc_list_ref list = AT_loc_list (a);
22247 /* TODO: perform some optimizations here, before hashing
22248 it and storing into the hash table. */
22249 hash_loc_list (list);
22250 slot = htab_find_slot_with_hash (htab, list, list->hash,
22253 *slot = (void *) list;
22255 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
22258 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
22261 /* Optimize location lists referenced from DIE
22262 children and share them whenever possible. */
22265 optimize_location_lists (dw_die_ref die)
22267 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
22268 optimize_location_lists_1 (die, htab);
22269 htab_delete (htab);
22272 /* Output stuff that dwarf requires at the end of every file,
22273 and generate the DWARF-2 debugging info. */
22276 dwarf2out_finish (const char *filename)
22278 limbo_die_node *node, *next_node;
22279 comdat_type_node *ctnode;
22280 htab_t comdat_type_table;
22283 gen_scheduled_generic_parms_dies ();
22284 gen_remaining_tmpl_value_param_die_attribute ();
22286 /* Add the name for the main input file now. We delayed this from
22287 dwarf2out_init to avoid complications with PCH. */
22288 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
22289 if (!IS_ABSOLUTE_PATH (filename))
22290 add_comp_dir_attribute (comp_unit_die ());
22291 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
22294 htab_traverse (file_table, file_table_relative_p, &p);
22296 add_comp_dir_attribute (comp_unit_die ());
22299 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
22301 add_location_or_const_value_attribute (
22302 VEC_index (deferred_locations, deferred_locations_list, i)->die,
22303 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
22308 /* Traverse the limbo die list, and add parent/child links. The only
22309 dies without parents that should be here are concrete instances of
22310 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22311 For concrete instances, we can get the parent die from the abstract
22313 for (node = limbo_die_list; node; node = next_node)
22315 dw_die_ref die = node->die;
22316 next_node = node->next;
22318 if (die->die_parent == NULL)
22320 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
22322 if (origin && origin->die_parent)
22323 add_child_die (origin->die_parent, die);
22324 else if (is_cu_die (die))
22326 else if (seen_error ())
22327 /* It's OK to be confused by errors in the input. */
22328 add_child_die (comp_unit_die (), die);
22331 /* In certain situations, the lexical block containing a
22332 nested function can be optimized away, which results
22333 in the nested function die being orphaned. Likewise
22334 with the return type of that nested function. Force
22335 this to be a child of the containing function.
22337 It may happen that even the containing function got fully
22338 inlined and optimized out. In that case we are lost and
22339 assign the empty child. This should not be big issue as
22340 the function is likely unreachable too. */
22341 tree context = NULL_TREE;
22343 gcc_assert (node->created_for);
22345 if (DECL_P (node->created_for))
22346 context = DECL_CONTEXT (node->created_for);
22347 else if (TYPE_P (node->created_for))
22348 context = TYPE_CONTEXT (node->created_for);
22350 gcc_assert (context
22351 && (TREE_CODE (context) == FUNCTION_DECL
22352 || TREE_CODE (context) == NAMESPACE_DECL));
22354 origin = lookup_decl_die (context);
22356 add_child_die (origin, die);
22358 add_child_die (comp_unit_die (), die);
22363 limbo_die_list = NULL;
22365 #if ENABLE_ASSERT_CHECKING
22367 dw_die_ref die = comp_unit_die (), c;
22368 FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
22371 resolve_addr (comp_unit_die ());
22372 move_marked_base_types ();
22374 for (node = deferred_asm_name; node; node = node->next)
22376 tree decl = node->created_for;
22377 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22379 add_linkage_attr (node->die, decl);
22380 move_linkage_attr (node->die);
22384 deferred_asm_name = NULL;
22386 /* Walk through the list of incomplete types again, trying once more to
22387 emit full debugging info for them. */
22388 retry_incomplete_types ();
22390 if (flag_eliminate_unused_debug_types)
22391 prune_unused_types ();
22393 /* Generate separate CUs for each of the include files we've seen.
22394 They will go into limbo_die_list. */
22395 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22396 break_out_includes (comp_unit_die ());
22398 /* Generate separate COMDAT sections for type DIEs. */
22399 if (use_debug_types)
22401 break_out_comdat_types (comp_unit_die ());
22403 /* Each new type_unit DIE was added to the limbo die list when created.
22404 Since these have all been added to comdat_type_list, clear the
22406 limbo_die_list = NULL;
22408 /* For each new comdat type unit, copy declarations for incomplete
22409 types to make the new unit self-contained (i.e., no direct
22410 references to the main compile unit). */
22411 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22412 copy_decls_for_unworthy_types (ctnode->root_die);
22413 copy_decls_for_unworthy_types (comp_unit_die ());
22415 /* In the process of copying declarations from one unit to another,
22416 we may have left some declarations behind that are no longer
22417 referenced. Prune them. */
22418 prune_unused_types ();
22421 /* Traverse the DIE's and add add sibling attributes to those DIE's
22422 that have children. */
22423 add_sibling_attributes (comp_unit_die ());
22424 for (node = limbo_die_list; node; node = node->next)
22425 add_sibling_attributes (node->die);
22426 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22427 add_sibling_attributes (ctnode->root_die);
22429 /* Output a terminator label for the .text section. */
22430 switch_to_section (text_section);
22431 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
22432 if (cold_text_section)
22434 switch_to_section (cold_text_section);
22435 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
22438 /* We can only use the low/high_pc attributes if all of the code was
22440 if (!have_multiple_function_sections
22441 || (dwarf_version < 3 && dwarf_strict))
22443 /* Don't add if the CU has no associated code. */
22444 if (text_section_used)
22446 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
22447 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
22452 unsigned fde_idx = 0;
22453 bool range_list_added = false;
22455 if (text_section_used)
22456 add_ranges_by_labels (comp_unit_die (), text_section_label,
22457 text_end_label, &range_list_added);
22458 if (cold_text_section_used)
22459 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
22460 cold_end_label, &range_list_added);
22462 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
22464 dw_fde_ref fde = &fde_table[fde_idx];
22466 if (!fde->in_std_section)
22467 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
22468 fde->dw_fde_end, &range_list_added);
22469 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
22470 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
22471 fde->dw_fde_second_end, &range_list_added);
22474 if (range_list_added)
22476 /* We need to give .debug_loc and .debug_ranges an appropriate
22477 "base address". Use zero so that these addresses become
22478 absolute. Historically, we've emitted the unexpected
22479 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
22480 Emit both to give time for other tools to adapt. */
22481 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
22482 if (! dwarf_strict && dwarf_version < 4)
22483 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
22489 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22490 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
22491 debug_line_section_label);
22493 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22494 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
22496 if (have_location_lists)
22497 optimize_location_lists (comp_unit_die ());
22499 /* Output all of the compilation units. We put the main one last so that
22500 the offsets are available to output_pubnames. */
22501 for (node = limbo_die_list; node; node = node->next)
22502 output_comp_unit (node->die, 0);
22504 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
22505 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
22507 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
22509 /* Don't output duplicate types. */
22510 if (*slot != HTAB_EMPTY_ENTRY)
22513 /* Add a pointer to the line table for the main compilation unit
22514 so that the debugger can make sense of DW_AT_decl_file
22516 if (debug_info_level >= DINFO_LEVEL_NORMAL)
22517 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
22518 debug_line_section_label);
22520 output_comdat_type_unit (ctnode);
22523 htab_delete (comdat_type_table);
22525 /* Output the main compilation unit if non-empty or if .debug_macinfo
22526 will be emitted. */
22527 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
22529 /* Output the abbreviation table. */
22530 if (abbrev_die_table_in_use != 1)
22532 switch_to_section (debug_abbrev_section);
22533 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
22534 output_abbrev_section ();
22537 /* Output location list section if necessary. */
22538 if (have_location_lists)
22540 /* Output the location lists info. */
22541 switch_to_section (debug_loc_section);
22542 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
22543 DEBUG_LOC_SECTION_LABEL, 0);
22544 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
22545 output_location_lists (comp_unit_die ());
22548 /* Output public names table if necessary. */
22549 if (!VEC_empty (pubname_entry, pubname_table))
22551 gcc_assert (info_section_emitted);
22552 switch_to_section (debug_pubnames_section);
22553 output_pubnames (pubname_table);
22556 /* Output public types table if necessary. */
22557 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
22558 It shouldn't hurt to emit it always, since pure DWARF2 consumers
22559 simply won't look for the section. */
22560 if (!VEC_empty (pubname_entry, pubtype_table))
22562 bool empty = false;
22564 if (flag_eliminate_unused_debug_types)
22566 /* The pubtypes table might be emptied by pruning unused items. */
22570 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
22571 if (p->die->die_offset != 0)
22579 gcc_assert (info_section_emitted);
22580 switch_to_section (debug_pubtypes_section);
22581 output_pubnames (pubtype_table);
22585 /* Output the address range information if a CU (.debug_info section)
22586 was emitted. We output an empty table even if we had no functions
22587 to put in it. This because the consumer has no way to tell the
22588 difference between an empty table that we omitted and failure to
22589 generate a table that would have contained data. */
22590 if (info_section_emitted)
22592 unsigned long aranges_length = size_of_aranges ();
22594 switch_to_section (debug_aranges_section);
22595 output_aranges (aranges_length);
22598 /* Output ranges section if necessary. */
22599 if (ranges_table_in_use)
22601 switch_to_section (debug_ranges_section);
22602 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
22606 /* Output the source line correspondence table. We must do this
22607 even if there is no line information. Otherwise, on an empty
22608 translation unit, we will generate a present, but empty,
22609 .debug_info section. IRIX 6.5 `nm' will then complain when
22610 examining the file. This is done late so that any filenames
22611 used by the debug_info section are marked as 'used'. */
22612 switch_to_section (debug_line_section);
22613 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
22614 if (! DWARF2_ASM_LINE_DEBUG_INFO)
22615 output_line_info ();
22617 /* Have to end the macro section. */
22618 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22620 switch_to_section (debug_macinfo_section);
22621 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
22622 if (!VEC_empty (macinfo_entry, macinfo_table))
22624 dw2_asm_output_data (1, 0, "End compilation unit");
22627 /* If we emitted any DW_FORM_strp form attribute, output the string
22629 if (debug_str_hash)
22630 htab_traverse (debug_str_hash, output_indirect_string, NULL);
22633 #include "gt-dwarf2out.h"